~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/session.cc

Merge Jay

Show diffs side-by-side

added added

removed removed

Lines of Context:
44
44
#include "drizzled/table_proto.h"
45
45
#include "drizzled/db.h"
46
46
#include "drizzled/pthread_globals.h"
 
47
#include "drizzled/transaction_services.h"
47
48
 
48
49
#include "plugin/myisam/myisam.h"
49
50
#include "drizzled/internal/iocache.h"
230
231
  query_length= 0;
231
232
  warn_query_id= 0;
232
233
  memset(ha_data, 0, sizeof(ha_data));
233
 
  replication_data= 0;
234
234
  mysys_var= 0;
235
235
  dbug_sentry=Session_SENTRY_MAGIC;
236
236
  cleanup_done= abort_on_warning= no_warnings_for_error= false;
237
 
  transaction.on= 1;
238
237
  pthread_mutex_init(&LOCK_delete, MY_MUTEX_INIT_FAST);
239
238
 
240
239
  /* Variables with default values */
369
368
  }
370
369
#endif
371
370
  {
372
 
    ha_rollback(this);
 
371
    TransactionServices &transaction_services= TransactionServices::singleton();
 
372
    transaction_services.ha_rollback_trans(this, true);
373
373
    xid_cache_delete(&transaction.xid_state);
374
374
  }
375
375
  hash_free(&user_vars);
407
407
  plugin_sessionvar_cleanup(this);
408
408
 
409
409
  free_root(&warn_root,MYF(0));
410
 
  free_root(&transaction.mem_root,MYF(0));
411
410
  mysys_var=0;                                  // Safety (shouldn't be needed)
412
411
  dbug_sentry= Session_SENTRY_GONE;
413
412
 
559
558
  set_proc_info(NULL);
560
559
  command= COM_SLEEP;
561
560
  set_time();
562
 
  ha_enable_transaction(this,true);
563
561
 
564
562
  reset_root_defaults(mem_root, variables.query_alloc_block_size,
565
563
                      variables.query_prealloc_size);
566
 
  reset_root_defaults(&transaction.mem_root,
567
 
                      variables.trans_alloc_block_size,
568
 
                      variables.trans_prealloc_size);
569
564
  transaction.xid_state.xid.null();
570
565
  transaction.xid_state.in_session=1;
571
566
}
778
773
{
779
774
  bool do_release= 0;
780
775
  bool result= true;
 
776
  TransactionServices &transaction_services= TransactionServices::singleton();
781
777
 
782
778
  if (transaction.xid_state.xa_state != XA_NOTR)
783
779
  {
793
789
       * (Which of course should never happen...)
794
790
       */
795
791
      server_status&= ~SERVER_STATUS_IN_TRANS;
796
 
      if (ha_commit(this))
 
792
      if (transaction_services.ha_commit_trans(this, true))
797
793
        result= false;
798
794
      options&= ~(OPTION_BEGIN);
799
795
      transaction.all.modified_non_trans_table= false;
811
807
    case ROLLBACK_AND_CHAIN:
812
808
    {
813
809
      server_status&= ~SERVER_STATUS_IN_TRANS;
814
 
      if (ha_rollback(this))
 
810
      if (transaction_services.ha_rollback_trans(this, true))
815
811
        result= false;
816
812
      options&= ~(OPTION_BEGIN);
817
813
      transaction.all.modified_non_trans_table= false;
835
831
bool Session::endActiveTransaction()
836
832
{
837
833
  bool result= true;
 
834
  TransactionServices &transaction_services= TransactionServices::singleton();
838
835
 
839
836
  if (transaction.xid_state.xa_state != XA_NOTR)
840
837
  {
844
841
  if (options & (OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN))
845
842
  {
846
843
    server_status&= ~SERVER_STATUS_IN_TRANS;
847
 
    if (ha_commit(this))
 
844
    if (transaction_services.ha_commit_trans(this, true))
848
845
      result= false;
849
846
  }
850
847
  options&= ~(OPTION_BEGIN);
926
923
  return lex_str;
927
924
}
928
925
 
929
 
/* routings to adding tables to list of changed in transaction tables */
930
 
inline static void list_include(CHANGED_TableList** prev,
931
 
                                CHANGED_TableList* curr,
932
 
                                CHANGED_TableList* new_table)
933
 
{
934
 
  if (new_table)
935
 
  {
936
 
    *prev = new_table;
937
 
    (*prev)->next = curr;
938
 
  }
939
 
}
940
 
 
941
 
/* add table to list of changed in transaction tables */
942
 
 
943
 
void Session::add_changed_table(Table *table)
944
 
{
945
 
  assert((options & (OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN)) &&
946
 
              table->cursor->has_transactions());
947
 
  add_changed_table(table->s->table_cache_key.str,
948
 
                    (long) table->s->table_cache_key.length);
949
 
}
950
 
 
951
 
 
952
 
void Session::add_changed_table(const char *key, long key_length)
953
 
{
954
 
  CHANGED_TableList **prev_changed = &transaction.changed_tables;
955
 
  CHANGED_TableList *curr = transaction.changed_tables;
956
 
 
957
 
  for (; curr; prev_changed = &(curr->next), curr = curr->next)
958
 
  {
959
 
    int cmp =  (long)curr->key_length - (long)key_length;
960
 
    if (cmp < 0)
961
 
    {
962
 
      list_include(prev_changed, curr, changed_table_dup(key, key_length));
963
 
      return;
964
 
    }
965
 
    else if (cmp == 0)
966
 
    {
967
 
      cmp = memcmp(curr->key, key, curr->key_length);
968
 
      if (cmp < 0)
969
 
      {
970
 
        list_include(prev_changed, curr, changed_table_dup(key, key_length));
971
 
        return;
972
 
      }
973
 
      else if (cmp == 0)
974
 
      {
975
 
        return;
976
 
      }
977
 
    }
978
 
  }
979
 
  *prev_changed = changed_table_dup(key, key_length);
980
 
}
981
 
 
982
 
 
983
 
CHANGED_TableList* Session::changed_table_dup(const char *key, long key_length)
984
 
{
985
 
  CHANGED_TableList* new_table =
986
 
    (CHANGED_TableList*) trans_alloc(ALIGN_SIZE(sizeof(CHANGED_TableList))+
987
 
                                      key_length + 1);
988
 
  if (!new_table)
989
 
  {
990
 
    my_error(EE_OUTOFMEMORY, MYF(ME_BELL),
991
 
             ALIGN_SIZE(sizeof(TableList)) + key_length + 1);
992
 
    killed= KILL_CONNECTION;
993
 
    return 0;
994
 
  }
995
 
 
996
 
  new_table->key= ((char*)new_table)+ ALIGN_SIZE(sizeof(CHANGED_TableList));
997
 
  new_table->next = 0;
998
 
  new_table->key_length = key_length;
999
 
  ::memcpy(new_table->key, key, key_length);
1000
 
  return new_table;
1001
 
}
1002
 
 
1003
 
 
1004
926
int Session::send_explain_fields(select_result *result)
1005
927
{
1006
928
  List<Item> field_list;
2067
1989
   */
2068
1990
  if (backups_available == false)
2069
1991
  {
 
1992
    TransactionServices &transaction_services= TransactionServices::singleton();
2070
1993
    main_da.can_overwrite_status= true;
2071
 
    ha_autocommit_or_rollback(this, is_error());
 
1994
    transaction_services.ha_autocommit_or_rollback(this, is_error());
2072
1995
    main_da.can_overwrite_status= false;
2073
1996
    transaction.stmt.reset();
2074
1997
  }