~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/drizzled.cc

  • Committer: Stewart Smith
  • Date: 2010-11-03 03:27:09 UTC
  • mto: (1902.1.1 build) (1910.1.2 build)
  • mto: This revision was merged to the branch mainline in revision 1903.
  • Revision ID: stewart@flamingspork.com-20101103032709-oyvfrc6eb8fzj0mr
fix docs warning: docs/unlock.rst:2: (WARNING/2) Title underline too short.

Show diffs side-by-side

added added

removed removed

Lines of Context:
60
60
#include "drizzled/plugin/monitored_in_transaction.h"
61
61
#include "drizzled/replication_services.h" /* For ReplicationServices::evaluateRegisteredPlugins() */
62
62
#include "drizzled/probes.h"
63
 
#include "drizzled/session/cache.h"
 
63
#include "drizzled/session_list.h"
64
64
#include "drizzled/charset.h"
65
65
#include "plugin/myisam/myisam.h"
66
66
#include "drizzled/drizzled.h"
67
67
#include "drizzled/module/registry.h"
68
68
#include "drizzled/module/load_list.h"
69
 
#include "drizzled/global_buffer.h"
70
 
 
71
 
#include "drizzled/definition/cache.h"
72
69
 
73
70
#include "drizzled/plugin/event_observer.h"
74
71
 
75
 
#include "drizzled/message/cache.h"
76
 
 
77
72
#include <google/protobuf/stubs/common.h>
78
73
 
79
74
#if TIME_WITH_SYS_TIME
339
334
SHOW_COMP_OPTION have_symlink;
340
335
 
341
336
/* Thread specific variables */
 
337
 
 
338
boost::mutex LOCK_open;
342
339
boost::mutex LOCK_global_system_variables;
 
340
boost::mutex LOCK_thread_count;
343
341
 
344
342
boost::condition_variable_any COND_refresh;
345
343
boost::condition_variable COND_thread_count;
354
352
 
355
353
atomic<uint32_t> connection_count;
356
354
 
357
 
global_buffer_constraint<uint64_t> global_sort_buffer(0);
358
 
global_buffer_constraint<uint64_t> global_join_buffer(0);
359
 
global_buffer_constraint<uint64_t> global_read_rnd_buffer(0);
360
 
global_buffer_constraint<uint64_t> global_read_buffer(0);
361
 
 
362
355
/** 
363
356
  Refresh value. We use to test this to find out if a refresh even has happened recently.
364
357
*/
417
410
 
418
411
  /* kill connection thread */
