~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sys_var.cc

  • Committer: Lee Bieber
  • Date: 2011-01-12 02:31:03 UTC
  • mfrom: (2068.7.5 session-fix)
  • mto: This revision was merged to the branch mainline in revision 2076.
  • Revision ID: kalebral@gmail.com-20110112023103-nmz26cv1j32jc6n3
Merge Brian - fix bug 527084 - DROP TABLE: getTableDefiniton returns EEXIST but doDropTable returns ENOENT leads to SIGSEGV

Show diffs side-by-side

added added

removed removed

Lines of Context:
60
60
#include "drizzled/charset.h"
61
61
#include "drizzled/transaction_services.h"
62
62
#include "drizzled/constrained_value.h"
63
 
#include "drizzled/visibility.h"
64
 
#include "drizzled/plugin/storage_engine.h"
65
63
 
66
64
#include <cstdio>
67
65
#include <map>
151
149
                                                     &drizzle_system_variables::join_buff_size);
152
150
static sys_var_session_uint32_t sys_max_allowed_packet("max_allowed_packet",
153
151
                                                       &drizzle_system_variables::max_allowed_packet);
 
152
static sys_var_uint64_t_ptr     sys_max_connect_errors("max_connect_errors",
 
153
                                               &max_connect_errors);
154
154
static sys_var_session_uint64_t sys_max_error_count("max_error_count",
155
155
                                                  &drizzle_system_variables::max_error_count);
