~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/session.cc

  • Committer: Brian Aker
  • Date: 2010-02-11 22:56:25 UTC
  • Revision ID: brian@gaz-20100211225625-63v3e79p78blva2u
Remove WEIGHT_STRING() from parser (where it does not belong). If someone
wants to they can reimplement this as a straight function.

Show diffs side-by-side

added added

removed removed

Lines of Context:
39
39
#include <drizzled/plugin/client.h>
40
40
#include "drizzled/plugin/scheduler.h"
41
41
#include "drizzled/plugin/authentication.h"
42
 
#include "drizzled/plugin/logging.h"
43
 
#include "drizzled/plugin/transactional_storage_engine.h"
44
42
#include "drizzled/probes.h"
45
43
#include "drizzled/table_proto.h"
46
44
#include "drizzled/db.h"
145
143
  return session->get_proc_info();
146
144
}
147
145
 
148
 
void **Session::getEngineData(const plugin::MonitoredInTransaction *monitored)
 
146
void **Session::getEngineData(const plugin::StorageEngine *engine)
149
147
{
150
 
  return static_cast<void **>(&ha_data[monitored->getId()].ha_ptr);
 
148
  return static_cast<void **>(&ha_data[engine->slot].ha_ptr);
151
149
}
152
150
 
153
 
ResourceContext *Session::getResourceContext(const plugin::MonitoredInTransaction *monitored,
154
 
                                             size_t index)
 
151
Ha_trx_info *Session::getEngineInfo(const plugin::StorageEngine *engine,
 
152
                                    size_t index)
155
153
{
156
 
  return &ha_data[monitored->getId()].resource_context[index];
 
154
  return &ha_data[engine->getSlot()].ha_info[index];
157
155
}
158
156
 
159
157
extern "C"
179
177
  Open_tables_state(refresh_version),
180
178
  mem_root(&main_mem_root),
181
179
  lex(&main_lex),
182
 
  query(),
183
180
  client(client_arg),
184
181
  scheduler(NULL),
185
182
  scheduler_arg(NULL),
186
183
  lock_id(&main_lock_id),
187
184
  user_time(0),
188
 
  ha_data(plugin::num_trx_monitored_objects),
189
185
  arg_of_last_insert_id_function(false),
190
186
  first_successful_insert_id_in_prev_stmt(0),
191
187
  first_successful_insert_id_in_cur_stmt(0),
231
227
  thread_id= 0;
232
228
  file_id = 0;
233
229
  query_id= 0;
 
230
  query= NULL;
 
231
  query_length= 0;
234
232
  warn_query_id= 0;
 
233
  memset(ha_data, 0, sizeof(ha_data));
235
234
  mysys_var= 0;
236
235
  dbug_sentry=Session_SENTRY_MAGIC;
237
236
  cleanup_done= abort_on_warning= no_warnings_for_error= false;
257
256
  else
258
257
    options &= ~OPTION_BIG_SELECTS;
259
258
 
 
259
  transaction.all.modified_non_trans_table= transaction.stmt.modified_non_trans_table= false;
260
260
  open_options=ha_open_options;
261
261
  update_lock_default= TL_WRITE;
262
262
  session_tx_isolation= (enum_tx_isolation) variables.tx_isolation;
413
413
  free_root(&main_mem_root, MYF(0));
414
414
  pthread_setspecific(THR_Session,  0);
415
415
 
416
 
  plugin::Logging::postEndDo(this);
417
416
 
418
417
  /* Ensure that no one is using Session */
419
418
  pthread_mutex_unlock(&LOCK_delete);
433
432
    If this assumption will change, then we have to explictely add
434
433
    the other variables after the while loop
435
434
*/
436
 
void add_to_status(system_status_var *to_var, system_status_var *from_var)
 
