~drizzle-developers/ubuntu/karmic/drizzle/ppa

« back to all changes in this revision

Viewing changes to drizzled/drizzled.cc

  • Committer: Monty Taylor
  • Date: 2010-11-24 18:44:57 UTC
  • mfrom: (1308.1.31 trunk)
  • Revision ID: mordred@inaugust.com-20101124184457-qd6jvoe2wgnvl3yq
Tags: 2010.11.04-0ubuntu1~karmic1
* New upstream release.
* Turn off -Werror for packaging builds. (Closes: #602662)

Show diffs side-by-side

added added

removed removed

Lines of Context:
68
68
#include "drizzled/module/load_list.h"
69
69
#include "drizzled/global_buffer.h"
70
70
 
 
71
#include "drizzled/definition/cache.h"
 
72
 
71
73
#include "drizzled/plugin/event_observer.h"
72
74
 
 
75
#include "drizzled/message/cache.h"
 
76
 
73
77
#include <google/protobuf/stubs/common.h>
74
78
 
75
79
#if TIME_WITH_SYS_TIME
335
339
SHOW_COMP_OPTION have_symlink;
336
340
 
337
341
/* Thread specific variables */
338
 
 
339
 
boost::mutex LOCK_open;
340
342
boost::mutex LOCK_global_system_variables;
341
 
boost::mutex LOCK_thread_count;
342
343
 
343
344
boost::condition_variable_any COND_refresh;
344
345
boost::condition_variable COND_thread_count;
416
417
 
417
418
  /* kill connection thread */
418
419
  {
419
 
    boost::mutex::scoped_lock scopedLock(LOCK_thread_count);
 
420
    boost::mutex::scoped_lock scopedLock(session::Cache::singleton().mutex());
420
421
 
421
422
    while (select_thread_in_use)
422
423
    {
440
441
    statements and inform their clients that the server is about to die.
441
442
  */
442
443
 
443
 
  Session *tmp;
444
 
 
445
444
  {
446
 
    boost::mutex::scoped_lock scoped(LOCK_thread_count);
447
 
    for( SessionList::iterator it= getSessionList().begin(); it != getSessionList().end(); ++it )
 
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 )
448
449
    {
449
 
      tmp= *it;
 
450
      Session::shared_ptr tmp(*it);
 
451
 
450
452
      tmp->setKilled(Session::KILL_CONNECTION);
451
 
      tmp->scheduler->killSession(tmp);
 
453
      tmp->scheduler->killSession(tmp.get());
452
454
      DRIZZLE_CONNECTION_DONE(tmp->thread_id);
453
455
      tmp->lockOnSys();
454
456
    }
455
457
  }
456
458
 
457
 
  if (connection_count)
 
459
  if (session::Cache::singleton().count())
458
460
    sleep(2);                                   // Give threads time to die
459
461
 
460
462
  /*
464
466
  */
465
467
  for (;;)
466
468
  {
467
 
    boost::mutex::scoped_lock scoped(LOCK_thread_count);
468
 
    if (getSessionList().empty())
 
469
    boost::mutex::scoped_lock scopedLock(session::Cache::singleton().mutex());
 
470
    session::Cache::List list= session::Cache::singleton().getCache();
 
471
 
 
472
    if (list.empty())
469
473
    {
470
474
      break;
471
475
    }
472
 
    tmp= getSessionList().front();
473
476
    /* Close before unlock, avoiding crash. See LP bug#436685 */
474
 
    tmp->client->close();
 
477
    list.front()->client->close();
475
478
  }
476
479
}
477
480
 
510
513
 
511
514
  if (print_message && server_start_time)
512
515
    errmsg_printf(ERRMSG_LVL_INFO, _(ER(ER_SHUTDOWN_COMPLETE)),internal::my_progname);
513
 
  LOCK_thread_count.lock();
514
 
  ready_to_exit=1;
515
 
  /* do the broadcast inside the lock to ensure that my_end() is not called */
516
 
  COND_server_end.notify_all();
517
 
  LOCK_thread_count.unlock();
 
516
  {
 
517
    boost::mutex::scoped_lock scopedLock(session::Cache::singleton().mutex());
 
518
    ready_to_exit= true;
 
519
 
 
520
    /* do the broadcast inside the lock to ensure that my_end() is not called */
 
521
    COND_server_end.notify_all();
 
522
  }
518
523
 
519
524
  /*
520
525
    The following lines may never be executed as the main thread may have
620
625
  SYNOPSIS
621
626
    Session::unlink()
622
627
    session              Thread handler
623
 
 
624
 
  NOTES
625
 
    LOCK_thread_count is locked and left locked
626
628
*/
627
629
 
628
 
void Session::unlink(Session *session)
 
630
void drizzled::Session::unlink(Session::shared_ptr &session)
629
631
{
630
632
  connection_count.decrement();
631
633
 
632
634
  session->cleanup();
633
635
 
634
 
  boost::mutex::scoped_lock scoped(LOCK_thread_count);
635
 
  session->lockForDelete();
 
636
  boost::mutex::scoped_lock scopedLock(session::Cache::singleton().mutex());
636
637
 
637
 
  getSessionList().erase(remove(getSessionList().begin(),
638
 
                         getSessionList().end(),
639
 
                         session));
640
638
  if (unlikely(plugin::EventObserver::disconnectSession(*session)))
641
639
  {
642
640
    // We should do something about an error...
643
641
  }
644
 
 
645
 
  delete session;
 
642
  session::Cache::singleton().erase(session);
646
643
}
647
644
 
648
645
 
1044
1041
  global_system_variables.transaction_message_threshold= in_transaction_message_threshold;
1045
1042
}
1046
1043
 
1047
 
static pair<string, string> parse_size_suffixes(string s)
1048
 