419
412
  {
420
 
    boost::mutex::scoped_lock scopedLock(session::Cache::singleton().mutex());
 
413
    boost::mutex::scoped_lock scopedLock(LOCK_thread_count);
421
414
 
422
415
    while (select_thread_in_use)
423
416
    {
441
434
    statements and inform their clients that the server is about to die.
442
435
  */
443
436
 
 
437
  Session *tmp;
 
438
 
444
439
  {
445
 
    boost::mutex::scoped_lock scopedLock(session::Cache::singleton().mutex());
446
 
    session::Cache::list list= session::Cache::singleton().getCache();
447
 
 
448
 
    for (session::Cache::list::iterator it= list.begin(); it != list.end(); ++it )
 
440
    boost::mutex::scoped_lock scoped(LOCK_thread_count);
 
441
    for( SessionList::iterator it= getSessionList().begin(); it != getSessionList().end(); ++it )
449
442
    {
450
 
      Session::shared_ptr tmp(*it);
451
 
 
452
 
      tmp->setKilled(Session::KILL_CONNECTION);
453
 
      tmp->scheduler->killSession(tmp.get());
 
443
      tmp= *it;
 
444
      tmp->killed= Session::KILL_CONNECTION;
 
445
      tmp->scheduler->killSession(tmp);
454
446
      DRIZZLE_CONNECTION_DONE(tmp->thread_id);
455
 
 
456
447
      tmp->lockOnSys();
457
448
    }
458
449
  }
459
450
 
460
 
  if (session::Cache::singleton().count())
 
451
  if (connection_count)
461
452
    sleep(2);                                   // Give threads time to die
462
453
 
463
454
  /*
467
458
  */
468
459
  for (;;)
469
460
  {
470
 
    boost::mutex::scoped_lock scopedLock(session::Cache::singleton().mutex());
471
 
    session::Cache::list list= session::Cache::singleton().getCache();
472
 
 
473
 
    if (list.empty())
 
461
    boost::mutex::scoped_lock scoped(LOCK_thread_count);
 
462
    if (getSessionList().empty())
474
463
    {
475
464
      break;
476
465
    }
 
466
    tmp= getSessionList().front();
477
467
    /* Close before unlock, avoiding crash. See LP bug#436685 */
478
 
    list.front()->client->close();
 
468
    tmp->client->close();
479
469
  }
480
470
}
481
471
 
514
504
 
515
505
  if (print_message && server_start_time)
516
506
    errmsg_printf(ERRMSG_LVL_INFO, _(ER(ER_SHUTDOWN_COMPLETE)),internal::my_progname);
517
 
  {
518
 
    boost::mutex::scoped_lock scopedLock(session::Cache::singleton().mutex());
519
 
    ready_to_exit= true;
520
 
 
521
 
    /* do the broadcast inside the lock to ensure that my_end() is not called */
522
 
    COND_server_end.notify_all();
523
 
  }
 
507
  LOCK_thread_count.lock();
 
508
  ready_to_exit=1;
 
509
  /* do the broadcast inside the lock to ensure that my_end() is not called */
 
510
  COND_server_end.notify_all();
 
511
  LOCK_thread_count.unlock();
524
512
 
525
513
  /*
526
514
    The following lines may never be executed as the main thread may have
550
538
    }
551
539
    return NULL;
552
540
  }
553
 
  if (not user)
 
541
  if (!user)
554
542
  {
555
543
      errmsg_printf(ERRMSG_LVL_ERROR, _("Fatal error: Please read \"Security\" section of "
556
544
                      "the manual to find out how to run drizzled as root!\n"));
626
614
  SYNOPSIS
627
615
    Session::unlink()
628
616
    session              Thread handler
 
617
 
 
618
  NOTES
 
619
    LOCK_thread_count is locked and left locked
629
620
*/
630
621
 
631
 
void drizzled::Session::unlink(Session::shared_ptr &session)
 
622
void Session::unlink(Session *session)
632
623
{
633
624
  connection_count.decrement();
634
625
 
635
626
  session->cleanup();
636
627
 
637
 
  boost::mutex::scoped_lock scopedLock(session::Cache::singleton().mutex());
 
628
  boost::mutex::scoped_lock scoped(LOCK_thread_count);
 
629
  session->lockForDelete();
638
630
 
 
631
  getSessionList().erase(remove(getSessionList().begin(),
 
632
                         getSessionList().end(),
 
633
                         session));
639
634
  if (unlikely(plugin::EventObserver::disconnectSession(*session)))
640
635
  {
641
636
    // We should do something about an error...
642
637
  }
643
 
  session::Cache::singleton().erase(session);
 
638
 
 
639
  delete session;
644
640
}
645
641
 
646
642
 
1042
1038
  global_system_variables.transaction_message_threshold= in_transaction_message_threshold;
1043
1039
}
1044
1040
 
 
1041
static pair<string, string> parse_size_suffixes(string s)
 
