~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/drizzled.cc

  • Committer: Stewart Smith
  • Date: 2011-01-14 05:16:49 UTC
  • mto: (2086.1.3 build)
  • mto: This revision was merged to the branch mainline in revision 2087.
  • Revision ID: stewart@flamingspork.com-20110114051649-4kg0mdrgdtako8vp
add a FIXME to flesh out insert docs

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18
18
 */
19
19
 
20
 
#include <config.h>
21
 
 
22
 
#include <drizzled/configmake.h>
23
 
#include <drizzled/atomics.h>
24
 
#include <drizzled/data_home.h>
 
20
#include "config.h"
 
21
#include "drizzled/configmake.h"
 
22
#include "drizzled/atomics.h"
 
23
#include "drizzled/data_home.h"
25
24
 
26
25
#include <netdb.h>
27
26
#include <sys/types.h>
32
31
#include <stdexcept>
33
32
 
34
33
#include <boost/program_options.hpp>
35
 
#include <drizzled/program_options/config_file.h>
 
34
#include "drizzled/program_options/config_file.h"
36
35
#include <boost/thread/recursive_mutex.hpp>
37
36
#include <boost/thread/mutex.hpp>
38
37
#include <boost/thread/shared_mutex.hpp>
40
39
#include <boost/filesystem.hpp>
41
40
#include <boost/detail/atomic_count.hpp>
42
41
 
43
 
#include <drizzled/cached_directory.h>
44
 
#include <drizzled/charset.h>
45
 
#include <drizzled/data_home.h>
46
 
#include <drizzled/debug.h>
47
 
#include <drizzled/definition/cache.h>
48
 
#include <drizzled/drizzled.h>
 
42
#include "drizzled/internal/my_sys.h"
 
43
#include "drizzled/internal/my_bit.h"
 
44
#include <drizzled/my_hash.h>
 
45
#include <drizzled/error.h>
49
46
#include <drizzled/errmsg_print.h>
50
 
#include <drizzled/error.h>
51
 
#include <drizzled/global_buffer.h>
52
 
#include <drizzled/internal/my_bit.h>
53
 
#include <drizzled/internal/my_sys.h>
 
47
#include <drizzled/tztime.h>
 
48
#include <drizzled/sql_base.h>
 
49
#include <drizzled/show.h>
 
50
#include <drizzled/sql_parse.h>
54
51
#include <drizzled/item/cmpfunc.h>
 
52
#include <drizzled/session.h>
55
53
#include <drizzled/item/create.h>
56
 
#include <drizzled/message/cache.h>
57
 
#include <drizzled/module/load_list.h>
58
 
#include <drizzled/module/registry.h>
59
 
#include <drizzled/my_hash.h>
60
 
#include <drizzled/plugin/client.h>
61
 
#include <drizzled/plugin/error_message.h>
62
 
#include <drizzled/plugin/event_observer.h>
63
 
#include <drizzled/plugin/listen.h>
64
 
#include <drizzled/plugin/monitored_in_transaction.h>
65
 
#include <drizzled/plugin/scheduler.h>
66
 
#include <drizzled/plugin/storage_engine.h>
67
 
#include <drizzled/plugin/xa_resource_manager.h>
68
 
#include <drizzled/probes.h>
69
 
#include <drizzled/replication_services.h> /* For ReplicationServices::evaluateRegisteredPlugins() */
70
 
#include <drizzled/session.h>
71
 
#include <drizzled/session/cache.h>
72
 
#include <drizzled/show.h>
73
 
#include <drizzled/sql_base.h>
74
 
#include <drizzled/sql_parse.h>
75
 
#include <drizzled/temporal_format.h> /* For init_temporal_formats() */
76
 
#include <drizzled/tztime.h>
77
54
#include <drizzled/unireg.h>
78
 
#include <plugin/myisam/myisam.h>
79
 
#include <drizzled/typelib.h>
80
 
#include <drizzled/visibility.h>
 
55
#include "drizzled/temporal_format.h" /* For init_temporal_formats() */
 
56
#include "drizzled/plugin/listen.h"
 
57
#include "drizzled/plugin/error_message.h"
 
58
#include "drizzled/plugin/client.h"
 
59
#include "drizzled/plugin/scheduler.h"
 
60
#include "drizzled/plugin/xa_resource_manager.h"
 
61
#include "drizzled/plugin/monitored_in_transaction.h"
 
62
#include "drizzled/replication_services.h" /* For ReplicationServices::evaluateRegisteredPlugins() */
 
63
#include "drizzled/probes.h"
 
64
#include "drizzled/session/cache.h"
 
65
#include "drizzled/charset.h"
 
66
#include "plugin/myisam/myisam.h"
 
67
#include "drizzled/drizzled.h"
 
68
#include "drizzled/module/registry.h"
 
69
#include "drizzled/module/load_list.h"
 
70
#include "drizzled/global_buffer.h"
 
71
 
 
72
#include "drizzled/definition/cache.h"
 
73
 
 
74
#include "drizzled/plugin/event_observer.h"
 
75
 
 
76
#include "drizzled/message/cache.h"
81
77
 