156
156
static sys_var_session_uint64_t sys_max_heap_table_size("max_heap_table_size",
213
213
static sys_var_session_size_t   sys_sort_buffer("sort_buffer_size",
214
214
                                                &drizzle_system_variables::sortbuff_size);
215
215
 
216
 
static sys_var_size_t_ptr_readonly sys_transaction_message_threshold("transaction_message_threshold",
217
 
                                                                &transaction_message_threshold);
 
216
static sys_var_session_size_t sys_transaction_message_threshold("transaction_message_threshold",
 
217
                                                                &drizzle_system_variables::transaction_message_threshold);
218
218
 
219
219
static sys_var_session_storage_engine sys_storage_engine("storage_engine",
220
220
                                       &drizzle_system_variables::storage_engine);
432
432
{
433
433
  if (fixed)
434
434
  {
435
 
    char buf[DECIMAL_LONGLONG_DIGITS];
 
435
    char buf[22];
436
436
 
437
437
    if (unsignd)
438
438
      internal::ullstr((uint64_t) val, buf);
476
476
bool sys_var_uint32_t_ptr::update(Session *session, set_var *var)
477
477
{
478
478
  uint64_t tmp= var->getInteger();
479
 
  boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
480
 
 
 
479
  LOCK_global_system_variables.lock();
481
480
  if (option_limits)
482
481
  {
483
482
    uint32_t newvalue= (uint32_t) fix_unsigned(session, tmp, option_limits);
485
484
      *value= newvalue;
486
485
  }
487
486
  else
488
 
  {
489
487
    *value= static_cast<uint32_t>(tmp);
490
 
  }
491
 
 
 
488
  LOCK_global_system_variables.unlock();
492
489
  return 0;
493
490
}
494
491
 
495
492
 
496
 
void sys_var_uint32_t_ptr::set_default(Session *session, sql_var_t)
 
493
void sys_var_uint32_t_ptr::set_default(Session *, sql_var_t)
497
494
{
498
495
  bool not_used;
499
 
  boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
 
496
  LOCK_global_system_variables.lock();
500
497
  *value= (uint32_t)getopt_ull_limit_value((uint32_t) option_limits->def_value,
501
498
                                           option_limits, &not_used);
 
499
  LOCK_global_system_variables.unlock();
502
500
}
503
501
 
504
502
 
505
503
bool sys_var_uint64_t_ptr::update(Session *session, set_var *var)
506
504
{
507
505
  uint64_t tmp= var->getInteger();
508
 
  boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
509
 
 
 
506
  LOCK_global_system_variables.lock();
510
507
  if (option_limits)
511
508
  {
512
509
    uint64_t newvalue= fix_unsigned(session, tmp, option_limits);
514
511
      *value= newvalue;
515
512
  }
516
513
  else
517
 
  {
518
514
    *value= tmp;
519
 
  }
520
 
 
 
515
  LOCK_global_system_variables.unlock();
521
516
  return 0;
522
517
}
523
518
 
524
519
 
525
 
void sys_var_uint64_t_ptr::set_default(Session *session, sql_var_t)
 
520
void sys_var_uint64_t_ptr::set_default(Session *, sql_var_t)
526
521
{
527
522
  if (have_default_value)
528
523
  {
531
526
  else
532
527
  {
533
528
    bool not_used;
534
 
    boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
 
529
    LOCK_global_system_variables.lock();
535
530
    *value= getopt_ull_limit_value((uint64_t) option_limits->def_value,
536
531
                                   option_limits, &not_used);
 
532
    LOCK_global_system_variables.unlock();
537
533
  }
538
534
}
539
535
 
541
537
bool sys_var_size_t_ptr::update(Session *session, set_var *var)
542
538
{
543
539
  size_t tmp= size_t(var->getInteger());
544
 
 
545
 
  boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
546
 
 
 
540
  LOCK_global_system_variables.lock();
547
541
  if (option_limits)
548
542
    *value= fix_size_t(session, tmp, option_limits);
549
543
  else
550
544
    *value= tmp;
551
 
 
 
545
  LOCK_global_system_variables.unlock();
552
546
  return 0;
553
547
}
554
548
 
555
549
 
556
 
void sys_var_size_t_ptr::set_default(Session *session, sql_var_t)
 
550
void sys_var_size_t_ptr::set_default(Session *, sql_var_t)
557
551
{
558
552
  bool not_used;
559
 
  boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
 
553
  LOCK_global_system_variables.lock();
560
554
  *value= (size_t)getopt_ull_limit_value((size_t) option_limits->def_value,
561
555
                                         option_limits, &not_used);
562
 
}
563
 
 
564
 
bool sys_var_bool_ptr::check(Session *session, set_var *var)
565
 
{
566
 
  return check_enum(session, var, &bool_typelib);
 
556
  LOCK_global_system_variables.unlock();
567
557
}
568
558
 
569
559
bool sys_var_bool_ptr::update(Session *, set_var *var)
654
644
  if (var->type == OPT_GLOBAL)
655
645
  {
656
646
    /* Lock is needed to make things safe on 32 bit systems */
657
 
    boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
 
647
    LOCK_global_system_variables.lock();
658
648
    global_system_variables.*offset= (ha_rows) tmp;
 
649
    LOCK_global_system_variables.unlock();
659
650
  }
660
651
  else
661
 
  {
662
652
    session->variables.*offset= (ha_rows) tmp;
663
 
  }
664
 
 
665
653
  return 0;
666
654
}
667
655
 
672
660
  {
673
661
    bool not_used;
674
662
    /* We will not come here if option_limits is not set */
675
 
    boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
 
663
    LOCK_global_system_variables.lock();
676
664
    global_system_variables.*offset=
677
665
      (ha_rows) getopt_ull_limit_value((ha_rows) option_limits->def_value,
678
666
                                       option_limits, &not_used);
 
667
    LOCK_global_system_variables.unlock();
679
668
  }
680
669
  else
681
 
  {
682
670
    session->variables.*offset= global_system_variables.*offset;
683
 
  }
684
671
}
685
672
 
686
673
 
714
701
  if (var->type == OPT_GLOBAL)
715
702
  {
716
703
    /* Lock is needed to make things safe on 32 bit systems */
717
 
    boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
 
704
    LOCK_global_system_variables.lock();
718
705
    global_system_variables.*offset= (uint64_t) tmp;
 
706
    LOCK_global_system_variables.unlock();
719
707
  }
720
708
  else
721
 
  {
722
709
    session->variables.*offset= (uint64_t) tmp;
723
 
  }
724
 
 
725
710
  return 0;
726
711
}
727
712
 
731
716
  if (type == OPT_GLOBAL)
732
717
  {
733
718
    bool not_used;
734
 
    boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
 
719
    LOCK_global_system_variables.lock();
735
720
    global_system_variables.*offset=
736
721
      getopt_ull_limit_value((uint64_t) option_limits->def_value,
737
722
                             option_limits, &not_used);
 
723
    LOCK_global_system_variables.unlock();
738
724
  }
739
725
  else
740
 
  {
741
726
    session->variables.*offset= global_system_variables.*offset;
742
 
  }
743
727
}
744
728
 
745
729
 
770
754
  if (var->type == OPT_GLOBAL)
771
755
  {
772
756
    /* Lock is needed to make things safe on 32 bit systems */
773
 
    boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
 
757
    LOCK_global_system_variables.lock();
774
758
    global_system_variables.*offset= tmp;
 
759
    LOCK_global_system_variables.unlock();
775
760
  }