1042
{
 
1043
  size_t equal_pos= s.find("=");
 
1044
  if (equal_pos != string::npos)
 
1045
  {
 
1046
    string arg_key(s.substr(0, equal_pos));
 
1047
    string arg_val(s.substr(equal_pos+1));
 
1048
 
 
1049
    try
 
1050
    {
 
1051
      size_t size_suffix_pos= arg_val.find_last_of("kmgKMG");
 
1052
      if (size_suffix_pos == arg_val.size()-1)
 
1053
      {
 
1054
        char suffix= arg_val[size_suffix_pos];
 
1055
        string size_val(arg_val.substr(0, size_suffix_pos));
 
1056
 
 
1057
        uint64_t base_size= boost::lexical_cast<uint64_t>(size_val);
 
1058
        uint64_t new_size= 0;
 
1059
 
 
1060
        switch (suffix)
 
1061
        {
 
1062
        case 'K':
 
1063
        case 'k':
 
1064
          new_size= base_size * 1024;
 
1065
          break;
 
1066
        case 'M':
 
1067
        case 'm':
 
1068
          new_size= base_size * 1024 * 1024;
 
1069
          break;
 
1070
        case 'G':
 
1071
        case 'g':
 
1072
          new_size= base_size * 1024 * 1024 * 1024;
 
1073
          break;
 
1074
        }
 
1075
        return make_pair(arg_key,
 
1076
                         boost::lexical_cast<string>(new_size));
 
1077
      }
 
1078
    }
 
1079
    catch (...)
 
1080
    {
 
1081
      /* Screw it, let the normal parser take over */
 
1082
    }
 
1083
  }
 
1084
 
 
1085
  return make_pair(string(""), string(""));
 
1086
}
 
1087
 
 
1088
static pair<string, string> parse_size_arg(string s)
 
1089
{
 
1090
  if (s.find("--") == 0)
 
1091
  {
 
1092
    return parse_size_suffixes(s.substr(2));
 
1093
  }
 
1094
  return make_pair(string(""), string(""));
 
1095
}
 
1096
 