435
void add_to_status(STATUS_VAR *to_var, STATUS_VAR *from_var)
437
436
{
438
437
  ulong *end= (ulong*) ((unsigned char*) to_var +
439
 
                        offsetof(system_status_var, last_system_status_var) +
 
438
                        offsetof(STATUS_VAR, last_system_status_var) +
440
439
                        sizeof(ulong));
441
440
  ulong *to= (ulong*) to_var, *from= (ulong*) from_var;
442
441
 
456
455
  NOTE
457
456
    This function assumes that all variables are long/ulong.
458
457
*/
459
 
void add_diff_to_status(system_status_var *to_var, system_status_var *from_var,
460
 
                        system_status_var *dec_var)
 
458
void add_diff_to_status(STATUS_VAR *to_var, STATUS_VAR *from_var,
 
459
                        STATUS_VAR *dec_var)
461
460
{
462
 
  ulong *end= (ulong*) ((unsigned char*) to_var + offsetof(system_status_var,
 
461
  ulong *end= (ulong*) ((unsigned char*) to_var + offsetof(STATUS_VAR,
463
462
                                                  last_system_status_var) +
464
463
                        sizeof(ulong));
465
464
  ulong *to= (ulong*) to_var, *from= (ulong*) from_var, *dec= (ulong*) dec_var;
673
672
 
674
673
bool Session::checkUser(const char *passwd, uint32_t passwd_len, const char *in_db)
675
674
{
676
 
  const string passwd_str(passwd, passwd_len);
677
 
  bool is_authenticated=
678
 
    plugin::Authentication::isAuthenticated(getSecurityContext(),
679
 
                                            passwd_str);
 
675
  LEX_STRING db_str= { (char *) in_db, in_db ? strlen(in_db) : 0 };
 
676
  bool is_authenticated;
 
677
 
 
678
  if (passwd_len != 0 && passwd_len != SCRAMBLE_LENGTH)
 
679
  {
 
680
    my_error(ER_HANDSHAKE_ERROR, MYF(0), getSecurityContext().getIp().c_str());
 
681
    return false;
 
682
  }
 
683
 
 
684
  is_authenticated= plugin::Authentication::isAuthenticated(this, passwd);
680
685
 
681
686
  if (is_authenticated != true)
682
687
  {
683
 
    /* isAuthenticated has pushed the error message */
 
688
    my_error(ER_ACCESS_DENIED_ERROR, MYF(0),
 
689
             getSecurityContext().getUser().c_str(),
 
690
             getSecurityContext().getIp().c_str(),
 
691
             passwd_len ? ER(ER_YES) : ER(ER_NO));
 
692
 
684
693
    return false;
685
694
  }
686
695
 
687
696
  /* Change database if necessary */
688
697
  if (in_db && in_db[0])
689
698
  {
690
 
    if (mysql_change_db(this, in_db))
 
699
    if (mysql_change_db(this, &db_str, false))
691
700
    {
692
701
      /* mysql_change_db() has pushed the error message. */
693
702
      return false;
746
755
    in_packet_length--;
747
756
  }
748
757
 
749
 
  query.assign(in_packet, in_packet + in_packet_length);
 
758
  /* We must allocate some extra memory for the cached query string */
 
759
  query_length= 0; /* Extra safety: Avoid races */
 
760
  query= (char*) memdup_w_gap((unsigned char*) in_packet, in_packet_length, db.length() + 1);
 
761
  if (! query)
 
762
    return false;
 
763
 
 
764
  query[in_packet_length]=0;
 
765
  query_length= in_packet_length;
750
766
 
751
767
  return true;
752
768
}
774
790
      if (transaction_services.ha_commit_trans(this, true))
775
791
        result= false;
776
792
      options&= ~(OPTION_BEGIN);
 
793
      transaction.all.modified_non_trans_table= false;
777
794
      break;
778
795
    case COMMIT_RELEASE:
779
796
      do_release= 1; /* fall through */
791
808
      if (transaction_services.ha_rollback_trans(this, true))
792
809
        result= false;
793
810
      options&= ~(OPTION_BEGIN);
 
811
      transaction.all.modified_non_trans_table= false;
794
812
      if (result == true && (completion == ROLLBACK_AND_CHAIN))
795
813
        result= startTransaction();
796
814
      break;
825
843
      result= false;
826
844
  }
827
845
  options&= ~(OPTION_BEGIN);
 
846
  transaction.all.modified_non_trans_table= false;
828
847
  return result;
829
848
}
830
849
 
841
860
    options|= OPTION_BEGIN;
842
861
    server_status|= SERVER_STATUS_IN_TRANS;
843
862
 
844
 
    if (plugin::TransactionalStorageEngine::notifyStartTransaction(this, opt))
 
863
    if (opt == START_TRANS_OPT_WITH_CONS_SNAPSHOT)
845
864
    {
846
 
      result= false;
 
865
      // TODO make this a loop for all engines, not just this one (Inno only
 
866
      // right now)
 
867
      if (plugin::StorageEngine::startConsistentSnapshot(this))
 
868
      {
 
869
        result= false;
 
870
      }
847
871
    }
848
872
  }
849
873
 
885
909
  @return  NULL on failure, or pointer to the LEX_STRING object
886
910
*/
887
911
LEX_STRING *Session::make_lex_string(LEX_STRING *lex_str,
888
 
                                     const std::string &str,
889
 
                                     bool allocate_lex_string)
890
 
{
891
 
  return make_lex_string(lex_str, str.c_str(), str.length(), allocate_lex_string);
892
 
}
893
 
 
894
 
LEX_STRING *Session::make_lex_string(LEX_STRING *lex_str,
895
 
                                     const char* str, uint32_t length,
896
 
                                     bool allocate_lex_string)
 
912
                                 const char* str, uint32_t length,
 
913
                                 bool allocate_lex_string)
897
914
{
898
915
  if (allocate_lex_string)
899
916
    if (!(lex_str= (LEX_STRING *)alloc(sizeof(LEX_STRING))))
1664
1681
  return(session->charset());
1665
1682
}
1666
1683
 
 
1684
char **session_query(Session *session)
 
1685
{
 
1686
  return(&session->query);
 
1687
}
 
1688
 
1667
1689
int session_non_transactional_update(const Session *session)
1668
1690
{
1669
 
  return(session->transaction.all.hasModifiedNonTransData());
 
1691
  return(session->transaction.all.modified_non_trans_table);
1670
1692
}
1671
1693
 
1672
1694
void session_mark_transaction_to_rollback(Session *session, bool all)
1744
1766
  server_status&= ~ (SERVER_MORE_RESULTS_EXISTS |
1745
1767
                          SERVER_QUERY_NO_INDEX_USED |
1746
1768
                          SERVER_QUERY_NO_GOOD_INDEX_USED);
 
1769
  /*
 
1770
    If in autocommit mode and not in a transaction, reset
 
1771
    OPTION_STATUS_NO_TRANS_UPDATE to not get warnings
 
1772
    in ha_rollback_trans() about some tables couldn't be rolled back.
 
1773
  */
 
1774
  if (!(options & (OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN)))
 
1775
  {
 
1776
    transaction.all.modified_non_trans_table= false;
 
1777
  }
1747
1778
 
1748
1779
  clear_error();
1749
1780
  main_da.reset_diagnostics_area();
2031
2062
  return false;
2032
2063
}
2033
2064
 
