drizzle
C++ MySQL-protocol-compatible database server
Loading...
Searching...
No Matches
drizzled.cc
1/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3 *
4 * Copyright (C) 2008 Sun Microsystems, Inc.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 2 of the License.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 */
19
20#include <config.h>
21
22#include <drizzled/vc_version.h>
23#include <drizzled/configmake.h>
24#include <drizzled/atomics.h>
25#include <drizzled/data_home.h>
26
27#include <climits>
28#include <fcntl.h>
29#include <netdb.h>
30#include <netinet/in.h>
31#include <netinet/tcp.h>
32#include <signal.h>
33#include <stdexcept>
34#include <sys/stat.h>
35#include <sys/types.h>
36#include <sys/types.h>
37
38#include <boost/program_options.hpp>
39#include <drizzled/program_options/config_file.h>
40#include <boost/thread/recursive_mutex.hpp>
41#include <boost/thread/mutex.hpp>
42#include <boost/thread/shared_mutex.hpp>
43#include <boost/thread/condition_variable.hpp>
44#include <boost/filesystem.hpp>
45#include <boost/smart_ptr/detail/atomic_count.hpp>
46
48#include <drizzled/charset.h>
49#include <drizzled/data_home.h>
50#include <drizzled/debug.h>
51#include <drizzled/definition/cache.h>
52#include <drizzled/drizzled.h>
53#include <drizzled/errmsg_print.h>
54#include <drizzled/error.h>
55#include <drizzled/global_buffer.h>
56#include <drizzled/internal/my_bit.h>
57#include <drizzled/internal/my_sys.h>
58#include <drizzled/item/cmpfunc.h>
59#include <drizzled/item/create.h>
60#include <drizzled/message/cache.h>
61#include <drizzled/module/load_list.h>
62#include <drizzled/module/registry.h>
63#include <drizzled/plugin/client.h>
64#include <drizzled/plugin/error_message.h>
65#include <drizzled/plugin/event_observer.h>
66#include <drizzled/plugin/listen.h>
67#include <drizzled/plugin/monitored_in_transaction.h>
68#include <drizzled/plugin/scheduler.h>
69#include <drizzled/plugin/storage_engine.h>
70#include <drizzled/plugin/xa_resource_manager.h>
71#include <drizzled/probes.h>
72#include <drizzled/replication_services.h> /* For ReplicationServices::evaluateRegisteredPlugins() */
73#include <drizzled/session.h>
74#include <drizzled/session/cache.h>
75#include <drizzled/show.h>
76#include <drizzled/sql_base.h>
77#include <drizzled/sql_parse.h>
78#include <drizzled/statistics_variables.h>
79#include <drizzled/table/cache.h>
80#include <drizzled/temporal_format.h> /* For init_temporal_formats() */
81#include <drizzled/drizzled_abort.h>
82#include <plugin/myisam/myisam.h>
83#include <drizzled/typelib.h>
84#include <drizzled/visibility.h>
85#include <drizzled/system_variables.h>
86#include <drizzled/open_tables_state.h>
87
88#include <google/protobuf/stubs/common.h>
89
90#include <sys/time.h>
91#include <time.h>
92
93#include <sys/prctl.h>
94#include <sys/socket.h>
95
96
97#include <errno.h>
98#include <sys/stat.h>
99#include <drizzled/option.h>
100#ifdef HAVE_SYSENT_H
101#include <sysent.h>
102#endif
103#include <pwd.h> // For getpwent
104#include <grp.h>
105
106
107#include <sys/select.h>
108
109#include <sys/utsname.h>
110
111#include <sys/mman.h>
112
113
114#include <fpu_control.h>
115
116
117#include <drizzled/internal/my_pthread.h> // For thr_setconcurency()
118#include <drizzled/constrained_value.h>
119
120#include <drizzled/gettext.h>
121
122
123#ifdef HAVE_VALGRIND
124#define IF_PURIFY(A,B) (A)
125#else
126#define IF_PURIFY(A,B) (B)
127#endif
128
129#define MAX_MEM_TABLE_SIZE SIZE_MAX
130#include <iostream>
131#include <fstream>
132
133
134using namespace std;
135namespace fs=boost::filesystem;
136namespace po=boost::program_options;
137namespace dpo=drizzled::program_options;
138
139namespace drizzled {
140
141inline void setup_fpu()
142{
143
144 /*
145 x86 (32-bit) requires FPU precision to be explicitly set to 64 bit for
146 portable results of floating point operations
147 */
148#if defined(__i386__) && defined(_FPU_DOUBLE)
149 fpu_control_t cw;
150 _FPU_GETCW(cw);
151 cw= (cw & ~_FPU_EXTENDED) | _FPU_DOUBLE;
152 _FPU_SETCW(cw);
153#endif /* __i386__ && _FPU_DOUBLE */
154}
155
156
157const char *first_keyword= "first";
158const char * const DRIZZLE_CONFIG_NAME= "drizzled";
159
160#define GET_HA_ROWS GET_ULL
161
162const char *tx_isolation_names[] = {"READ-UNCOMMITTED", "READ-COMMITTED", "REPEATABLE-READ", "SERIALIZABLE", NULL};
163
164TYPELIB tx_isolation_typelib= {array_elements(tx_isolation_names) - 1, "", tx_isolation_names, NULL};
165
166arg_cmp_func Arg_comparator::comparator_matrix[5][2] =
167{{&Arg_comparator::compare_string, &Arg_comparator::compare_e_string},
168 {&Arg_comparator::compare_real, &Arg_comparator::compare_e_real},
169 {&Arg_comparator::compare_int_signed, &Arg_comparator::compare_e_int},
170 {&Arg_comparator::compare_row, &Arg_comparator::compare_e_row},
171 {&Arg_comparator::compare_decimal, &Arg_comparator::compare_e_decimal}};
172
173/* static variables */
174
175static bool opt_debugging= false;
176static uint32_t wake_thread;
177static const char* drizzled_chroot;
178static const char* default_character_set_name= "utf8";
179static const char* lc_time_names_name= "en_US";
180static const char* default_storage_engine_str= "innodb";
181static const char* const compiled_default_collation_name= "utf8_general_ci";
182static const char* default_collation_name= compiled_default_collation_name;
183
184/* Global variables */
185
186const char *drizzled_user;
187bool volatile select_thread_in_use;
188bool volatile abort_loop;
189DRIZZLED_API bool volatile shutdown_in_progress;
190const char* opt_scheduler= "multi_thread";
191
192DRIZZLED_API size_t my_thread_stack_size= 0;
193
194/*
195 Legacy global plugin::StorageEngine. These will be removed (please do not add more).
196*/
197plugin::StorageEngine *heap_engine;
198plugin::StorageEngine *myisam_engine;
199
201
202uint32_t drizzled_bind_timeout;
203uint32_t dropping_tables, ha_open_options;
204uint32_t tc_heuristic_recover= 0;
205uint64_t session_startup_options;
206back_log_constraints back_log(SOMAXCONN);
207DRIZZLED_API uint32_t server_id;
208DRIZZLED_API string server_uuid;
209uint64_t table_cache_size;
210size_t table_def_size;
211uint32_t global_thread_id= 1UL;
212pid_t current_pid;
213
214extern const double log_10[309];
215
216const double log_10[] = {
217 1e000, 1e001, 1e002, 1e003, 1e004, 1e005, 1e006, 1e007, 1e008, 1e009,
218 1e010, 1e011, 1e012, 1e013, 1e014, 1e015, 1e016, 1e017, 1e018, 1e019,
219 1e020, 1e021, 1e022, 1e023, 1e024, 1e025, 1e026, 1e027, 1e028, 1e029,
220 1e030, 1e031, 1e032, 1e033, 1e034, 1e035, 1e036, 1e037, 1e038, 1e039,
221 1e040, 1e041, 1e042, 1e043, 1e044, 1e045, 1e046, 1e047, 1e048, 1e049,
222 1e050, 1e051, 1e052, 1e053, 1e054, 1e055, 1e056, 1e057, 1e058, 1e059,
223 1e060, 1e061, 1e062, 1e063, 1e064, 1e065, 1e066, 1e067, 1e068, 1e069,
224 1e070, 1e071, 1e072, 1e073, 1e074, 1e075, 1e076, 1e077, 1e078, 1e079,
225 1e080, 1e081, 1e082, 1e083, 1e084, 1e085, 1e086, 1e087, 1e088, 1e089,
226 1e090, 1e091, 1e092, 1e093, 1e094, 1e095, 1e096, 1e097, 1e098, 1e099,
227 1e100, 1e101, 1e102, 1e103, 1e104, 1e105, 1e106, 1e107, 1e108, 1e109,
228 1e110, 1e111, 1e112, 1e113, 1e114, 1e115, 1e116, 1e117, 1e118, 1e119,
229 1e120, 1e121, 1e122, 1e123, 1e124, 1e125, 1e126, 1e127, 1e128, 1e129,
230 1e130, 1e131, 1e132, 1e133, 1e134, 1e135, 1e136, 1e137, 1e138, 1e139,
231 1e140, 1e141, 1e142, 1e143, 1e144, 1e145, 1e146, 1e147, 1e148, 1e149,
232 1e150, 1e151, 1e152, 1e153, 1e154, 1e155, 1e156, 1e157, 1e158, 1e159,
233 1e160, 1e161, 1e162, 1e163, 1e164, 1e165, 1e166, 1e167, 1e168, 1e169,
234 1e170, 1e171, 1e172, 1e173, 1e174, 1e175, 1e176, 1e177, 1e178, 1e179,
235 1e180, 1e181, 1e182, 1e183, 1e184, 1e185, 1e186, 1e187, 1e188, 1e189,
236 1e190, 1e191, 1e192, 1e193, 1e194, 1e195, 1e196, 1e197, 1e198, 1e199,
237 1e200, 1e201, 1e202, 1e203, 1e204, 1e205, 1e206, 1e207, 1e208, 1e209,
238 1e210, 1e211, 1e212, 1e213, 1e214, 1e215, 1e216, 1e217, 1e218, 1e219,
239 1e220, 1e221, 1e222, 1e223, 1e224, 1e225, 1e226, 1e227, 1e228, 1e229,
240 1e230, 1e231, 1e232, 1e233, 1e234, 1e235, 1e236, 1e237, 1e238, 1e239,
241 1e240, 1e241, 1e242, 1e243, 1e244, 1e245, 1e246, 1e247, 1e248, 1e249,
242 1e250, 1e251, 1e252, 1e253, 1e254, 1e255, 1e256, 1e257, 1e258, 1e259,
243 1e260, 1e261, 1e262, 1e263, 1e264, 1e265, 1e266, 1e267, 1e268, 1e269,
244 1e270, 1e271, 1e272, 1e273, 1e274, 1e275, 1e276, 1e277, 1e278, 1e279,
245 1e280, 1e281, 1e282, 1e283, 1e284, 1e285, 1e286, 1e287, 1e288, 1e289,
246 1e290, 1e291, 1e292, 1e293, 1e294, 1e295, 1e296, 1e297, 1e298, 1e299,
247 1e300, 1e301, 1e302, 1e303, 1e304, 1e305, 1e306, 1e307, 1e308
248};
249
250time_t server_start_time;
252
253fs::path basedir(PREFIX);
254fs::path pid_file;
255fs::path secure_file_priv;
256fs::path plugin_dir;
257fs::path system_config_dir(SYSCONFDIR);
258
259const key_map key_map_empty(0);
260key_map key_map_full(0); // Will be initialized later
261
262std::string drizzle_tmpdir;
263char *opt_drizzle_tmpdir= NULL;
264
266const char *in_left_expr_name= "<left expr>";
268const char *in_additional_cond= "<IN COND>";
269const char *in_having_cond= "<IN HAVING>";
270
271/* classes for comparation parsing/processing */
272
273FILE *stderror_file=0;
274
275drizzle_system_variables global_system_variables;
276drizzle_system_variables max_system_variables;
277global_counters current_global_counters;
278
279DRIZZLED_API const charset_info_st *system_charset_info;
280const charset_info_st *files_charset_info;
281const charset_info_st *table_alias_charset;
282const charset_info_st *character_set_filesystem;
283
284MY_LOCALE *my_default_lc_time_names;
285
286SHOW_COMP_OPTION have_symlink;
287
288boost::condition_variable_any COND_refresh;
289boost::condition_variable COND_thread_count;
290pthread_t signal_thread;
291
292/* Static variables */
293
294int cleanup_done;
295
296passwd *user_info;
297
298boost::detail::atomic_count connection_count(0);
299
300global_buffer_constraint<uint64_t> global_sort_buffer(0);
301global_buffer_constraint<uint64_t> global_join_buffer(0);
302global_buffer_constraint<uint64_t> global_read_rnd_buffer(0);
303global_buffer_constraint<uint64_t> global_read_buffer(0);
304
305DRIZZLED_API size_t transaction_message_threshold;
306
307static void drizzle_init_variables();
308static void get_options();
309static void fix_paths();
310
311void close_connections();
312
313fs::path base_plugin_dir(PKGPLUGINDIR);
314
315po::options_description general_options(_("General Options"));
316po::options_description config_options(_("Config File Options"));
317po::options_description long_options(_("Kernel Options"));
318po::options_description plugin_load_options(_("Plugin Loading Options"));
319po::options_description plugin_options(_("Plugin Options"));
320po::options_description initial_options(_("Config and Plugin Loading"));
321po::options_description full_options(_("Kernel and Plugin Loading and Plugin"));
322vector<string> unknown_options;
323vector<string> defaults_file_list;
324po::variables_map vm;
325
326po::variables_map &getVariablesMap()
327{
328 return vm;
329}
330
331static std::string g_hostname= "localhost";
332
333const std::string& getServerHostname()
334{
335 return g_hostname;
336}
337
338static void print_version()
339{
340 /*
341 Note: the instance manager keys off the string 'Ver' so it can find the
342 version from the output of 'drizzled --version', so don't change it!
343 */
344 printf("%s Ver %s for %s-%s on %s (%s)\n", internal::my_progname,
345 DRIZZLE_RELEASE_VERSION, HOST_VENDOR, HOST_OS, HOST_CPU, COMPILATION_COMMENT);
346}
347
348extern "C" {
349
350 char at_exit_pid_file[1024 * 4]= { 0 };
351
352 static void remove_pidfile(void)
353 {
354 if (at_exit_pid_file[0])
355 {
356 if (unlink(at_exit_pid_file) == -1)
357 {
358 std::cerr << "Could not remove pidfile: " << at_exit_pid_file << "(" << strerror(errno) << ")" << std::endl;
359 }
360
361 at_exit_pid_file[0]= 0;
362 }
363 }
364}
365
369
370#ifndef O_CLOEXEC
371#define O_CLOEXEC 0
372#define DEFINED_O_CLOEXEC
373#endif
374
375static void create_pid_file()
376{
377 int file;
378
379 if ((file = open(pid_file.string().c_str(), O_CREAT|O_WRONLY|O_TRUNC|O_CLOEXEC, S_IRWXU|S_IRGRP|S_IROTH)) > 0)
380 {
381 char buff[1024];
382 int length= snprintf(buff, sizeof(buff), "%ld\n", (long) getpid());
383
384 if ((write(file, buff, length)) == length)
385 {
386 if (close(file) != -1)
387 {
388 snprintf(at_exit_pid_file, sizeof(at_exit_pid_file), "%s", pid_file.string().c_str());
389 atexit(remove_pidfile);
390 return;
391 }
392 }
393 (void)close(file); /* We can ignore the error, since we are going to error anyway at this point */
394 }
395
396 drizzled_abort << "Can't start server, was unable to create PID file: " << pid_file.string();
397}
398
399#ifdef DEFINED_O_CLOEXEC
400#undef O_CLOEXEC
401#endif
402
403/****************************************************************************
404** Code to end drizzled
405****************************************************************************/
406
407void close_connections()
408{
409 /* Abort listening to new connections */
411
412 /* kill connection thread */
413 {
414 boost::mutex::scoped_lock scopedLock(session::Cache::mutex());
415
416 while (select_thread_in_use)
417 {
418 boost::xtime xt;
419#if BOOST_VERSION >= 105000
420 xtime_get(&xt, boost::TIME_UTC_);
421#else
422 xtime_get(&xt, boost::TIME_UTC);
423#endif
424 xt.sec += 2;
425
426 for (uint32_t tmp=0 ; tmp < 10 && select_thread_in_use; tmp++)
427 {
428 bool success= COND_thread_count.timed_wait(scopedLock, xt);
429 if (not success)
430 break;
431 }
432 }
433 }
434
435
436 /*
437 First signal all threads that it's time to die
438 This will give the threads some time to gracefully abort their
439 statements and inform their clients that the server is about to die.
440 */
441
442 {
443 boost::mutex::scoped_lock scopedLock(session::Cache::mutex());
444 session::Cache::list list= session::Cache::getCache();
445
446 for (session::Cache::list::reference tmp : list)
447 {
448 tmp->setKilled(Session::KILL_CONNECTION);
449 tmp->scheduler->killSession(tmp.get());
450 DRIZZLE_CONNECTION_DONE(tmp->thread_id);
451
452 tmp->lockOnSys();
453 }
454 }
455
456 if (session::Cache::count()) // Give threads time to die
457 {
458 struct timespec requested;
459 requested.tv_sec= 2;
460 requested.tv_nsec= 0;
461 nanosleep(&requested, NULL);
462 }
463
464 /*
465 Force remaining threads to die by closing the connection to the client
466 This will ensure that threads that are waiting for a command from the
467 client on a blocking read call are aborted.
468 */
469 for (;;)
470 {
471 boost::mutex::scoped_lock scopedLock(session::Cache::mutex());
472 session::Cache::list list= session::Cache::getCache();
473
474 if (list.empty())
475 {
476 break;
477 }
478 /* Close before unlock, avoiding crash. See LP bug#436685 */
479 list.front()->getClient()->close();
480 }
481}
482
483static bool drizzled_startup_completed= false;
484void drizzled_startup_finished()
485{
486 drizzled_startup_completed= true;
487}
488
489void drizzled_exit()
490{
491 internal::my_end();
492 assert(drizzled_startup_completed == false);
493 exit(EXIT_SUCCESS);
494}
495
496void drizzled_actual_abort(const char *file, int line, const char *func, const std::string& message)
497{
498 std::stringstream temp;
499 temp << _("Aborting:") << "\"" << message << "\"" << ". Abort was called from " << file << ":" << line << " in " << func << "()";
500 errmsg_printf(error::ERROR, "%s", temp.str().c_str());
501
502 clean_up(vm.count("help") == 0);
503 internal::my_end();
504
505 assert(drizzled_startup_completed == false);
506 exit(EXIT_FAILURE);
507}
508
509
510void clean_up(bool print_message)
511{
512 if (cleanup_done++)
513 {
514 return;
515 }
516
517 table_cache_free();
518 free_charsets();
519 module::Registry &modules= module::Registry::singleton();
520 modules.shutdownModules();
521
523
524#if GOOGLE_PROTOBUF_VERSION >= 2001000
525 google::protobuf::ShutdownProtobufLibrary();
526#endif
527
528 if (print_message && server_start_time)
529 {
530 errmsg_printf(drizzled::error::INFO, _(ER(ER_SHUTDOWN_COMPLETE)),internal::my_progname);
531 }
532
533 session::Cache::shutdownFirst();
534
535 /*
536 The following lines may never be executed as the main thread may have
537 killed us
538 */
539} /* clean_up */
540
541
542/* Change to run as another user if started with --user */
543
544passwd *check_user(const char *user)
545{
546 passwd *tmp_user_info;
547 uid_t user_id= geteuid();
548
549 // Don't bother if we aren't superuser
550 if (user_id)
551 {
552 if (user)
553 {
554 /* Don't give a warning, if real user is same as given with --user */
555 tmp_user_info= getpwnam(user);
556 if ((!tmp_user_info || user_id != tmp_user_info->pw_uid) &&
557 global_system_variables.log_warnings)
558 {
559 errmsg_printf(error::WARN, _("One can only use the --user switch if running as root"));
560 }
561 }
562 return NULL;
563 }
564
565 if (user == NULL || strcmp(user, "root") == 0)
566 {
567 // No --user given, or --user=root: run as root without changing
568 // identity. user==NULL reached here only as the superuser, so a
569 // bare strcmp() would dereference NULL.
570 return NULL; // Avoid problem with dynamic libraries
571 }
572
573 bool failed= false;
574 if ((tmp_user_info= getpwnam(user)) == NULL)
575 {
576 // Allow a numeric uid to be used
577 const char *pos= user;
578 for (; my_charset_utf8_general_ci.isdigit(*pos); pos++)
579 { }
580 if (*pos) // Not numeric id
581 {
582 failed= true;
583 }
584
585 if ((tmp_user_info= getpwuid(atoi(user))) == NULL)
586 {
587 failed= true;
588 }
589 }
590
591 if (failed)
592 {
593 drizzled_abort << "Fatal error: Can't change to run as user '" << user << "' ; Please check that the user exists!";
594
595#ifdef PR_SET_DUMPABLE
596 if (getDebug().test(debug::CORE_ON_SIGNAL))
597 {
598 /* inform kernel that process is dumpable */
599 (void) prctl(PR_SET_DUMPABLE, 1);
600 }
601#endif
602
603 return NULL;
604 }
605
606 return tmp_user_info;
607}
608
609void set_user(const char *user, passwd *user_info_arg)
610{
611 assert(user_info_arg != 0);
612 initgroups(user, user_info_arg->pw_gid);
613 if (setgid(user_info_arg->pw_gid) == -1)
614 {
615 drizzled_abort << _("Set process group ID failed ") << strerror(errno);
616 }
617 if (setuid(user_info_arg->pw_uid) == -1)
618 {
619 drizzled_abort << _("Set process user ID failed") << strerror(errno);
620 }
621}
622
623
624
626static void set_root(const char *path)
627{
628 if ((chroot(path) == -1) or chdir("/") == 0)
629 {
630 drizzled_abort << _("Process chroot failed");
631 }
632}
633
634
635/*
636 Unlink session from global list of available connections and free session
637
638 SYNOPSIS
639 Session::unlink()
640 session Thread handler
641*/
642
643void Session::unlink(session_id_t &session_id)
644{
645 Session::shared_ptr session= session::Cache::find(session_id);
646
647 if (session)
648 unlink(session);
649}
650
651void Session::unlink(const Session::shared_ptr& session)
652{
653 --connection_count;
654
655 session->cleanup();
656
657 boost::mutex::scoped_lock scopedLock(session::Cache::mutex());
658
659 if (DRIZZLE_UNLIKELY(plugin::EventObserver::disconnectSession(*session)))
660 {
661 // We should do something about an error...
662 }
663 session::Cache::erase(session);
664}
665
666
667#ifndef SA_RESETHAND
668#define SA_RESETHAND 0
669#endif
670#ifndef SA_NODEFER
671#define SA_NODEFER 0
672#endif
673
674
675
676
677const char *load_default_groups[]=
678{
679 DRIZZLE_CONFIG_NAME, "server", 0, 0
680};
681
682static void find_plugin_dir(string progname)
683{
684 fs::path full_progname(fs::system_complete(progname));
685
686 fs::path progdir(full_progname.parent_path());
687 if (progdir.filename() == ".libs")
688 {
689 progdir= progdir.parent_path();
690 }
691
692 if (fs::exists(progdir / "drizzled.lo") || fs::exists(progdir / "drizzled.o"))
693 {
694 /* We are in a source dir! Plugin dir is ../plugin/.libs */
695 base_plugin_dir= progdir.parent_path();
696 base_plugin_dir /= "plugin";
697 base_plugin_dir /= ".libs";
698 }
699
700 if (plugin_dir.root_directory() == "")
701 {
702 fs::path full_plugin_dir(fs::system_complete(base_plugin_dir));
703 full_plugin_dir /= plugin_dir;
704 plugin_dir= full_plugin_dir;
705 }
706}
707
708static void notify_plugin_dir(fs::path in_plugin_dir)
709{
710 plugin_dir= in_plugin_dir;
711 if (plugin_dir.root_directory() == "")
712 {
713 fs::path full_plugin_dir(fs::system_complete(basedir));
714 full_plugin_dir /= plugin_dir;
715 plugin_dir= full_plugin_dir;
716 }
717}
718
719static void expand_secure_file_priv(fs::path in_secure_file_priv)
720{
721 secure_file_priv= fs::system_complete(in_secure_file_priv);
722}
723
724static void check_limits_aii(uint64_t in_auto_increment_increment)
725{
726 global_system_variables.auto_increment_increment= 1;
727 if (in_auto_increment_increment < 1 || in_auto_increment_increment > UINT64_MAX)
728 {
729 drizzled_abort << _("Invalid Value for auto_increment_increment");
730 }
731 global_system_variables.auto_increment_increment= in_auto_increment_increment;
732}
733
734static void check_limits_aio(uint64_t in_auto_increment_offset)
735{
736 global_system_variables.auto_increment_offset= 1;
737 if (in_auto_increment_offset < 1 || in_auto_increment_offset > UINT64_MAX)
738 {
739 drizzled_abort << _("Invalid Value for auto_increment_offset");
740 }
741 global_system_variables.auto_increment_offset= in_auto_increment_offset;
742}
743
744static void check_limits_completion_type(uint32_t in_completion_type)
745{
746 global_system_variables.completion_type= 0;
747 if (in_completion_type > 2)
748 {
749 drizzled_abort << _("Invalid Value for completion_type");
750 }
751 global_system_variables.completion_type= in_completion_type;
752}
753
754
755static void check_limits_dpi(uint32_t in_div_precincrement)
756{
757 global_system_variables.div_precincrement= 4;
758 if (in_div_precincrement > DECIMAL_MAX_SCALE)
759 {
760 drizzled_abort << _("Invalid Value for div-precision-increment");
761 }
762 global_system_variables.div_precincrement= in_div_precincrement;
763}
764
765static void check_limits_gcml(uint64_t in_group_concat_max_len)
766{
767 global_system_variables.group_concat_max_len= 1024;
768 if (in_group_concat_max_len > ULONG_MAX || in_group_concat_max_len < 4)
769 {
770 drizzled_abort << _("Invalid Value for group_concat_max_len");
771 }
772 global_system_variables.group_concat_max_len= in_group_concat_max_len;
773}
774
775static void check_limits_join_buffer_size(uint64_t in_join_buffer_size)
776{
777 global_system_variables.join_buff_size= (128*1024L);
778 if (in_join_buffer_size < IO_SIZE*2 || in_join_buffer_size > ULONG_MAX)
779 {
780 drizzled_abort << _("Invalid Value for join_buffer_size");
781 }
782 in_join_buffer_size-= in_join_buffer_size % IO_SIZE;
783 global_system_variables.join_buff_size= in_join_buffer_size;
784}
785
786static void check_limits_map(uint32_t in_max_allowed_packet)
787{
788 global_system_variables.max_allowed_packet= (64*1024*1024L);
789 if (in_max_allowed_packet < 1024 || in_max_allowed_packet > 1024*1024L*1024L)
790 {
791 drizzled_abort << _("Invalid Value for max_allowed_packet");
792 }
793 in_max_allowed_packet-= in_max_allowed_packet % 1024;
794 global_system_variables.max_allowed_packet= in_max_allowed_packet;
795}
796
797static void check_limits_max_err_cnt(uint64_t in_max_error_count)
798{
799 global_system_variables.max_error_count= DEFAULT_ERROR_COUNT;
800 if (in_max_error_count > 65535)
801 {
802 drizzled_abort << _("Invalid Value for max_error_count");
803 }
804 global_system_variables.max_error_count= in_max_error_count;
805}
806
807static void check_limits_mhts(uint64_t in_max_heap_table_size)
808{
809 global_system_variables.max_heap_table_size= (16*1024*1024L);
810 if (in_max_heap_table_size < 16384 || in_max_heap_table_size > MAX_MEM_TABLE_SIZE)
811 {
812 drizzled_abort << _("Invalid Value for max_heap_table_size");
813 }
814 in_max_heap_table_size-= in_max_heap_table_size % 1024;
815 global_system_variables.max_heap_table_size= in_max_heap_table_size;
816}
817
818static void check_limits_merl(uint64_t in_min_examined_row_limit)
819{
820 global_system_variables.min_examined_row_limit= 0;
821 if (in_min_examined_row_limit > ULONG_MAX)
822 {
823 drizzled_abort << _("Invalid Value for min_examined_row_limit");
824 }
825 global_system_variables.min_examined_row_limit= in_min_examined_row_limit;
826}
827
828static void check_limits_max_join_size(ha_rows in_max_join_size)
829{
830 global_system_variables.max_join_size= INT32_MAX;
831 if ((uint64_t)in_max_join_size < 1 || (uint64_t)in_max_join_size > INT32_MAX)
832 {
833 drizzled_abort << _("Invalid Value for max_join_size");
834 }
835 global_system_variables.max_join_size= in_max_join_size;
836}
837
838static void check_limits_mlfsd(int64_t in_max_length_for_sort_data)
839{
840 global_system_variables.max_length_for_sort_data= 1024;
841 if (in_max_length_for_sort_data < 4 || in_max_length_for_sort_data > 8192*1024L)
842 {
843 drizzled_abort << _("Invalid Value for max_length_for_sort_data");
844 }
845 global_system_variables.max_length_for_sort_data= in_max_length_for_sort_data;
846}
847
848static void check_limits_msfk(uint64_t in_max_seeks_for_key)
849{
850 global_system_variables.max_seeks_for_key= ULONG_MAX;
851 if (in_max_seeks_for_key < 1 || in_max_seeks_for_key > ULONG_MAX)
852 {
853 drizzled_abort << _("Invalid Value for max_seeks_for_key");
854 }
855 global_system_variables.max_seeks_for_key= in_max_seeks_for_key;
856}
857
858static void check_limits_max_sort_length(size_t in_max_sort_length)
859{
860 global_system_variables.max_sort_length= 1024;
861 if ((int64_t)in_max_sort_length < 4 || (int64_t)in_max_sort_length > 8192*1024L)
862 {
863 drizzled_abort << _("Invalid Value for max_sort_length");
864 }
865 global_system_variables.max_sort_length= in_max_sort_length;
866}
867
868static void check_limits_osd(uint32_t in_optimizer_search_depth)
869{
870 global_system_variables.optimizer_search_depth= 0;
871 if (in_optimizer_search_depth > MAX_TABLES + 2)
872 {
873 drizzled_abort << _("Invalid Value for optimizer_search_depth");
874 }
875 global_system_variables.optimizer_search_depth= in_optimizer_search_depth;
876}
877
878static void check_limits_pbs(uint64_t in_preload_buff_size)
879{
880 global_system_variables.preload_buff_size= (32*1024L);
881 if (in_preload_buff_size < 1024 || in_preload_buff_size > 1024*1024*1024L)
882 {
883 drizzled_abort << _("Invalid Value for preload_buff_size");
884 }
885 global_system_variables.preload_buff_size= in_preload_buff_size;
886}
887
888static void check_limits_qabs(uint32_t in_query_alloc_block_size)
889{
890 global_system_variables.query_alloc_block_size= QUERY_ALLOC_BLOCK_SIZE;
891 if (in_query_alloc_block_size < 1024)
892 {
893 drizzled_abort << _("Invalid Value for query_alloc_block_size");
894 }
895 in_query_alloc_block_size-= in_query_alloc_block_size % 1024;
896 global_system_variables.query_alloc_block_size= in_query_alloc_block_size;
897}
898
899static void check_limits_qps(uint32_t in_query_prealloc_size)
900{
901 global_system_variables.query_prealloc_size= QUERY_ALLOC_PREALLOC_SIZE;
902 if (in_query_prealloc_size < QUERY_ALLOC_PREALLOC_SIZE)
903 {
904 drizzled_abort << _("Invalid Value for query_prealloc_size");
905 }
906 in_query_prealloc_size-= in_query_prealloc_size % 1024;
907 global_system_variables.query_prealloc_size= in_query_prealloc_size;
908}
909
910static void check_limits_rabs(size_t in_range_alloc_block_size)
911{
912 global_system_variables.range_alloc_block_size= RANGE_ALLOC_BLOCK_SIZE;
913 if (in_range_alloc_block_size < RANGE_ALLOC_BLOCK_SIZE)
914 {
915 drizzled_abort << _("Invalid Value for range_alloc_block_size");
916 }
917 in_range_alloc_block_size-= in_range_alloc_block_size % 1024;
918 global_system_variables.range_alloc_block_size= in_range_alloc_block_size;
919}
920
921static void check_limits_read_buffer_size(int32_t in_read_buff_size)
922{
923 global_system_variables.read_buff_size= (128*1024L);
924 if (in_read_buff_size < IO_SIZE*2 || in_read_buff_size > INT32_MAX)
925 {
926 drizzled_abort << _("Invalid Value for read_buff_size");
927 }
928 in_read_buff_size-= in_read_buff_size % IO_SIZE;
929 global_system_variables.read_buff_size= in_read_buff_size;
930}
931
932static void check_limits_read_rnd_buffer_size(uint32_t in_read_rnd_buff_size)
933{
934 global_system_variables.read_rnd_buff_size= (256*1024L);
935 if (in_read_rnd_buff_size < 64 || in_read_rnd_buff_size > UINT32_MAX)
936 {
937 drizzled_abort << _("Invalid Value for read_rnd_buff_size");
938 }
939 global_system_variables.read_rnd_buff_size= in_read_rnd_buff_size;
940}
941
942static void check_limits_sort_buffer_size(size_t in_sortbuff_size)
943{
944 global_system_variables.sortbuff_size= MAX_SORT_MEMORY;
945 if ((uint32_t)in_sortbuff_size < MIN_SORT_MEMORY)
946 {
947 drizzled_abort << _("Invalid Value for sort_buff_size");
948 }
949 global_system_variables.sortbuff_size= in_sortbuff_size;
950}
951
952static void check_limits_tdc(uint32_t in_table_def_size)
953{
954 table_def_size= 128;
955 if (in_table_def_size < 1 || in_table_def_size > 512*1024L)
956 {
957 drizzled_abort << _("Invalid Value for table_def_size");
958 }
959 table_def_size= in_table_def_size;
960}
961
962static void check_limits_toc(uint32_t in_table_cache_size)
963{
964 table_cache_size= TABLE_OPEN_CACHE_DEFAULT;
965 if (in_table_cache_size < TABLE_OPEN_CACHE_MIN || in_table_cache_size > 512*1024L)
966 {
967 drizzled_abort << _("Invalid Value for table_cache_size");
968 }
969 table_cache_size= in_table_cache_size;
970}
971
972static void check_limits_tlwt(uint64_t in_table_lock_wait_timeout)
973{
974 table_lock_wait_timeout= 50;
975 if (in_table_lock_wait_timeout < 1 || in_table_lock_wait_timeout > 1024*1024*1024)
976 {
977 drizzled_abort << _("Invalid Value for table_lock_wait_timeout");
978 }
979 table_lock_wait_timeout= in_table_lock_wait_timeout;
980}
981
982static void check_limits_thread_stack(uint32_t in_my_thread_stack_size)
983{
984 my_thread_stack_size= in_my_thread_stack_size - (in_my_thread_stack_size % 1024);
985}
986
987static void check_limits_tmp_table_size(uint64_t in_tmp_table_size)
988{
989 global_system_variables.tmp_table_size= 16*1024*1024L;
990 if (in_tmp_table_size < 1024 || in_tmp_table_size > MAX_MEM_TABLE_SIZE)
991 {
992 drizzled_abort << _("Invalid Value for table_lock_wait_timeout");
993 }
994 global_system_variables.tmp_table_size= in_tmp_table_size;
995}
996
997static void check_limits_transaction_message_threshold(size_t in_transaction_message_threshold)
998{
999 transaction_message_threshold= 1024*1024;
1000 if ((int64_t) in_transaction_message_threshold < 128*1024 || (int64_t)in_transaction_message_threshold > 1024*1024)
1001 {
1002 drizzled_abort << _("Invalid Value for transaction_message_threshold valid values are between 131072 - 1048576 bytes");
1003 }
1004 transaction_message_threshold= in_transaction_message_threshold;
1005}
1006
1007static void process_defaults_files()
1008{
1009 for (vector<string>::reference iter : defaults_file_list)
1010 {
1011 fs::path file_location= iter;
1012
1013 ifstream input_defaults_file(file_location.string().c_str());
1014
1015 po::parsed_options file_parsed= dpo::parse_config_file(input_defaults_file, full_options, true);
1016 vector<string> file_unknown= po::collect_unrecognized(file_parsed.options, po::include_positional);
1017
1018 for (vector<string>::iterator it= file_unknown.begin(); it != file_unknown.end(); ++it)
1019 {
1020 string new_unknown_opt("--" + *it);
1021 ++it;
1022
1023 if (it == file_unknown.end())
1024 {
1025 break;
1026 }
1027
1028 if (*it != "true")
1029 {
1030 new_unknown_opt += "=" + *it;
1031 }
1032
1033 unknown_options.push_back(new_unknown_opt);
1034 }
1035 store(file_parsed, vm);
1036 }
1037}
1038
1039static void compose_defaults_file_list(const vector<string>& in_options)
1040{
1041 for (const string& it : in_options)
1042 {
1043 fs::path p(it);
1044 if (fs::is_regular_file(p))
1045 {
1046 defaults_file_list.push_back(it);
1047 }
1048 else
1049 {
1050 drizzled_abort << "Defaults file '" << it << "' not found";
1051 }
1052 }
1053}
1054
1055bool init_variables_before_daemonizing(int argc, char **argv)
1056{
1057 umask(((~internal::get_my_umask()) & 0666));
1058 decimal_zero.set_zero(); // set decimal_zero constant;
1059 tzset(); // Set tzname
1060
1061 time_t curr_time= time(NULL);
1062 if (curr_time == (time_t)-1)
1063 {
1064 return false;
1065 }
1066
1067 max_system_variables.pseudo_thread_id= UINT32_MAX;
1068 server_start_time= flush_status_time= curr_time;
1069
1071
1072 find_plugin_dir(argv[0]);
1073
1074 char ret_hostname[FN_REFLEN];
1075 if (gethostname(ret_hostname,sizeof(ret_hostname)) < 0)
1076 {
1077 errmsg_printf(error::WARN, _("gethostname failed, using '%s' as hostname"), getServerHostname().c_str());
1078 pid_file= "drizzle";
1079 }
1080 else
1081 {
1082 g_hostname= ret_hostname;
1083 pid_file= getServerHostname();
1084 }
1085 pid_file.replace_extension(".pid");
1086
1087 system_config_dir /= "drizzle";
1088
1089 general_options.add_options()
1090 ("help,?",
1091 _("Display help and exit."))
1092 ("user,u", po::value<string>(),
1093 _("Run drizzled daemon as user."))
1094 ("version,V",
1095 _("Print version information and exit."))
1096 ;
1097
1098 config_options.add_options()
1099 ("no-defaults", po::value<bool>()->default_value(false)->zero_tokens(),
1100 _("Configuration file defaults are not used if no-defaults is set"))
1101 ("defaults-file", po::value<vector<string> >()->composing()->notifier(&compose_defaults_file_list),
1102 _("Configuration file to use"))
1103 ("config-dir", po::value<fs::path>(&system_config_dir),
1104 _("Base location for config files"))
1105 ("plugin-dir", po::value<fs::path>(&plugin_dir)->notifier(&notify_plugin_dir),
1106 _("Directory for plugins."))
1107 ;
1108
1109 plugin_load_options.add_options()
1110 ("plugin-add", po::value<vector<string> >()->composing()->notifier(&compose_plugin_add),
1111 _("Optional comma separated list of plugins to load at startup in addition "
1112 "to the default list of plugins. "
1113 "[for example: --plugin_add=crc32,logger_gearman]"))
1114 ("plugin-remove", po::value<vector<string> >()->composing()->notifier(&compose_plugin_remove),
1115 _("Optional comma separated list of plugins to not load at startup. Effectively "
1116 "removes a plugin from the list of plugins to be loaded. "
1117 "[for example: --plugin_remove=crc32,logger_gearman]"))
1118 ("plugin-load", po::value<string>()->notifier(&notify_plugin_load)->default_value(PANDORA_PLUGIN_LIST),
1119 _("Optional comma separated list of plugins to load at starup instead of "
1120 "the default plugin load list. "
1121 "[for example: --plugin_load=crc32,logger_gearman]"))
1122 ;
1123
1124 long_options.add_options()
1125 ("auto-increment-increment", po::value<uint64_t>(&global_system_variables.auto_increment_increment)->default_value(1)->notifier(&check_limits_aii),
1126 _("Auto-increment columns are incremented by this"))
1127 ("auto-increment-offset", po::value<uint64_t>(&global_system_variables.auto_increment_offset)->default_value(1)->notifier(&check_limits_aio),
1128 _("Offset added to Auto-increment columns. Used when auto-increment-increment != 1"))
1129 ("basedir,b", po::value<fs::path>(&basedir),
1130 _("Path to installation directory. All paths are usually resolved "
1131 "relative to this."))
1132 ("chroot,r", po::value<string>(),
1133 _("Chroot drizzled daemon during startup."))
1134 ("collation-server", po::value<string>(),
1135 _("Set the default collation."))
1136 ("completion-type", po::value<uint32_t>(&global_system_variables.completion_type)->default_value(0)->notifier(&check_limits_completion_type),
1137 _("Default completion type."))
1138 ("core-file", _("Write core on errors."))
1139 ("datadir", po::value<fs::path>(&getMutableDataHome()),
1140 _("Path to the database root."))
1141 ("default-storage-engine", po::value<string>(),
1142 _("Set the default storage engine for tables."))
1143 ("exit-info,T", po::value<long>(),
1144 _("Used for debugging; Use at your own risk!"))
1145 ("gdb", po::value<bool>(&opt_debugging)->default_value(false)->zero_tokens(),
1146 _("Set up signals usable for debugging"))
1147 ("lc-time-name", po::value<string>(),
1148 _("Set the language used for the month names and the days of the week."))
1149 ("log-warnings,W", po::value<bool>(&global_system_variables.log_warnings)->default_value(false)->zero_tokens(),
1150 _("Log some not critical warnings to the log file."))
1151 ("pid-file", po::value<fs::path>(&pid_file),
1152 _("Pid file used by drizzled."))
1153 ("port-open-timeout", po::value<uint32_t>(&drizzled_bind_timeout)->default_value(0),
1154 _("Maximum time in seconds to wait for the port to become free. "))
1155 ("replicate-query", po::value<bool>(&global_system_variables.replicate_query)->default_value(false)->zero_tokens(),
1156 _("Include the SQL query in replicated protobuf messages."))
1157 ("secure-file-priv", po::value<fs::path>(&secure_file_priv)->notifier(expand_secure_file_priv),
1158 _("Limit LOAD DATA, SELECT ... OUTFILE, and LOAD_FILE() to files "
1159 "within specified directory"))
1160 ("server-id", po::value<uint32_t>(&server_id)->default_value(0),
1161 _("Uniquely identifies the server instance in the community of "
1162 "replication partners."))
1163 ("skip-stack-trace",
1164 _("Don't print a stack trace on failure."))
1165 ("symbolic-links,s", po::value<bool>(&internal::my_use_symdir)->default_value(IF_PURIFY(false,true))->zero_tokens(),
1166 _("Enable symbolic link support."))
1167 ("tmpdir,t", po::value<string>(),
1168 _("Path for temporary files."))
1169 ("transaction-isolation", po::value<string>(),
1170 _("Default transaction isolation level."))
1171 ("transaction-message-threshold", po::value<size_t>(&transaction_message_threshold)->default_value(1024*1024)->notifier(&check_limits_transaction_message_threshold),
1172 _("Max message size written to transaction log, valid values 131072 - 1048576 bytes."))
1173 ("back-log", po::value<back_log_constraints>(&back_log),
1174 _("The number of outstanding connection requests Drizzle can have. This "
1175 "comes into play when the main Drizzle thread gets very many connection "
1176 "requests in a very short time."))
1177 ("bulk-insert-buffer-size",
1178 po::value<uint64_t>(&global_system_variables.bulk_insert_buff_size)->default_value(8192*1024),
1179 _("Size of tree cache used in bulk insert optimization. Note that this is "
1180 "a limit per thread!"))
1181 ("div-precision-increment", po::value<uint32_t>(&global_system_variables.div_precincrement)->default_value(4)->notifier(&check_limits_dpi),
1182 _("Precision of the result of '/' operator will be increased on that "
1183 "value."))
1184 ("group-concat-max-len", po::value<uint64_t>(&global_system_variables.group_concat_max_len)->default_value(1024)->notifier(&check_limits_gcml),
1185 _("The maximum length of the result of function group_concat."))
1186 ("join-buffer-size", po::value<uint64_t>(&global_system_variables.join_buff_size)->default_value(128*1024L)->notifier(&check_limits_join_buffer_size),
1187 _("The size of the buffer that is used for full joins."))
1188 ("join-heap-threshold",
1189 po::value<uint64_t>()->default_value(0),
1190 _("A global cap on the amount of memory that can be allocated by session join buffers (0 means unlimited)"))
1191 ("max-allowed-packet", po::value<uint32_t>(&global_system_variables.max_allowed_packet)->default_value(64*1024*1024L)->notifier(&check_limits_map),
1192 _("Max packetlength to send/receive from to server."))
1193 ("max-error-count", po::value<uint64_t>(&global_system_variables.max_error_count)->default_value(DEFAULT_ERROR_COUNT)->notifier(&check_limits_max_err_cnt),
1194 _("Max number of errors/warnings to store for a statement."))
1195 ("max-heap-table-size", po::value<uint64_t>(&global_system_variables.max_heap_table_size)->default_value(16*1024*1024L)->notifier(&check_limits_mhts),
1196 _("Don't allow creation of heap tables bigger than this."))
1197 ("max-join-size", po::value<ha_rows>(&global_system_variables.max_join_size)->default_value(INT32_MAX)->notifier(&check_limits_max_join_size),
1198 _("Joins that are probably going to read more than max_join_size records "
1199 "return an error."))
1200 ("max-length-for-sort-data", po::value<uint64_t>(&global_system_variables.max_length_for_sort_data)->default_value(1024)->notifier(&check_limits_mlfsd),
1201 _("Max number of bytes in sorted records."))
1202 ("max-seeks-for-key", po::value<uint64_t>(&global_system_variables.max_seeks_for_key)->default_value(ULONG_MAX)->notifier(&check_limits_msfk),
1203 _("Limit assumed max number of seeks when looking up rows based on a key"))
1204 ("max-sort-length", po::value<size_t>(&global_system_variables.max_sort_length)->default_value(1024)->notifier(&check_limits_max_sort_length),
1205 _("The number of bytes to use when sorting BLOB or TEXT values "
1206 "(only the first max_sort_length bytes of each value are used; the "
1207 "rest are ignored)."))
1208 ("max-write-lock-count", po::value<uint64_t>(&max_write_lock_count)->default_value(UINT64_MAX),
1209 _("After this many write locks, allow some read locks to run in between."))
1210 ("min-examined-row-limit", po::value<uint64_t>(&global_system_variables.min_examined_row_limit)->default_value(0)->notifier(&check_limits_merl),
1211 _("Don't log queries which examine less than min_examined_row_limit "
1212 "rows to file."))
1213 ("disable-optimizer-prune",
1214 _("Do not apply any heuristic(s) during query optimization to prune, "
1215 "thus perform an exhaustive search from the optimizer search space."))
1216 ("optimizer-search-depth", po::value<uint32_t>(&global_system_variables.optimizer_search_depth)->default_value(0)->notifier(&check_limits_osd),
1217 _("Maximum depth of search performed by the query optimizer. Values "
1218 "larger than the number of relations in a query result in better query "
1219 "plans, but take longer to compile a query. Smaller values than the "
1220 "number of tables in a relation result in faster optimization, but may "
1221 "produce very bad query plans. If set to 0, the system will "
1222 "automatically pick a reasonable value; if set to MAX_TABLES+2, the "
1223 "optimizer will switch to the original find_best (used for "
1224 "testing/comparison)."))
1225 ("preload-buffer-size", po::value<uint64_t>(&global_system_variables.preload_buff_size)->default_value(32*1024L)->notifier(&check_limits_pbs),
1226 _("The size of the buffer that is allocated when preloading indexes"))
1227 ("query-alloc-block-size",
1228 po::value<uint32_t>(&global_system_variables.query_alloc_block_size)->default_value(QUERY_ALLOC_BLOCK_SIZE)->notifier(&check_limits_qabs),
1229 _("Allocation block size for query parsing and execution"))
1230 ("query-prealloc-size",
1231 po::value<uint32_t>(&global_system_variables.query_prealloc_size)->default_value(QUERY_ALLOC_PREALLOC_SIZE)->notifier(&check_limits_qps),
1232 _("Persistent buffer for query parsing and execution"))
1233 ("range-alloc-block-size",
1234 po::value<size_t>(&global_system_variables.range_alloc_block_size)->default_value(RANGE_ALLOC_BLOCK_SIZE)->notifier(&check_limits_rabs),
1235 _("Allocation block size for storing ranges during optimization"))
1236 ("read-buffer-size",
1237 po::value<uint32_t>(&global_system_variables.read_buff_size)->default_value(128*1024L)->notifier(&check_limits_read_buffer_size),
1238 _("Each thread that does a sequential scan allocates a buffer of this "
1239 "size for each table it scans. If you do many sequential scans, you may "
1240 "want to increase this value."))
1241 ("read-buffer-threshold",
1242 po::value<uint64_t>()->default_value(0),
1243 _("A global cap on the size of read-buffer-size (0 means unlimited)"))
1244 ("read-rnd-buffer-size",
1245 po::value<uint32_t>(&global_system_variables.read_rnd_buff_size)->default_value(256*1024L)->notifier(&check_limits_read_rnd_buffer_size),
1246 _("When reading rows in sorted order after a sort, the rows are read "
1247 "through this buffer to avoid a disk seeks. If not set, then it's set "
1248 "to the value of record_buffer."))
1249 ("read-rnd-threshold",
1250 po::value<uint64_t>()->default_value(0),
1251 _("A global cap on the size of read-rnd-buffer-size (0 means unlimited)"))
1252 ("scheduler", po::value<string>(),
1253 _("Select scheduler to be used (by default multi-thread)."))
1254 ("sort-buffer-size",
1255 po::value<size_t>(&global_system_variables.sortbuff_size)->default_value(MAX_SORT_MEMORY)->notifier(&check_limits_sort_buffer_size),
1256 _("Each thread that needs to do a sort allocates a buffer of this size."))
1257 ("sort-heap-threshold",
1258 po::value<uint64_t>()->default_value(0),
1259 _("A global cap on the amount of memory that can be allocated by session sort buffers (0 means unlimited)"))
1260 ("table-definition-cache", po::value<size_t>(&table_def_size)->default_value(128)->notifier(&check_limits_tdc),
1261 _("The number of cached table definitions."))
1262 ("table-open-cache", po::value<uint64_t>(&table_cache_size)->default_value(TABLE_OPEN_CACHE_DEFAULT)->notifier(&check_limits_toc),
1263 _("The number of cached open tables."))
1264 ("table-lock-wait-timeout", po::value<uint64_t>(&table_lock_wait_timeout)->default_value(50)->notifier(&check_limits_tlwt),
1265 _("Timeout in seconds to wait for a table level lock before returning an "
1266 "error. Used only if the connection has active cursors."))
1267 ("thread-stack", po::value<size_t>(&my_thread_stack_size)->default_value(0)->notifier(&check_limits_thread_stack),
1268 _("The stack size for each thread."))
1269 ("tmp-table-size",
1270 po::value<uint64_t>(&global_system_variables.tmp_table_size)->default_value(16*1024*1024L)->notifier(&check_limits_tmp_table_size),
1271 _("If an internal in-memory temporary table exceeds this size, Drizzle will"
1272 " automatically convert it to an on-disk MyISAM table."))
1273 ("verbose", po::value<std::string>()->default_value(error::verbose_string())->notifier(&error::check_verbosity),
1274 _("The verbosity of messages from drizzled. Possible values are INSPECT, INFO, WARN or ERROR"))
1275 ;
1276
1277 full_options.add(long_options);
1278 full_options.add(plugin_load_options);
1279
1280 initial_options.add(general_options);
1281 initial_options.add(config_options);
1282 initial_options.add(plugin_load_options);
1283
1284 int style = po::command_line_style::default_style & ~po::command_line_style::allow_guessing;
1285
1286 /* Get options about where config files and the like are */
1287 po::parsed_options parsed= po::command_line_parser(argc, argv).style(style).
1288 options(initial_options).allow_unregistered().run();
1289
1290 unknown_options= po::collect_unrecognized(parsed.options, po::include_positional);
1291
1292 try
1293 {
1294 po::store(parsed, vm);
1295 }
1296 catch (std::exception&)
1297 {
1298 drizzled_abort << _("Duplicate entry for command line option");
1299 }
1300
1301 /* TODO(mordred): here is where we should add:
1302 po::store(po::parse_environment(full_options, "DRIZZLE_"), vm);
1303 but we'll do that once we've up to speed. This will make running
1304 in containers more nicer.
1305 */
1306
1307 /* We need a notify here so that plugin_init will work properly */
1308 try
1309 {
1310 po::notify(vm);
1311 }
1312 catch (po::validation_error &err)
1313 {
1314 drizzled_abort << err.what() << ". " << "Use --help to get a list of available options. ";
1315 }
1316
1317 if (vm.count("version"))
1318 {
1319 print_version();
1320 drizzled_exit();
1321 }
1322
1323 if (!vm["no-defaults"].as<bool>())
1324 {
1325 fs::path system_config_file_drizzle(system_config_dir);
1326 system_config_file_drizzle /= "drizzled.cnf";
1327 defaults_file_list.insert(defaults_file_list.begin(), system_config_file_drizzle.string());
1328
1329 fs::path config_conf_d_location(system_config_dir);
1330 config_conf_d_location /= "conf.d";
1331
1332 CachedDirectory config_conf_d(config_conf_d_location.string());
1333 if (not config_conf_d.fail())
1334 {
1335 for (CachedDirectory::Entries::const_reference iter : config_conf_d.getEntries())
1336 {
1337 string file_entry(iter->filename);
1338 if (not file_entry.empty() && file_entry != "." && file_entry != "..")
1339 defaults_file_list.push_back((config_conf_d_location / file_entry).string());
1340 }
1341 }
1342 }
1343
1344 process_defaults_files();
1345
1346 /* Process with notify a second time because a config file may contain
1347 plugin loader options */
1348
1349 try
1350 {
1351 po::notify(vm);
1352 }
1353 catch (po::validation_error &err)
1354 {
1355 drizzled_abort << err.what() << ". " << "Use --help to get a list of available options. ";
1356 }
1357
1358 return true;
1359}
1360
1361// Return failure if we can't pass this, drizzled_abort() will then be called
1362// by the caller.
1363void usage();
1364
1365bool init_variables_after_daemonizing(module::Registry &plugins)
1366{
1367 int style = po::command_line_style::default_style & ~po::command_line_style::allow_guessing;
1368
1369 current_pid= getpid(); /* Save for later ref */
1370
1371 /* At this point, we've read all the options we need to read from files and
1372 collected most of them into unknown options - now let's load everything
1373 */
1374
1375 if (plugin_init(plugins, plugin_options))
1376 {
1377 drizzled_abort << _("Failed to initialize plugins");
1378 }
1379
1380 full_options.add(plugin_options);
1381
1382 if ( was_help_requested())
1383 {
1384 usage();
1385 }
1386
1387 vector<string> final_unknown_options;
1388 try
1389 {
1390 po::parsed_options final_parsed=
1391 po::command_line_parser(unknown_options).style(style).
1392 options(full_options).extra_parser(dpo::parse_size_arg).run();
1393
1394 final_unknown_options=
1395 po::collect_unrecognized(final_parsed.options, po::include_positional);
1396
1397 po::store(final_parsed, vm);
1398
1399 }
1400 catch (po::validation_error &err)
1401 {
1402 drizzled_abort << err.what() << ". " << "Use --help to get a list of available options. ";
1403 }
1404 catch (po::invalid_command_line_syntax &err)
1405 {
1406 drizzled_abort << err.what() << ". " << "Use --help to get a list of available options. ";
1407 }
1408 catch (po::unknown_option &err)
1409 {
1410 drizzled_abort << err.what() << ". " << "Use --help to get a list of available options. ";
1411 }
1412
1413 try
1414 {
1415 po::notify(vm);
1416 }
1417 catch (po::validation_error &err)
1418 {
1419 drizzled_abort << err.what() << ". " << "Use --help to get a list of available options. ";
1420 }
1421
1422 get_options();
1423
1424 /* Inverted Booleans */
1425
1426 global_system_variables.optimizer_prune_level= not vm.count("disable-optimizer-prune");
1427
1428 if ((user_info= check_user(drizzled_user)))
1429 {
1430 set_user(drizzled_user, user_info);
1431 }
1432
1433 fix_paths();
1434
1435 /* Save pid to this process (or thread on Linux) */
1436 create_pid_file();
1437
1438 init_time(); /* Init time-functions (read zone) */
1439
1440 item_create_init();
1441 if (sys_var_init())
1442 {
1443 return false;
1444 }
1445
1446 /* Creates static regex matching for temporal values */
1447 if (not init_temporal_formats())
1448 {
1449 return false;
1450 }
1451
1452 if (!(default_charset_info= get_charset_by_csname(default_character_set_name, MY_CS_PRIMARY)))
1453 {
1454 errmsg_printf(error::ERROR, _("Error getting default charset"));
1455 return false; // Eof of the list
1456 }
1457
1458 if (vm.count("scheduler"))
1459 {
1460 opt_scheduler= vm["scheduler"].as<string>().c_str();
1461 }
1462
1463 /* Set collactions that depends on the default collation */
1464 global_system_variables.collation_server= default_charset_info;
1465
1466 if (not (character_set_filesystem= get_charset_by_csname("binary", MY_CS_PRIMARY)))
1467 {
1468 errmsg_printf(error::ERROR, _("Error setting collation"));
1469 return false;
1470 }
1471 global_system_variables.character_set_filesystem= character_set_filesystem;
1472
1473 if ((my_default_lc_time_names= my_locale_by_name(lc_time_names_name)) == NULL)
1474 {
1475 errmsg_printf(error::ERROR, _("Unknown locale: '%s'"), lc_time_names_name);
1476 return false;
1477 }
1478 global_system_variables.lc_time_names= my_default_lc_time_names;
1479
1480 /* Reset table_alias_charset */
1481 table_alias_charset= files_charset_info;
1482
1483 return true;
1484}
1485
1486bool was_help_requested()
1487{
1488 return bool(vm.count("help"));
1489}
1490
1491void init_server_components(module::Registry &plugins)
1492{
1493 if (was_help_requested())
1494 {
1495 usage();
1496 }
1497
1498 /*
1499 We need to call each of these following functions to ensure that
1500 all things are initialized so that drizzled_abort() doesn't fail
1501 */
1502
1503 // Resize the definition Cache at startup
1504 table::Cache::rehash(table_def_size);
1505 definition::Cache::rehash(table_def_size);
1506 message::Cache::singleton().rehash(table_def_size);
1507
1508 setup_fpu();
1509
1510 /* Allow storage engine to give real error messages */
1512
1513 if (plugin_finalize(plugins))
1514 {
1515 drizzled_abort << "plugin_finalize() failed";
1516 }
1517
1518 if (plugin::Scheduler::setPlugin(opt_scheduler))
1519 {
1520 drizzled_abort << _("No scheduler found");
1521 }
1522
1523 /*
1524 This is entirely for legacy. We will create a new "disk based" engine and a
1525 "memory" engine which will be configurable longterm.
1526 */
1527 myisam_engine= plugin::StorageEngine::findByName("MyISAM");
1528 heap_engine= plugin::StorageEngine::findByName("MEMORY");
1529
1530 /*
1531 Check that the default storage engine is actually available.
1532 */
1533 if (default_storage_engine_str)
1534 {
1535 plugin::StorageEngine *engine= plugin::StorageEngine::findByName(default_storage_engine_str);
1536 if (engine == NULL)
1537 {
1538 drizzled_abort << _("Unknown/unsupported storage engine: ") << default_storage_engine_str;
1539 }
1540 global_system_variables.storage_engine= engine;
1541 }
1542
1543 if (plugin::XaResourceManager::recoverAllXids())
1544 {
1545 /* This function alredy generates error messages */
1546 drizzled_abort << "plugin::XaResourceManager::recoverAllXids() failed";
1547 }
1548
1549 init_update_queries();
1550}
1551
1552
1553/****************************************************************************
1554 Handle start options
1555******************************************************************************/
1556
1557enum options_drizzled
1558{
1559 OPT_SOCKET=256,
1560 OPT_BIND_ADDRESS,
1561 OPT_PID_FILE,
1562 OPT_STORAGE_ENGINE,
1563 OPT_INIT_FILE,
1564 OPT_WANT_CORE,
1565 OPT_MEMLOCK,
1566 OPT_SERVER_ID,
1567 OPT_TC_HEURISTIC_RECOVER,
1568 OPT_TEMP_POOL, OPT_TX_ISOLATION, OPT_COMPLETION_TYPE,
1569 OPT_SKIP_STACK_TRACE, OPT_SKIP_SYMLINKS,
1570 OPT_DO_PSTACK,
1571 OPT_LOCAL_INFILE,
1572 OPT_BACK_LOG,
1573 OPT_JOIN_BUFF_SIZE,
1574 OPT_MAX_ALLOWED_PACKET,
1575 OPT_MAX_HEP_TABLE_SIZE,
1576 OPT_MAX_JOIN_SIZE,
1577 OPT_MAX_SORT_LENGTH,
1578 OPT_MAX_SEEKS_FOR_KEY, OPT_MAX_TMP_TABLES, OPT_MAX_USER_CONNECTIONS,
1579 OPT_MAX_LENGTH_FOR_SORT_DATA,
1580 OPT_MAX_WRITE_LOCK_COUNT, OPT_BULK_INSERT_BUFFER_SIZE,
1581 OPT_MAX_ERROR_COUNT, OPT_MULTI_RANGE_COUNT, OPT_MYISAM_DATA_POINTER_SIZE,
1582 OPT_MYISAM_BLOCK_SIZE, OPT_MYISAM_MAX_EXTRA_SORT_FILE_SIZE,
1583 OPT_MYISAM_MAX_SORT_FILE_SIZE, OPT_MYISAM_SORT_BUFFER_SIZE,
1584 OPT_MYISAM_USE_MMAP, OPT_MYISAM_REPAIR_THREADS,
1585 OPT_NET_BUFFER_LENGTH,
1586 OPT_PRELOAD_BUFFER_SIZE,
1587 OPT_RECORD_BUFFER,
1588 OPT_RECORD_RND_BUFFER, OPT_DIV_PRECINCREMENT,
1589 OPT_DEBUGGING,
1590 OPT_SORT_BUFFER, OPT_TABLE_OPEN_CACHE, OPT_TABLE_DEF_CACHE,
1591 OPT_TMP_TABLE_SIZE, OPT_THREAD_STACK,
1592 OPT_WAIT_TIMEOUT,
1593 OPT_RANGE_ALLOC_BLOCK_SIZE,
1594 OPT_QUERY_ALLOC_BLOCK_SIZE, OPT_QUERY_PREALLOC_SIZE,
1595 OPT_TRANS_ALLOC_BLOCK_SIZE, OPT_TRANS_PREALLOC_SIZE,
1596 OPT_OLD_ALTER_TABLE,
1597 OPT_GROUP_CONCAT_MAX_LEN,
1598 OPT_DEFAULT_COLLATION,
1599 OPT_CHARACTER_SET_FILESYSTEM,
1600 OPT_LC_TIME_NAMES,
1601 OPT_INIT_CONNECT,
1602 OPT_DEFAULT_TIME_ZONE,
1603 OPT_OPTIMIZER_SEARCH_DEPTH,
1604 OPT_SCHEDULER,
1605 OPT_PROTOCOL,
1606 OPT_OPTIMIZER_PRUNE_LEVEL,
1607 OPT_AUTO_INCREMENT, OPT_AUTO_INCREMENT_OFFSET,
1608 OPT_ENABLE_LARGE_PAGES,
1609 OPT_TABLE_LOCK_WAIT_TIMEOUT,
1610 OPT_PLUGIN_ADD,
1611 OPT_PLUGIN_REMOVE,
1612 OPT_PLUGIN_LOAD,
1613 OPT_PLUGIN_DIR,
1614 OPT_PORT_OPEN_TIMEOUT,
1615 OPT_SECURE_FILE_PRIV,
1616 OPT_MIN_EXAMINED_ROW_LIMIT,
1617 OPT_PRINT_DEFAULTS
1618};
1619
1620
1621struct option my_long_options[] =
1622{
1623 {"auto-increment-increment", OPT_AUTO_INCREMENT,
1624 N_("Auto-increment columns are incremented by this"),
1625 (char**) &global_system_variables.auto_increment_increment,
1626 NULL, 0, GET_ULL,
1627 OPT_ARG, 1, 1, INT64_MAX, 0, 1, 0 },
1628 {"auto-increment-offset", OPT_AUTO_INCREMENT_OFFSET,
1629 N_("Offset added to Auto-increment columns. Used when "
1630 "auto-increment-increment != 1"),
1631 (char**) &global_system_variables.auto_increment_offset,
1632 NULL, 0, GET_ULL, OPT_ARG,
1633 1, 1, INT64_MAX, 0, 1, 0 },
1634 {"basedir", 'b',
1635 N_("Path to installation directory. All paths are usually resolved "
1636 "relative to this."),
1637 NULL, NULL, 0, GET_STR, REQUIRED_ARG,
1638 0, 0, 0, 0, 0, 0},
1639 {"chroot", 'r',
1640 N_("Chroot drizzled daemon during startup."),
1641 (char**) &drizzled_chroot, NULL, 0, GET_STR, REQUIRED_ARG,
1642 0, 0, 0, 0, 0, 0},
1643 {"completion-type", OPT_COMPLETION_TYPE,
1644 N_("Default completion type."),
1645 (char**) &global_system_variables.completion_type,
1646 NULL, 0, GET_UINT,
1647 REQUIRED_ARG, 0, 0, 2, 0, 1, 0},
1648 {"core-file", OPT_WANT_CORE,
1649 N_("Write core on errors."),
1650 0, 0, 0, GET_NO_ARG,
1651 NO_ARG, 0, 0, 0, 0, 0, 0},
1652 {"datadir", 'h',
1653 N_("Path to the database root."),
1654 NULL, NULL, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
1655 /* See how it's handled in get_one_option() */
1656 {"exit-info", 'T',
1657 N_("Used for debugging; Use at your own risk!"),
1658 0, 0, 0, GET_LONG, OPT_ARG, 0, 0, 0, 0, 0, 0},
1659 /* We must always support the next option to make scripts like mysqltest
1660 easier to do */
1661 {"gdb", OPT_DEBUGGING,
1662 N_("Set up signals usable for debugging"),
1663 (char**) &opt_debugging, NULL,
1664 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
1665 {"log-warnings", 'W',
1666 N_("Log some not critical warnings to the log file."),
1667 (char**) &global_system_variables.log_warnings,
1668 NULL, 0, GET_BOOL, OPT_ARG, 1, 0, 0,
1669 0, 0, 0},
1670 {"pid-file", OPT_PID_FILE,
1671 N_("Pid file used by drizzled."),
1672 NULL, NULL, 0, GET_STR,
1673 REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
1674 {"port-open-timeout", OPT_PORT_OPEN_TIMEOUT,
1675 N_("Maximum time in seconds to wait for the port to become free. "
1676 "(Default: no wait)"),
1677 (char**) &drizzled_bind_timeout,
1678 NULL, 0, GET_UINT, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
1679 {"secure-file-priv", OPT_SECURE_FILE_PRIV,
1680 N_("Limit LOAD DATA, SELECT ... OUTFILE, and LOAD_FILE() to files "
1681 "within specified directory"),
1682 NULL, NULL, 0,
1683 GET_STR_ALLOC, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
1684 {"server-id", OPT_SERVER_ID,
1685 N_("Uniquely identifies the server instance in the community of "
1686 "replication partners."),
1687 (char**) &server_id, NULL, 0, GET_UINT32, REQUIRED_ARG, 0, 0, 0,
1688 0, 0, 0},
1689 {"skip-stack-trace", OPT_SKIP_STACK_TRACE,
1690 N_("Don't print a stack trace on failure."),
1691 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0,
1692 0, 0, 0, 0},
1693 {"symbolic-links", 's',
1694 N_("Enable symbolic link support."),
1695 (char**) &internal::my_use_symdir, NULL, 0, GET_BOOL, NO_ARG,
1696 /*
1697 The system call realpath() produces warnings under valgrind and
1698 purify. These are not suppressed: instead we disable symlinks
1699 option if compiled with valgrind support.
1700 */
1701 IF_PURIFY(0,1), 0, 0, 0, 0, 0},
1702 {"transaction-isolation", OPT_TX_ISOLATION,
1703 N_("Default transaction isolation level."),
1704 0, 0, 0, GET_STR, REQUIRED_ARG, 0,
1705 0, 0, 0, 0, 0},
1706 {"user", 'u',
1707 N_("Run drizzled daemon as user."),
1708 0, 0, 0, GET_STR, REQUIRED_ARG,
1709 0, 0, 0, 0, 0, 0},
1710 {"back_log", OPT_BACK_LOG,
1711 N_("The number of outstanding connection requests Drizzle can have. This "
1712 "comes into play when the main Drizzle thread gets very many connection "
1713 "requests in a very short time."),
1714 (char**) &back_log, NULL, 0, GET_UINT,
1715 REQUIRED_ARG, 50, 1, 65535, 0, 1, 0 },
1716 { "bulk_insert_buffer_size", OPT_BULK_INSERT_BUFFER_SIZE,
1717 N_("Size of tree cache used in bulk insert optimization. Note that this is "
1718 "a limit per thread!"),
1719 (char**) &global_system_variables.bulk_insert_buff_size,
1720 NULL,
1721 0, GET_ULL, REQUIRED_ARG, 8192*1024, 0, (int64_t)ULONG_MAX, 0, 1, 0},
1722 { "div_precision_increment", OPT_DIV_PRECINCREMENT,
1723 N_("Precision of the result of '/' operator will be increased on that "
1724 "value."),
1725 (char**) &global_system_variables.div_precincrement,
1726 NULL, 0, GET_UINT,
1727 REQUIRED_ARG, 4, 0, DECIMAL_MAX_SCALE, 0, 0, 0},
1728 { "join_buffer_size", OPT_JOIN_BUFF_SIZE,
1729 N_("The size of the buffer that is used for full joins."),
1730 (char**) &global_system_variables.join_buff_size,
1731 NULL, 0, GET_UINT64,
1732 REQUIRED_ARG, 128*1024L, IO_SIZE*2+MALLOC_OVERHEAD, (int64_t)ULONG_MAX,
1733 MALLOC_OVERHEAD, IO_SIZE, 0},
1734 {"max_allowed_packet", OPT_MAX_ALLOWED_PACKET,
1735 N_("Max packetlength to send/receive from to server."),
1736 (char**) &global_system_variables.max_allowed_packet,
1737 NULL, 0, GET_UINT32,
1738 REQUIRED_ARG, 64*1024*1024L, 1024, 1024L*1024L*1024L, MALLOC_OVERHEAD, 1024, 0},
1739 {"max_heap_table_size", OPT_MAX_HEP_TABLE_SIZE,
1740 N_("Don't allow creation of heap tables bigger than this."),
1741 (char**) &global_system_variables.max_heap_table_size,
1742 NULL, 0, GET_ULL,
1743 REQUIRED_ARG, 16*1024*1024L, 16384, (int64_t)MAX_MEM_TABLE_SIZE,
1744 MALLOC_OVERHEAD, 1024, 0},
1745 {"max_join_size", OPT_MAX_JOIN_SIZE,
1746 N_("Joins that are probably going to read more than max_join_size records "
1747 "return an error."),
1748 (char**) &global_system_variables.max_join_size,
1749 NULL, 0, GET_HA_ROWS, REQUIRED_ARG,
1750 INT32_MAX, 1, INT32_MAX, 0, 1, 0},
1751 {"max_length_for_sort_data", OPT_MAX_LENGTH_FOR_SORT_DATA,
1752 N_("Max number of bytes in sorted records."),
1753 (char**) &global_system_variables.max_length_for_sort_data,
1754 NULL, 0, GET_ULL,
1755 REQUIRED_ARG, 1024, 4, 8192*1024L, 0, 1, 0},
1756 { "max_seeks_for_key", OPT_MAX_SEEKS_FOR_KEY,
1757 N_("Limit assumed max number of seeks when looking up rows based on a key"),
1758 (char**) &global_system_variables.max_seeks_for_key,
1759 NULL, 0, GET_UINT64,
1760 REQUIRED_ARG, (int64_t)ULONG_MAX, 1, (int64_t)ULONG_MAX, 0, 1, 0 },
1761 {"max_sort_length", OPT_MAX_SORT_LENGTH,
1762 N_("The number of bytes to use when sorting BLOB or TEXT values "
1763 "(only the first max_sort_length bytes of each value are used; the "
1764 "rest are ignored)."),
1765 (char**) &global_system_variables.max_sort_length,
1766 NULL, 0, GET_SIZE,
1767 REQUIRED_ARG, 1024, 4, 8192*1024L, 0, 1, 0},
1768 {"max_write_lock_count", OPT_MAX_WRITE_LOCK_COUNT,
1769 N_("After this many write locks, allow some read locks to run in between."),
1770 (char**) &max_write_lock_count, NULL, 0, GET_ULL,
1771 REQUIRED_ARG, (int64_t)ULONG_MAX, 1, (int64_t)ULONG_MAX, 0, 1, 0},
1772 {"min_examined_row_limit", OPT_MIN_EXAMINED_ROW_LIMIT,
1773 N_("Don't log queries which examine less than min_examined_row_limit "
1774 "rows to file."),
1775 (char**) &global_system_variables.min_examined_row_limit,
1776 NULL, 0, GET_ULL,
1777 REQUIRED_ARG, 0, 0, (int64_t)ULONG_MAX, 0, 1L, 0},
1778 {"optimizer_prune_level", OPT_OPTIMIZER_PRUNE_LEVEL,
1779 N_("Controls the heuristic(s) applied during query optimization to prune "
1780 "less-promising partial plans from the optimizer search space. Meaning: "
1781 "false - do not apply any heuristic, thus perform exhaustive search; "
1782 "true - prune plans based on number of retrieved rows."),
1783 (char**) &global_system_variables.optimizer_prune_level,
1784 NULL,
1785 0, GET_BOOL, OPT_ARG, 1, 0, 1, 0, 1, 0},
1786 {"optimizer_search_depth", OPT_OPTIMIZER_SEARCH_DEPTH,
1787 N_("Maximum depth of search performed by the query optimizer. Values "
1788 "larger than the number of relations in a query result in better query "
1789 "plans, but take longer to compile a query. Smaller values than the "
1790 "number of tables in a relation result in faster optimization, but may "
1791 "produce very bad query plans. If set to 0, the system will "
1792 "automatically pick a reasonable value; if set to MAX_TABLES+2, the "
1793 "optimizer will switch to the original find_best (used for "
1794 "testing/comparison)."),
1795 (char**) &global_system_variables.optimizer_search_depth,
1796 NULL,
1797 0, GET_UINT, OPT_ARG, 0, 0, MAX_TABLES+2, 0, 1, 0},
1798 {"plugin_dir", OPT_PLUGIN_DIR,
1799 N_("Directory for plugins."),
1800 NULL, NULL, 0,
1801 GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
1802 {"plugin_add", OPT_PLUGIN_ADD,
1803 N_("Optional comma separated list of plugins to load at startup in addition "
1804 "to the default list of plugins. "
1805 "[for example: --plugin_add=crc32,logger_gearman]"),
1806 NULL, NULL, 0,
1807 GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
1808 {"plugin_remove", OPT_PLUGIN_ADD,
1809 N_("Optional comma separated list of plugins to not load at startup. Effectively "
1810 "removes a plugin from the list of plugins to be loaded. "
1811 "[for example: --plugin_remove=crc32,logger_gearman]"),
1812 NULL, NULL, 0,
1813 GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
1814 {"plugin_load", OPT_PLUGIN_LOAD,
1815 N_("Optional comma separated list of plugins to load at starup instead of "
1816 "the default plugin load list. "
1817 "[for example: --plugin_load=crc32,logger_gearman]"),
1818 NULL, NULL, 0,
1819 GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
1820 {"preload_buffer_size", OPT_PRELOAD_BUFFER_SIZE,
1821 N_("The size of the buffer that is allocated when preloading indexes"),
1822 (char**) &global_system_variables.preload_buff_size,
1823 NULL, 0, GET_ULL,
1824 REQUIRED_ARG, 32*1024L, 1024, 1024*1024*1024L, 0, 1, 0},
1825 {"query_alloc_block_size", OPT_QUERY_ALLOC_BLOCK_SIZE,
1826 N_("Allocation block size for query parsing and execution"),
1827 (char**) &global_system_variables.query_alloc_block_size,
1828 NULL, 0, GET_UINT,
1829 REQUIRED_ARG, QUERY_ALLOC_BLOCK_SIZE, 1024, (int64_t)ULONG_MAX, 0, 1024, 0},
1830 {"query_prealloc_size", OPT_QUERY_PREALLOC_SIZE,
1831 N_("Persistent buffer for query parsing and execution"),
1832 (char**) &global_system_variables.query_prealloc_size,
1833 NULL, 0, GET_UINT,
1834 REQUIRED_ARG, QUERY_ALLOC_PREALLOC_SIZE, QUERY_ALLOC_PREALLOC_SIZE,
1835 (int64_t)ULONG_MAX, 0, 1024, 0},
1836 {"range_alloc_block_size", OPT_RANGE_ALLOC_BLOCK_SIZE,
1837 N_("Allocation block size for storing ranges during optimization"),
1838 (char**) &global_system_variables.range_alloc_block_size,
1839 NULL, 0, GET_SIZE,
1840 REQUIRED_ARG, RANGE_ALLOC_BLOCK_SIZE, RANGE_ALLOC_BLOCK_SIZE, (int64_t)SIZE_MAX,
1841 0, 1024, 0},
1842 {"read_buffer_size", OPT_RECORD_BUFFER,
1843 N_("Each thread that does a sequential scan allocates a buffer of this "
1844 "size for each table it scans. If you do many sequential scans, you may "
1845 "want to increase this value."),
1846 (char**) &global_system_variables.read_buff_size,
1847 NULL,0, GET_UINT, REQUIRED_ARG,
1848 128*1024L, IO_SIZE*2+MALLOC_OVERHEAD, INT32_MAX, MALLOC_OVERHEAD, IO_SIZE,
1849 0},
1850 {"read_rnd_buffer_size", OPT_RECORD_RND_BUFFER,
1851 N_("When reading rows in sorted order after a sort, the rows are read "
1852 "through this buffer to avoid a disk seeks. If not set, then it's set "
1853 "to the value of record_buffer."),
1854 (char**) &global_system_variables.read_rnd_buff_size,
1855 NULL, 0,
1856 GET_UINT, REQUIRED_ARG, 256*1024L, 64 /*IO_SIZE*2+MALLOC_OVERHEAD*/ ,
1857 UINT32_MAX, MALLOC_OVERHEAD, 1 /* Small lower limit to be able to test MRR */, 0},
1858 /* x8 compared to MySQL's x2. We have UTF8 to consider. */
1859 {"sort_buffer_size", OPT_SORT_BUFFER,
1860 N_("Each thread that needs to do a sort allocates a buffer of this size."),
1861 (char**) &global_system_variables.sortbuff_size,
1862 NULL, 0, GET_SIZE, REQUIRED_ARG,
1863 MAX_SORT_MEMORY, MIN_SORT_MEMORY+MALLOC_OVERHEAD*8, (int64_t)SIZE_MAX,
1864 MALLOC_OVERHEAD, 1, 0},
1865 {"table_definition_cache", OPT_TABLE_DEF_CACHE,
1866 N_("The number of cached table definitions."),
1867 (char**) &table_def_size, NULL,
1868 0, GET_SIZE, REQUIRED_ARG, 128, 1, 512*1024L, 0, 1, 0},
1869 {"table_open_cache", OPT_TABLE_OPEN_CACHE,
1870 N_("The number of cached open tables."),
1871 (char**) &table_cache_size, NULL, 0, GET_UINT64,
1872 REQUIRED_ARG, TABLE_OPEN_CACHE_DEFAULT, TABLE_OPEN_CACHE_MIN, 512*1024L, 0, 1, 0},
1873 {"table_lock_wait_timeout", OPT_TABLE_LOCK_WAIT_TIMEOUT,
1874 N_("Timeout in seconds to wait for a table level lock before returning an "
1875 "error. Used only if the connection has active cursors."),
1876 (char**) &table_lock_wait_timeout, NULL,
1877 0, GET_ULL, REQUIRED_ARG, 50, 1, 1024 * 1024 * 1024, 0, 1, 0},
1878 {"thread_stack", OPT_THREAD_STACK,
1879 N_("The stack size for each thread."),
1880 (char**) &my_thread_stack_size,
1881 NULL, 0, GET_SIZE,
1882 REQUIRED_ARG,0,
1883 UINT32_C(1024*512), (int64_t)SIZE_MAX, 0, 1024, 0},
1884 {"tmp_table_size", OPT_TMP_TABLE_SIZE,
1885 N_("If an internal in-memory temporary table exceeds this size, Drizzle will"
1886 " automatically convert it to an on-disk MyISAM table."),
1887 (char**) &global_system_variables.tmp_table_size,
1888 NULL, 0, GET_ULL,
1889 REQUIRED_ARG, 16*1024*1024L, 1024, (int64_t)MAX_MEM_TABLE_SIZE, 0, 1, 0},
1890 {0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}
1891};
1892
1893void usage()
1894{
1895 if ((default_charset_info= get_charset_by_csname(default_character_set_name, MY_CS_PRIMARY)) == NULL)
1896 {
1897 drizzled_abort << "Failed to load default_charset_info:" << default_character_set_name;
1898 }
1899
1900 if (default_collation_name == NULL)
1901 {
1902 default_collation_name= default_charset_info->name;
1903 }
1904
1905 print_version();
1906 puts(_("Copyright (C) 2010-2011 Drizzle Developers, Copyright (C) 2008 Sun Microsystems\n"
1907 "This software comes with ABSOLUTELY NO WARRANTY. "
1908 "This is free software,\n"
1909 "and you are welcome to modify and redistribute it under the GPL "
1910 "license\n\n"));
1911
1912
1913 printf(_("Usage: %s [OPTIONS]\n"), internal::my_progname);
1914
1915 po::options_description all_options("Drizzled Options");
1916 all_options.add(general_options);
1917 all_options.add(config_options);
1918 all_options.add(plugin_load_options);
1919 all_options.add(long_options);
1920 all_options.add(plugin_options);
1921 cout << all_options << endl;
1922
1923 drizzled_exit();
1924}
1925
1941
1943{
1944 /* Things reset to zero */
1945 cleanup_done= 0;
1946 dropping_tables= ha_open_options=0;
1947 getDebug().reset();
1948 wake_thread=0;
1949 abort_loop= false;
1950 select_thread_in_use= false;
1951 shutdown_in_progress= 0;
1952 drizzled_user= drizzled_chroot= 0;
1953 memset(&current_global_counters, 0, sizeof(current_global_counters));
1954 key_map_full.set();
1955
1956 /* Character sets */
1957 system_charset_info= &my_charset_utf8_general_ci;
1958 files_charset_info= &my_charset_utf8_general_ci;
1959 table_alias_charset= &my_charset_bin;
1960 character_set_filesystem= &my_charset_bin;
1961
1962 /* Things with default values that are not zero */
1963 session_startup_options= (OPTION_AUTO_IS_NULL | OPTION_SQL_NOTES);
1964 global_thread_id= 1;
1965 session::Cache::getCache().clear();
1966
1967 /* Set default values for some option variables */
1968 global_system_variables.storage_engine= NULL;
1969 global_system_variables.tx_isolation= ISO_REPEATABLE_READ;
1970 global_system_variables.select_limit= (uint64_t) HA_POS_ERROR;
1971 max_system_variables.select_limit= (uint64_t) HA_POS_ERROR;
1972 global_system_variables.max_join_size= (uint64_t) HA_POS_ERROR;
1973 max_system_variables.max_join_size= (uint64_t) HA_POS_ERROR;
1974 max_system_variables.auto_increment_increment= UINT64_MAX;
1975 max_system_variables.auto_increment_offset= UINT64_MAX;
1976 max_system_variables.completion_type= 2;
1977 max_system_variables.log_warnings= true;
1978 max_system_variables.bulk_insert_buff_size= ULONG_MAX;
1979 max_system_variables.div_precincrement= DECIMAL_MAX_SCALE;
1980 max_system_variables.group_concat_max_len= ULONG_MAX;
1981 max_system_variables.join_buff_size= ULONG_MAX;
1982 max_system_variables.max_allowed_packet= 1024L*1024L*1024L;
1983 max_system_variables.max_error_count= 65535;
1984 max_system_variables.max_heap_table_size= MAX_MEM_TABLE_SIZE;
1985 max_system_variables.max_join_size= INT32_MAX;
1986 max_system_variables.max_length_for_sort_data= 8192*1024L;
1987 max_system_variables.max_seeks_for_key= ULONG_MAX;
1988 max_system_variables.max_sort_length= 8192*1024L;
1989 max_system_variables.min_examined_row_limit= ULONG_MAX;
1990 max_system_variables.optimizer_prune_level= 1;
1991 max_system_variables.optimizer_search_depth= MAX_TABLES+2;
1992 max_system_variables.preload_buff_size= 1024*1024*1024L;
1993 max_system_variables.query_alloc_block_size= UINT32_MAX;
1994 max_system_variables.query_prealloc_size= UINT32_MAX;
1995 max_system_variables.range_alloc_block_size= SIZE_MAX;
1996 max_system_variables.read_buff_size= INT32_MAX;
1997 max_system_variables.read_rnd_buff_size= UINT32_MAX;
1998 max_system_variables.sortbuff_size= SIZE_MAX;
1999 max_system_variables.tmp_table_size= MAX_MEM_TABLE_SIZE;
2000
2001 /* Variables that depends on compile options */
2002#ifdef HAVE_BROKEN_REALPATH
2003 have_symlink=SHOW_OPTION_NO;
2004#else
2005 have_symlink=SHOW_OPTION_YES;
2006#endif
2007}
2008
2009
2014static void get_options()
2015{
2016 catalog::resetPath_for_local_identifier();
2017
2018 if (vm.count("user"))
2019 {
2020 if (drizzled_user == NULL or strcmp(drizzled_user, vm["user"].as<string>().c_str()) == 0)
2021 {
2022 drizzled_user= (char *)vm["user"].as<string>().c_str();
2023 }
2024 else
2025 {
2026 errmsg_printf(error::WARN, _("Ignoring user change to '%s' because the user was set to '%s' earlier on the command line"),
2027 vm["user"].as<string>().c_str(), drizzled_user);
2028 }
2029 }
2030
2031 if (vm.count("sort-heap-threshold"))
2032 {
2033 if ((vm["sort-heap-threshold"].as<uint64_t>() > 0) and
2034 (vm["sort-heap-threshold"].as<uint64_t>() < global_system_variables.sortbuff_size))
2035 {
2036 drizzled_abort << _("sort-heap-threshold cannot be less than sort-buffer-size");
2037 }
2038
2039 global_sort_buffer.setMaxSize(vm["sort-heap-threshold"].as<uint64_t>());
2040 }
2041
2042 if (vm.count("join-heap-threshold"))
2043 {
2044 if ((vm["join-heap-threshold"].as<uint64_t>() > 0) and
2045 (vm["join-heap-threshold"].as<uint64_t>() < global_system_variables.join_buff_size))
2046 {
2047 drizzled_abort << _("join-heap-threshold cannot be less than join-buffer-size");
2048 }
2049
2050 global_join_buffer.setMaxSize(vm["join-heap-threshold"].as<uint64_t>());
2051 }
2052
2053 if (vm.count("read-rnd-threshold"))
2054 {
2055 if ((vm["read-rnd-threshold"].as<uint64_t>() > 0) and
2056 (vm["read-rnd-threshold"].as<uint64_t>() < global_system_variables.read_rnd_buff_size))
2057 {
2058 drizzled_abort << _("read-rnd-threshold cannot be less than read-rnd-buffer-size");
2059 }
2060
2061 global_read_rnd_buffer.setMaxSize(vm["read-rnd-threshold"].as<uint64_t>());
2062 }
2063
2064 if (vm.count("read-buffer-threshold"))
2065 {
2066 if ((vm["read-buffer-threshold"].as<uint64_t>() > 0) and
2067 (vm["read-buffer-threshold"].as<uint64_t>() < global_system_variables.read_buff_size))
2068 {
2069 drizzled_abort << _("read-buffer-threshold cannot be less than read-buffer-size");
2070 }
2071
2072 global_read_buffer.setMaxSize(vm["read-buffer-threshold"].as<uint64_t>());
2073 }
2074
2075 if (vm.count("exit-info"))
2076 {
2077 if (vm["exit-info"].as<long>())
2078 {
2079 getDebug().set((uint32_t) vm["exit-info"].as<long>());
2080 }
2081 }
2082
2083 if (vm.count("want-core"))
2084 {
2085 getDebug().set(debug::CORE_ON_SIGNAL);
2086 }
2087
2088 if (vm.count("skip-stack-trace"))
2089 {
2090 getDebug().set(debug::NO_STACKTRACE);
2091 }
2092
2093 if (vm.count("skip-symlinks"))
2094 {
2095 internal::my_use_symdir= 0;
2096 }
2097
2098 if (vm.count("collation-server"))
2099 {
2100 const charset_info_st * const default_collation= get_charset_by_name(vm["collation-server"].as<string>().c_str());
2101 if (not default_collation)
2102 {
2103 drizzled_abort << "Unknown collation: " << default_collation_name;
2104 }
2105
2106 if (not my_charset_same(default_charset_info, default_collation))
2107 {
2108 drizzled_abort << "COLLATION '" << default_collation_name << "' is not valid for CHARACTER SET '" << default_charset_info->csname << "'";
2109 }
2110 default_charset_info= default_collation;
2111 }
2112
2113 if (vm.count("transaction-isolation"))
2114 {
2115 int type= tx_isolation_typelib.find_type_or_exit(vm["transaction-isolation"].as<string>().c_str(), "transaction-isolation");
2116 global_system_variables.tx_isolation= type - 1;
2117 }
2118
2119 /* @TODO Make this all strings */
2120 if (vm.count("default-storage-engine"))
2121 {
2122 default_storage_engine_str= vm["default-storage-engine"].as<string>().c_str();
2123 }
2124
2125
2126#if defined(HAVE_BROKEN_REALPATH)
2127 internal::my_use_symdir=0;
2128 internal::my_disable_symlinks=1;
2129 have_symlink=SHOW_OPTION_NO;
2130#else
2131 if (!internal::my_use_symdir)
2132 {
2133 internal::my_disable_symlinks=1;
2134 have_symlink=SHOW_OPTION_DISABLED;
2135 }
2136#endif
2137 if (opt_debugging)
2138 {
2139 /* Allow break with SIGINT, no core or stack trace */
2140 getDebug().set(debug::ALLOW_SIGINT);
2141 getDebug().set(debug::NO_STACKTRACE);
2142 getDebug().reset(debug::CORE_ON_SIGNAL);
2143 }
2144
2145 if (drizzled_chroot)
2146 {
2147 set_root(drizzled_chroot);
2148 }
2149
2150 /*
2151 Set some global variables from the global_system_variables
2152 In most cases the global variables will not be used
2153 */
2154 internal::my_default_record_cache_size=global_system_variables.read_buff_size;
2155}
2156
2157
2158static void fix_paths()
2159{
2160
2161 {
2162 if (pid_file.string().size() and pid_file.string()[0] == '/')
2163 { } // Do nothing if the file starts with a slash
2164 else
2165 {
2166 fs::path pid_file_path(pid_file);
2167 if (pid_file_path.root_path().string() == "")
2168 {
2169 pid_file_path= getDataHome();
2170 pid_file_path /= pid_file;
2171 }
2172 pid_file= fs::system_complete(pid_file_path);
2173 }
2174 }
2175
2176 const char *tmp_string= getenv("TMPDIR");
2177 struct stat buf;
2178 drizzle_tmpdir.clear();
2179
2180 if (vm.count("tmpdir"))
2181 {
2182 drizzle_tmpdir.append(vm["tmpdir"].as<string>());
2183 }
2184 else if (tmp_string == NULL)
2185 {
2186 drizzle_tmpdir.append(getDataHome().string());
2187 drizzle_tmpdir.push_back(FN_LIBCHAR);
2188 drizzle_tmpdir.append(GLOBAL_TEMPORARY_EXT);
2189 }
2190 else
2191 {
2192 drizzle_tmpdir.append(tmp_string);
2193 }
2194
2195 drizzle_tmpdir= fs::path(fs::system_complete(fs::path(drizzle_tmpdir))).string();
2196 assert(drizzle_tmpdir.size());
2197
2198 if (mkdir(drizzle_tmpdir.c_str(), 0777) == -1)
2199 {
2200 if (errno != EEXIST)
2201 {
2202 drizzled_abort << "There was an error creating the '"
2203 << fs::path(drizzle_tmpdir).filename()
2204 << "' part of the path '"
2205 << drizzle_tmpdir
2206 << "'. Please check the path exists and is writable.";
2207 }
2208 }
2209
2210 if (stat(drizzle_tmpdir.c_str(), &buf) || not S_ISDIR(buf.st_mode))
2211 {
2212 drizzled_abort << "There was an error opening the path '" << drizzle_tmpdir << "', please check the path exists and is writable.";
2213 }
2214}
2215
2216} /* namespace drizzled */
Defines the interface to the CachedDirectory class.
static void shutdown()
Definition listen.cc:189
Convert from decimal to binary representation.
Definition common_fwd.h:215
TODO: Rename this file - func.h is stupid.
bool calling_initgroups
Definition drizzled.cc:200
const char * in_additional_cond
Definition drizzled.cc:268
static void set_root(const char *path)
Definition drizzled.cc:626
void ha_init_errors(void)
static void drizzle_init_variables()
Definition drizzled.cc:1942
time_t flush_status_time
Definition drizzled.cc:251
bool init_temporal_formats()
static void get_options()
Definition drizzled.cc:2014
void deinit_temporal_formats()
const char * in_left_expr_name
Definition drizzled.cc:266
STL namespace.
Visibility Control Macros.
#define DRIZZLED_API
Definition visibility.h:38