1045
1097
static void process_defaults_files()
1046
1098
{
1047
1099
  for (vector<string>::iterator iter= defaults_file_list.begin();
1147
1199
  pid_file.replace_extension(".pid");
1148
1200
 
1149
1201
  system_config_dir /= "drizzle";
 
1202
  std::string system_config_file_drizzle("drizzled.cnf");
1150
1203
 
1151
1204
  config_options.add_options()
1152
1205
  ("help,?", po::value<bool>(&opt_help)->default_value(false)->zero_tokens(),
1209
1262
  N_("Pid file used by drizzled."))
1210
1263
  ("port-open-timeout", po::value<uint32_t>(&drizzled_bind_timeout)->default_value(0),
1211
1264
  N_("Maximum time in seconds to wait for the port to become free. "))
1212
 
  ("replicate-query", po::value<bool>(&global_system_variables.replicate_query)->default_value(false)->zero_tokens(),
1213
 
  N_("Include the SQL query in replicated protobuf messages."))
1214
1265
  ("secure-file-priv", po::value<fs::path>(&secure_file_priv)->notifier(expand_secure_file_priv),
1215
1266
  N_("Limit LOAD DATA, SELECT ... OUTFILE, and LOAD_FILE() to files "
1216
1267
     "within specified directory"))
1249
1300
  N_("The maximum length of the result of function  group_concat."))
1250
1301
  ("join-buffer-size", po::value<uint64_t>(&global_system_variables.join_buff_size)->default_value(128*1024L)->notifier(&check_limits_join_buffer_size),
1251
1302
  N_("The size of the buffer that is used for full joins."))
1252
 
  ("join-heap-threshold",
1253
 
  po::value<uint64_t>()->default_value(0),
1254
 
  N_("A global cap on the amount of memory that can be allocated by session join buffers (0 means unlimited)"))
1255
1303
  ("max-allowed-packet", po::value<uint32_t>(&global_system_variables.max_allowed_packet)->default_value(64*1024*1024L)->notifier(&check_limits_map),
1256
1304
  N_("Max packetlength to send/receive from to server."))
1257
1305
  ("max-connect-errors", po::value<uint64_t>(&max_connect_errors)->default_value(MAX_CONNECT_ERRORS)->notifier(&check_limits_mce),
1305
1353
  N_("Each thread that does a sequential scan allocates a buffer of this "
1306
1354
      "size for each table it scans. If you do many sequential scans, you may "
1307
1355
      "want to increase this value."))
1308
 
  ("read-buffer-threshold",
1309
 
  po::value<uint64_t>()->default_value(0),
1310
 
  N_("A global cap on the size of read-buffer-size (0 means unlimited)"))
1311
1356
  ("read-rnd-buffer-size",
1312
1357
  po::value<uint32_t>(&global_system_variables.read_rnd_buff_size)->default_value(256*1024L)->notifier(&check_limits_read_rnd_buffer_size),
1313
1358
  N_("When reading rows in sorted order after a sort, the rows are read "
1314
1359
     "through this buffer to avoid a disk seeks. If not set, then it's set "
1315
1360
     "to the value of record_buffer."))
1316
 
  ("read-rnd-threshold",
1317
 
  po::value<uint64_t>()->default_value(0),
1318
 
  N_("A global cap on the size of read-rnd-buffer-size (0 means unlimited)"))
1319
1361
  ("scheduler", po::value<string>(),
1320
1362
  N_("Select scheduler to be used (by default multi-thread)."))
1321
1363
  ("sort-buffer-size",
1322
1364
  po::value<size_t>(&global_system_variables.sortbuff_size)->default_value(MAX_SORT_MEMORY)->notifier(&check_limits_sort_buffer_size),
1323
1365
  N_("Each thread that needs to do a sort allocates a buffer of this size."))
1324
 
  ("sort-heap-threshold",
1325
 
  po::value<uint64_t>()->default_value(0),
1326
 
  N_("A global cap on the amount of memory that can be allocated by session sort buffers (0 means unlimited)"))
1327
1366
  ("table-definition-cache", po::value<size_t>(&table_def_size)->default_value(128)->notifier(&check_limits_tdc),
1328
1367
  N_("The number of cached table definitions."))
1329
1368
  ("table-open-cache", po::value<uint64_t>(&table_cache_size)->default_value(TABLE_OPEN_CACHE_DEFAULT)->notifier(&check_limits_toc),
1356
1395
  {
1357
1396
    po::store(parsed, vm);
1358
1397
  }
1359
 
  catch (std::exception&)
 
1398
  catch (...)
1360
1399
  {
1361
1400
    errmsg_printf(ERRMSG_LVL_ERROR, _("Duplicate entry for command line option\n"));
1362
1401
    unireg_abort(1);
1364
1403
 
1365
1404
  if (not vm["no-defaults"].as<bool>())
1366
1405
  {
1367
 
    fs::path system_config_file_drizzle(system_config_dir);
1368
 
    system_config_file_drizzle /= "drizzled.cnf";
1369
1406
    defaults_file_list.insert(defaults_file_list.begin(),
1370
 
                              system_config_file_drizzle.file_string());
 
1407
                              system_config_file_drizzle);
1371
1408
 
1372
1409
    fs::path config_conf_d_location(system_config_dir);
1373
1410
    config_conf_d_location /= "conf.d";
1374
1411
 
1375
 
 
1376
1412
    CachedDirectory config_conf_d(config_conf_d_location.file_string());
1377
1413
    if (not config_conf_d.fail())
1378
1414
    {
1446
1482
  {
1447
1483
    po::parsed_options final_parsed=
1448
1484
      po::command_line_parser(unknown_options).style(style).
1449
 
      options(full_options).extra_parser(dpo::parse_size_arg).run();
 
1485
      options(full_options).extra_parser(parse_size_arg).run();
1450
1486
 
1451
1487
    final_unknown_options=
1452
1488
      po::collect_unrecognized(final_parsed.options, po::include_positional);
1585
1621
  }
1586
1622
 
1587
1623
  // Resize the definition Cache at startup
1588
 
  table::Cache::singleton().rehash(table_def_size);
1589
1624
  definition::Cache::singleton().rehash(table_def_size);
1590
 
  message::Cache::singleton().rehash(table_def_size);
1591
1625
 
1592
1626
  setup_fpu();
1593
1627
 
2139
2173
  session_startup_options= (OPTION_AUTO_IS_NULL | OPTION_SQL_NOTES);
2140
2174
  refresh_version= 1L;  /* Increments on each reload */
2141
2175
  global_thread_id= 1UL;
2142
 
  session::Cache::singleton().getCache().clear();
 
2176
  getSessionList().clear();
2143
2177
 
2144
2178
  /* Variables in libraries */
2145
2179
  default_character_set_name= "utf8";
2222
2256
    exit(0);
2223
2257
  }
2224
2258
 
2225
 
  if (vm.count("sort-heap-threshold"))
2226
 
  {
2227
 
    if ((vm["sort-heap-threshold"].as<uint64_t>() > 0) and
2228
 
      (vm["sort-heap-threshold"].as<uint64_t>() < 
2229
 
      global_system_variables.sortbuff_size))
2230
 
    {
2231
 
      cout << N_("Error: sort-heap-threshold cannot be less than sort-buffer-size") << endl;
2232
 
      exit(-1);
2233
 
    }
2234
 
 
2235
 
    global_sort_buffer.setMaxSize(vm["sort-heap-threshold"].as<uint64_t>());
2236
 
  }
2237
 
 
2238
 
  if (vm.count("join-heap-threshold"))
2239
 
  {
2240
 
    if ((vm["join-heap-threshold"].as<uint64_t>() > 0) and
2241
 
      (vm["join-heap-threshold"].as<uint64_t>() <
2242
 
      global_system_variables.join_buff_size))
2243
 
    {
2244
 
      cout << N_("Error: join-heap-threshold cannot be less than join-buffer-size") << endl;
2245
 
      exit(-1);
2246
 
    }
2247
 
 
2248
 
    global_join_buffer.setMaxSize(vm["join-heap-threshold"].as<uint64_t>());
2249
 
  }
2250
 
 
2251
 
  if (vm.count("read-rnd-threshold"))
2252
 
  {
2253
 
    if ((vm["read-rnd-threshold"].as<uint64_t>() > 0) and
2254
 
      (vm["read-rnd-threshold"].as<uint64_t>() <
2255
 
      global_system_variables.read_rnd_buff_size))
2256
 
    {
2257
 
      cout << N_("Error: read-rnd-threshold cannot be less than read-rnd-buffer-size") << endl;
2258
 
      exit(-1);
2259
 
    }
2260
 
 
2261
 
    global_read_rnd_buffer.setMaxSize(vm["read-rnd-threshold"].as<uint64_t>());
2262
 
  }
2263
 
 
2264
 
  if (vm.count("read-buffer-threshold"))
2265
 
  {
2266
 
    if ((vm["read-buffer-threshold"].as<uint64_t>() > 0) and
2267
 
      (vm["read-buffer-threshold"].as<uint64_t>() <
2268
 
      global_system_variables.read_buff_size))
2269
 
    {
2270
 
      cout << N_("Error: read-buffer-threshold cannot be less than read-buffer-size") << endl;
2271
 
      exit(-1);
2272
 
    }
2273
 
 
2274
 
    global_read_buffer.setMaxSize(vm["read-buffer-threshold"].as<uint64_t>());
2275
 
  }
2276
 
 
2277
2259
  if (vm.count("exit-info"))
2278
2260
  {
2279
2261
    if (vm["exit-info"].as<long>())
2352
2334
    pid_file_path= getDataHome();
2353
2335
    pid_file_path /= pid_file;
2354
2336
  }
2355
 
  pid_file= fs::system_complete(pid_file_path);
 
2337
  pid_file= pid_file_path;
2356
2338
 
2357
2339
  if (not opt_help)
2358
2340
  {