776
761
  else
777
 
  {
778
762
    session->variables.*offset= tmp;
779
 
  }
780
 
 
781
763
  return 0;
782
764
}
783
765
 
787
769
  if (type == OPT_GLOBAL)
788
770
  {
789
771
    bool not_used;
790
 
    boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
 
772
    LOCK_global_system_variables.lock();
791
773
    global_system_variables.*offset=
792
774
      (size_t)getopt_ull_limit_value((size_t) option_limits->def_value,
793
775
                                     option_limits, &not_used);
 
776
    LOCK_global_system_variables.unlock();
794
777
  }
795
778
  else
796
 
  {
797
779
    session->variables.*offset= global_system_variables.*offset;
798
 
  }
799
780
}
800
781
 
801
782
 
808
789
  return (unsigned char*) &(session->variables.*offset);
809
790
}
810
791
 
811
 
bool sys_var_session_bool::check(Session *session, set_var *var)
812
 
{
813
 
  return check_enum(session, var, &bool_typelib);
814
 
}
815
792
 
816
793
bool sys_var_session_bool::update(Session *session,  set_var *var)
817
794
{
819
796
    global_system_variables.*offset= bool(var->getInteger());
820
797
  else
821
798
    session->variables.*offset= bool(var->getInteger());
822
 
 
823
799
  return 0;
824
800
}
825
801
 
912
888
  case SHOW_INT:
913
889
  {
914
890
    uint32_t value;
915
 
    boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
 
891
    LOCK_global_system_variables.lock();
916
892
    value= *(uint*) value_ptr(session, var_type, base);
917
 
 
 
893
    LOCK_global_system_variables.unlock();
918
894
    return new Item_uint((uint64_t) value);
919
895
  }
920
896
  case SHOW_LONGLONG:
921
897
  {
922
898
    int64_t value;
923
 
    boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
 
899
    LOCK_global_system_variables.lock();
924
900
    value= *(int64_t*) value_ptr(session, var_type, base);
925
 
 
 
901
    LOCK_global_system_variables.unlock();
926
902
    return new Item_int(value);
927
903
  }
928
904
  case SHOW_DOUBLE:
929
905
  {
930
906
    double value;
931
 
    {
932
 
      boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
933
 
      value= *(double*) value_ptr(session, var_type, base);
934
 
    }
935
 
 
 
907
    LOCK_global_system_variables.lock();
 
908
    value= *(double*) value_ptr(session, var_type, base);
 
909
    LOCK_global_system_variables.unlock();
936
910
    /* 6, as this is for now only used with microseconds */
937
911
    return new Item_float(value, 6);
938
912
  }
939
913
  case SHOW_HA_ROWS:
940
914
  {
941
915
    ha_rows value;
942
 
    boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
 
916
    LOCK_global_system_variables.lock();
943
917
    value= *(ha_rows*) value_ptr(session, var_type, base);
944
 
 
 
918
    LOCK_global_system_variables.unlock();
945
919
    return new Item_int((uint64_t) value);
946
920
  }
947
921
  case SHOW_SIZE:
948
922
  {
949
923
    size_t value;
950
 
    boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
 
924
    LOCK_global_system_variables.lock();
951
925
    value= *(size_t*) value_ptr(session, var_type, base);
952
 
 
 
926
    LOCK_global_system_variables.unlock();
953
927
    return new Item_int((uint64_t) value);
954
928
  }
955
929
  case SHOW_MY_BOOL:
956
930
  {
957
931
    int32_t value;
958
 
    boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
 
932
    LOCK_global_system_variables.lock();
959
933
    value= *(bool*) value_ptr(session, var_type, base);
 
934
    LOCK_global_system_variables.unlock();
960
935
    return new Item_int(value,1);
961
936
  }
962
937
  case SHOW_CHAR_PTR:
963
938
  {
964
939
    Item *tmp;
965
 
    boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
 
940
    LOCK_global_system_variables.lock();
966
941
    char *str= *(char**) value_ptr(session, var_type, base);
967
942
    if (str)
968
943
    {
975
950
      tmp= new Item_null();
976
951
      tmp->collation.set(system_charset_info, DERIVATION_SYSCONST);
977
952
    }
978
 
 
 
953
    LOCK_global_system_variables.unlock();
979
954
    return tmp;
980
955
  }
981
956
  case SHOW_CHAR:
