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
132
127
#include "drizzled/internal/my_pthread.h" // For thr_setconcurency()
133
#include "drizzled/constrained_value.h"
135
129
#include <drizzled/gettext.h>
139
133
#define IF_PURIFY(A,B) (A)
141
135
#define IF_PURIFY(A,B) (B)
327
321
FILE *stderror_file=0;
329
struct drizzle_system_variables global_system_variables;
330
struct drizzle_system_variables max_system_variables;
323
struct system_variables global_system_variables;
324
struct system_variables max_system_variables;
331
325
struct global_counters current_global_counters;
333
327
const CHARSET_INFO *system_charset_info, *files_charset_info ;
339
333
SHOW_COMP_OPTION have_symlink;
341
335
/* Thread specific variables */
337
boost::mutex LOCK_open;
342
338
boost::mutex LOCK_global_system_variables;
339
boost::mutex LOCK_thread_count;
344
341
boost::condition_variable_any COND_refresh;
345
342
boost::condition_variable COND_thread_count;
355
352
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
355
Refresh value. We use to test this to find out if a refresh even has happened recently.
441
433
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 )
439
boost::mutex::scoped_lock scoped(LOCK_thread_count);
440
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());
443
tmp->killed= Session::KILL_CONNECTION;
444
tmp->scheduler->killSession(tmp);
454
445
DRIZZLE_CONNECTION_DONE(tmp->thread_id);
456
446
tmp->lockOnSys();
460
if (session::Cache::singleton().count())
450
if (connection_count)
461
451
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();
460
boost::mutex::scoped_lock scoped(LOCK_thread_count);
461
if (getSessionList().empty())
465
tmp= getSessionList().front();
477
466
/* Close before unlock, avoiding crash. See LP bug#436685 */
478
list.front()->client->close();
467
tmp->client->close();
515
504
if (print_message && server_start_time)
516
505
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();
506
LOCK_thread_count.lock();
508
/* do the broadcast inside the lock to ensure that my_end() is not called */
509
COND_server_end.notify_all();
510
LOCK_thread_count.unlock();
526
513
The following lines may never be executed as the main thread may have
627
614
Session::unlink()
628
615
session Thread handler
618
LOCK_thread_count is locked and left locked
631
void drizzled::Session::unlink(Session::shared_ptr &session)
621
void Session::unlink(Session *session)
633
623
connection_count.decrement();
635
625
session->cleanup();
637
boost::mutex::scoped_lock scopedLock(session::Cache::singleton().mutex());
627
boost::mutex::scoped_lock scoped(LOCK_thread_count);
628
session->lockForDelete();
630
getSessionList().erase(remove(getSessionList().begin(),
631
getSessionList().end(),
639
633
if (unlikely(plugin::EventObserver::disconnectSession(*session)))
641
635
// We should do something about an error...
643
session::Cache::singleton().erase(session);
1042
1047
global_system_variables.transaction_message_threshold= in_transaction_message_threshold;
1050
static pair<string, string> parse_size_suffixes(string s)
1052
size_t equal_pos= s.find("=");
1053
if (equal_pos != string::npos)
1055
string arg_key(s.substr(0, equal_pos));
1056
string arg_val(s.substr(equal_pos+1));
1060
size_t size_suffix_pos= arg_val.find_last_of("kmgKMG");
1061
if (size_suffix_pos == arg_val.size()-1)
1063
char suffix= arg_val[size_suffix_pos];
1064
string size_val(arg_val.substr(0, size_suffix_pos));
1066
uint64_t base_size= boost::lexical_cast<uint64_t>(size_val);
1067
uint64_t new_size= 0;
1073
new_size= base_size * 1024;
1077
new_size= base_size * 1024 * 1024;
1081
new_size= base_size * 1024 * 1024 * 1024;
1084
return make_pair(arg_key,
1085
boost::lexical_cast<string>(new_size));
1090
/* Screw it, let the normal parser take over */
1094
return make_pair(string(""), string(""));
1097
static pair<string, string> parse_size_arg(string s)
1099
if (s.find("--") == 0)
1101
return parse_size_suffixes(s.substr(2));
1103
return make_pair(string(""), string(""));
1045
1106
static void process_defaults_files()
1047
1108
for (vector<string>::iterator iter= defaults_file_list.begin();
1048
1109
iter != defaults_file_list.end();
1051
fs::path file_location= *iter;
1112
fs::path file_location(system_config_dir);
1113
if ((*iter)[0] != '/')
1115
/* Relative path - add config dir */
1116
file_location /= *iter;
1120
file_location= *iter;
1053
1123
ifstream input_defaults_file(file_location.file_string().c_str());
1147
1208
pid_file.replace_extension(".pid");
1149
1210
system_config_dir /= "drizzle";
1211
std::string system_config_file_drizzle("drizzled.cnf");
1151
1213
config_options.add_options()
1152
1214
("help,?", po::value<bool>(&opt_help)->default_value(false)->zero_tokens(),
1209
1271
N_("Pid file used by drizzled."))
1210
1272
("port-open-timeout", po::value<uint32_t>(&drizzled_bind_timeout)->default_value(0),
1211
1273
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
1274
("secure-file-priv", po::value<fs::path>(&secure_file_priv)->notifier(expand_secure_file_priv),
1215
1275
N_("Limit LOAD DATA, SELECT ... OUTFILE, and LOAD_FILE() to files "
1216
1276
"within specified directory"))
1234
1294
N_("Run drizzled daemon as user."))
1236
1296
N_("Output version information and exit."))
1237
("back-log", po::value<back_log_constraints>(&back_log),
1297
("back-log", po::value<uint32_t>(&back_log)->default_value(50)->notifier(&check_limits_back_log),
1238
1298
N_("The number of outstanding connection requests Drizzle can have. This "
1239
1299
"comes into play when the main Drizzle thread gets very many connection "
1240
1300
"requests in a very short time."))
1249
1309
N_("The maximum length of the result of function group_concat."))
1250
1310
("join-buffer-size", po::value<uint64_t>(&global_system_variables.join_buff_size)->default_value(128*1024L)->notifier(&check_limits_join_buffer_size),
1251
1311
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
("max-allowed-packet", po::value<uint32_t>(&global_system_variables.max_allowed_packet)->default_value(64*1024*1024L)->notifier(&check_limits_map),
1312
("max-allowed-packet", po::value<uint32_t>(&global_system_variables.max_allowed_packet)->default_value(1024*1024L)->notifier(&check_limits_map),
1256
1313
N_("Max packetlength to send/receive from to server."))
1257
1314
("max-connect-errors", po::value<uint64_t>(&max_connect_errors)->default_value(MAX_CONNECT_ERRORS)->notifier(&check_limits_mce),
1258
1315
N_("If there is more than this number of interrupted connections from a "
1305
1362
N_("Each thread that does a sequential scan allocates a buffer of this "
1306
1363
"size for each table it scans. If you do many sequential scans, you may "
1307
1364
"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
1365
("read-rnd-buffer-size",
1312
1366
po::value<uint32_t>(&global_system_variables.read_rnd_buff_size)->default_value(256*1024L)->notifier(&check_limits_read_rnd_buffer_size),
1313
1367
N_("When reading rows in sorted order after a sort, the rows are read "
1314
1368
"through this buffer to avoid a disk seeks. If not set, then it's set "
1315
1369
"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
1370
("scheduler", po::value<string>(),
1320
1371
N_("Select scheduler to be used (by default multi-thread)."))
1321
1372
("sort-buffer-size",
1322
1373
po::value<size_t>(&global_system_variables.sortbuff_size)->default_value(MAX_SORT_MEMORY)->notifier(&check_limits_sort_buffer_size),
1323
1374
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
1375
("table-definition-cache", po::value<size_t>(&table_def_size)->default_value(128)->notifier(&check_limits_tdc),
1328
1376
N_("The number of cached table definitions."))
1329
1377
("table-open-cache", po::value<uint64_t>(&table_cache_size)->default_value(TABLE_OPEN_CACHE_DEFAULT)->notifier(&check_limits_toc),
1365
1413
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
1415
defaults_file_list.insert(defaults_file_list.begin(),
1370
system_config_file_drizzle.file_string());
1372
fs::path config_conf_d_location(system_config_dir);
1373
config_conf_d_location /= "conf.d";
1376
CachedDirectory config_conf_d(config_conf_d_location.file_string());
1377
if (not config_conf_d.fail())
1416
system_config_file_drizzle);
1419
fs::path config_conf_d_location(system_config_dir);
1420
config_conf_d_location /= "conf.d";
1422
CachedDirectory config_conf_d(config_conf_d_location.file_string());
1423
if (not config_conf_d.fail())
1426
for (CachedDirectory::Entries::const_iterator iter= config_conf_d.getEntries().begin();
1427
iter != config_conf_d.getEntries().end();
1380
for (CachedDirectory::Entries::const_iterator iter= config_conf_d.getEntries().begin();
1381
iter != config_conf_d.getEntries().end();
1430
string file_entry((*iter)->filename);
1432
if (not file_entry.empty()
1433
&& file_entry != "."
1434
&& file_entry != "..")
1384
string file_entry((*iter)->filename);
1386
if (not file_entry.empty()
1387
&& file_entry != "."
1388
&& file_entry != "..")
1390
fs::path the_entry(config_conf_d_location);
1391
the_entry /= file_entry;
1392
defaults_file_list.push_back(the_entry.file_string());
1436
fs::path the_entry(config_conf_d_location);
1437
the_entry /= file_entry;
1438
defaults_file_list.push_back(the_entry.file_string());
1443
process_defaults_files();
1398
1444
/* TODO: here is where we should add a process_env_vars */
1400
1446
/* We need a notify here so that plugin_init will work properly */
1405
catch (po::validation_error &err)
1407
errmsg_printf(ERRMSG_LVL_ERROR,
1409
"Use --help to get a list of available options\n"),
1410
internal::my_progname, err.what());
1414
process_defaults_files();
1416
/* Process with notify a second time because a config file may contain
1417
plugin loader options */
1423
catch (po::validation_error &err)
1425
errmsg_printf(ERRMSG_LVL_ERROR,
1427
"Use --help to get a list of available options\n"),
1428
internal::my_progname, err.what());
1432
1448
/* At this point, we've read all the options we need to read from files and
1433
1449
collected most of them into unknown options - now let's load everything
1454
1470
po::store(final_parsed, vm);
1457
catch (po::validation_error &err)
1459
errmsg_printf(ERRMSG_LVL_ERROR,
1461
"Use --help to get a list of available options\n"),
1462
internal::my_progname, err.what());
1465
1473
catch (po::invalid_command_line_syntax &err)
1467
1475
errmsg_printf(ERRMSG_LVL_ERROR,
1583
1580
errmsg_printf(ERRMSG_LVL_ERROR, _("Could not initialize table cache\n"));
1584
1581
unireg_abort(1);
1587
// Resize the definition Cache at startup
1588
table::Cache::singleton().rehash(table_def_size);
1589
definition::Cache::singleton().rehash(table_def_size);
1590
message::Cache::singleton().rehash(table_def_size);
1583
TableShare::cacheStart();
1894
1887
N_("Max packetlength to send/receive from to server."),
1895
1888
(char**) &global_system_variables.max_allowed_packet,
1896
1889
(char**) &max_system_variables.max_allowed_packet, 0, GET_UINT32,
1897
REQUIRED_ARG, 64*1024*1024L, 1024, 1024L*1024L*1024L, MALLOC_OVERHEAD, 1024, 0},
1890
REQUIRED_ARG, 1024*1024L, 1024, 1024L*1024L*1024L, MALLOC_OVERHEAD, 1024, 0},
1898
1891
{"max_connect_errors", OPT_MAX_CONNECT_ERRORS,
1899
1892
N_("If there is more than this number of interrupted connections from a "
1900
1893
"host this host will be blocked from further connections."),
2139
2132
session_startup_options= (OPTION_AUTO_IS_NULL | OPTION_SQL_NOTES);
2140
2133
refresh_version= 1L; /* Increments on each reload */
2141
2134
global_thread_id= 1UL;
2142
session::Cache::singleton().getCache().clear();
2135
getSessionList().clear();
2144
2137
/* Variables in libraries */
2145
2138
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
2218
if (vm.count("exit-info"))
2279
2220
if (vm["exit-info"].as<long>())