659
698
DRIZZLE_CONFIG_NAME, "server", 0, 0
662
static void find_plugin_dir(string progname)
664
if (progname[0] != FN_LIBCHAR)
666
/* We have a relative path and need to find the absolute */
667
char working_dir[FN_REFLEN];
668
char *working_dir_ptr= working_dir;
669
working_dir_ptr= getcwd(working_dir_ptr, FN_REFLEN);
670
string new_path(working_dir);
671
if (*(new_path.end()-1) != '/')
672
new_path.push_back('/');
673
if (progname[0] == '.' && progname[1] == '/')
674
new_path.append(progname.substr(2));
676
new_path.append(progname);
677
progname.swap(new_path);
680
/* Now, trim off the exe name */
681
string progdir(progname.substr(0, progname.rfind(FN_LIBCHAR)+1));
682
if (progdir.rfind(".libs/") != string::npos)
684
progdir.assign(progdir.substr(0, progdir.rfind(".libs/")));
686
string testlofile(progdir);
687
testlofile.append("drizzled.lo");
688
string testofile(progdir);
689
testofile.append("drizzled.o");
690
struct stat testfile_stat;
691
if (not (stat(testlofile.c_str(), &testfile_stat) && stat(testofile.c_str(), &testfile_stat)))
693
/* We are in a source dir! Plugin dir is ../plugin/.libs */
694
size_t last_libchar_pos= progdir.rfind(FN_LIBCHAR,progdir.size()-2)+1;
695
base_plugin_dir= progdir.substr(0,last_libchar_pos);
696
base_plugin_dir /= "plugin";
697
base_plugin_dir /= ".libs";
700
if (plugin_dir.root_directory() == "")
702
fs::path full_plugin_dir(fs::system_complete(base_plugin_dir));
703
full_plugin_dir /= plugin_dir;
704
plugin_dir= full_plugin_dir;
708
static void notify_plugin_dir(fs::path in_plugin_dir)
710
plugin_dir= in_plugin_dir;
711
if (plugin_dir.root_directory() == "")
713
fs::path full_plugin_dir(fs::system_complete(basedir));
714
full_plugin_dir /= plugin_dir;
715
plugin_dir= full_plugin_dir;
719
static void expand_secure_file_priv(fs::path in_secure_file_priv)
721
secure_file_priv= fs::system_complete(in_secure_file_priv);
724
static void check_limits_aii(uint64_t in_auto_increment_increment)
726
global_system_variables.auto_increment_increment= 1;
727
if (in_auto_increment_increment < 1 || in_auto_increment_increment > UINT64_MAX)
729
cout << N_("Error: Invalid Value for auto_increment_increment");
732
global_system_variables.auto_increment_increment= in_auto_increment_increment;
735
static void check_limits_aio(uint64_t in_auto_increment_offset)
737
global_system_variables.auto_increment_offset= 1;
738
if (in_auto_increment_offset < 1 || in_auto_increment_offset > UINT64_MAX)
740
cout << N_("Error: Invalid Value for auto_increment_offset");
743
global_system_variables.auto_increment_offset= in_auto_increment_offset;
746
static void check_limits_completion_type(uint32_t in_completion_type)
748
global_system_variables.completion_type= 0;
749
if (in_completion_type > 2)
751
cout << N_("Error: Invalid Value for completion_type");
754
global_system_variables.completion_type= in_completion_type;
758
static void check_limits_dpi(uint32_t in_div_precincrement)
760
global_system_variables.div_precincrement= 4;
761
if (in_div_precincrement > DECIMAL_MAX_SCALE)
763
cout << N_("Error: Invalid Value for div-precision-increment");
766
global_system_variables.div_precincrement= in_div_precincrement;
769
static void check_limits_gcml(uint64_t in_group_concat_max_len)
771
global_system_variables.group_concat_max_len= 1024;
772
if (in_group_concat_max_len > ULONG_MAX || in_group_concat_max_len < 4)
774
cout << N_("Error: Invalid Value for group_concat_max_len");
777
global_system_variables.group_concat_max_len= in_group_concat_max_len;
780
static void check_limits_join_buffer_size(uint64_t in_join_buffer_size)
782
global_system_variables.join_buff_size= (128*1024L);
783
if (in_join_buffer_size < IO_SIZE*2 || in_join_buffer_size > ULONG_MAX)
785
cout << N_("Error: Invalid Value for join_buffer_size");
788
in_join_buffer_size-= in_join_buffer_size % IO_SIZE;
789
global_system_variables.join_buff_size= in_join_buffer_size;
792
static void check_limits_map(uint32_t in_max_allowed_packet)
794
global_system_variables.max_allowed_packet= (64*1024*1024L);
795
if (in_max_allowed_packet < 1024 || in_max_allowed_packet > 1024*1024L*1024L)
797
cout << N_("Error: Invalid Value for max_allowed_packet");
800
in_max_allowed_packet-= in_max_allowed_packet % 1024;
801
global_system_variables.max_allowed_packet= in_max_allowed_packet;
804
static void check_limits_mce(uint64_t in_max_connect_errors)
806
max_connect_errors= MAX_CONNECT_ERRORS;
807
if (in_max_connect_errors < 1 || in_max_connect_errors > ULONG_MAX)
809
cout << N_("Error: Invalid Value for max_connect_errors");
812
max_connect_errors= in_max_connect_errors;
815
static void check_limits_max_err_cnt(uint64_t in_max_error_count)
817
global_system_variables.max_error_count= DEFAULT_ERROR_COUNT;
818
if (in_max_error_count > 65535)
820
cout << N_("Error: Invalid Value for max_error_count");
823
global_system_variables.max_error_count= in_max_error_count;
826
static void check_limits_mhts(uint64_t in_max_heap_table_size)
828
global_system_variables.max_heap_table_size= (16*1024*1024L);
829
if (in_max_heap_table_size < 16384 || in_max_heap_table_size > MAX_MEM_TABLE_SIZE)
831
cout << N_("Error: Invalid Value for max_heap_table_size");
834
in_max_heap_table_size-= in_max_heap_table_size % 1024;
835
global_system_variables.max_heap_table_size= in_max_heap_table_size;
838
static void check_limits_merl(uint64_t in_min_examined_row_limit)
840
global_system_variables.min_examined_row_limit= 0;
841
if (in_min_examined_row_limit > ULONG_MAX)
843
cout << N_("Error: Invalid Value for min_examined_row_limit");
846
global_system_variables.min_examined_row_limit= in_min_examined_row_limit;
849
static void check_limits_max_join_size(drizzled::ha_rows in_max_join_size)
851
global_system_variables.max_join_size= INT32_MAX;
852
if ((uint64_t)in_max_join_size < 1 || (uint64_t)in_max_join_size > INT32_MAX)
854
cout << N_("Error: Invalid Value for max_join_size");
857
global_system_variables.max_join_size= in_max_join_size;
860
static void check_limits_mlfsd(int64_t in_max_length_for_sort_data)
862
global_system_variables.max_length_for_sort_data= 1024;
863
if (in_max_length_for_sort_data < 4 || in_max_length_for_sort_data > 8192*1024L)
865
cout << N_("Error: Invalid Value for max_length_for_sort_data");
868
global_system_variables.max_length_for_sort_data= in_max_length_for_sort_data;
871
static void check_limits_msfk(uint64_t in_max_seeks_for_key)
873
global_system_variables.max_seeks_for_key= ULONG_MAX;
874
if (in_max_seeks_for_key < 1 || in_max_seeks_for_key > ULONG_MAX)
876
cout << N_("Error: Invalid Value for max_seeks_for_key");
879
global_system_variables.max_seeks_for_key= in_max_seeks_for_key;
882
static void check_limits_max_sort_length(size_t in_max_sort_length)
884
global_system_variables.max_sort_length= 1024;
885
if ((int64_t)in_max_sort_length < 4 || (int64_t)in_max_sort_length > 8192*1024L)
887
cout << N_("Error: Invalid Value for max_sort_length");
890
global_system_variables.max_sort_length= in_max_sort_length;
893
static void check_limits_osd(uint32_t in_optimizer_search_depth)
895
global_system_variables.optimizer_search_depth= 0;
896
if (in_optimizer_search_depth > MAX_TABLES + 2)
898
cout << N_("Error: Invalid Value for optimizer_search_depth");
901
global_system_variables.optimizer_search_depth= in_optimizer_search_depth;
904
static void check_limits_pbs(uint64_t in_preload_buff_size)
906
global_system_variables.preload_buff_size= (32*1024L);
907
if (in_preload_buff_size < 1024 || in_preload_buff_size > 1024*1024*1024L)
909
cout << N_("Error: Invalid Value for preload_buff_size");
912
global_system_variables.preload_buff_size= in_preload_buff_size;
915
static void check_limits_qabs(uint32_t in_query_alloc_block_size)
917
global_system_variables.query_alloc_block_size= QUERY_ALLOC_BLOCK_SIZE;
918
if (in_query_alloc_block_size < 1024)
920
cout << N_("Error: Invalid Value for query_alloc_block_size");
923
in_query_alloc_block_size-= in_query_alloc_block_size % 1024;
924
global_system_variables.query_alloc_block_size= in_query_alloc_block_size;
927
static void check_limits_qps(uint32_t in_query_prealloc_size)
929
global_system_variables.query_prealloc_size= QUERY_ALLOC_PREALLOC_SIZE;
930
if (in_query_prealloc_size < QUERY_ALLOC_PREALLOC_SIZE)
932
cout << N_("Error: Invalid Value for query_prealloc_size");
935
in_query_prealloc_size-= in_query_prealloc_size % 1024;
936
global_system_variables.query_prealloc_size= in_query_prealloc_size;
939
static void check_limits_rabs(size_t in_range_alloc_block_size)
941
global_system_variables.range_alloc_block_size= RANGE_ALLOC_BLOCK_SIZE;
942
if (in_range_alloc_block_size < RANGE_ALLOC_BLOCK_SIZE)
944
cout << N_("Error: Invalid Value for range_alloc_block_size");
947
in_range_alloc_block_size-= in_range_alloc_block_size % 1024;
948
global_system_variables.range_alloc_block_size= in_range_alloc_block_size;
951
static void check_limits_read_buffer_size(int32_t in_read_buff_size)
953
global_system_variables.read_buff_size= (128*1024L);
954
if (in_read_buff_size < IO_SIZE*2 || in_read_buff_size > INT32_MAX)
956
cout << N_("Error: Invalid Value for read_buff_size");
959
in_read_buff_size-= in_read_buff_size % IO_SIZE;
960
global_system_variables.read_buff_size= in_read_buff_size;
963
static void check_limits_read_rnd_buffer_size(uint32_t in_read_rnd_buff_size)
965
global_system_variables.read_rnd_buff_size= (256*1024L);
966
if (in_read_rnd_buff_size < 64 || in_read_rnd_buff_size > UINT32_MAX)
968
cout << N_("Error: Invalid Value for read_rnd_buff_size");
971
global_system_variables.read_rnd_buff_size= in_read_rnd_buff_size;
974
static void check_limits_sort_buffer_size(size_t in_sortbuff_size)
976
global_system_variables.sortbuff_size= MAX_SORT_MEMORY;
977
if ((uint32_t)in_sortbuff_size < MIN_SORT_MEMORY)
979
cout << N_("Error: Invalid Value for sort_buff_size");
982
global_system_variables.sortbuff_size= in_sortbuff_size;
985
static void check_limits_tdc(uint32_t in_table_def_size)
988
if (in_table_def_size < 1 || in_table_def_size > 512*1024L)
990
cout << N_("Error: Invalid Value for table_def_size");
993
table_def_size= in_table_def_size;
996
static void check_limits_toc(uint32_t in_table_cache_size)
998
table_cache_size= TABLE_OPEN_CACHE_DEFAULT;
999
if (in_table_cache_size < TABLE_OPEN_CACHE_MIN || in_table_cache_size > 512*1024L)
1001
cout << N_("Error: Invalid Value for table_cache_size");
1004
table_cache_size= in_table_cache_size;
1007
static void check_limits_tlwt(uint64_t in_table_lock_wait_timeout)
1009
table_lock_wait_timeout= 50;
1010
if (in_table_lock_wait_timeout < 1 || in_table_lock_wait_timeout > 1024*1024*1024)
1012
cout << N_("Error: Invalid Value for table_lock_wait_timeout");
1015
table_lock_wait_timeout= in_table_lock_wait_timeout;
1018
static void check_limits_thread_stack(uint32_t in_my_thread_stack_size)
1020
my_thread_stack_size= in_my_thread_stack_size - (in_my_thread_stack_size % 1024);
1023
static void check_limits_tmp_table_size(uint64_t in_tmp_table_size)
1025
global_system_variables.tmp_table_size= 16*1024*1024L;
1026
if (in_tmp_table_size < 1024 || in_tmp_table_size > MAX_MEM_TABLE_SIZE)
1028
cout << N_("Error: Invalid Value for table_lock_wait_timeout");
1031
global_system_variables.tmp_table_size= in_tmp_table_size;
1034
static void check_limits_transaction_message_threshold(size_t in_transaction_message_threshold)
1036
global_system_variables.transaction_message_threshold= 1024*1024;
1037
if ((int64_t) in_transaction_message_threshold < 128*1024 || (int64_t)in_transaction_message_threshold > 1024*1024)
1039
cout << N_("Error: Invalid Value for transaction_message_threshold valid values are between 131072 - 1048576 bytes");
1042
global_system_variables.transaction_message_threshold= in_transaction_message_threshold;
1045
static void process_defaults_files()
1047
for (vector<string>::iterator iter= defaults_file_list.begin();
1048
iter != defaults_file_list.end();
1051
fs::path file_location= *iter;
1053
ifstream input_defaults_file(file_location.file_string().c_str());
1055
po::parsed_options file_parsed=
1056
dpo::parse_config_file(input_defaults_file, full_options, true);
1057
vector<string> file_unknown=
1058
po::collect_unrecognized(file_parsed.options, po::include_positional);
1060
for (vector<string>::iterator it= file_unknown.begin();
1061
it != file_unknown.end();
1064
string new_unknown_opt("--");
1065
new_unknown_opt.append(*it);
1067
if (it != file_unknown.end())
1069
if ((*it) != "true")
1071
new_unknown_opt.push_back('=');
1072
new_unknown_opt.append(*it);
1079
unknown_options.push_back(new_unknown_opt);
1081
store(file_parsed, vm);
1085
static void compose_defaults_file_list(vector<string> in_options)
1087
for (vector<string>::iterator it= in_options.begin();
1088
it != in_options.end();
1092
if (fs::is_regular_file(p))
1093
defaults_file_list.push_back(*it);
1096
errmsg_printf(ERRMSG_LVL_ERROR,
1097
_("Defaults file '%s' not found\n"), (*it).c_str());
1104
int init_common_variables(int argc, char **argv, module::Registry &plugins)
701
int init_common_variables(const char *conf_file_name, int argc,
702
char **argv, const char **groups)
1106
704
time_t curr_time;
1107
705
umask(((~internal::my_umask) & 0666));
1138
737
strncpy(glob_hostname, STRING_WITH_LEN("localhost"));
1139
738
errmsg_printf(ERRMSG_LVL_WARN, _("gethostname failed, using '%s' as hostname"),
1141
pid_file= "drizzle";
740
strncpy(pidfile_name, STRING_WITH_LEN("drizzle"));
1145
pid_file= glob_hostname;
1147
pid_file.replace_extension(".pid");
1149
system_config_dir /= "drizzle";
1151
config_options.add_options()
1152
("help,?", po::value<bool>(&opt_help)->default_value(false)->zero_tokens(),
1153
N_("Display this help and exit."))
1154
("no-defaults", po::value<bool>()->default_value(false)->zero_tokens(),
1155
N_("Configuration file defaults are not used if no-defaults is set"))
1156
("defaults-file", po::value<vector<string> >()->composing()->notifier(&compose_defaults_file_list),
1157
N_("Configuration file to use"))
1158
("config-dir", po::value<fs::path>(&system_config_dir),
1159
N_("Base location for config files"))
1160
("plugin-dir", po::value<fs::path>(&plugin_dir)->notifier(¬ify_plugin_dir),
1161
N_("Directory for plugins."))
1164
plugin_load_options.add_options()
1165
("plugin-add", po::value<vector<string> >()->composing()->notifier(&compose_plugin_add),
1166
N_("Optional comma separated list of plugins to load at startup in addition "
1167
"to the default list of plugins. "
1168
"[for example: --plugin_add=crc32,logger_gearman]"))
1169
("plugin-remove", po::value<vector<string> >()->composing()->notifier(&compose_plugin_remove),
1170
N_("Optional comma separated list of plugins to not load at startup. Effectively "
1171
"removes a plugin from the list of plugins to be loaded. "
1172
"[for example: --plugin_remove=crc32,logger_gearman]"))
1173
("plugin-load", po::value<string>()->notifier(¬ify_plugin_load)->default_value(PANDORA_PLUGIN_LIST),
1174
N_("Optional comma separated list of plugins to load at starup instead of "
1175
"the default plugin load list. "
1176
"[for example: --plugin_load=crc32,logger_gearman]"))
1179
long_options.add_options()
1180
("auto-increment-increment", po::value<uint64_t>(&global_system_variables.auto_increment_increment)->default_value(1)->notifier(&check_limits_aii),
1181
N_("Auto-increment columns are incremented by this"))
1182
("auto-increment-offset", po::value<uint64_t>(&global_system_variables.auto_increment_offset)->default_value(1)->notifier(&check_limits_aio),
1183
N_("Offset added to Auto-increment columns. Used when auto-increment-increment != 1"))
1184
("basedir,b", po::value<fs::path>(&basedir),
1185
N_("Path to installation directory. All paths are usually resolved "
1186
"relative to this."))
1187
("chroot,r", po::value<string>(),
1188
N_("Chroot drizzled daemon during startup."))
1189
("collation-server", po::value<string>(),
1190
N_("Set the default collation."))
1191
("completion-type", po::value<uint32_t>(&global_system_variables.completion_type)->default_value(0)->notifier(&check_limits_completion_type),
1192
N_("Default completion type."))
1193
("core-file", N_("Write core on errors."))
1194
("datadir", po::value<fs::path>(&data_home),
1195
N_("Path to the database root."))
1196
("default-storage-engine", po::value<string>(),
1197
N_("Set the default storage engine for tables."))
1198
("default-time-zone", po::value<string>(),
1199
N_("Set the default time zone."))
1200
("exit-info,T", po::value<long>(),
1201
N_("Used for debugging; Use at your own risk!"))
1202
("gdb", po::value<bool>(&opt_debugging)->default_value(false)->zero_tokens(),
1203
N_("Set up signals usable for debugging"))
1204
("lc-time-name", po::value<string>(),
1205
N_("Set the language used for the month names and the days of the week."))
1206
("log-warnings,W", po::value<bool>(&global_system_variables.log_warnings)->default_value(false)->zero_tokens(),
1207
N_("Log some not critical warnings to the log file."))
1208
("pid-file", po::value<fs::path>(&pid_file),
1209
N_("Pid file used by drizzled."))
1210
("port-open-timeout", po::value<uint32_t>(&drizzled_bind_timeout)->default_value(0),
1211
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
("secure-file-priv", po::value<fs::path>(&secure_file_priv)->notifier(expand_secure_file_priv),
1215
N_("Limit LOAD DATA, SELECT ... OUTFILE, and LOAD_FILE() to files "
1216
"within specified directory"))
1217
("server-id", po::value<uint32_t>(&server_id)->default_value(0),
1218
N_("Uniquely identifies the server instance in the community of "
1219
"replication partners."))
1220
("skip-stack-trace",
1221
N_("Don't print a stack trace on failure."))
1222
("symbolic-links,s", po::value<bool>(&internal::my_use_symdir)->default_value(IF_PURIFY(false,true))->zero_tokens(),
1223
N_("Enable symbolic link support."))
1224
("timed-mutexes", po::value<bool>(&internal::timed_mutexes)->default_value(false)->zero_tokens(),
1225
N_("Specify whether to time mutexes (only InnoDB mutexes are currently "
1227
("tmpdir,t", po::value<string>(),
1228
N_("Path for temporary files."))
1229
("transaction-isolation", po::value<string>(),
1230
N_("Default transaction isolation level."))
1231
("transaction-message-threshold", po::value<size_t>(&global_system_variables.transaction_message_threshold)->default_value(1024*1024)->notifier(&check_limits_transaction_message_threshold),
1232
N_("Max message size written to transaction log, valid values 131072 - 1048576 bytes."))
1233
("user,u", po::value<string>(),
1234
N_("Run drizzled daemon as user."))
1236
N_("Output version information and exit."))
1237
("back-log", po::value<back_log_constraints>(&back_log),
1238
N_("The number of outstanding connection requests Drizzle can have. This "
1239
"comes into play when the main Drizzle thread gets very many connection "
1240
"requests in a very short time."))
1241
("bulk-insert-buffer-size",
1242
po::value<uint64_t>(&global_system_variables.bulk_insert_buff_size)->default_value(8192*1024),
1243
N_("Size of tree cache used in bulk insert optimization. Note that this is "
1244
"a limit per thread!"))
1245
("div-precision-increment", po::value<uint32_t>(&global_system_variables.div_precincrement)->default_value(4)->notifier(&check_limits_dpi),
1246
N_("Precision of the result of '/' operator will be increased on that "
1248
("group-concat-max-len", po::value<uint64_t>(&global_system_variables.group_concat_max_len)->default_value(1024)->notifier(&check_limits_gcml),
1249
N_("The maximum length of the result of function group_concat."))
1250
("join-buffer-size", po::value<uint64_t>(&global_system_variables.join_buff_size)->default_value(128*1024L)->notifier(&check_limits_join_buffer_size),
1251
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),
1256
N_("Max packetlength to send/receive from to server."))
1257
("max-connect-errors", po::value<uint64_t>(&max_connect_errors)->default_value(MAX_CONNECT_ERRORS)->notifier(&check_limits_mce),
1258
N_("If there is more than this number of interrupted connections from a "
1259
"host this host will be blocked from further connections."))
1260
("max-error-count", po::value<uint64_t>(&global_system_variables.max_error_count)->default_value(DEFAULT_ERROR_COUNT)->notifier(&check_limits_max_err_cnt),
1261
N_("Max number of errors/warnings to store for a statement."))
1262
("max-heap-table-size", po::value<uint64_t>(&global_system_variables.max_heap_table_size)->default_value(16*1024*1024L)->notifier(&check_limits_mhts),
1263
N_("Don't allow creation of heap tables bigger than this."))
1264
("max-join-size", po::value<drizzled::ha_rows>(&global_system_variables.max_join_size)->default_value(INT32_MAX)->notifier(&check_limits_max_join_size),
1265
N_("Joins that are probably going to read more than max_join_size records "
1266
"return an error."))
1267
("max-length-for-sort-data", po::value<uint64_t>(&global_system_variables.max_length_for_sort_data)->default_value(1024)->notifier(&check_limits_mlfsd),
1268
N_("Max number of bytes in sorted records."))
1269
("max-seeks-for-key", po::value<uint64_t>(&global_system_variables.max_seeks_for_key)->default_value(ULONG_MAX)->notifier(&check_limits_msfk),
1270
N_("Limit assumed max number of seeks when looking up rows based on a key"))
1271
("max-sort-length", po::value<size_t>(&global_system_variables.max_sort_length)->default_value(1024)->notifier(&check_limits_max_sort_length),
1272
N_("The number of bytes to use when sorting BLOB or TEXT values "
1273
"(only the first max_sort_length bytes of each value are used; the "
1274
"rest are ignored)."))
1275
("max-write-lock-count", po::value<uint64_t>(&max_write_lock_count)->default_value(UINT64_MAX),
1276
N_("After this many write locks, allow some read locks to run in between."))
1277
("min-examined-row-limit", po::value<uint64_t>(&global_system_variables.min_examined_row_limit)->default_value(0)->notifier(&check_limits_merl),
1278
N_("Don't log queries which examine less than min_examined_row_limit "
1280
("disable-optimizer-prune",
1281
N_("Do not apply any heuristic(s) during query optimization to prune, "
1282
"thus perform an exhaustive search from the optimizer search space."))
1283
("optimizer-search-depth", po::value<uint32_t>(&global_system_variables.optimizer_search_depth)->default_value(0)->notifier(&check_limits_osd),
1284
N_("Maximum depth of search performed by the query optimizer. Values "
1285
"larger than the number of relations in a query result in better query "
1286
"plans, but take longer to compile a query. Smaller values than the "
1287
"number of tables in a relation result in faster optimization, but may "
1288
"produce very bad query plans. If set to 0, the system will "
1289
"automatically pick a reasonable value; if set to MAX_TABLES+2, the "
1290
"optimizer will switch to the original find_best (used for "
1291
"testing/comparison)."))
1292
("preload-buffer-size", po::value<uint64_t>(&global_system_variables.preload_buff_size)->default_value(32*1024L)->notifier(&check_limits_pbs),
1293
N_("The size of the buffer that is allocated when preloading indexes"))
1294
("query-alloc-block-size",
1295
po::value<uint32_t>(&global_system_variables.query_alloc_block_size)->default_value(QUERY_ALLOC_BLOCK_SIZE)->notifier(&check_limits_qabs),
1296
N_("Allocation block size for query parsing and execution"))
1297
("query-prealloc-size",
1298
po::value<uint32_t>(&global_system_variables.query_prealloc_size)->default_value(QUERY_ALLOC_PREALLOC_SIZE)->notifier(&check_limits_qps),
1299
N_("Persistent buffer for query parsing and execution"))
1300
("range-alloc-block-size",
1301
po::value<size_t>(&global_system_variables.range_alloc_block_size)->default_value(RANGE_ALLOC_BLOCK_SIZE)->notifier(&check_limits_rabs),
1302
N_("Allocation block size for storing ranges during optimization"))
1303
("read-buffer-size",
1304
po::value<uint32_t>(&global_system_variables.read_buff_size)->default_value(128*1024L)->notifier(&check_limits_read_buffer_size),
1305
N_("Each thread that does a sequential scan allocates a buffer of this "
1306
"size for each table it scans. If you do many sequential scans, you may "
1307
"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
("read-rnd-buffer-size",
1312
po::value<uint32_t>(&global_system_variables.read_rnd_buff_size)->default_value(256*1024L)->notifier(&check_limits_read_rnd_buffer_size),
1313
N_("When reading rows in sorted order after a sort, the rows are read "
1314
"through this buffer to avoid a disk seeks. If not set, then it's set "
1315
"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
("scheduler", po::value<string>(),
1320
N_("Select scheduler to be used (by default multi-thread)."))
1321
("sort-buffer-size",
1322
po::value<size_t>(&global_system_variables.sortbuff_size)->default_value(MAX_SORT_MEMORY)->notifier(&check_limits_sort_buffer_size),
1323
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
("table-definition-cache", po::value<size_t>(&table_def_size)->default_value(128)->notifier(&check_limits_tdc),
1328
N_("The number of cached table definitions."))
1329
("table-open-cache", po::value<uint64_t>(&table_cache_size)->default_value(TABLE_OPEN_CACHE_DEFAULT)->notifier(&check_limits_toc),
1330
N_("The number of cached open tables."))
1331
("table-lock-wait-timeout", po::value<uint64_t>(&table_lock_wait_timeout)->default_value(50)->notifier(&check_limits_tlwt),
1332
N_("Timeout in seconds to wait for a table level lock before returning an "
1333
"error. Used only if the connection has active cursors."))
1334
("thread-stack", po::value<size_t>(&my_thread_stack_size)->default_value(DEFAULT_THREAD_STACK)->notifier(&check_limits_thread_stack),
1335
N_("The stack size for each thread."))
1337
po::value<uint64_t>(&global_system_variables.tmp_table_size)->default_value(16*1024*1024L)->notifier(&check_limits_tmp_table_size),
1338
N_("If an internal in-memory temporary table exceeds this size, Drizzle will"
1339
" automatically convert it to an on-disk MyISAM table."))
1342
full_options.add(long_options);
1343
full_options.add(plugin_load_options);
1345
initial_options.add(config_options);
1346
initial_options.add(plugin_load_options);
1348
int style = po::command_line_style::default_style & ~po::command_line_style::allow_guessing;
1349
/* Get options about where config files and the like are */
1350
po::parsed_options parsed= po::command_line_parser(argc, argv).style(style).
1351
options(initial_options).allow_unregistered().run();
1353
po::collect_unrecognized(parsed.options, po::include_positional);
1357
po::store(parsed, vm);
1359
catch (std::exception&)
1361
errmsg_printf(ERRMSG_LVL_ERROR, _("Duplicate entry for command line option\n"));
1365
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
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())
1380
for (CachedDirectory::Entries::const_iterator iter= config_conf_d.getEntries().begin();
1381
iter != config_conf_d.getEntries().end();
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());
1398
/* TODO: here is where we should add a process_env_vars */
1400
/* 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
/* At this point, we've read all the options we need to read from files and
1433
collected most of them into unknown options - now let's load everything
1436
if (plugin_init(plugins, plugin_options))
1438
errmsg_printf(ERRMSG_LVL_ERROR, _("Failed to initialize plugins\n"));
1442
full_options.add(plugin_options);
1444
vector<string> final_unknown_options;
1447
po::parsed_options final_parsed=
1448
po::command_line_parser(unknown_options).style(style).
1449
options(full_options).extra_parser(dpo::parse_size_arg).run();
1451
final_unknown_options=
1452
po::collect_unrecognized(final_parsed.options, po::include_positional);
1454
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
catch (po::invalid_command_line_syntax &err)
1467
errmsg_printf(ERRMSG_LVL_ERROR,
1469
"Use --help to get a list of available options\n"),
1470
internal::my_progname, err.what());
1473
catch (po::unknown_option &err)
1475
errmsg_printf(ERRMSG_LVL_ERROR,
1476
_("%s\nUse --help to get a list of available options\n"),
1485
catch (po::validation_error &err)
1487
errmsg_printf(ERRMSG_LVL_ERROR,
1489
"Use --help to get a list of available options\n"),
1490
internal::my_progname, err.what());
1496
/* Inverted Booleans */
1498
global_system_variables.optimizer_prune_level=
1499
vm.count("disable-optimizer-prune") ? false : true;
1501
if (vm.count("help") == 0 && vm.count("help-extended") == 0)
1503
if ((user_info= check_user(drizzled_user)))
1505
set_user(drizzled_user, user_info);
743
strncpy(pidfile_name, glob_hostname, sizeof(pidfile_name)-5);
744
strcpy(internal::fn_ext(pidfile_name),".pid"); // Add proper extension
746
internal::load_defaults(conf_file_name, groups, &argc, &argv);
749
get_options(&defaults_argc, defaults_argv);
1511
751
current_pid= getpid(); /* Save for later ref */
1512
752
init_time(); /* Init time-functions (read zone) */
1514
754
if (item_create_init())
1518
758
/* Creates static regex matching for temporal values */
1519
759
if (! init_temporal_formats())
2190
1470
have_symlink=SHOW_OPTION_YES;
1474
if (!(tmpenv = getenv("MY_BASEDIR_VERSION")))
1476
(void) strncpy(drizzle_home, tmpenv, sizeof(drizzle_home)-1);
2193
1478
connection_count= 0;
2199
- FIXME add EXIT_TOO_MANY_ARGUMENTS to "drizzled/error.h" and return that code?
2201
static void get_options()
1482
int drizzled_get_one_option(int optid, const struct option *opt,
2204
fs::path &data_home_catalog= getDataHomeCatalog();
2205
data_home_catalog= getDataHome();
2206
data_home_catalog /= "local";
2208
if (vm.count("user"))
2210
if (! drizzled_user || ! strcmp(drizzled_user, vm["user"].as<string>().c_str()))
2211
drizzled_user= (char *)vm["user"].as<string>().c_str();
1487
global_system_variables.tx_isolation= ISO_SERIALIZABLE;
1490
strncpy(drizzle_home,argument,sizeof(drizzle_home)-1);
1493
if (default_collation_name == compiled_default_collation_name)
1494
default_collation_name= 0;
1497
strncpy(data_home_real,argument, sizeof(data_home_real)-1);
1498
/* Correct pointer set by my_getopt (for embedded library) */
1499
data_home= data_home_real;
1500
data_home_len= strlen(data_home);
1503
if (!drizzled_user || !strcmp(drizzled_user, argument))
1504
drizzled_user= argument;
2214
1506
errmsg_printf(ERRMSG_LVL_WARN, _("Ignoring user change to '%s' because the user was "
2215
"set to '%s' earlier on the command line\n"),
2216
vm["user"].as<string>().c_str(), drizzled_user);
2219
if (vm.count("version"))
1507
"set to '%s' earlier on the command line\n"),
1508
argument, drizzled_user);
1511
strncpy(language, argument, sizeof(language)-1);
2221
1514
print_version();
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
if (vm.count("exit-info"))
2279
if (vm["exit-info"].as<long>())
2281
test_flags.set((uint32_t) vm["exit-info"].as<long>());
2285
if (vm.count("want-core"))
1518
global_system_variables.log_warnings++;
1519
else if (argument == disabled_my_option)
1520
global_system_variables.log_warnings= 0L;
1522
global_system_variables.log_warnings= atoi(argument);
1527
test_flags.set((uint32_t) atoi(argument));
1530
case (int) OPT_WANT_CORE:
2287
1531
test_flags.set(TEST_CORE_ON_SIGNAL);
2290
if (vm.count("skip-stack-trace"))
1533
case (int) OPT_SKIP_STACK_TRACE:
2292
1534
test_flags.set(TEST_NO_STACKTRACE);
2295
if (vm.count("skip-symlinks"))
1536
case (int) OPT_SKIP_SYMLINKS:
2297
1537
internal::my_use_symdir=0;
2300
if (vm.count("transaction-isolation"))
2303
type= find_type_or_exit((char *)vm["transaction-isolation"].as<string>().c_str(), &tx_isolation_typelib, "transaction-isolation");
2304
global_system_variables.tx_isolation= (type-1);
2307
/* @TODO Make this all strings */
2308
if (vm.count("default-storage-engine"))
2310
default_storage_engine_str= (char *)vm["default-storage-engine"].as<string>().c_str();
1539
case (int) OPT_BIND_ADDRESS:
1541
struct addrinfo *res_lst, hints;
1543
memset(&hints, 0, sizeof(struct addrinfo));
1544
hints.ai_socktype= SOCK_STREAM;
1545
hints.ai_protocol= IPPROTO_TCP;
1547
if (getaddrinfo(argument, NULL, &hints, &res_lst) != 0)
1549
errmsg_printf(ERRMSG_LVL_ERROR, _("Can't start server: cannot resolve hostname!"));
1550
return EXIT_ARGUMENT_INVALID;
1553
if (res_lst->ai_next)
1555
errmsg_printf(ERRMSG_LVL_ERROR, _("Can't start server: bind-address refers to "
1556
"multiple interfaces!"));
1557
return EXIT_ARGUMENT_INVALID;
1559
freeaddrinfo(res_lst);
1562
case (int) OPT_PID_FILE:
1563
strncpy(pidfile_name, argument, sizeof(pidfile_name)-1);
1567
case OPT_TX_ISOLATION:
1570
type= find_type_or_exit(argument, &tx_isolation_typelib, opt->name);
1571
global_system_variables.tx_isolation= (type-1);
1574
case OPT_TC_HEURISTIC_RECOVER:
1575
tc_heuristic_recover= find_type_or_exit(argument,
1576
&tc_heuristic_recover_typelib,
1584
static void option_error_reporter(enum loglevel level, const char *format, ...)
1587
va_start(args, format);
1589
/* Don't print warnings for --loose options during bootstrap */
1590
if (level == ERROR_LEVEL || global_system_variables.log_warnings)
1592
plugin::ErrorMessage::vprintf(NULL, ERROR_LEVEL, format, args);
1600
- FIXME add EXIT_TOO_MANY_ARGUMENTS to "drizzled/error.h" and return that code?
1602
static void get_options(int *argc,char **argv)
1606
my_getopt_error_reporter= option_error_reporter;
1608
string progname(argv[0]);
2313
1610
/* Skip unknown options so that they may be processed later by plugins */
2314
1611
my_getopt_skip_unknown= true;
1613
if ((ho_error= handle_options(argc, &argv, my_long_options,
1614
drizzled_get_one_option)))
1616
(*argc)++; /* add back one for the progname handle_options removes */
1617
/* no need to do this for argv as we are discarding it. */
2317
1619
#if defined(HAVE_BROKEN_REALPATH)
2318
1620
internal::my_use_symdir=0;
2347
static void fix_paths()
2349
fs::path pid_file_path(pid_file);
2350
if (pid_file_path.root_path().string() == "")
2352
pid_file_path= getDataHome();
2353
pid_file_path /= pid_file;
2355
pid_file= fs::system_complete(pid_file_path);
2359
const char *tmp_string= getenv("TMPDIR") ? getenv("TMPDIR") : NULL;
1650
static const char *get_relative_path(const char *path)
1652
if (internal::test_if_hard_path(path) &&
1653
(strncmp(path, PREFIX, strlen(PREFIX)) == 0) &&
1654
strcmp(PREFIX,FN_ROOTDIR))
1656
if (strlen(PREFIX) < strlen(path))
1657
path+=(size_t) strlen(PREFIX);
1658
while (*path == FN_LIBCHAR)
1665
static void fix_paths(string &progname)
1667
char buff[FN_REFLEN],*pos,rp_buff[PATH_MAX];
1668
internal::convert_dirname(drizzle_home,drizzle_home,NULL);
1669
/* Resolve symlinks to allow 'drizzle_home' to be a relative symlink */
1670
#if defined(HAVE_BROKEN_REALPATH)
1671
internal::my_load_path(drizzle_home, drizzle_home, NULL);
1673
if (!realpath(drizzle_home,rp_buff))
1674
internal::my_load_path(rp_buff, drizzle_home, NULL);
1675
rp_buff[FN_REFLEN-1]= '\0';
1676
strcpy(drizzle_home,rp_buff);
1677
/* Ensure that drizzle_home ends in FN_LIBCHAR */
1678
pos= strchr(drizzle_home, '\0');
1680
if (pos[-1] != FN_LIBCHAR)
1685
internal::convert_dirname(data_home_real,data_home_real,NULL);
1686
(void) internal::fn_format(buff, data_home_real, "", "",
1687
(MY_RETURN_REAL_PATH|MY_RESOLVE_SYMLINKS));
1688
(void) internal::unpack_dirname(data_home_real_unpacked, buff);
1689
internal::convert_dirname(language,language,NULL);
1690
(void) internal::my_load_path(drizzle_home, drizzle_home,""); // Resolve current dir
1691
(void) internal::my_load_path(data_home_real, data_home_real,drizzle_home);
1692
(void) internal::my_load_path(pidfile_name, pidfile_name,data_home_real);
1694
if (opt_plugin_dir_ptr == NULL)
1696
/* No plugin dir has been specified. Figure out where the plugins are */
1697
if (progname[0] != FN_LIBCHAR)
1699
/* We have a relative path and need to find the absolute */
1700
char working_dir[FN_REFLEN];
1701
char *working_dir_ptr= working_dir;
1702
working_dir_ptr= getcwd(working_dir_ptr, FN_REFLEN);
1703
string new_path(working_dir);
1704
if (*(new_path.end()-1) != '/')
1705
new_path.push_back('/');
1706
if (progname[0] == '.' && progname[1] == '/')
1707
new_path.append(progname.substr(2));
1709
new_path.append(progname);
1710
progname.swap(new_path);
1713
/* Now, trim off the exe name */
1714
string progdir(progname.substr(0, progname.rfind(FN_LIBCHAR)+1));
1715
if (progdir.rfind(".libs/") != string::npos)
1717
progdir.assign(progdir.substr(0, progdir.rfind(".libs/")));
1719
string testlofile(progdir);
1720
testlofile.append("drizzled.lo");
1721
string testofile(progdir);
1722
testofile.append("drizzled.o");
1723
struct stat testfile_stat;
1724
if (stat(testlofile.c_str(), &testfile_stat) && stat(testofile.c_str(), &testfile_stat))
1726
/* neither drizzled.lo or drizzled.o exist - we are not in a source dir.
1729
(void) internal::my_load_path(opt_plugin_dir, get_relative_path(PKGPLUGINDIR),
1734
/* We are in a source dir! Plugin dir is ../plugin/.libs */
1735
size_t last_libchar_pos= progdir.rfind(FN_LIBCHAR,progdir.size()-2)+1;
1736
string source_plugindir(progdir.substr(0,last_libchar_pos));
1737
source_plugindir.append("plugin/.libs");
1738
(void) internal::my_load_path(opt_plugin_dir, source_plugindir.c_str(), "");
1743
(void) internal::my_load_path(opt_plugin_dir, opt_plugin_dir_ptr, drizzle_home);
1745
opt_plugin_dir_ptr= opt_plugin_dir;
1747
const char *sharedir= get_relative_path(PKGDATADIR);
1748
if (internal::test_if_hard_path(sharedir))
1749
strncpy(buff,sharedir,sizeof(buff)-1);
1752
strcpy(buff, drizzle_home);
1753
strncat(buff, sharedir, sizeof(buff)-strlen(drizzle_home)-1);
1755
internal::convert_dirname(buff,buff,NULL);
1756
(void) internal::my_load_path(language,language,buff);
1758
if (not opt_help and not opt_help_extended)
2360
1761
struct stat buf;
2361
drizzle_tmpdir.clear();
2363
if (vm.count("tmpdir"))
1763
tmp_string= getenv("TMPDIR");
1765
if (opt_drizzle_tmpdir)
2365
drizzle_tmpdir.append(vm["tmpdir"].as<string>());
1767
drizzle_tmpdir.append(opt_drizzle_tmpdir);
2367
1769
else if (tmp_string == NULL)
2369
drizzle_tmpdir.append(getDataHome().file_string());
2370
drizzle_tmpdir.push_back(FN_LIBCHAR);
2371
drizzle_tmpdir.append(GLOBAL_TEMPORARY_EXT);
1771
drizzle_tmpdir.append(data_home);
2375
1775
drizzle_tmpdir.append(tmp_string);
2378
drizzle_tmpdir= fs::path(fs::system_complete(fs::path(drizzle_tmpdir))).file_string();
2379
1778
assert(drizzle_tmpdir.size());
1779
if (stat(drizzle_tmpdir.c_str(), &buf) || (S_ISDIR(buf.st_mode) == false))
1781
perror(drizzle_tmpdir.c_str());
1785
drizzle_tmpdir.append(FN_ROOTDIR);
1786
drizzle_tmpdir.append(GLOBAL_TEMPORARY_EXT);
2381
1788
if (mkdir(drizzle_tmpdir.c_str(), 0777) == -1)