40
39
#include <boost/filesystem.hpp>
41
40
#include <boost/detail/atomic_count.hpp>
43
#include <drizzled/cached_directory.h>
44
#include <drizzled/charset.h>
45
#include <drizzled/data_home.h>
46
#include <drizzled/debug.h>
47
#include <drizzled/definition/cache.h>
48
#include <drizzled/drizzled.h>
42
#include "drizzled/internal/my_sys.h"
43
#include "drizzled/internal/my_bit.h"
44
#include <drizzled/my_hash.h>
45
#include <drizzled/error.h>
49
46
#include <drizzled/errmsg_print.h>
50
#include <drizzled/error.h>
51
#include <drizzled/global_buffer.h>
52
#include <drizzled/internal/my_bit.h>
53
#include <drizzled/internal/my_sys.h>
47
#include <drizzled/tztime.h>
48
#include <drizzled/sql_base.h>
49
#include <drizzled/show.h>
50
#include <drizzled/sql_parse.h>
54
51
#include <drizzled/item/cmpfunc.h>
52
#include <drizzled/session.h>
55
53
#include <drizzled/item/create.h>
56
#include <drizzled/message/cache.h>
57
#include <drizzled/module/load_list.h>
58
#include <drizzled/module/registry.h>
59
#include <drizzled/plugin/client.h>
60
#include <drizzled/plugin/error_message.h>
61
#include <drizzled/plugin/event_observer.h>
62
#include <drizzled/plugin/listen.h>
63
#include <drizzled/plugin/monitored_in_transaction.h>
64
#include <drizzled/plugin/scheduler.h>
65
#include <drizzled/plugin/storage_engine.h>
66
#include <drizzled/plugin/xa_resource_manager.h>
67
#include <drizzled/probes.h>
68
#include <drizzled/replication_services.h> /* For ReplicationServices::evaluateRegisteredPlugins() */
69
#include <drizzled/session.h>
70
#include <drizzled/session/cache.h>
71
#include <drizzled/show.h>
72
#include <drizzled/sql_base.h>
73
#include <drizzled/sql_parse.h>
74
#include <drizzled/statistics_variables.h>
75
#include <drizzled/table/cache.h>
76
#include <drizzled/temporal_format.h> /* For init_temporal_formats() */
77
54
#include <drizzled/unireg.h>
78
#include <plugin/myisam/myisam.h>
79
#include <drizzled/typelib.h>
80
#include <drizzled/visibility.h>
81
#include <drizzled/system_variables.h>
82
#include <drizzled/open_tables_state.h>
55
#include "drizzled/temporal_format.h" /* For init_temporal_formats() */
56
#include "drizzled/plugin/listen.h"
57
#include "drizzled/plugin/error_message.h"
58
#include "drizzled/plugin/client.h"
59
#include "drizzled/plugin/scheduler.h"
60
#include "drizzled/plugin/xa_resource_manager.h"
61
#include "drizzled/plugin/monitored_in_transaction.h"
62
#include "drizzled/replication_services.h" /* For ReplicationServices::evaluateRegisteredPlugins() */
63
#include "drizzled/probes.h"
64
#include "drizzled/session/cache.h"
65
#include "drizzled/charset.h"
66
#include "plugin/myisam/myisam.h"
67
#include "drizzled/drizzled.h"
68
#include "drizzled/module/registry.h"
69
#include "drizzled/module/load_list.h"
70
#include "drizzled/global_buffer.h"
72
#include "drizzled/debug.h"
74
#include "drizzled/definition/cache.h"
76
#include "drizzled/plugin/event_observer.h"
78
#include "drizzled/message/cache.h"
80
#include "drizzled/visibility.h"
84
82
#include <google/protobuf/stubs/common.h>
330
331
drizzle_system_variables max_system_variables;
331
332
global_counters current_global_counters;
333
DRIZZLED_API const charset_info_st *system_charset_info;
334
const charset_info_st *files_charset_info;
335
const charset_info_st *table_alias_charset;
336
const charset_info_st *character_set_filesystem;
334
DRIZZLED_API const CHARSET_INFO *system_charset_info;
335
const CHARSET_INFO *files_charset_info;
336
const CHARSET_INFO *table_alias_charset;
337
const CHARSET_INFO *character_set_filesystem;
338
339
MY_LOCALE *my_default_lc_time_names;
368
375
fs::path base_plugin_dir(PKGPLUGINDIR);
370
po::options_description config_options(_("Config File Options"));
371
po::options_description long_options(_("Kernel Options"));
372
po::options_description plugin_load_options(_("Plugin Loading Options"));
373
po::options_description plugin_options(_("Plugin Options"));
374
po::options_description initial_options(_("Config and Plugin Loading"));
375
po::options_description full_options(_("Kernel and Plugin Loading and Plugin"));
377
po::options_description config_options("Config File Options");
378
po::options_description long_options("Kernel Options");
379
po::options_description plugin_load_options("Plugin Loading Options");
380
po::options_description plugin_options("Plugin Options");
381
po::options_description initial_options("Config and Plugin Loading");
382
po::options_description full_options("Kernel and Plugin Loading and Plugin");
376
383
vector<string> unknown_options;
377
384
vector<string> defaults_file_list;
378
385
po::variables_map vm;
387
fs::path data_home(LOCALSTATEDIR);
388
fs::path full_data_home(LOCALSTATEDIR);
380
390
po::variables_map &getVariablesMap()
388
std::string &getGlobHostname()
390
static std::string glob_hostname("localhost");
391
return glob_hostname;
394
void setServerHostname(const std::string &hostname)
396
getGlobHostname()= hostname;
400
const std::string &getServerHostname()
402
return getGlobHostname();
395
fs::path& getFullDataHome()
397
return full_data_home;
400
fs::path& getDataHome()
405
fs::path& getDataHomeCatalog()
407
static fs::path data_home_catalog(getDataHome());
408
return data_home_catalog;
405
412
/****************************************************************************
406
413
** Code to end drizzled
407
414
****************************************************************************/
538
547
tmp_user_info= getpwnam(user);
539
548
if ((!tmp_user_info || user_id != tmp_user_info->pw_uid) &&
540
549
global_system_variables.log_warnings)
541
errmsg_printf(error::WARN, _("One can only use the --user switch "
550
errmsg_printf(ERRMSG_LVL_WARN, _("One can only use the --user switch "
542
551
"if running as root\n"));
548
errmsg_printf(error::ERROR, _("Fatal error: Please read \"Security\" section of "
549
"the manual to find out how to run drizzled as root"));
557
errmsg_printf(ERRMSG_LVL_ERROR, _("Fatal error: Please read \"Security\" section of "
558
"the manual to find out how to run drizzled as root!\n"));
553
if (not strcmp(user, "root"))
561
if (!strcmp(user,"root"))
554
562
return NULL; // Avoid problem with dynamic libraries
556
564
if (!(tmp_user_info= getpwnam(user)))
622
630
session Thread handler
625
void Session::unlink(session_id_t &session_id)
633
void drizzled::Session::unlink(session_id_t &session_id)
627
Session::shared_ptr session= session::Cache::find(session_id);
635
Session::shared_ptr session= session::Cache::singleton().find(session_id);
633
void Session::unlink(Session::shared_ptr &session)
641
void drizzled::Session::unlink(Session::shared_ptr &session)
635
643
--connection_count;
637
645
session->cleanup();
639
boost::mutex::scoped_lock scopedLock(session::Cache::mutex());
647
boost::mutex::scoped_lock scopedLock(session::Cache::singleton().mutex());
641
649
if (unlikely(plugin::EventObserver::disconnectSession(*session)))
643
651
// We should do something about an error...
645
session::Cache::erase(session);
653
session::Cache::singleton().erase(session);
659
const char *load_default_groups[]=
667
const char *load_default_groups[]=
661
669
DRIZZLE_CONFIG_NAME, "server", 0, 0
664
672
static void find_plugin_dir(string progname)
666
fs::path full_progname(fs::system_complete(progname));
668
fs::path progdir(full_progname.parent_path());
669
if (progdir.filename() == ".libs")
671
progdir= progdir.parent_path();
674
if (fs::exists(progdir / "drizzled.lo") || fs::exists(progdir / "drizzled.o"))
674
if (progname[0] != FN_LIBCHAR)
676
/* We have a relative path and need to find the absolute */
677
char working_dir[FN_REFLEN];
678
char *working_dir_ptr= working_dir;
679
working_dir_ptr= getcwd(working_dir_ptr, FN_REFLEN);
680
string new_path(working_dir);
681
if (*(new_path.end()-1) != '/')
682
new_path.push_back('/');
683
if (progname[0] == '.' && progname[1] == '/')
684
new_path.append(progname.substr(2));
686
new_path.append(progname);
687
progname.swap(new_path);
690
/* Now, trim off the exe name */
691
string progdir(progname.substr(0, progname.rfind(FN_LIBCHAR)+1));
692
if (progdir.rfind(".libs/") != string::npos)
694
progdir.assign(progdir.substr(0, progdir.rfind(".libs/")));
696
string testlofile(progdir);
697
testlofile.append("drizzled.lo");
698
string testofile(progdir);
699
testofile.append("drizzled.o");
700
struct stat testfile_stat;
701
if (not (stat(testlofile.c_str(), &testfile_stat) && stat(testofile.c_str(), &testfile_stat)))
676
703
/* We are in a source dir! Plugin dir is ../plugin/.libs */
677
base_plugin_dir= progdir.parent_path();
704
size_t last_libchar_pos= progdir.rfind(FN_LIBCHAR,progdir.size()-2)+1;
705
base_plugin_dir= progdir.substr(0,last_libchar_pos);
678
706
base_plugin_dir /= "plugin";
679
707
base_plugin_dir /= ".libs";
1005
1033
static void check_limits_transaction_message_threshold(size_t in_transaction_message_threshold)
1007
transaction_message_threshold= 1024*1024;
1035
global_system_variables.transaction_message_threshold= 1024*1024;
1008
1036
if ((int64_t) in_transaction_message_threshold < 128*1024 || (int64_t)in_transaction_message_threshold > 1024*1024)
1010
1038
cout << _("Error: Invalid Value for transaction_message_threshold valid values are between 131072 - 1048576 bytes");
1013
transaction_message_threshold= in_transaction_message_threshold;
1041
global_system_variables.transaction_message_threshold= in_transaction_message_threshold;
1016
1044
static void process_defaults_files()
1018
BOOST_FOREACH(vector<string>::reference iter, defaults_file_list)
1046
for (vector<string>::iterator iter= defaults_file_list.begin();
1047
iter != defaults_file_list.end();
1020
fs::path file_location= iter;
1050
fs::path file_location= *iter;
1022
1052
ifstream input_defaults_file(file_location.file_string().c_str());
1024
1054
po::parsed_options file_parsed=
1025
1055
dpo::parse_config_file(input_defaults_file, full_options, true);
1026
vector<string> file_unknown=
1056
vector<string> file_unknown=
1027
1057
po::collect_unrecognized(file_parsed.options, po::include_positional);
1029
1059
for (vector<string>::iterator it= file_unknown.begin();
1049
1084
static void compose_defaults_file_list(vector<string> in_options)
1051
BOOST_FOREACH(vector<string>::reference it, in_options)
1086
for (vector<string>::iterator it= in_options.begin();
1087
it != in_options.end();
1054
1091
if (fs::is_regular_file(p))
1055
defaults_file_list.push_back(it);
1092
defaults_file_list.push_back(*it);
1058
errmsg_printf(error::ERROR, _("Defaults file '%s' not found\n"), it.c_str());
1095
errmsg_printf(ERRMSG_LVL_ERROR,
1096
_("Defaults file '%s' not found\n"), (*it).c_str());
1059
1097
unireg_abort(1);
1064
int init_basic_variables(int argc, char **argv)
1103
int init_common_variables(int argc, char **argv, module::Registry &plugins)
1066
1105
time_t curr_time;
1067
1106
umask(((~internal::my_umask) & 0666));
1078
1117
drizzle_init_variables();
1080
1119
find_plugin_dir(argv[0]);
1082
char ret_hostname[FN_REFLEN];
1083
if (gethostname(ret_hostname,sizeof(ret_hostname)) < 0)
1085
errmsg_printf(error::WARN,
1086
_("gethostname failed, using '%s' as hostname"),
1087
getServerHostname().c_str());
1122
localtime_r(&server_start_time,&tm_tmp);
1123
strncpy(system_time_zone, tzname[tm_tmp.tm_isdst != 0 ? 1 : 0],
1124
sizeof(system_time_zone)-1);
1128
We set SYSTEM time zone as reasonable default and
1129
also for failure of my_tz_init() and bootstrap mode.
1130
If user explicitly set time zone with --default-time-zone
1131
option we will change this value in my_tz_init().
1133
global_system_variables.time_zone= my_tz_SYSTEM;
1135
if (gethostname(glob_hostname,sizeof(glob_hostname)) < 0)
1137
strncpy(glob_hostname, STRING_WITH_LEN("localhost"));
1138
errmsg_printf(ERRMSG_LVL_WARN, _("gethostname failed, using '%s' as hostname"),
1088
1140
pid_file= "drizzle";
1092
setServerHostname(ret_hostname);
1093
pid_file= getServerHostname();
1144
pid_file= glob_hostname;
1095
1146
pid_file.replace_extension(".pid");
1099
1150
config_options.add_options()
1100
1151
("help,?", po::value<bool>(&opt_help)->default_value(false)->zero_tokens(),
1101
1152
_("Display this help and exit."))
1102
("daemon,d", po::value<bool>(&opt_daemon)->default_value(false)->zero_tokens(),
1103
_("Run as a daemon."))
1104
1153
("no-defaults", po::value<bool>()->default_value(false)->zero_tokens(),
1105
1154
_("Configuration file defaults are not used if no-defaults is set"))
1106
1155
("defaults-file", po::value<vector<string> >()->composing()->notifier(&compose_defaults_file_list),
1115
1164
("plugin-add", po::value<vector<string> >()->composing()->notifier(&compose_plugin_add),
1116
1165
_("Optional comma separated list of plugins to load at startup in addition "
1117
1166
"to the default list of plugins. "
1118
"[for example: --plugin_add=crc32,logger_gearman]"))
1167
"[for example: --plugin_add=crc32,logger_gearman]"))
1119
1168
("plugin-remove", po::value<vector<string> >()->composing()->notifier(&compose_plugin_remove),
1120
1169
_("Optional comma separated list of plugins to not load at startup. Effectively "
1121
1170
"removes a plugin from the list of plugins to be loaded. "
1137
1186
("chroot,r", po::value<string>(),
1138
1187
_("Chroot drizzled daemon during startup."))
1139
1188
("collation-server", po::value<string>(),
1140
_("Set the default collation."))
1189
_("Set the default collation."))
1141
1190
("completion-type", po::value<uint32_t>(&global_system_variables.completion_type)->default_value(0)->notifier(&check_limits_completion_type),
1142
1191
_("Default completion type."))
1143
1192
("core-file", _("Write core on errors."))
1144
("datadir", po::value<fs::path>(&getDataHome()),
1193
("datadir", po::value<fs::path>(&data_home),
1145
1194
_("Path to the database root."))
1146
1195
("default-storage-engine", po::value<string>(),
1147
1196
_("Set the default storage engine for tables."))
1154
1203
("lc-time-name", po::value<string>(),
1155
1204
_("Set the language used for the month names and the days of the week."))
1156
1205
("log-warnings,W", po::value<bool>(&global_system_variables.log_warnings)->default_value(false)->zero_tokens(),
1157
_("Log some not critical warnings to the log file."))
1206
_("Log some not critical warnings to the log file."))
1158
1207
("pid-file", po::value<fs::path>(&pid_file),
1159
1208
_("Pid file used by drizzled."))
1160
1209
("port-open-timeout", po::value<uint32_t>(&drizzled_bind_timeout)->default_value(0),
1167
1216
("server-id", po::value<uint32_t>(&server_id)->default_value(0),
1168
1217
_("Uniquely identifies the server instance in the community of "
1169
1218
"replication partners."))
1170
("skip-stack-trace",
1219
("skip-stack-trace",
1171
1220
_("Don't print a stack trace on failure."))
1172
1221
("symbolic-links,s", po::value<bool>(&internal::my_use_symdir)->default_value(IF_PURIFY(false,true))->zero_tokens(),
1173
1222
_("Enable symbolic link support."))
1174
1223
("timed-mutexes", po::value<bool>(&internal::timed_mutexes)->default_value(false)->zero_tokens(),
1175
1224
_("Specify whether to time mutexes (only InnoDB mutexes are currently "
1177
1226
("tmpdir,t", po::value<string>(),
1178
1227
_("Path for temporary files."))
1179
1228
("transaction-isolation", po::value<string>(),
1180
1229
_("Default transaction isolation level."))
1181
("transaction-message-threshold", po::value<size_t>(&transaction_message_threshold)->default_value(1024*1024)->notifier(&check_limits_transaction_message_threshold),
1230
("transaction-message-threshold", po::value<size_t>(&global_system_variables.transaction_message_threshold)->default_value(1024*1024)->notifier(&check_limits_transaction_message_threshold),
1182
1231
_("Max message size written to transaction log, valid values 131072 - 1048576 bytes."))
1183
1232
("user,u", po::value<string>(),
1184
_("Run drizzled daemon as user."))
1233
_("Run drizzled daemon as user."))
1186
1235
_("Output version information and exit."))
1187
1236
("back-log", po::value<back_log_constraints>(&back_log),
1188
1237
_("The number of outstanding connection requests Drizzle can have. This "
1189
1238
"comes into play when the main Drizzle thread gets very many connection "
1190
1239
"requests in a very short time."))
1191
("bulk-insert-buffer-size",
1240
("bulk-insert-buffer-size",
1192
1241
po::value<uint64_t>(&global_system_variables.bulk_insert_buff_size)->default_value(8192*1024),
1193
1242
_("Size of tree cache used in bulk insert optimization. Note that this is "
1194
1243
"a limit per thread!"))
1208
1257
_("Max number of errors/warnings to store for a statement."))
1209
1258
("max-heap-table-size", po::value<uint64_t>(&global_system_variables.max_heap_table_size)->default_value(16*1024*1024L)->notifier(&check_limits_mhts),
1210
1259
_("Don't allow creation of heap tables bigger than this."))
1211
("max-join-size", po::value<ha_rows>(&global_system_variables.max_join_size)->default_value(INT32_MAX)->notifier(&check_limits_max_join_size),
1260
("max-join-size", po::value<drizzled::ha_rows>(&global_system_variables.max_join_size)->default_value(INT32_MAX)->notifier(&check_limits_max_join_size),
1212
1261
_("Joins that are probably going to read more than max_join_size records "
1213
1262
"return an error."))
1214
1263
("max-length-for-sort-data", po::value<uint64_t>(&global_system_variables.max_length_for_sort_data)->default_value(1024)->notifier(&check_limits_mlfsd),
1215
1264
_("Max number of bytes in sorted records."))
1216
1265
("max-seeks-for-key", po::value<uint64_t>(&global_system_variables.max_seeks_for_key)->default_value(ULONG_MAX)->notifier(&check_limits_msfk),
1217
1266
_("Limit assumed max number of seeks when looking up rows based on a key"))
1218
("max-sort-length", po::value<size_t>(&global_system_variables.max_sort_length)->default_value(1024)->notifier(&check_limits_max_sort_length),
1267
("max-sort-length", po::value<size_t>(&global_system_variables.max_sort_length)->default_value(1024)->notifier(&check_limits_max_sort_length),
1219
1268
_("The number of bytes to use when sorting BLOB or TEXT values "
1220
1269
"(only the first max_sort_length bytes of each value are used; the "
1221
1270
"rest are ignored)."))
1280
1329
"error. Used only if the connection has active cursors."))
1281
1330
("thread-stack", po::value<size_t>(&my_thread_stack_size)->default_value(DEFAULT_THREAD_STACK)->notifier(&check_limits_thread_stack),
1282
1331
_("The stack size for each thread."))
1284
1333
po::value<uint64_t>(&global_system_variables.tmp_table_size)->default_value(16*1024*1024L)->notifier(&check_limits_tmp_table_size),
1285
1334
_("If an internal in-memory temporary table exceeds this size, Drizzle will"
1286
1335
" automatically convert it to an on-disk MyISAM table."))
1287
("verbose", po::value<std::string>()->default_value(error::verbose_string())->notifier(&error::check_verbosity),
1288
_("The verbosity of messages from drizzled. Possible values are INSPECT, INFO, WARN or ERROR"))
1291
1338
full_options.add(long_options);
1369
1419
catch (po::validation_error &err)
1371
errmsg_printf(error::ERROR,
1421
errmsg_printf(ERRMSG_LVL_ERROR,
1373
1423
"Use --help to get a list of available options\n"),
1374
1424
internal::my_progname, err.what());
1375
1425
unireg_abort(1);
1381
int init_remaining_variables(module::Registry &plugins)
1383
int style = po::command_line_style::default_style & ~po::command_line_style::allow_guessing;
1385
current_pid= getpid(); /* Save for later ref */
1387
1428
/* At this point, we've read all the options we need to read from files and
1388
1429
collected most of them into unknown options - now let's load everything
1391
1432
if (plugin_init(plugins, plugin_options))
1393
errmsg_printf(error::ERROR, _("Failed to initialize plugins\n"));
1434
errmsg_printf(ERRMSG_LVL_ERROR, _("Failed to initialize plugins\n"));
1394
1435
unireg_abort(1);
1485
1528
if (default_collation_name)
1487
const charset_info_st * const default_collation= get_charset_by_name(default_collation_name);
1530
const CHARSET_INFO * const default_collation= get_charset_by_name(default_collation_name);
1488
1531
if (not default_collation)
1490
errmsg_printf(error::ERROR, _(ER(ER_UNKNOWN_COLLATION)), default_collation_name);
1533
errmsg_printf(ERRMSG_LVL_ERROR, _(ER(ER_UNKNOWN_COLLATION)), default_collation_name);
1493
1536
if (not my_charset_same(default_charset_info, default_collation))
1495
errmsg_printf(error::ERROR, _(ER(ER_COLLATION_CHARSET_MISMATCH)),
1538
errmsg_printf(ERRMSG_LVL_ERROR, _(ER(ER_COLLATION_CHARSET_MISMATCH)),
1496
1539
default_collation_name,
1497
1540
default_charset_info->csname);
1534
1577
if (table_cache_init())
1536
errmsg_printf(error::ERROR, _("Could not initialize table cache\n"));
1579
errmsg_printf(ERRMSG_LVL_ERROR, _("Could not initialize table cache\n"));
1537
1580
unireg_abort(1);
1540
1583
// Resize the definition Cache at startup
1541
table::Cache::rehash(table_def_size);
1542
definition::Cache::rehash(table_def_size);
1584
table::Cache::singleton().rehash(table_def_size);
1585
definition::Cache::singleton().rehash(table_def_size);
1543
1586
message::Cache::singleton().rehash(table_def_size);
1592
if (xid_cache_init())
1594
errmsg_printf(ERRMSG_LVL_ERROR, _("XA cache initialization failed: Out of memory\n"));
1547
1598
/* Allow storage engine to give real error messages */
1548
1599
ha_init_errors();
1688
1739
{"help", '?', N_("Display this help and exit."),
1689
1740
(char**) &opt_help, (char**) &opt_help, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0,
1691
{"daemon", 'd', N_("Run as daemon."),
1692
(char**) &opt_daemon, (char**) &opt_daemon, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0,
1694
1742
{"auto-increment-increment", OPT_AUTO_INCREMENT,
1695
1743
N_("Auto-increment columns are incremented by this"),
1696
1744
(char**) &global_system_variables.auto_increment_increment,
2287
2336
if (errno != EEXIST)
2289
errmsg_printf(error::ERROR, _("There was an error creating the '%s' part of the path '%s'. Please check the path exists and is writable.\n"), fs::path(drizzle_tmpdir).leaf().c_str(), drizzle_tmpdir.c_str());
2338
errmsg_printf(ERRMSG_LVL_ERROR, _("There was an error creating the '%s' part of the path '%s'. Please check the path exists and is writable.\n"), fs::path(drizzle_tmpdir).leaf().c_str(), drizzle_tmpdir.c_str());
2294
2343
if (stat(drizzle_tmpdir.c_str(), &buf) || (S_ISDIR(buf.st_mode) == false))
2296
errmsg_printf(error::ERROR, _("There was an error opening the path '%s', please check the path exists and is writable.\n"), drizzle_tmpdir.c_str());
2345
errmsg_printf(ERRMSG_LVL_ERROR, _("There was an error opening the path '%s', please check the path exists and is writable.\n"), drizzle_tmpdir.c_str());