~posulliv/drizzle/optimizer-style-cleanup

« back to all changes in this revision

Viewing changes to drizzled/session.cc

  • Committer: Padraig O'Sullivan
  • Date: 2010-03-15 14:05:26 UTC
  • mfrom: (1237.9.99 staging)
  • Revision ID: osullivan.padraig@gmail.com-20100315140526-opbgwdwn6tfecdkq
MergeĀ fromĀ trunk.

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"
42
44
#include "drizzled/probes.h"
43
45
#include "drizzled/table_proto.h"
44
46
#include "drizzled/db.h"
143
145
  return session->get_proc_info();
144
146
}
145
147
 
146
 
void **Session::getEngineData(const plugin::StorageEngine *engine)
 
148
void **Session::getEngineData(const plugin::MonitoredInTransaction *monitored)
147
149
{
148
 
  return static_cast<void **>(&ha_data[engine->slot].ha_ptr);
 
150
  return static_cast<void **>(&ha_data[monitored->getId()].ha_ptr);
149
151
}
150
152
 
151
 
Ha_trx_info *Session::getEngineInfo(const plugin::StorageEngine *engine,
152
 
                                    size_t index)
 
153
ResourceContext *Session::getResourceContext(const plugin::MonitoredInTransaction *monitored,
 
154
                                             size_t index)
153
155
{
154
 
  return &ha_data[engine->getSlot()].ha_info[index];
 
156
  return &ha_data[monitored->getId()].resource_context[index];
155
157
}
156
158
 
157
159
extern "C"
177
179
  Open_tables_state(refresh_version),
178
180
  mem_root(&main_mem_root),
179
181
  lex(&main_lex),
 
182
  query(),
180
183
  client(client_arg),
181
184
  scheduler(NULL),
182
185
  scheduler_arg(NULL),
183
186
  lock_id(&main_lock_id),
184
187
  user_time(0),
 
188
  ha_data(plugin::num_trx_monitored_objects),
185
189
  arg_of_last_insert_id_function(false),
186
190
  first_successful_insert_id_in_prev_stmt(0),
187
191
  first_successful_insert_id_in_cur_stmt(0),
227
231
  thread_id= 0;
228
232
  file_id = 0;
229
233
  query_id= 0;
230
 
  query= NULL;
231
 
  query_length= 0;
232
234
  warn_query_id= 0;
233
 
  memset(ha_data, 0, sizeof(ha_data));
234
235
  mysys_var= 0;
235
236
  dbug_sentry=Session_SENTRY_MAGIC;
236
237
  cleanup_done= abort_on_warning= no_warnings_for_error= false;
256
257
  else
257
258
    options &= ~OPTION_BIG_SELECTS;
258
259
 
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);
416
417
 
417
418
  /* Ensure that no one is using Session */
418
419
  pthread_mutex_unlock(&LOCK_delete);
432
433
    If this assumption will change, then we have to explictely add
433
434
    the other variables after the while loop
434
435
*/
435
 
void add_to_status(STATUS_VAR *to_var, STATUS_VAR *from_var)
 
