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"
71
#include "drizzled/definition/cache.h"
73
70
#include "drizzled/plugin/event_observer.h"
75
#include "drizzled/message/cache.h"
77
72
#include <google/protobuf/stubs/common.h>
79
74
#if TIME_WITH_SYS_TIME
339
334
SHOW_COMP_OPTION have_symlink;
341
336
/* Thread specific variables */
338
boost::mutex LOCK_open;
342
339
boost::mutex LOCK_global_system_variables;
340
boost::mutex LOCK_thread_count;
344
342
boost::condition_variable_any COND_refresh;
345
343
boost::condition_variable COND_thread_count;
355
353
atomic<uint32_t> connection_count;
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);
363
356
Refresh value. We use to test this to find out if a refresh even has happened recently.
441
434
statements and inform their clients that the server is about to die.
445
boost::mutex::scoped_lock scopedLock(session::Cache::singleton().mutex());
446
session::Cache::list list= session::Cache::singleton().getCache();
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 )
450
Session::shared_ptr tmp(*it);
452
tmp->setKilled(Session::KILL_CONNECTION);
453
tmp->scheduler->killSession(tmp.get());
444
tmp->killed= Session::KILL_CONNECTION;
445
tmp->scheduler->killSession(tmp);
454
446
DRIZZLE_CONNECTION_DONE(tmp->thread_id);
456
447
tmp->lockOnSys();
460
if (session::Cache::singleton().count())
451
if (connection_count)
461
452
sleep(2); // Give threads time to die
470
boost::mutex::scoped_lock scopedLock(session::Cache::singleton().mutex());
471
session::Cache::list list= session::Cache::singleton().getCache();
461
boost::mutex::scoped_lock scoped(LOCK_thread_count);
462
if (getSessionList().empty())
466
tmp= getSessionList().front();
477
467
/* Close before unlock, avoiding crash. See LP bug#436685 */
478
list.front()->client->close();
468
tmp->client->close();
515
505
if (print_message && server_start_time)
516
506
errmsg_printf(ERRMSG_LVL_INFO, _(ER(ER_SHUTDOWN_COMPLETE)),internal::my_progname);
518
boost::mutex::scoped_lock scopedLock(session::Cache::singleton().mutex());
521
/* do the broadcast inside the lock to ensure that my_end() is not called */
522
COND_server_end.notify_all();
507
LOCK_thread_count.lock();
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();
526
514
The following lines may never be executed as the main thread may have
627
615
Session::unlink()
628
616
session Thread handler
619
LOCK_thread_count is locked and left locked
631
void drizzled::Session::unlink(Session::shared_ptr &session)
622
void Session::unlink(Session *session)
633
624
connection_count.decrement();
635
626
session->cleanup();
637
boost::mutex::scoped_lock scopedLock(session::Cache::singleton().mutex());
628
boost::mutex::scoped_lock scoped(LOCK_thread_count);
629
session->lockForDelete();
631
getSessionList().erase(remove(getSessionList().begin(),
632
getSessionList().end(),
639
634
if (unlikely(plugin::EventObserver::disconnectSession(*session)))
641
636
// We should do something about an error...
643
session::Cache::singleton().erase(session);
1042
1038
global_system_variables.transaction_message_threshold= in_transaction_message_threshold;
1041
static pair<string, string> parse_size_suffixes(string s)
1043
size_t equal_pos= s.find("=");
1044
if (equal_pos != string::npos)
1046
string arg_key(s.substr(0, equal_pos));
1047
string arg_val(s.substr(equal_pos+1));
1051
size_t size_suffix_pos= arg_val.find_last_of("kmgKMG");
1052
if (size_suffix_pos == arg_val.size()-1)
1054
char suffix= arg_val[size_suffix_pos];
1055
string size_val(arg_val.substr(0, size_suffix_pos));
1057
uint64_t base_size= boost::lexical_cast<uint64_t>(size_val);
1058
uint64_t new_size= 0;
1064
new_size= base_size * 1024;
1068
new_size= base_size * 1024 * 1024;
1072
new_size= base_size * 1024 * 1024 * 1024;
1075
return make_pair(arg_key,
1076
boost::lexical_cast<string>(new_size));
1081
/* Screw it, let the normal parser take over */
1085
return make_pair(string(""), string(""));
1088
static pair<string, string> parse_size_arg(string s)
1090
if (s.find("--") == 0)
1092
return parse_size_suffixes(s.substr(2));
1094
return make_pair(string(""), string(""));
1045
1097
static void process_defaults_files()
1047
1099
for (vector<string>::iterator iter= defaults_file_list.begin();
1147
1199
pid_file.replace_extension(".pid");
1149
1201
system_config_dir /= "drizzle";
1202
std::string system_config_file_drizzle("drizzled.cnf");
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),
1365
1404
if (not vm["no-defaults"].as<bool>())
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);
1372
1409
fs::path config_conf_d_location(system_config_dir);
1373
1410
config_conf_d_location /= "conf.d";
1376
1412
CachedDirectory config_conf_d(config_conf_d_location.file_string());
1377
1413
if (not config_conf_d.fail())
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();
1451
1487
final_unknown_options=
1452
1488
po::collect_unrecognized(final_parsed.options, po::include_positional);
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();
2144
2178
/* Variables in libraries */
2145
2179
default_character_set_name= "utf8";
2225
if (vm.count("sort-heap-threshold"))
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))
2231
cout << N_("Error: sort-heap-threshold cannot be less than sort-buffer-size") << endl;
2235
global_sort_buffer.setMaxSize(vm["sort-heap-threshold"].as<uint64_t>());
2238
if (vm.count("join-heap-threshold"))
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))
2244
cout << N_("Error: join-heap-threshold cannot be less than join-buffer-size") << endl;
2248
global_join_buffer.setMaxSize(vm["join-heap-threshold"].as<uint64_t>());
2251
if (vm.count("read-rnd-threshold"))
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))
2257
cout << N_("Error: read-rnd-threshold cannot be less than read-rnd-buffer-size") << endl;
2261
global_read_rnd_buffer.setMaxSize(vm["read-rnd-threshold"].as<uint64_t>());
2264
if (vm.count("read-buffer-threshold"))
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))
2270
cout << N_("Error: read-buffer-threshold cannot be less than read-buffer-size") << endl;
2274
global_read_buffer.setMaxSize(vm["read-buffer-threshold"].as<uint64_t>());
2277
2259
if (vm.count("exit-info"))
2279
2261
if (vm["exit-info"].as<long>())