2034
 
bool Session::rm_temporary_table(TableIdentifier &identifier)
 
2065
bool Session::rm_temporary_table(plugin::StorageEngine *base, TableIdentifier &identifier)
2035
2066
{
2036
 
  if (not plugin::StorageEngine::dropTable(*this, identifier))
 
2067
  bool error= false;
 
2068
 
 
2069
  assert(base);
 
2070
 
 
2071
  if (plugin::StorageEngine::deleteDefinitionFromPath(identifier))
 
2072
    error= true;
 
2073
 
 
2074
  if (base->doDropTable(*this, identifier.getPath()))
2037
2075
  {
 
2076
    error= true;
2038
2077
    errmsg_printf(ERRMSG_LVL_WARN, _("Could not remove temporary table: '%s', error: %d"),
2039
 
                  identifier.getPath().c_str(), errno);
2040
 
 
2041
 
    return true;
 
2078
                  identifier.getPath(), errno);
2042
2079
  }
2043
 
 
2044
 
  return false;
 
2080
  return error;
2045
2081
}
2046
2082
 
2047
2083
bool Session::rm_temporary_table(plugin::StorageEngine *base, const char *path)
2048
2084
{
2049
2085
  bool error= false;
2050
 
  TableIdentifier dummy(path);
2051
2086
 
2052
2087
  assert(base);
2053
2088
 
2054
2089
  if (delete_table_proto_file(path))
2055
2090
    error= true;
2056
2091
 
2057
 
  if (base->doDropTable(*this, dummy))
 
2092
  if (base->doDropTable(*this, path))
2058
2093
  {
2059
2094
    error= true;
2060
2095
    errmsg_printf(ERRMSG_LVL_WARN, _("Could not remove temporary table: '%s', error: %d"),
2063
2098
  return error;
2064
2099
}
2065
2100
 
2066
 
bool Session::storeTableMessage(TableIdentifier &identifier, message::Table &table_message)
2067
 
{
2068
 
  table_message_cache.insert(make_pair(identifier.getPath(), table_message));
2069
 
 
2070
 
  return true;
2071
 
}
2072
 
 
2073
 
bool Session::removeTableMessage(TableIdentifier &identifier)
2074
 
{
2075
 
  TableMessageCache::iterator iter;
2076
 
 
2077
 
  iter= table_message_cache.find(identifier.getPath());
2078
 
 
2079
 
  if (iter == table_message_cache.end())
2080
 
    return false;
2081
 
 
2082
 
  table_message_cache.erase(iter);
2083
 
 
2084
 
  return true;
2085
 
}
2086
 
 
2087
 
bool Session::getTableMessage(TableIdentifier &identifier, message::Table &table_message)
2088
 
{
2089
 
  TableMessageCache::iterator iter;
2090
 
 
2091
 
  iter= table_message_cache.find(identifier.getPath());
2092
 
 
2093
 
  if (iter == table_message_cache.end())
2094
 
    return false;
2095
 
 
2096
 
  table_message.CopyFrom(((*iter).second));
2097
 
 
2098
 
  return true;
2099
 
}
2100
 
 
2101
 
bool Session::doesTableMessageExist(TableIdentifier &identifier)
2102
 
{
2103
 
  TableMessageCache::iterator iter;
2104
 
 
2105
 
  iter= table_message_cache.find(identifier.getPath());
2106
 
 
2107
 
  if (iter == table_message_cache.end())
2108
 
  {
2109
 
    return false;
2110
 
  }
2111
 
 
2112
 
  return true;
2113
 
}
2114
 
 
2115
2101
} /* namespace drizzled */