982
957
  {
983
958
    Item *tmp;
984
 
    boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
 
959
    LOCK_global_system_variables.lock();
985
960
    char *str= (char*) value_ptr(session, var_type, base);
986
961
    if (str)
987
962
      tmp= new Item_string(str, strlen(str),
991
966
      tmp= new Item_null();
992
967
      tmp->collation.set(system_charset_info, DERIVATION_SYSCONST);
993
968
    }
994
 
 
 
969
    LOCK_global_system_variables.unlock();
995
970
    return tmp;
996
971
  }
997
972
  default:
1177
1152
  /* We are using Time_zone object found during check() phase. */
1178
1153
  if (var->type == OPT_GLOBAL)
1179
1154
  {
1180
 
    boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
 
1155
    LOCK_global_system_variables.lock();
1181
1156
    global_system_variables.time_zone= tmp;
 
1157
    LOCK_global_system_variables.unlock();
1182
1158
  }
1183
1159
  else
1184
 
  {
1185
1160
    session->variables.time_zone= tmp;
1186
 
  }
1187
 
 
1188
1161
  return 0;
1189
1162
}
1190
1163
 
1216
1189
 
1217
1190
void sys_var_session_time_zone::set_default(Session *session, sql_var_t type)
1218
1191
{
1219
 
  boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
1220
 
  if (type == OPT_GLOBAL)
1221
 
  {
1222
 
    if (default_tz_name)
1223
 
    {
1224
 
      String str(default_tz_name, &my_charset_utf8_general_ci);
1225
 
      /*
1226
 
        We are guaranteed to find this time zone since its existence
1227
 
        is checked during start-up.
1228
 
      */
1229
 
      global_system_variables.time_zone= my_tz_find(session, &str);
1230
 
    }
1231
 
    else
1232
 
      global_system_variables.time_zone= my_tz_SYSTEM;
1233
 
  }
1234
 
  else
1235
 
    session->variables.time_zone= global_system_variables.time_zone;
 
1192
 LOCK_global_system_variables.lock();
 
1193
 if (type == OPT_GLOBAL)
 
1194
 {
 
1195
   if (default_tz_name)
 
1196
   {
 
1197
     String str(default_tz_name, &my_charset_utf8_general_ci);
 
1198
     /*
 
1199
       We are guaranteed to find this time zone since its existence
 
1200
       is checked during start-up.
 
1201
     */
 
1202
     global_system_variables.time_zone= my_tz_find(session, &str);
 
1203
   }
 
1204
   else
 
1205
     global_system_variables.time_zone= my_tz_SYSTEM;
 
1206
 }
 
1207
 else
 
1208
   session->variables.time_zone= global_system_variables.time_zone;
 
1209
 LOCK_global_system_variables.unlock();
1236
1210
}
1237
1211
 
1238
1212
 