82
78
#include <google/protobuf/stubs/common.h>
83
79
 
84
 
#include <drizzled/refresh_version.h>
85
 
 
86
80
#if TIME_WITH_SYS_TIME
87
81
# include <sys/time.h>
88
82
# include <time.h>
102
96
 
103
97
#include <errno.h>
104
98
#include <sys/stat.h>
105
 
#include <drizzled/option.h>
 
99
#include "drizzled/option.h"
106
100
#ifdef HAVE_SYSENT_H
107
101
#include <sysent.h>
108
102
#endif
136
130
#include <sys/fpu.h>
137
131
#endif
138
132
 
139
 
#include <drizzled/internal/my_pthread.h>                       // For thr_setconcurency()
140
 
#include <drizzled/constrained_value.h>
 
133
#include "drizzled/internal/my_pthread.h"                       // For thr_setconcurency()
 
134
#include "drizzled/constrained_value.h"
141
135
 
142
136
#include <drizzled/gettext.h>
143
137
 
158
152
namespace po=boost::program_options;
159
153
namespace dpo=drizzled::program_options;
160
154
 
161
 
bool opt_daemon= false;
162
155
 
163
156
namespace drizzled
164
157
{
234
227
 
235
228
/* Global variables */
236
229
 
 
230
bool volatile ready_to_exit;
237
231
char *drizzled_user;
238
232
bool volatile select_thread_in_use;
239
233
bool volatile abort_loop;
240
 
DRIZZLED_API bool volatile shutdown_in_progress;
 
234
bool volatile shutdown_in_progress;
241
235
char *opt_scheduler_default;
242
236
const char *opt_scheduler= NULL;
243
237
 
244
 
DRIZZLED_API size_t my_thread_stack_size= 0;
 
238
size_t my_thread_stack_size= 0;
245
239
 
246
240
/*
247
241
  Legacy global plugin::StorageEngine. These will be removed (please do not add more).
252
246
bool calling_initgroups= false; /**< Used in SIGSEGV handler. */
253
247
 
254
248
uint32_t drizzled_bind_timeout;
 
249
std::bitset<12> test_flags;
255
250
uint32_t dropping_tables, ha_open_options;
256
251
uint32_t tc_heuristic_recover= 0;
257
252
uint64_t session_startup_options;
258
253
back_log_constraints back_log(50);
259
 
DRIZZLED_API uint32_t server_id;
 
254
uint32_t server_id;
260
255
uint64_t table_cache_size;
261
256
size_t table_def_size;
 
257
uint64_t max_connect_errors;
262
258
uint32_t global_thread_id= 1UL;
263
259
pid_t current_pid;
264
260
 
308
304
fs::path system_config_dir(SYSCONFDIR);
309
305
 
310
306
 
 
307
char system_time_zone[30];
 
308
char *default_tz_name;
 
309
char glob_hostname[FN_REFLEN];
 
310
 
311
311
char *opt_tc_log_file;
312
312
const key_map key_map_empty(0);
313
313
key_map key_map_full(0);                        // Will be initialized later
321
321
const char *in_additional_cond= "<IN COND>";
322
322
const char *in_having_cond= "<IN HAVING>";
323
323
 
 
324
type::Decimal decimal_zero;
324
325
/* classes for comparation parsing/processing */
325
326
 
326
327
FILE *stderror_file=0;
327
328
 
328
 
drizzle_system_variables global_system_variables;
329
 
drizzle_system_variables max_system_variables;
330
 
global_counters current_global_counters;
 
329
struct drizzle_system_variables global_system_variables;
 
330
struct drizzle_system_variables max_system_variables;
 
331
struct global_counters current_global_counters;
331
332
 
332
 
DRIZZLED_API const CHARSET_INFO *system_charset_info;
333
 
const CHARSET_INFO *files_charset_info;
 
333
const CHARSET_INFO *system_charset_info, *files_charset_info ;
334
334
const CHARSET_INFO *table_alias_charset;
335
335
const CHARSET_INFO *character_set_filesystem;
336
336
 
338
338
 
339
339
SHOW_COMP_OPTION have_symlink;
340
340
 
 
341
/* Thread specific variables */
 
342
boost::mutex LOCK_global_system_variables;
 
343
 
341
344
boost::condition_variable_any COND_refresh;
342
345
boost::condition_variable COND_thread_count;
343
346
pthread_t signal_thread;
 
347
boost::condition_variable COND_server_end;
344
348
 
345
349
/* Static variables */
346
350
 
355
359
global_buffer_constraint<uint64_t> global_read_rnd_buffer(0);
356
360
global_buffer_constraint<uint64_t> global_read_buffer(0);
357
361
 
358
 
DRIZZLED_API size_t transaction_message_threshold;
 
362
/** 
 
363
  Refresh value. We use to test this to find out if a refresh even has happened recently.
 
364
*/
 
365
uint64_t refresh_version;  /* Increments on each reload */
 
366
 
 
367
/* Function declarations */
 
368
bool drizzle_rm_tmp_tables();
359
369
 
360
370
static void drizzle_init_variables(void);
361
371
static void get_options();
366
376
 
367
377
fs::path base_plugin_dir(PKGPLUGINDIR);
368
378
 
369
 
po::options_description config_options(_("Config File Options"));
370
 
po::options_description long_options(_("Kernel Options"));
371
 
po::options_description plugin_load_options(_("Plugin Loading Options"));
372
 
po::options_description plugin_options(_("Plugin Options"));
373
 
po::options_description initial_options(_("Config and Plugin Loading"));
374
 
po::options_description full_options(_("Kernel and Plugin Loading and Plugin"));
 
379
po::options_description config_options("Config File Options");
 
380
po::options_description long_options("Kernel Options");
 
381
po::options_description plugin_load_options("Plugin Loading Options");
 
382
po::options_description plugin_options("Plugin Options");
 
383
po::options_description initial_options("Config and Plugin Loading");
 
384
po::options_description full_options("Kernel and Plugin Loading and Plugin");
375
385
vector<string> unknown_options;
376
386
vector<string> defaults_file_list;
377
387
po::variables_map vm;
378
388
 
 
389
fs::path data_home(LOCALSTATEDIR);
 
390
fs::path full_data_home(LOCALSTATEDIR);
 
391
 
379
392
po::variables_map &getVariablesMap()
380
393
{
381
394
  return vm;
382
395
}
383
396
 
384
 
namespace
385
 
{
386
 
 
387
 
std::string &getGlobHostname()
388
 
{
389
 
  static std::string glob_hostname("localhost");
390
 
  return glob_hostname;
391
 
}
392
 
 
393
 
void setServerHostname(const std::string &hostname)
394
 
{
395
 
  getGlobHostname()= hostname;
396
 
}
397
 
}
398
 
 
399
 
const std::string &getServerHostname()
400
 
{
401
 
  return getGlobHostname();
402
 
}
403
 
 
 
397
fs::path& getFullDataHome()
 
398
{
 
399
  return full_data_home;
 
400
}
 
401
 
 
402
fs::path& getDataHome()
 
403
{
 
404
  return data_home;
 
405
}
 
406
 
 
407
fs::path& getDataHomeCatalog()
 
408
{
 
409
  static fs::path data_home_catalog(getDataHome());
 
410
  return data_home_catalog;
 
411
}
 
412
 
 
413
 
404
414
/****************************************************************************
405
415
** Code to end drizzled
406
416
****************************************************************************/
479
489
{
480
490
 
481
491
  if (exit_code)
482
 
  {
483
 
    errmsg_printf(error::ERROR, _("Aborting"));
484
 
  }
 
492
    errmsg_printf(ERRMSG_LVL_ERROR, _("Aborting\n"));
485
493
  else if (opt_help)
486
 
  {
487
494
    usage();
488
 
  }
489
 
 
490
495
  clean_up(!opt_help && (exit_code));
491
496
  internal::my_end();
492
497
  exit(exit_code);
513
518
  (void) unlink(pid_file.file_string().c_str());        // This may not always exist
514
519
 
515
520
  if (print_message && server_start_time)
516
 
    errmsg_printf(drizzled::error::INFO, _(ER(ER_SHUTDOWN_COMPLETE)),internal::my_progname);
 
521
    errmsg_printf(ERRMSG_LVL_INFO, _(ER(ER_SHUTDOWN_COMPLETE)),internal::my_progname);
 
522
  {
 
523
    boost::mutex::scoped_lock scopedLock(session::Cache::singleton().mutex());
 
524
    ready_to_exit= true;
517
525
 
518
 
  session::Cache::singleton().shutdownFirst();
 
526
    /* do the broadcast inside the lock to ensure that my_end() is not called */
 
527
    COND_server_end.notify_all();
 
528
  }
519
529
 
520
530
  /*
521
531
    The following lines may never be executed as the main thread may have
540
550
      tmp_user_info= getpwnam(user);
541
551
      if ((!tmp_user_info || user_id != tmp_user_info->pw_uid) &&
542
552
          global_system_variables.log_warnings)
543
 
            errmsg_printf(error::WARN, _("One can only use the --user switch "
 
553
            errmsg_printf(ERRMSG_LVL_WARN, _("One can only use the --user switch "
544
554
                            "if running as root\n"));
545
555
    }
546
556
    return NULL;
547
557
  }
548
558
  if (not user)
549
559
  {
550
 
      errmsg_printf(error::ERROR, _("Fatal error: Please read \"Security\" section of "
551
 
                                    "the manual to find out how to run drizzled as root"));
 
560
      errmsg_printf(ERRMSG_LVL_ERROR, _("Fatal error: Please read \"Security\" section of "
 
561
                      "the manual to find out how to run drizzled as root!\n"));
552
562
    unireg_abort(1);
553
563
  }
554
 
 
555
 
  if (not strcmp(user, "root"))
 
564
  if (!strcmp(user,"root"))
556
565
    return NULL;                        // Avoid problem with dynamic libraries
557
566
 
558
567
  if (!(tmp_user_info= getpwnam(user)))
568
577
  return tmp_user_info;
569
578
 
570
579
err:
571
 
  errmsg_printf(error::ERROR, _("Fatal error: Can't change to run as user '%s' ;  "
 
580
  errmsg_printf(ERRMSG_LVL_ERROR, _("Fatal error: Can't change to run as user '%s' ;  "
572
581
                    "Please check that the user exists!\n"),user);
573
582
  unireg_abort(1);
574
583
 
575
584
#ifdef PR_SET_DUMPABLE
576
 
  if (getDebug().test(debug::CORE_ON_SIGNAL))
 
585
  if (test_flags.test(TEST_CORE_ON_SIGNAL))
577
586
  {
578
587
    /* inform kernel that process is dumpable */
579
588
    (void) prctl(PR_SET_DUMPABLE, 1);
665
674
 
666
675
static void find_plugin_dir(string progname)
667
676
{
668
 
  fs::path full_progname(fs::system_complete(progname));
669
 
 
670
 
  fs::path progdir(full_progname.parent_path());
671
 
  if (progdir.filename() == ".libs")
672
 
  {
673
 
    progdir= progdir.parent_path();
674
 
  }
675
 
 
676
 
  if (fs::exists(progdir / "drizzled.lo") || fs::exists(progdir / "drizzled.o"))
 
677
  if (progname[0] != FN_LIBCHAR)
 
678
  {
 
679
    /* We have a relative path and need to find the absolute */
 
680
    char working_dir[FN_REFLEN];
 
681
    char *working_dir_ptr= working_dir;
 
682
    working_dir_ptr= getcwd(working_dir_ptr, FN_REFLEN);
 
683
    string new_path(working_dir);
 
684
    if (*(new_path.end()-1) != '/')
 
685
      new_path.push_back('/');
 
686
    if (progname[0] == '.' && progname[1] == '/')
 
687
      new_path.append(progname.substr(2));
 
688
    else
 
689
      new_path.append(progname);
 
690
    progname.swap(new_path);
 
691
  }
 
692
 
 
693
  /* Now, trim off the exe name */
 
694
  string progdir(progname.substr(0, progname.rfind(FN_LIBCHAR)+1));
 
695
  if (progdir.rfind(".libs/") != string::npos)
 
696
  {
 
697
    progdir.assign(progdir.substr(0, progdir.rfind(".libs/")));
 
698
  }
 
699
  string testlofile(progdir);
 
700
  testlofile.append("drizzled.lo");
 
701
  string testofile(progdir);
 
702
  testofile.append("drizzled.o");
 
703
  struct stat testfile_stat;
 
704
  if (not (stat(testlofile.c_str(), &testfile_stat) && stat(testofile.c_str(), &testfile_stat)))
677
705
  {
678
706
    /* We are in a source dir! Plugin dir is ../plugin/.libs */
679
 
    base_plugin_dir= progdir.parent_path();
 
707
    size_t last_libchar_pos= progdir.rfind(FN_LIBCHAR,progdir.size()-2)+1;
 
708
    base_plugin_dir= progdir.substr(0,last_libchar_pos);
680
709
    base_plugin_dir /= "plugin";
681
710
    base_plugin_dir /= ".libs";
682
711
  }
785
814
  global_system_variables.max_allowed_packet= in_max_allowed_packet;
786
815
}
787
816
 
 
817
static void check_limits_mce(uint64_t in_max_connect_errors)
 
818
{
 
819
  max_connect_errors= MAX_CONNECT_ERRORS;
 
820
  if (in_max_connect_errors < 1 || in_max_connect_errors > ULONG_MAX)
 
821
  {
 
822
    cout << _("Error: Invalid Value for max_connect_errors");
 
823
    exit(-1);
 
824
  }
 
825
  max_connect_errors= in_max_connect_errors;
 
826
}
 
827
 
788
828
static void check_limits_max_err_cnt(uint64_t in_max_error_count)
789
829
{
790
830
  global_system_variables.max_error_count= DEFAULT_ERROR_COUNT;
1006
1046
 
1007
1047
static void check_limits_transaction_message_threshold(size_t in_transaction_message_threshold)
1008
1048
{
1009
 
  transaction_message_threshold= 1024*1024;
 
1049
  global_system_variables.transaction_message_threshold= 1024*1024;
1010
1050
  if ((int64_t) in_transaction_message_threshold < 128*1024 || (int64_t)in_transaction_message_threshold > 1024*1024)
1011
1051
  {
1012
1052
    cout << _("Error: Invalid Value for transaction_message_threshold valid values are between 131072 - 1048576 bytes");
1013
1053
    exit(-1);
1014
1054
  }
1015
 
  transaction_message_threshold= in_transaction_message_threshold;
 
1055
  global_system_variables.transaction_message_threshold= in_transaction_message_threshold;
1016
1056
}
1017
1057
 
1018
1058
static void process_defaults_files()
1066
1106
      defaults_file_list.push_back(*it);
1067
1107
    else
1068
1108
    {
1069
 
      errmsg_printf(error::ERROR,
 
1109
      errmsg_printf(ERRMSG_LVL_ERROR,
1070
1110
                  _("Defaults file '%s' not found\n"), (*it).c_str());
1071
1111
      unireg_abort(1);
1072
1112
    }
1074
1114
  }
1075
1115
}
1076
1116
 
1077
 
int init_basic_variables(int argc, char **argv)
 
1117
int init_common_variables(int argc, char **argv, module::Registry &plugins)
1078
1118
{
1079
1119
  time_t curr_time;
1080
1120
  umask(((~internal::my_umask) & 0666));
1091
1131
  drizzle_init_variables();
1092
1132
 
1093
1133
  find_plugin_dir(argv[0]);
 
1134
  {
 
1135
    struct tm tm_tmp;
 
1136
    localtime_r(&server_start_time,&tm_tmp);
 
1137
    strncpy(system_time_zone, tzname[tm_tmp.tm_isdst != 0 ? 1 : 0],
 
1138
            sizeof(system_time_zone)-1);
1094
1139
 
 
1140
  }
1095
1141
  /*
1096
1142
    We set SYSTEM time zone as reasonable default and
1097
1143
    also for failure of my_tz_init() and bootstrap mode.
1100
1146
  */
1101
1147
  global_system_variables.time_zone= my_tz_SYSTEM;
1102
1148
 
1103
 
  char ret_hostname[FN_REFLEN];
1104
 
  if (gethostname(ret_hostname,sizeof(ret_hostname)) < 0)
 
1149
  if (gethostname(glob_hostname,sizeof(glob_hostname)) < 0)
1105
1150
  {
1106
 
    errmsg_printf(error::WARN,
1107
 
                  _("gethostname failed, using '%s' as hostname"),
1108
 
                  getServerHostname().c_str());
 
1151
    strncpy(glob_hostname, STRING_WITH_LEN("localhost"));
 
1152
    errmsg_printf(ERRMSG_LVL_WARN, _("gethostname failed, using '%s' as hostname"),
 
1153
                  glob_hostname);
1109
1154
    pid_file= "drizzle";
1110
1155
  }
1111
1156
  else
1112
1157
  {
1113
 
    setServerHostname(ret_hostname);
1114
 
    pid_file= getServerHostname();
 
1158
    pid_file= glob_hostname;
1115
1159
  }
1116
1160
  pid_file.replace_extension(".pid");
1117
1161
 
1120
1164
  config_options.add_options()
1121
1165
  ("help,?", po::value<bool>(&opt_help)->default_value(false)->zero_tokens(),
1122
1166
  _("Display this help and exit."))
1123
 
  ("daemon,d", po::value<bool>(&opt_daemon)->default_value(false)->zero_tokens(),
1124
 
  _("Run as a daemon."))
1125
1167
  ("no-defaults", po::value<bool>()->default_value(false)->zero_tokens(),
1126
1168
  _("Configuration file defaults are not used if no-defaults is set"))
1127
1169
  ("defaults-file", po::value<vector<string> >()->composing()->notifier(&compose_defaults_file_list),
1162
1204
  ("completion-type", po::value<uint32_t>(&global_system_variables.completion_type)->default_value(0)->notifier(&check_limits_completion_type),
1163
1205
  _("Default completion type."))
1164
1206
  ("core-file",  _("Write core on errors."))
1165
 
  ("datadir", po::value<fs::path>(&getDataHome()),
 
1207
  ("datadir", po::value<fs::path>(&data_home),
1166
1208
  _("Path to the database root."))
1167
1209
  ("default-storage-engine", po::value<string>(),
1168
1210
  _("Set the default storage engine for tables."))
1199
1241
  _("Path for temporary files."))
1200
1242
  ("transaction-isolation", po::value<string>(),
1201
1243
  _("Default transaction isolation level."))
1202
 
  ("transaction-message-threshold", po::value<size_t>(&transaction_message_threshold)->default_value(1024*1024)->notifier(&check_limits_transaction_message_threshold),
 
1244
  ("transaction-message-threshold", po::value<size_t>(&global_system_variables.transaction_message_threshold)->default_value(1024*1024)->notifier(&check_limits_transaction_message_threshold),
1203
1245
  _("Max message size written to transaction log, valid values 131072 - 1048576 bytes."))
1204
1246
  ("user,u", po::value<string>(),
1205
1247
  _("Run drizzled daemon as user."))  
1225
1267
  _("A global cap on the amount of memory that can be allocated by session join buffers (0 means unlimited)"))
1226
1268
  ("max-allowed-packet", po::value<uint32_t>(&global_system_variables.max_allowed_packet)->default_value(64*1024*1024L)->notifier(&check_limits_map),
1227
1269
  _("Max packetlength to send/receive from to server."))
 
1270
  ("max-connect-errors", po::value<uint64_t>(&max_connect_errors)->default_value(MAX_CONNECT_ERRORS)->notifier(&check_limits_mce),
 
1271
  _("If there is more than this number of interrupted connections from a "
 
1272
     "host this host will be blocked from further connections."))
1228
1273
  ("max-error-count", po::value<uint64_t>(&global_system_variables.max_error_count)->default_value(DEFAULT_ERROR_COUNT)->notifier(&check_limits_max_err_cnt),
1229
1274
  _("Max number of errors/warnings to store for a statement."))
1230
1275
  ("max-heap-table-size", po::value<uint64_t>(&global_system_variables.max_heap_table_size)->default_value(16*1024*1024L)->notifier(&check_limits_mhts),
1305
1350
  po::value<uint64_t>(&global_system_variables.tmp_table_size)->default_value(16*1024*1024L)->notifier(&check_limits_tmp_table_size),
1306
1351
  _("If an internal in-memory temporary table exceeds this size, Drizzle will"
1307
1352
     " automatically convert it to an on-disk MyISAM table."))
1308
 
  ("verbose", po::value<std::string>()->default_value(error::verbose_string())->notifier(&error::check_verbosity),
1309
 
  _("The stack size for each thread."))
1310
1353
  ;
1311
1354
 
1312
1355
  full_options.add(long_options);
1328
1371
  }
1329
1372
  catch (std::exception&)
1330
1373
  {
1331
 
    errmsg_printf(error::ERROR, _("Duplicate entry for command line option\n"));
 
1374
    errmsg_printf(ERRMSG_LVL_ERROR, _("Duplicate entry for command line option\n"));
1332
1375
    unireg_abort(1);
1333
1376
  }
1334
1377
 
1374
1417
  }
1375
1418
  catch (po::validation_error &err)
1376
1419
  {
1377
 
    errmsg_printf(error::ERROR,  
 
1420
    errmsg_printf(ERRMSG_LVL_ERROR,  
1378
1421
                  _("%s: %s.\n"
1379
1422
                    "Use --help to get a list of available options\n"),
1380
1423
                  internal::my_progname, err.what());
1392
1435
  }
1393
1436
  catch (po::validation_error &err)
1394
1437
  {
1395
 
    errmsg_printf(error::ERROR,
 
1438
    errmsg_printf(ERRMSG_LVL_ERROR,
1396
1439
                  _("%s: %s.\n"
1397
1440
                    "Use --help to get a list of available options\n"),
1398
1441
                  internal::my_progname, err.what());
1399
1442
    unireg_abort(1);
1400
1443
  }
1401
1444
 
1402
 
  return 0;
1403
 
}
1404
 
 
1405
 
int init_remaining_variables(module::Registry &plugins)
1406
 
{
1407
 
  int style = po::command_line_style::default_style & ~po::command_line_style::allow_guessing;
1408
 
 
1409
 
  current_pid= getpid();                /* Save for later ref */
1410
 
 
1411
1445
  /* At this point, we've read all the options we need to read from files and
1412
1446
     collected most of them into unknown options - now let's load everything
1413
1447
  */
1414
1448
 
1415
1449
  if (plugin_init(plugins, plugin_options))
1416
1450
  {
1417
 
    errmsg_printf(error::ERROR, _("Failed to initialize plugins\n"));
 
1451
    errmsg_printf(ERRMSG_LVL_ERROR, _("Failed to initialize plugins\n"));
1418
1452
    unireg_abort(1);
1419
1453
  }
1420
1454
 
1435
1469
  }
1436
1470
  catch (po::validation_error &err)
1437
1471
  {
1438
 
    errmsg_printf(error::ERROR,
 
1472
    errmsg_printf(ERRMSG_LVL_ERROR,
1439
1473
                  _("%s: %s.\n"
1440
1474
                    "Use --help to get a list of available options\n"),
1441
1475
                  internal::my_progname, err.what());
1443
1477
  }
1444
1478
  catch (po::invalid_command_line_syntax &err)
1445
1479
  {
1446
 
    errmsg_printf(error::ERROR,
 
1480
    errmsg_printf(ERRMSG_LVL_ERROR,
1447
1481
                  _("%s: %s.\n"
1448
1482
                    "Use --help to get a list of available options\n"),
1449
1483
                  internal::my_progname, err.what());
1451
1485
  }
1452
1486
  catch (po::unknown_option &err)
1453
1487
  {
1454
 
    errmsg_printf(error::ERROR,
 
1488
    errmsg_printf(ERRMSG_LVL_ERROR,
1455
1489
                  _("%s\nUse --help to get a list of available options\n"),
1456
1490
                  err.what());
1457
1491
    unireg_abort(1);
1463
1497
  }
1464
1498
  catch (po::validation_error &err)
1465
1499
  {
1466
 
    errmsg_printf(error::ERROR,  
 
1500
    errmsg_printf(ERRMSG_LVL_ERROR,  
1467
1501
                  _("%s: %s.\n"
1468
1502
                    "Use --help to get a list of available options\n"),
1469
1503
                  internal::my_progname, err.what());
1487
1521
 
1488
1522
  fix_paths();
1489
1523
 
 
1524
  current_pid= getpid();                /* Save for later ref */
1490
1525
  init_time();                          /* Init time-functions (read zone) */
1491
1526
 
1492
1527
  if (item_create_init())
1500
1535
  if (!(default_charset_info=
1501
1536
        get_charset_by_csname(default_character_set_name, MY_CS_PRIMARY)))
1502
1537
  {
1503
 
    errmsg_printf(error::ERROR, _("Error getting default charset"));
 
1538
    errmsg_printf(ERRMSG_LVL_ERROR, _("Error getting default charset"));
1504
1539
    return 1;                           // Eof of the list
1505
1540
  }
1506
1541
 
1512
1547
    const CHARSET_INFO * const default_collation= get_charset_by_name(default_collation_name);
1513
1548
    if (not default_collation)
1514
1549
    {
1515
 
      errmsg_printf(error::ERROR, _(ER(ER_UNKNOWN_COLLATION)), default_collation_name);
 
1550
      errmsg_printf(ERRMSG_LVL_ERROR, _(ER(ER_UNKNOWN_COLLATION)), default_collation_name);
1516
1551
      return 1;
1517
1552
    }
1518
1553
    if (not my_charset_same(default_charset_info, default_collation))
1519
1554
    {
1520
 
      errmsg_printf(error::ERROR, _(ER(ER_COLLATION_CHARSET_MISMATCH)),
 
1555
      errmsg_printf(ERRMSG_LVL_ERROR, _(ER(ER_COLLATION_CHARSET_MISMATCH)),
1521
1556
                    default_collation_name,
1522
1557
                    default_charset_info->csname);
1523
1558
      return 1;
1530
1565
  if (not (character_set_filesystem=
1531
1566
           get_charset_by_csname(character_set_filesystem_name, MY_CS_PRIMARY)))
1532
1567
  {
1533
 
    errmsg_printf(error::ERROR, _("Error setting collation"));
 
1568
    errmsg_printf(ERRMSG_LVL_ERROR, _("Error setting collation"));
1534
1569
    return 1;
1535
1570
  }
1536
1571
  global_system_variables.character_set_filesystem= character_set_filesystem;
1538
1573
  if (!(my_default_lc_time_names=
1539
1574
        my_locale_by_name(lc_time_names_name)))
1540
1575
  {
1541
 
    errmsg_printf(error::ERROR, _("Unknown locale: '%s'"), lc_time_names_name);
 
1576
    errmsg_printf(ERRMSG_LVL_ERROR, _("Unknown locale: '%s'"), lc_time_names_name);
1542
1577
    return 1;
1543
1578
  }
1544
1579
  global_system_variables.lc_time_names= my_default_lc_time_names;
1558
1593
  */
1559
1594
  if (table_cache_init())
1560
1595
  {
1561
 
    errmsg_printf(error::ERROR, _("Could not initialize table cache\n"));
 
1596
    errmsg_printf(ERRMSG_LVL_ERROR, _("Could not initialize table cache\n"));
1562
1597
    unireg_abort(1);
1563
1598
  }
1564
1599
 
1573
1608
 
1574
1609
  if (xid_cache_init())
1575
1610
  {
1576
 
    errmsg_printf(error::ERROR, _("XA cache initialization failed: Out of memory\n"));
 
1611
    errmsg_printf(ERRMSG_LVL_ERROR, _("XA cache initialization failed: Out of memory\n"));
1577
1612
    unireg_abort(1);
1578
1613
  }
1579
1614
 
1602
1637
 
1603
1638
  if (plugin::Scheduler::setPlugin(scheduler_name))
1604
1639
  {
1605
 
      errmsg_printf(error::ERROR,
 
1640
      errmsg_printf(ERRMSG_LVL_ERROR,
1606
1641
                   _("No scheduler found, cannot continue!\n"));
1607
1642
      unireg_abort(1);
1608
1643
  }
1627
1662
    engine= plugin::StorageEngine::findByName(name);
1628
1663
    if (engine == NULL)
1629
1664
    {
1630
 
      errmsg_printf(error::ERROR, _("Unknown/unsupported storage engine: %s\n"),
 
1665
      errmsg_printf(ERRMSG_LVL_ERROR, _("Unknown/unsupported storage engine: %s\n"),
1631
1666
                    default_storage_engine_str);
1632
1667
      unireg_abort(1);
1633
1668
    }
1668
1703
  OPT_BACK_LOG,
1669
1704
  OPT_JOIN_BUFF_SIZE,
1670
1705
  OPT_MAX_ALLOWED_PACKET,
 
1706
  OPT_MAX_CONNECT_ERRORS,
1671
1707
  OPT_MAX_HEP_TABLE_SIZE,
1672
1708
  OPT_MAX_JOIN_SIZE,
1673
1709
  OPT_MAX_SORT_LENGTH,
1721
1757
  {"help", '?', N_("Display this help and exit."),
1722
1758
   (char**) &opt_help, (char**) &opt_help, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0,
1723
1759
   0, 0},
1724
 
  {"daemon", 'd', N_("Run as daemon."),
1725
 
   (char**) &opt_daemon, (char**) &opt_daemon, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0,
1726
 
   0, 0},
1727
1760
  {"auto-increment-increment", OPT_AUTO_INCREMENT,
1728
1761
   N_("Auto-increment columns are incremented by this"),
1729
1762
   (char**) &global_system_variables.auto_increment_increment,
1849
1882
   (char**) &global_system_variables.max_allowed_packet,
1850
1883
   (char**) &max_system_variables.max_allowed_packet, 0, GET_UINT32,
1851
1884
   REQUIRED_ARG, 64*1024*1024L, 1024, 1024L*1024L*1024L, MALLOC_OVERHEAD, 1024, 0},
 
1885
  {"max_connect_errors", OPT_MAX_CONNECT_ERRORS,
 
1886
   N_("If there is more than this number of interrupted connections from a "
 
1887
      "host this host will be blocked from further connections."),
 
1888
   (char**) &max_connect_errors, (char**) &max_connect_errors, 0, GET_UINT64,
 
1889
   REQUIRED_ARG, MAX_CONNECT_ERRORS, 1, ULONG_MAX, 0, 1, 0},
1852
1890
  {"max_heap_table_size", OPT_MAX_HEP_TABLE_SIZE,
1853
1891
   N_("Don't allow creation of heap tables bigger than this."),
1854
1892
   (char**) &global_system_variables.max_heap_table_size,
2061
2099
  opt_tc_log_file= (char *)"tc.log";      // no hostname in tc_log file name !
2062
2100
  cleanup_done= 0;
2063
2101
  dropping_tables= ha_open_options=0;
2064
 
  getDebug().reset();
 
2102
  test_flags.reset();
2065
2103
  wake_thread=0;
2066
2104
  abort_loop= select_thread_in_use= false;
2067
 
  shutdown_in_progress= 0;
 
2105
  ready_to_exit= shutdown_in_progress= 0;
2068
2106
  drizzled_user= drizzled_chroot= 0;
2069
2107
  memset(&current_global_counters, 0, sizeof(current_global_counters));
2070
2108
  key_map_full.set();
2149
2187
      drizzled_user= (char *)vm["user"].as<string>().c_str();
2150
2188
 
2151
2189
    else
2152
 
      errmsg_printf(error::WARN, _("Ignoring user change to '%s' because the user was "
 
2190
      errmsg_printf(ERRMSG_LVL_WARN, _("Ignoring user change to '%s' because the user was "
2153
2191
                                       "set to '%s' earlier on the command line\n"),
2154
2192
                    vm["user"].as<string>().c_str(), drizzled_user);
2155
2193
  }
2216
2254
  {
2217
2255
    if (vm["exit-info"].as<long>())
2218
2256
    {
2219
 
      getDebug().set((uint32_t) vm["exit-info"].as<long>());
 
2257
      test_flags.set((uint32_t) vm["exit-info"].as<long>());
2220
2258
    }
2221
2259
  }
2222
2260
 
2223
2261
  if (vm.count("want-core"))
2224
2262
  {
2225
 
    getDebug().set(debug::CORE_ON_SIGNAL);
 
2263
    test_flags.set(TEST_CORE_ON_SIGNAL);
2226
2264
  }
2227
2265
 
2228
2266
  if (vm.count("skip-stack-trace"))
2229
2267
  {
2230
 
    getDebug().set(debug::NO_STACKTRACE);
 
2268
    test_flags.set(TEST_NO_STACKTRACE);
2231
2269
  }
2232
2270
 
2233
2271
  if (vm.count("skip-symlinks"))
2237
2275
 
2238
2276
  if (vm.count("transaction-isolation"))
2239
2277
  {
2240
 
    int type= tx_isolation_typelib.find_type_or_exit(vm["transaction-isolation"].as<string>().c_str(), "transaction-isolation");
2241
 
    global_system_variables.tx_isolation= type - 1;
 
2278
    int type;
 
2279
    type= find_type_or_exit((char *)vm["transaction-isolation"].as<string>().c_str(), &tx_isolation_typelib, "transaction-isolation");
 
2280
    global_system_variables.tx_isolation= (type-1);
2242
2281
  }
2243
2282
 
2244
2283
  /* @TODO Make this all strings */
2265
2304
  if (opt_debugging)
2266
2305
  {
2267
2306
    /* Allow break with SIGINT, no core or stack trace */
2268
 
    getDebug().set(debug::ALLOW_SIGINT);
2269
 
    getDebug().set(debug::NO_STACKTRACE);
2270
 
    getDebug().reset(debug::CORE_ON_SIGNAL);
 
2307
    test_flags.set(TEST_SIGINT);
 
2308
    test_flags.set(TEST_NO_STACKTRACE);
 
2309
    test_flags.reset(TEST_CORE_ON_SIGNAL);
2271
2310
  }
2272
2311
 
2273
2312
  if (drizzled_chroot)
2319
2358
    {
2320
2359
      if (errno != EEXIST)
2321
2360
      {
2322
 
        errmsg_printf(error::ERROR, _("There was an error creating the '%s' part of the path '%s'.  Please check the path exists and is writable.\n"), fs::path(drizzle_tmpdir).leaf().c_str(), drizzle_tmpdir.c_str());
 
2361
        perror(drizzle_tmpdir.c_str());
2323
2362
        exit(1);
2324
2363
      }
2325
2364
    }
2326
2365
 
2327
2366
    if (stat(drizzle_tmpdir.c_str(), &buf) || (S_ISDIR(buf.st_mode) == false))
2328
2367
    {
2329
 
      errmsg_printf(error::ERROR, _("There was an error opening the path '%s', please check the path exists and is writable.\n"), drizzle_tmpdir.c_str());
 
2368
      perror(drizzle_tmpdir.c_str());
2330
2369
      exit(1);
2331
2370
    }
2332
2371
  }