{
1049
 
  size_t equal_pos= s.find("=");
1050
 
  if (equal_pos != string::npos)
1051
 
  {
1052
 
    string arg_key(s.substr(0, equal_pos));
1053
 
    string arg_val(s.substr(equal_pos+1));
1054
 
 
1055
 
    try
1056
 
    {
1057
 
      size_t size_suffix_pos= arg_val.find_last_of("kmgKMG");
1058
 
      if (size_suffix_pos == arg_val.size()-1)
1059
 
      {
1060
 
        char suffix= arg_val[size_suffix_pos];
1061
 
        string size_val(arg_val.substr(0, size_suffix_pos));
1062
 
 
1063
 
        uint64_t base_size= boost::lexical_cast<uint64_t>(size_val);
1064
 
        uint64_t new_size= 0;
1065
 
 
1066
 
        switch (suffix)
1067
 
        {
1068
 
        case 'K':
1069
 
        case 'k':
1070
 
          new_size= base_size * 1024;
1071
 
          break;
1072
 
        case 'M':
1073
 
        case 'm':
1074
 
          new_size= base_size * 1024 * 1024;
1075
 
          break;
1076
 
        case 'G':
1077
 
        case 'g':
1078
 
          new_size= base_size * 1024 * 1024 * 1024;
1079
 
          break;
1080
 
        }
1081
 
        return make_pair(arg_key,
1082
 
                         boost::lexical_cast<string>(new_size));
1083
 
      }
1084
 
    }
1085
 
    catch (...)
1086
 
    {
1087
 
      /* Screw it, let the normal parser take over */
1088
 
    }
1089
 
  }
1090
 
 
1091
 
  return make_pair(string(""), string(""));
1092
 
}
1093
 
 
1094
 
static pair<string, string> parse_size_arg(string s)
1095
 
{
1096
 
  if (s.find("--") == 0)
1097
 
  {
1098
 
    return parse_size_suffixes(s.substr(2));
1099
 
  }
1100
 
  return make_pair(string(""), string(""));
1101
 
}
1102
 
 
1103
1044
static void process_defaults_files()
1104
1045
{
1105
1046
  for (vector<string>::iterator iter= defaults_file_list.begin();
1205
1146
  pid_file.replace_extension(".pid");
1206
1147
 
1207
1148
  system_config_dir /= "drizzle";
1208
 
  std::string system_config_file_drizzle("drizzled.cnf");
1209
1149
 
1210
1150
  config_options.add_options()
1211
1151
  ("help,?", po::value<bool>(&opt_help)->default_value(false)->zero_tokens(),
1268
1208
  N_("Pid file used by drizzled."))
1269
1209
  ("port-open-timeout", po::value<uint32_t>(&drizzled_bind_timeout)->default_value(0),
1270
1210
  N_("Maximum time in seconds to wait for the port to become free. "))
 
1211
  ("replicate-query", po::value<bool>(&global_system_variables.replicate_query)->default_value(false)->zero_tokens(),
 
1212
  N_("Include the SQL query in replicated protobuf messages."))
1271
1213
  ("secure-file-priv", po::value<fs::path>(&secure_file_priv)->notifier(expand_secure_file_priv),
1272
1214
  N_("Limit LOAD DATA, SELECT ... OUTFILE, and LOAD_FILE() to files "
1273
1215
     "within specified directory"))
1421
1363
 
1422
1364
  if (not vm["no-defaults"].as<bool>())
1423
1365
  {
 
1366
    fs::path system_config_file_drizzle(system_config_dir);
 
1367
    system_config_file_drizzle /= "drizzled.cnf";
1424
1368
    defaults_file_list.insert(defaults_file_list.begin(),
1425
 
                              system_config_file_drizzle);
 
1369
                              system_config_file_drizzle.file_string());
1426
1370
 
1427
1371
    fs::path config_conf_d_location(system_config_dir);
1428
1372
    config_conf_d_location /= "conf.d";
1429
1373
 
 
1374
 
1430
1375
    CachedDirectory config_conf_d(config_conf_d_location.file_string());
1431
1376
    if (not config_conf_d.fail())
1432
1377
    {
1500
1445
  {
1501
1446
    po::parsed_options final_parsed=
1502
1447
      po::command_line_parser(unknown_options).style(style).
1503
 
      options(full_options).extra_parser(parse_size_arg).run();
 
1448
      options(full_options).extra_parser(dpo::parse_size_arg).run();
1504
1449
 
1505
1450
    final_unknown_options=
1506
1451
      po::collect_unrecognized(final_parsed.options, po::include_positional);
1639
1584
  }
1640
1585
 
1641
1586
  // Resize the definition Cache at startup
 
1587
  table::Cache::singleton().rehash(table_def_size);
1642
1588
  definition::Cache::singleton().rehash(table_def_size);
 
1589
  message::Cache::singleton().rehash(table_def_size);
1643
1590
 
1644
1591
  setup_fpu();
1645
1592
 
2191
2138
  session_startup_options= (OPTION_AUTO_IS_NULL | OPTION_SQL_NOTES);
2192
2139
  refresh_version= 1L;  /* Increments on each reload */
2193
2140
  global_thread_id= 1UL;
2194
 
  getSessionList().clear();
 
2141
  session::Cache::singleton().getCache().clear();
2195
2142
 
2196
2143
  /* Variables in libraries */
2197
2144
  default_character_set_name= "utf8";
2404
2351
    pid_file_path= getDataHome();
2405
2352
    pid_file_path /= pid_file;
2406
2353
  }
2407
 
  pid_file= pid_file_path;
 
2354
  pid_file= fs::system_complete(pid_file_path);
2408
2355
 
2409
2356
  if (not opt_help)
2410
2357
  {