1245
1219
  {
1246
1220
    if (!(locale_match= my_locale_by_number((uint32_t) var->value->val_int())))
1247
1221
    {
1248
 
      char buf[DECIMAL_LONGLONG_DIGITS];
 
1222
      char buf[20];
1249
1223
      internal::int10_to_str((int) var->value->val_int(), buf, -10);
1250
1224
      my_printf_error(ER_UNKNOWN_ERROR, "Unknown locale: '%s'", MYF(0), buf);
1251
1225
      return 1;
1315
1289
  microseconds= (int64_t) (num * 1000000.0 + 0.5);
1316
1290
  if (var->type == OPT_GLOBAL)
1317
1291
  {
1318
 
    boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
 
1292
    LOCK_global_system_variables.lock();
1319
1293
    (global_system_variables.*offset)= microseconds;
 
1294
    LOCK_global_system_variables.unlock();
1320
1295
  }
1321
1296
  else
1322
1297
    session->variables.*offset= microseconds;
1329
1304
  int64_t microseconds= (int64_t) (option_limits->def_value * 1000000.0);
1330
1305
  if (type == OPT_GLOBAL)
1331
1306
  {
1332
 
    boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
 
1307
    LOCK_global_system_variables.lock();
1333
1308
    global_system_variables.*offset= microseconds;
 
1309
    LOCK_global_system_variables.unlock();
1334
1310
  }
1335
1311
  else
1336
1312
    session->variables.*offset= microseconds;
1353
1329
 
1354
1330
static bool set_option_autocommit(Session *session, set_var *var)
1355
1331
{
1356
 
  bool success= true;
1357
1332
  /* The test is negative as the flag we use is NOT autocommit */
1358
1333
 
1359
1334
  uint64_t org_options= session->options;
1360
 
  uint64_t new_options= session->options;
1361
1335
 
1362
1336
  if (var->getInteger() != 0)
1363
 
    new_options&= ~((sys_var_session_bit*) var->var)->bit_flag;
 
1337
    session->options&= ~((sys_var_session_bit*) var->var)->bit_flag;
1364
1338
  else
1365
 
    new_options|= ((sys_var_session_bit*) var->var)->bit_flag;
 
1339
    session->options|= ((sys_var_session_bit*) var->var)->bit_flag;
1366
1340
 
1367
 
  if ((org_options ^ new_options) & OPTION_NOT_AUTOCOMMIT)
 
1341
  if ((org_options ^ session->options) & OPTION_NOT_AUTOCOMMIT)
1368
1342
  {
1369
1343
    if ((org_options & OPTION_NOT_AUTOCOMMIT))
1370
1344
    {
1371
 
      success= session->endActiveTransaction();
1372
1345
      /* We changed to auto_commit mode */
1373
1346
      session->options&= ~(uint64_t) (OPTION_BEGIN);
1374
1347
      session->server_status|= SERVER_STATUS_AUTOCOMMIT;
 
1348
      TransactionServices &transaction_services= TransactionServices::singleton();
 
1349
      if (transaction_services.commitTransaction(session, true))
 
1350
        return 1;
1375
1351
    }
1376
1352
    else
1377
1353
    {
1378
1354
      session->server_status&= ~SERVER_STATUS_AUTOCOMMIT;
1379
1355
    }
1380
1356
  }
1381
 
 
1382
 
  if (var->getInteger() != 0)
1383
 
    session->options&= ~((sys_var_session_bit*) var->var)->bit_flag;
1384
 
  else
1385
 
    session->options|= ((sys_var_session_bit*) var->var)->bit_flag;
1386
 
 
1387
 
  if (not success)
1388
 
    return true;
1389
 
 
1390
1357
  return 0;
1391
1358
}
1392
1359
 
1490
1457
drizzle_show_var* enumerate_sys_vars(Session *session)
1491
1458
{
1492
1459
  int size= sizeof(drizzle_show_var) * (system_variable_map.size() + 1);
1493
 
  drizzle_show_var *result= (drizzle_show_var*) session->getMemRoot()->allocate(size);
 
1460
  drizzle_show_var *result= (drizzle_show_var*) session->alloc(size);
1494
1461
 
1495
1462
  if (result)
1496
1463
  {
1524
1491
  /* this fails if there is a conflicting variable name. */
1525
1492
  if (system_variable_map.find(lower_name) != system_variable_map.end())
1526
1493
  {
1527
 
    errmsg_printf(error::ERROR, _("Variable named %s already exists!\n"),
 
1494
    errmsg_printf(ERRMSG_LVL_ERROR, _("Variable named %s already exists!\n"),
1528
1495
                  var->getName().c_str());
1529
1496
    throw exception();
1530
1497
  } 
1533
1500
    system_variable_map.insert(make_pair(lower_name, var));
1534
1501
  if (ret.second == false)
1535
1502
  {
1536
 
    errmsg_printf(error::ERROR, _("Could not add Variable: %s\n"),
 
1503
    errmsg_printf(ERRMSG_LVL_ERROR, _("Could not add Variable: %s\n"),
1537
1504
                  var->getName().c_str());
1538
1505
    throw exception();
1539
1506
  }
1581
1548
    add_sys_var_to_list(&sys_last_insert_id, my_long_options);
1582
1549
    add_sys_var_to_list(&sys_lc_time_names, my_long_options);
1583
1550
    add_sys_var_to_list(&sys_max_allowed_packet, my_long_options);
 
1551
    add_sys_var_to_list(&sys_max_connect_errors, my_long_options);
1584
1552
    add_sys_var_to_list(&sys_max_error_count, my_long_options);
1585
1553
    add_sys_var_to_list(&sys_max_heap_table_size, my_long_options);
1586
1554
    add_sys_var_to_list(&sys_max_join_size, my_long_options);
1631
1599
  }
1632
1600
  catch (std::exception&)
1633
1601
  {
1634
 
    errmsg_printf(error::ERROR, _("Failed to initialize system variables"));
 
1602
    errmsg_printf(ERRMSG_LVL_ERROR, _("Failed to initialize system variables"));
1635
1603
    return(1);
1636
1604
  }
1637
1605
  return(0);