436
void add_to_status(system_status_var *to_var, system_status_var *from_var)
436
437
{
437
438
  ulong *end= (ulong*) ((unsigned char*) to_var +
438
 
                        offsetof(STATUS_VAR, last_system_status_var) +
 
439
                        offsetof(system_status_var, last_system_status_var) +
439
440
                        sizeof(ulong));
440
441
  ulong *to= (ulong*) to_var, *from= (ulong*) from_var;
441
442
 
455
456
  NOTE
456
457
    This function assumes that all variables are long/ulong.
457
458
*/
458
 
void add_diff_to_status(STATUS_VAR *to_var, STATUS_VAR *from_var,
459
 
                        STATUS_VAR *dec_var)
 
459
void add_diff_to_status(system_status_var *to_var, system_status_var *from_var,
 
460
                        system_status_var *dec_var)
460
461
{
461
 
  ulong *end= (ulong*) ((unsigned char*) to_var + offsetof(STATUS_VAR,
 
462
  ulong *end= (ulong*) ((unsigned char*) to_var + offsetof(system_status_var,
462
463
                                                  last_system_status_var) +
463
464
                        sizeof(ulong));
464
465
  ulong *to= (ulong*) to_var, *from= (ulong*) from_var, *dec= (ulong*) dec_var;
672
673
 
673
674
bool Session::checkUser(const char *passwd, uint32_t passwd_len, const char *in_db)
674
675
{
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);
 
676
  const string passwd_str(passwd, passwd_len);
 
677
  bool is_authenticated=
 
678
    plugin::Authentication::isAuthenticated(getSecurityContext(),
 
679
                                            passwd_str);
685
680
 
686
681
  if (is_authenticated != true)
687
682
  {
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
 
 
 
683
    /* isAuthenticated has pushed the error message */
693
684
    return false;
694
685
  }
695
686
 
696
687
  /* Change database if necessary */
697
688
  if (in_db && in_db[0])
698
689
  {
699
 
    if (mysql_change_db(this, &db_str, false))
 
690
    if (mysql_change_db(this, in_db))
700
691
    {
701
692
      /* mysql_change_db() has pushed the error message. */
702
693
      return false;
755
746
    in_packet_length--;
756
747
  }
757
748
 
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;
 
749
  query.assign(in_packet, in_packet + in_packet_length);
766
750
 
767
751
  return true;
768
752
}
790
774
      if (transaction_services.ha_commit_trans(this, true))
791
775
        result= false;
792
776
      options&= ~(OPTION_BEGIN);
793
 
      transaction.all.modified_non_trans_table= false;
794
777
      break;
795
778
    case COMMIT_RELEASE:
796
779
      do_release= 1; /* fall through */
808
791
      if (transaction_services.ha_rollback_trans(this, true))
809
792
        result= false;
810
793
      options&= ~(OPTION_BEGIN);
811
 
      transaction.all.modified_non_trans_table= false;
812
794
      if (result == true && (completion == ROLLBACK_AND_CHAIN))
813
795
        result= startTransaction();
814
796
      break;
843
825
      result= false;
844
826
  }
845
827
  options&= ~(OPTION_BEGIN);
846
 
  transaction.all.modified_non_trans_table= false;
847
828
  return result;
848
829
}
849
830
 
860
841
    options|= OPTION_BEGIN;
861
842
    server_status|= SERVER_STATUS_IN_TRANS;
862
843
 
863
 
    if (opt == START_TRANS_OPT_WITH_CONS_SNAPSHOT)
 
844
    if (plugin::TransactionalStorageEngine::notifyStartTransaction(this, opt))
864
845
    {
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
 
      }
 
846
      result= false;
871
847
    }
872
848
  }
873
849
 
1688
1664
  return(session->charset());
1689
1665
}
1690
1666
 
1691
 
char **session_query(Session *session)
1692
 
{
1693
 
  return(&session->query);
1694
 
}
1695
 
 
1696
1667
int session_non_transactional_update(const Session *session)
1697
1668
{
1698
 
  return(session->transaction.all.modified_non_trans_table);
 
1669
  return(session->transaction.all.hasModifiedNonTransData());
1699
1670
}
1700
1671
 
1701
1672
void session_mark_transaction_to_rollback(Session *session, bool all)
1773
1744
  server_status&= ~ (SERVER_MORE_RESULTS_EXISTS |
1774
1745
                          SERVER_QUERY_NO_INDEX_USED |
1775
1746
                          SERVER_QUERY_NO_GOOD_INDEX_USED);
1776
 
  /*
1777
 
    If in autocommit mode and not in a transaction, reset
1778
 
    OPTION_STATUS_NO_TRANS_UPDATE to not get warnings
1779
 
    in ha_rollback_trans() about some tables couldn't be rolled back.
1780
 
  */
1781
 
  if (!(options & (OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN)))
1782
 
  {
1783
 
    transaction.all.modified_non_trans_table= false;
1784
 
  }
1785
1747
 
1786
1748
  clear_error();
1787
1749
  main_da.reset_diagnostics_area();
2069
2031
  return false;
2070
2032
}
2071
2033
 
2072
 
bool Session::rm_temporary_table(plugin::StorageEngine *base, TableIdentifier &identifier)
 
2034
bool Session::rm_temporary_table(TableIdentifier &identifier)
2073
2035
{
2074
 
  bool error= false;
2075
 
 
2076
 
  assert(base);
2077
 
 
2078
 
  if (plugin::StorageEngine::deleteDefinitionFromPath(identifier))
2079
 
    error= true;
2080
 
 
2081
 
  if (base->doDropTable(*this, identifier.getPath()))
 
2036
  if (not plugin::StorageEngine::dropTable(*this, identifier))
2082
2037
  {
2083
 
    error= true;
2084
2038
    errmsg_printf(ERRMSG_LVL_WARN, _("Could not remove temporary table: '%s', error: %d"),
2085
2039
                  identifier.getPath(), errno);
 
2040
 
 
2041
    return true;
2086
2042
  }
2087
 
  return error;
 
2043
 
 
2044
  return false;
2088
2045
}
2089
2046
 
2090
2047
bool Session::rm_temporary_table(plugin::StorageEngine *base, const char *path)