~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to sql/mysqld.cc

  • Committer: Brian Aker
  • Date: 2008-06-29 20:10:28 UTC
  • mto: This revision was merged to the branch mainline in revision 16.
  • Revision ID: brian@tangent.org-20080629201028-923bdzz0qcjmd6cm
Cleaned up show status.

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
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
 
#include "drizzled/configmake.h"
22
 
#include "drizzled/atomics.h"
23
 
#include "drizzled/data_home.h"
24
 
 
25
 
#include <netdb.h>
26
 
#include <sys/types.h>
27
 
#include <netinet/tcp.h>
28
 
#include <netinet/in.h>
29
 
#include <signal.h>
30
 
#include <limits.h>
31
 
#include <stdexcept>
32
 
 
33
 
#include <boost/program_options.hpp>
34
 
#include "drizzled/program_options/config_file.h"
35
 
#include <boost/thread/recursive_mutex.hpp>
36
 
#include <boost/thread/mutex.hpp>
37
 
#include <boost/thread/shared_mutex.hpp>
38
 
#include <boost/thread/condition_variable.hpp>
39
 
#include <boost/filesystem.hpp>
40
 
 
41
 
#include "drizzled/internal/my_sys.h"
42
 
#include "drizzled/internal/my_bit.h"
43
 
#include <drizzled/my_hash.h>
44
 
#include <drizzled/error.h>
45
 
#include <drizzled/errmsg_print.h>
46
 
#include <drizzled/tztime.h>
47
 
#include <drizzled/sql_base.h>
48
 
#include <drizzled/show.h>
49
 
#include <drizzled/sql_parse.h>
50
 
#include <drizzled/item/cmpfunc.h>
51
 
#include <drizzled/session.h>
52
 
#include <drizzled/item/create.h>
53
 
#include <drizzled/unireg.h>
54
 
#include "drizzled/temporal_format.h" /* For init_temporal_formats() */
55
 
#include "drizzled/plugin/listen.h"
56
 
#include "drizzled/plugin/error_message.h"
57
 
#include "drizzled/plugin/client.h"
58
 
#include "drizzled/plugin/scheduler.h"
59
 
#include "drizzled/plugin/xa_resource_manager.h"
60
 
#include "drizzled/plugin/monitored_in_transaction.h"
61
 
#include "drizzled/replication_services.h" /* For ReplicationServices::evaluateRegisteredPlugins() */
62
 
#include "drizzled/probes.h"
63
 
#include "drizzled/session/cache.h"
64
 
#include "drizzled/charset.h"
65
 
#include "plugin/myisam/myisam.h"
66
 
#include "drizzled/drizzled.h"
67
 
#include "drizzled/module/registry.h"
68
 
#include "drizzled/module/load_list.h"
69
 
#include "drizzled/global_buffer.h"
70
 
 
71
 
#include "drizzled/definition/cache.h"
72
 
 
73
 
#include "drizzled/plugin/event_observer.h"
74
 
 
75
 
#include "drizzled/message/cache.h"
76
 
 
77
 
#include <google/protobuf/stubs/common.h>
78
 
 
79
 
#if TIME_WITH_SYS_TIME
80
 
# include <sys/time.h>
81
 
# include <time.h>
82
 
#else
83
 
# if HAVE_SYS_TIME_H
84
 
#  include <sys/time.h>
85
 
# else
86
 
#  include <time.h>
87
 
# endif
88
 
#endif
 
1
/* Copyright (C) 2000-2003 MySQL AB
 
2
 
 
3
   This program is free software; you can redistribute it and/or modify
 
4
   it under the terms of the GNU General Public License as published by
 
5
   the Free Software Foundation; version 2 of the License.
 
6
 
 
7
   This program is distributed in the hope that it will be useful,
 
8
   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
9
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
10
   GNU General Public License for more details.
 
11
 
 
12
   You should have received a copy of the GNU General Public License
 
13
   along with this program; if not, write to the Free Software
 
14
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
 
15
 
 
16
#include "mysql_priv.h"
 
17
#include <m_ctype.h>
 
18
#include <my_dir.h>
 
19
#include <my_bit.h>
 
20
#include "slave.h"
 
21
#include "rpl_mi.h"
 
22
#include "sql_repl.h"
 
23
#include "rpl_filter.h"
 
24
#include "repl_failsafe.h"
 
25
#include "stacktrace.h"
 
26
#include "mysqld_suffix.h"
 
27
#include "mysys_err.h"
 
28
 
 
29
#include "../storage/myisam/ha_myisam.h"
89
30
 
90
31
#ifdef HAVE_SYS_PRCTL_H
91
32
#include <sys/prctl.h>
92
33
#endif
93
 
#include <sys/socket.h>
94
 
 
95
 
 
 
34
 
 
35
#ifndef DEFAULT_SKIP_THREAD_PRIORITY
 
36
#define DEFAULT_SKIP_THREAD_PRIORITY 0
 
37
#endif
 
38
 
 
39
#include <thr_alarm.h>
 
40
#include <errmsg.h>
 
41
 
 
42
#define mysqld_charset &my_charset_latin1
 
43
 
 
44
#ifdef HAVE_purify
 
45
#define IF_PURIFY(A,B) (A)
 
46
#else
 
47
#define IF_PURIFY(A,B) (B)
 
48
#endif
 
49
 
 
50
#if SIZEOF_CHARP == 4
 
51
#define MAX_MEM_TABLE_SIZE ~(ulong) 0
 
52
#else
 
53
#define MAX_MEM_TABLE_SIZE ~(ulonglong) 0
 
54
#endif
 
55
 
 
56
/* We have HAVE_purify below as this speeds up the shutdown of MySQL */
 
57
 
 
58
#if defined(HAVE_DEC_3_2_THREADS) || defined(SIGNALS_DONT_BREAK_READ) || defined(HAVE_purify) && defined(__linux__)
 
59
#define HAVE_CLOSE_SERVER_SOCK 1
 
60
#endif
 
61
 
 
62
extern "C" {                                    // Because of SCO 3.2V4.2
96
63
#include <errno.h>
97
64
#include <sys/stat.h>
98
 
#include "drizzled/option.h"
 
65
#ifndef __GNU_LIBRARY__
 
66
#define __GNU_LIBRARY__                         // Skip warnings in getopt.h
 
67
#endif
 
68
#include <my_getopt.h>
99
69
#ifdef HAVE_SYSENT_H
100
70
#include <sysent.h>
101
71
#endif
 
72
#ifdef HAVE_PWD_H
102
73
#include <pwd.h>                                // For getpwent
 
74
#endif
 
75
#ifdef HAVE_GRP_H
103
76
#include <grp.h>
 
77
#endif
 
78
#include <my_net.h>
 
79
 
 
80
#include <sys/resource.h>
104
81
 
105
82
#ifdef HAVE_SELECT_H
106
83
#  include <select.h>
116
93
#include <sys/mman.h>
117
94
#endif
118
95
 
 
96
#define SIGNAL_FMT "signal %d"
 
97
  
 
98
 
119
99
#if defined(__FreeBSD__) && defined(HAVE_IEEEFP_H)
120
100
#include <ieeefp.h>
 
101
#ifdef HAVE_FP_EXCEPT                           // Fix type conflict
 
102
typedef fp_except fp_except_t;
 
103
#endif
121
104
#endif /* __FreeBSD__ && HAVE_IEEEFP_H */
122
105
 
123
106
#ifdef HAVE_FPU_CONTROL_H
129
112
#include <sys/fpu.h>
130
113
#endif
131
114
 
132
 
#include "drizzled/internal/my_pthread.h"                       // For thr_setconcurency()
133
 
#include "drizzled/constrained_value.h"
134
 
 
135
 
#include <drizzled/gettext.h>
136
 
 
137
 
 
138
 
#ifdef HAVE_VALGRIND
139
 
#define IF_PURIFY(A,B) (A)
140
 
#else
141
 
#define IF_PURIFY(A,B) (B)
142
 
#endif
143
 
 
144
 
#define MAX_MEM_TABLE_SIZE SIZE_MAX
145
 
#include <iostream>
146
 
#include <fstream>
147
 
 
148
 
 
149
 
using namespace std;
150
 
namespace fs=boost::filesystem;
151
 
namespace po=boost::program_options;
152
 
namespace dpo=drizzled::program_options;
153
 
 
154
 
 
155
 
namespace drizzled
156
 
{
157
 
 
158
 
#define mysqld_charset &my_charset_utf8_general_ci
159
115
inline void setup_fpu()
160
116
{
161
117
#if defined(__FreeBSD__) && defined(HAVE_IEEEFP_H)
185
141
#endif /* __i386__ && HAVE_FPU_CONTROL_H && _FPU_DOUBLE */
186
142
}
187
143
 
 
144
} /* cplusplus */
 
145
 
 
146
#define MYSQL_KILL_SIGNAL SIGTERM
 
147
 
 
148
#include <my_pthread.h>                 // For thr_setconcurency()
 
149
 
188
150
#ifdef SOLARIS
189
151
extern "C" int gethostname(char *name, int namelen);
190
152
#endif
191
153
 
192
 
const char *first_keyword= "first";
193
 
const char * const DRIZZLE_CONFIG_NAME= "drizzled";
194
 
 
 
154
extern "C" sig_handler handle_segfault(int sig);
 
155
 
 
156
/* Constants */
 
157
 
 
158
const char *show_comp_option_name[]= {"YES", "NO", "DISABLED"};
 
159
/*
 
160
  WARNING: When adding new SQL modes don't forget to update the
 
161
           tables definitions that stores it's value.
 
162
           (ie: mysql.event, mysql.proc)
 
163
*/
 
164
static const char *optimizer_switch_names[]=
 
165
{
 
166
  "no_materialization", "no_semijoin",
 
167
  NullS
 
168
};
 
169
 
 
170
/* Corresponding defines are named OPTIMIZER_SWITCH_XXX */
 
171
static const unsigned int optimizer_switch_names_len[]=
 
172
{
 
173
  /*no_materialization*/          19,
 
174
  /*no_semijoin*/                 11
 
175
};
 
176
 
 
177
TYPELIB optimizer_switch_typelib= { array_elements(optimizer_switch_names)-1,"",
 
178
                                    optimizer_switch_names,
 
179
                                    (unsigned int *)optimizer_switch_names_len };
 
180
 
 
181
static const char *tc_heuristic_recover_names[]=
 
182
{
 
183
  "COMMIT", "ROLLBACK", NullS
 
184
};
 
185
static TYPELIB tc_heuristic_recover_typelib=
 
186
{
 
187
  array_elements(tc_heuristic_recover_names)-1,"",
 
188
  tc_heuristic_recover_names, NULL
 
189
};
 
190
 
 
191
static const char *thread_handling_names[]=
 
192
{ "one-thread-per-connection", "no-threads",
 
193
  "pool-of-threads",
 
194
  NullS};
 
195
 
 
196
TYPELIB thread_handling_typelib=
 
197
{
 
198
  array_elements(thread_handling_names) - 1, "",
 
199
  thread_handling_names, NULL
 
200
};
 
201
 
 
202
const char *first_keyword= "first", *binary_keyword= "BINARY";
 
203
const char *my_localhost= "localhost";
 
204
#if SIZEOF_OFF_T > 4 && defined(BIG_TABLES)
195
205
#define GET_HA_ROWS GET_ULL
196
 
 
197
 
const char *tx_isolation_names[] =
198
 
{ "READ-UNCOMMITTED", "READ-COMMITTED", "REPEATABLE-READ", "SERIALIZABLE",
199
 
  NULL};
200
 
 
201
 
TYPELIB tx_isolation_typelib= {array_elements(tx_isolation_names)-1,"",
202
 
                               tx_isolation_names, NULL};
 
206
#else
 
207
#define GET_HA_ROWS GET_ULONG
 
208
#endif
 
209
 
 
210
bool opt_large_files= sizeof(my_off_t) > 4;
203
211
 
204
212
/*
205
213
  Used with --help for detailed option
206
214
*/
207
 
bool opt_help= false;
 
215
static my_bool opt_help= 0, opt_verbose= 0;
208
216
 
209
217
arg_cmp_func Arg_comparator::comparator_matrix[5][2] =
210
218
{{&Arg_comparator::compare_string,     &Arg_comparator::compare_e_string},
213
221
 {&Arg_comparator::compare_row,        &Arg_comparator::compare_e_row},
214
222
 {&Arg_comparator::compare_decimal,    &Arg_comparator::compare_e_decimal}};
215
223
 
 
224
const char *log_output_names[] = { "NONE", "FILE", "TABLE", NullS};
 
225
static const unsigned int log_output_names_len[]= { 4, 4, 5, 0 };
 
226
TYPELIB log_output_typelib= {array_elements(log_output_names)-1,"",
 
227
                             log_output_names, 
 
228
                             (unsigned int *) log_output_names_len};
 
229
 
216
230
/* static variables */
217
231
 
218
 
static bool opt_debugging= false;
219
 
static uint32_t wake_thread;
220
 
static char *drizzled_chroot;
221
 
static const char *default_character_set_name;
222
 
static const char *character_set_filesystem_name;
 
232
/* the default log output is log tables */
 
233
static bool lower_case_table_names_used= 0;
 
234
static bool volatile select_thread_in_use, signal_thread_in_use;
 
235
static bool volatile ready_to_exit;
 
236
static my_bool opt_debugging= 0, opt_external_locking= 0, opt_console= 0;
 
237
static my_bool opt_short_log_format= 0;
 
238
static uint kill_cached_threads, wake_thread;
 
239
static ulong killed_threads, thread_created;
 
240
static ulong max_used_connections;
 
241
static volatile ulong cached_thread_count= 0;
 
242
static char *mysqld_user, *mysqld_chroot, *log_error_file_ptr;
 
243
static char *opt_init_slave, *language_ptr, *opt_init_connect;
 
244
static char *default_character_set_name;
 
245
static char *character_set_filesystem_name;
223
246
static char *lc_time_names_name;
224
 
static char *default_collation_name;
 
247
static char *my_bind_addr_str;
 
248
static char *default_collation_name; 
225
249
static char *default_storage_engine_str;
226
 
static const char *compiled_default_collation_name= "utf8_general_ci";
 
250
static char compiled_default_collation_name[]= MYSQL_DEFAULT_COLLATION_NAME;
 
251
static I_List<THD> thread_cache;
 
252
static double long_query_time;
 
253
 
 
254
static pthread_cond_t COND_thread_cache, COND_flush_thread_cache;
227
255
 
228
256
/* Global variables */
229
257
 
230
 
bool volatile ready_to_exit;
231
 
char *drizzled_user;
232
 
bool volatile select_thread_in_use;
 
258
bool opt_update_log, opt_bin_log;
 
259
my_bool opt_log, opt_slow_log;
 
260
ulong log_output_options;
 
261
my_bool opt_log_queries_not_using_indexes= 0;
 
262
bool opt_error_log= IF_WIN(1,0);
 
263
bool opt_disable_networking=0, opt_skip_show_db=0;
 
264
my_bool opt_character_set_client_handshake= 1;
 
265
bool server_id_supplied = 0;
 
266
bool opt_endinfo, using_udf_functions;
 
267
my_bool locked_in_memory;
 
268
bool opt_using_transactions, using_update_log;
233
269
bool volatile abort_loop;
234
270
bool volatile shutdown_in_progress;
235
 
char *opt_scheduler_default;
236
 
const char *opt_scheduler= NULL;
237
 
 
238
 
size_t my_thread_stack_size= 0;
239
 
 
240
 
/*
241
 
  Legacy global plugin::StorageEngine. These will be removed (please do not add more).
242
 
*/
243
 
plugin::StorageEngine *heap_engine;
244
 
plugin::StorageEngine *myisam_engine;
245
 
 
246
 
bool calling_initgroups= false; /**< Used in SIGSEGV handler. */
247
 
 
248
 
uint32_t drizzled_bind_timeout;
249
 
std::bitset<12> test_flags;
250
 
uint32_t dropping_tables, ha_open_options;
251
 
uint32_t tc_heuristic_recover= 0;
252
 
uint64_t session_startup_options;
253
 
back_log_constraints back_log(50);
254
 
uint32_t server_id;
255
 
uint64_t table_cache_size;
256
 
size_t table_def_size;
257
 
uint64_t max_connect_errors;
258
 
uint32_t global_thread_id= 1UL;
259
 
pid_t current_pid;
260
 
 
261
 
extern const double log_10[309];
 
271
my_bool opt_skip_slave_start = 0; ///< If set, slave is not autostarted
 
272
my_bool opt_reckless_slave = 0;
 
273
my_bool opt_enable_named_pipe= 0;
 
274
my_bool opt_local_infile, opt_slave_compressed_protocol;
 
275
my_bool opt_safe_user_create = 0;
 
276
my_bool opt_show_slave_auth_info, opt_sql_bin_update = 0;
 
277
my_bool opt_log_slave_updates= 0;
 
278
 
 
279
/*
 
280
  Legacy global handlerton. These will be removed (please do not add more).
 
281
*/
 
282
handlerton *heap_hton;
 
283
handlerton *myisam_hton;
 
284
 
 
285
my_bool opt_readonly, use_temp_pool, relay_log_purge;
 
286
my_bool opt_sync_frm, opt_allow_suspicious_udfs;
 
287
my_bool opt_secure_auth= 0;
 
288
char* opt_secure_file_priv= 0;
 
289
my_bool opt_log_slow_admin_statements= 0;
 
290
my_bool opt_log_slow_slave_statements= 0;
 
291
my_bool lower_case_file_system= 0;
 
292
my_bool opt_large_pages= 0;
 
293
uint    opt_large_page_size= 0;
 
294
my_bool opt_old_style_user_limits= 0, trust_function_creators= 0;
 
295
/*
 
296
  True if there is at least one per-hour limit for some user, so we should
 
297
  check them before each query (and possibly reset counters when hour is
 
298
  changed). False otherwise.
 
299
*/
 
300
volatile bool mqh_used = 0;
 
301
my_bool opt_noacl;
 
302
 
 
303
ulong opt_binlog_rows_event_max_size;
 
304
const char *binlog_format_names[]= {"MIXED", "STATEMENT", "ROW", NullS};
 
305
TYPELIB binlog_format_typelib=
 
306
  { array_elements(binlog_format_names) - 1, "",
 
307
    binlog_format_names, NULL };
 
308
ulong opt_binlog_format_id= (ulong) BINLOG_FORMAT_UNSPEC;
 
309
const char *opt_binlog_format= binlog_format_names[opt_binlog_format_id];
 
310
#ifdef HAVE_INITGROUPS
 
311
static bool calling_initgroups= FALSE; /**< Used in SIGSEGV handler. */
 
312
#endif
 
313
uint mysqld_port, test_flags, select_errors, dropping_tables, ha_open_options;
 
314
uint mysqld_port_timeout;
 
315
uint delay_key_write_options, protocol_version;
 
316
uint lower_case_table_names;
 
317
uint tc_heuristic_recover= 0;
 
318
uint volatile thread_count, thread_running;
 
319
ulonglong thd_startup_options;
 
320
ulong back_log, connect_timeout, server_id;
 
321
ulong table_cache_size, table_def_size;
 
322
ulong what_to_log;
 
323
ulong query_buff_size, slow_launch_time, slave_open_temp_tables;
 
324
ulong open_files_limit, max_binlog_size, max_relay_log_size;
 
325
ulong slave_net_timeout, slave_trans_retries;
 
326
my_bool slave_allow_batching;
 
327
ulong slave_exec_mode_options;
 
328
const char *slave_exec_mode_str= "STRICT";
 
329
ulong thread_cache_size=0, thread_pool_size= 0;
 
330
ulong binlog_cache_size=0, max_binlog_cache_size=0;
 
331
ulong refresh_version;  /* Increments on each reload */
 
332
query_id_t global_query_id;
 
333
ulong aborted_threads, aborted_connects;
 
334
ulong flush_time;
 
335
ulong specialflag=0;
 
336
ulong binlog_cache_use= 0, binlog_cache_disk_use= 0;
 
337
ulong max_connections, max_connect_errors;
 
338
uint  max_user_connections= 0;
 
339
ulong thread_id=1L,current_pid;
 
340
ulong slow_launch_threads = 0, sync_binlog_period;
 
341
ulong expire_logs_days = 0;
 
342
ulong rpl_recovery_rank=0;
 
343
const char *log_output_str= "FILE";
262
344
 
263
345
const double log_10[] = {
264
346
  1e000, 1e001, 1e002, 1e003, 1e004, 1e005, 1e006, 1e007, 1e008, 1e009,
294
376
  1e300, 1e301, 1e302, 1e303, 1e304, 1e305, 1e306, 1e307, 1e308
295
377
};
296
378
 
297
 
time_t server_start_time;
298
 
time_t flush_status_time;
299
 
 
300
 
fs::path basedir(PREFIX);
301
 
fs::path pid_file;
302
 
fs::path secure_file_priv("");
303
 
fs::path plugin_dir;
304
 
fs::path system_config_dir(SYSCONFDIR);
305
 
 
306
 
 
307
 
char system_time_zone[30];
 
379
time_t server_start_time, flush_status_time;
 
380
 
 
381
char mysql_home[FN_REFLEN], pidfile_name[FN_REFLEN], system_time_zone[30];
308
382
char *default_tz_name;
309
 
char glob_hostname[FN_REFLEN];
310
 
 
311
 
char *opt_tc_log_file;
 
383
char log_error_file[FN_REFLEN], glob_hostname[FN_REFLEN];
 
384
char mysql_real_data_home[FN_REFLEN],
 
385
     language[FN_REFLEN], reg_ext[FN_EXTLEN], mysql_charsets_dir[FN_REFLEN],
 
386
     *opt_init_file, *opt_tc_log_file;
 
387
char mysql_unpacked_real_data_home[FN_REFLEN];
 
388
uint reg_ext_length;
312
389
const key_map key_map_empty(0);
313
390
key_map key_map_full(0);                        // Will be initialized later
314
391
 
315
 
std::string drizzle_tmpdir;
316
 
char *opt_drizzle_tmpdir= NULL;
 
392
const char *opt_date_time_formats[3];
 
393
 
 
394
uint mysql_data_home_len;
 
395
char mysql_data_home_buff[2], *mysql_data_home=mysql_real_data_home;
 
396
char server_version[SERVER_VERSION_LENGTH];
 
397
char *opt_mysql_tmpdir;
 
398
const char **errmesg;                   /**< Error messages */
 
399
const char *myisam_recover_options_str="OFF";
 
400
const char *myisam_stats_method_str="nulls_unequal";
317
401
 
318
402
/** name of reference on left espression in rewritten IN subquery */
319
403
const char *in_left_expr_name= "<left expr>";
323
407
 
324
408
my_decimal decimal_zero;
325
409
/* classes for comparation parsing/processing */
 
410
Eq_creator eq_creator;
 
411
Ne_creator ne_creator;
 
412
Gt_creator gt_creator;
 
413
Lt_creator lt_creator;
 
414
Ge_creator ge_creator;
 
415
Le_creator le_creator;
326
416
 
 
417
FILE *bootstrap_file;
 
418
int bootstrap_error;
327
419
FILE *stderror_file=0;
328
420
 
329
 
struct drizzle_system_variables global_system_variables;
330
 
struct drizzle_system_variables max_system_variables;
331
 
struct global_counters current_global_counters;
332
 
 
333
 
const CHARSET_INFO *system_charset_info, *files_charset_info ;
334
 
const CHARSET_INFO *table_alias_charset;
335
 
const CHARSET_INFO *character_set_filesystem;
 
421
I_List<THD> threads;
 
422
I_List<NAMED_LIST> key_caches;
 
423
Rpl_filter* rpl_filter;
 
424
Rpl_filter* binlog_filter;
 
425
 
 
426
struct system_variables global_system_variables;
 
427
struct system_variables max_system_variables;
 
428
struct system_status_var global_status_var;
 
429
 
 
430
MY_TMPDIR mysql_tmpdir_list;
 
431
MY_BITMAP temp_pool;
 
432
 
 
433
CHARSET_INFO *system_charset_info, *files_charset_info ;
 
434
CHARSET_INFO *national_charset_info, *table_alias_charset;
 
435
CHARSET_INFO *character_set_filesystem;
336
436
 
337
437
MY_LOCALE *my_default_lc_time_names;
338
438
 
339
 
SHOW_COMP_OPTION have_symlink;
 
439
SHOW_COMP_OPTION have_symlink, have_dlopen;
 
440
SHOW_COMP_OPTION have_crypt, have_compress;
340
441
 
341
442
/* Thread specific variables */
342
 
boost::mutex LOCK_global_system_variables;
343
 
 
344
 
boost::condition_variable_any COND_refresh;
345
 
boost::condition_variable COND_thread_count;
 
443
 
 
444
pthread_key(MEM_ROOT**,THR_MALLOC);
 
445
pthread_key(THD*, THR_THD);
 
446
pthread_mutex_t LOCK_mysql_create_db, LOCK_open, LOCK_thread_count,
 
447
                LOCK_mapped_file, LOCK_status, LOCK_global_read_lock,
 
448
                LOCK_error_log, LOCK_uuid_generator,
 
449
                LOCK_crypt,
 
450
                LOCK_global_system_variables,
 
451
                LOCK_user_conn, LOCK_slave_list, LOCK_active_mi,
 
452
                LOCK_connection_count;
 
453
 
 
454
rw_lock_t       LOCK_sys_init_connect, LOCK_sys_init_slave;
 
455
rw_lock_t       LOCK_system_variables_hash;
 
456
pthread_cond_t COND_refresh, COND_thread_count, COND_global_read_lock;
346
457
pthread_t signal_thread;
347
 
boost::condition_variable COND_server_end;
 
458
pthread_attr_t connection_attrib;
 
459
pthread_cond_t  COND_server_started;
 
460
 
 
461
/* replication parameters, if master_host is not NULL, we are a slave */
 
462
uint report_port= MYSQL_PORT;
 
463
ulong master_retry_count=0;
 
464
char *master_info_file;
 
465
char *relay_log_info_file, *report_user, *report_password, *report_host;
 
466
char *opt_relay_logname = 0, *opt_relaylog_index_name=0;
 
467
char *opt_logname, *opt_slow_logname;
348
468
 
349
469
/* Static variables */
350
470
 
351
 
int cleanup_done;
352
 
 
353
 
passwd *user_info;
354
 
 
355
 
atomic<uint32_t> connection_count;
356
 
 
357
 
global_buffer_constraint<uint64_t> global_sort_buffer(0);
358
 
global_buffer_constraint<uint64_t> global_join_buffer(0);
359
 
global_buffer_constraint<uint64_t> global_read_rnd_buffer(0);
360
 
global_buffer_constraint<uint64_t> global_read_buffer(0);
361
 
 
362
 
/** 
363
 
  Refresh value. We use to test this to find out if a refresh even has happened recently.
 
471
static bool kill_in_progress, segfaulted;
 
472
#ifdef HAVE_STACK_TRACE_ON_SEGV
 
473
static my_bool opt_do_pstack;
 
474
#endif /* HAVE_STACK_TRACE_ON_SEGV */
 
475
static my_bool opt_bootstrap, opt_myisam_log;
 
476
static int cleanup_done;
 
477
static ulong opt_specialflag, opt_myisam_block_size;
 
478
static char *opt_update_logname, *opt_binlog_index_name;
 
479
static char *opt_tc_heuristic_recover;
 
480
static char *mysql_home_ptr, *pidfile_name_ptr;
 
481
static int defaults_argc;
 
482
static char **defaults_argv;
 
483
static char *opt_bin_logname;
 
484
 
 
485
static my_socket ip_sock;
 
486
struct rand_struct sql_rand; ///< used by sql_class.cc:THD::THD()
 
487
 
 
488
struct passwd *user_info;
 
489
static pthread_t select_thread;
 
490
static uint thr_kill_signal;
 
491
 
 
492
/* OS specific variables */
 
493
 
 
494
bool mysqld_embedded=0;
 
495
 
 
496
#ifndef DBUG_OFF
 
497
static const char* default_dbug_option;
 
498
#endif
 
499
 
 
500
scheduler_functions thread_scheduler;
 
501
 
 
502
/**
 
503
  Number of currently active user connections. The variable is protected by
 
504
  LOCK_connection_count.
364
505
*/
365
 
uint64_t refresh_version;  /* Increments on each reload */
 
506
uint connection_count= 0;
366
507
 
367
508
/* Function declarations */
368
 
bool drizzle_rm_tmp_tables();
369
509
 
370
 
static void drizzle_init_variables(void);
371
 
static void get_options();
372
 
static void fix_paths();
 
510
pthread_handler_t signal_hand(void *arg);
 
511
static void mysql_init_variables(void);
 
512
static void get_options(int *argc,char **argv);
 
513
extern "C" my_bool mysqld_get_one_option(int, const struct my_option *, char *);
 
514
static void set_server_version(void);
 
515
static int init_thread_environment();
 
516
static char *get_relative_path(const char *path);
 
517
static void fix_paths(void);
 
518
void handle_connections_sockets();
 
519
pthread_handler_t kill_server_thread(void *arg);
 
520
static void bootstrap(FILE *file);
 
521
static bool read_init_file(char *file_name);
 
522
pthread_handler_t handle_slave(void *arg);
 
523
static ulong find_bit_type(const char *x, TYPELIB *bit_lib);
 
524
static ulong find_bit_type_or_exit(const char *x, TYPELIB *bit_lib,
 
525
                                   const char *option);
 
526
static void clean_up(bool print_message);
 
527
static int test_if_case_insensitive(const char *dir_name);
373
528
 
374
529
static void usage(void);
375
 
void close_connections(void);
376
 
 
377
 
fs::path base_plugin_dir(PKGPLUGINDIR);
378
 
 
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");
385
 
vector<string> unknown_options;
386
 
vector<string> defaults_file_list;
387
 
po::variables_map vm;
388
 
 
389
 
fs::path data_home(LOCALSTATEDIR);
390
 
fs::path full_data_home(LOCALSTATEDIR);
391
 
 
392
 
po::variables_map &getVariablesMap()
393
 
{
394
 
  return vm;
395
 
}
396
 
 
397
 
fs::path& getDataHome()
398
 
{
399
 
  return data_home;
400
 
}
401
 
 
402
 
fs::path& getDataHomeCatalog()
403
 
{
404
 
  static fs::path data_home_catalog(getDataHome());
405
 
  return data_home_catalog;
406
 
}
407
 
 
408
 
 
 
530
static void start_signal_handler(void);
 
531
static void close_server_sock();
 
532
static void clean_up_mutexes(void);
 
533
static void wait_for_signal_thread_to_end(void);
 
534
static void create_pid_file();
 
535
static void mysqld_exit(int exit_code) __attribute__((noreturn));
 
536
 
409
537
/****************************************************************************
410
 
** Code to end drizzled
 
538
** Code to end mysqld
411
539
****************************************************************************/
412
540
 
413
 
void close_connections(void)
 
541
static void close_connections(void)
414
542
{
 
543
#ifdef EXTRA_DEBUG
 
544
  int count=0;
 
545
#endif
 
546
  DBUG_ENTER("close_connections");
 
547
 
 
548
  /* Clear thread cache */
 
549
  kill_cached_threads++;
 
550
  flush_thread_cache();
 
551
 
 
552
  /* kill flush thread */
 
553
  (void) pthread_mutex_lock(&LOCK_manager);
 
554
  if (manager_thread_in_use)
 
555
  {
 
556
    DBUG_PRINT("quit", ("killing manager thread: 0x%lx",
 
557
                        (ulong)manager_thread));
 
558
   (void) pthread_cond_signal(&COND_manager);
 
559
  }
 
560
  (void) pthread_mutex_unlock(&LOCK_manager);
 
561
 
 
562
  /* kill connection thread */
 
563
  DBUG_PRINT("quit", ("waiting for select thread: 0x%lx",
 
564
                      (ulong) select_thread));
 
565
  (void) pthread_mutex_lock(&LOCK_thread_count);
 
566
 
 
567
  while (select_thread_in_use)
 
568
  {
 
569
    struct timespec abstime;
 
570
    int error;
 
571
    DBUG_PRINT("info",("Waiting for select thread"));
 
572
 
 
573
#ifndef DONT_USE_THR_ALARM
 
574
    if (pthread_kill(select_thread, thr_client_alarm))
 
575
      break;                                    // allready dead
 
576
#endif
 
577
    set_timespec(abstime, 2);
 
578
    for (uint tmp=0 ; tmp < 10 && select_thread_in_use; tmp++)
 
579
    {
 
580
      error=pthread_cond_timedwait(&COND_thread_count,&LOCK_thread_count,
 
581
                                   &abstime);
 
582
      if (error != EINTR)
 
583
        break;
 
584
    }
 
585
#ifdef EXTRA_DEBUG
 
586
    if (error != 0 && !count++)
 
587
      sql_print_error("Got error %d from pthread_cond_timedwait",error);
 
588
#endif
 
589
    close_server_sock();
 
590
  }
 
591
  (void) pthread_mutex_unlock(&LOCK_thread_count);
 
592
 
 
593
 
415
594
  /* Abort listening to new connections */
416
 
  plugin::Listen::shutdown();
417
 
 
418
 
  /* kill connection thread */
 
595
  DBUG_PRINT("quit",("Closing sockets"));
 
596
  if (!opt_disable_networking )
419
597
  {
420
 
    boost::mutex::scoped_lock scopedLock(session::Cache::singleton().mutex());
421
 
 
422
 
    while (select_thread_in_use)
 
598
    if (ip_sock != INVALID_SOCKET)
423
599
    {
424
 
      boost::xtime xt; 
425
 
      xtime_get(&xt, boost::TIME_UTC); 
426
 
      xt.sec += 2; 
427
 
 
428
 
      for (uint32_t tmp=0 ; tmp < 10 && select_thread_in_use; tmp++)
429
 
      {
430
 
        bool success= COND_thread_count.timed_wait(scopedLock, xt);
431
 
        if (not success)
432
 
          break;
433
 
      }
 
600
      (void) shutdown(ip_sock, SHUT_RDWR);
 
601
      (void) closesocket(ip_sock);
 
602
      ip_sock= INVALID_SOCKET;
434
603
    }
435
604
  }
436
 
 
 
605
  end_thr_alarm(0);                      // Abort old alarms.
437
606
 
438
607
  /*
439
608
    First signal all threads that it's time to die
441
610
    statements and inform their clients that the server is about to die.
442
611
  */
443
612
 
 
613
  THD *tmp;
 
614
  (void) pthread_mutex_lock(&LOCK_thread_count); // For unlink from list
 
615
 
 
616
  I_List_iterator<THD> it(threads);
 
617
  while ((tmp=it++))
444
618
  {
445
 
    boost::mutex::scoped_lock scopedLock(session::Cache::singleton().mutex());
446
 
    session::Cache::list list= session::Cache::singleton().getCache();
 
619
    DBUG_PRINT("quit",("Informing thread %ld that it's time to die",
 
620
                       tmp->thread_id));
 
621
    /* We skip slave threads & scheduler on this first loop through. */
 
622
    if (tmp->slave_thread)
 
623
      continue;
447
624
 
448
 
    for (session::Cache::list::iterator it= list.begin(); it != list.end(); ++it )
 
625
    tmp->killed= THD::KILL_CONNECTION;
 
626
    thread_scheduler.post_kill_notification(tmp);
 
627
    if (tmp->mysys_var)
449
628
    {
450
 
      Session::shared_ptr tmp(*it);
451
 
 
452
 
      tmp->setKilled(Session::KILL_CONNECTION);
453
 
      tmp->scheduler->killSession(tmp.get());
454
 
      DRIZZLE_CONNECTION_DONE(tmp->thread_id);
455
 
 
456
 
      tmp->lockOnSys();
 
629
      tmp->mysys_var->abort=1;
 
630
      pthread_mutex_lock(&tmp->mysys_var->mutex);
 
631
      if (tmp->mysys_var->current_cond)
 
632
      {
 
633
        pthread_mutex_lock(tmp->mysys_var->current_mutex);
 
634
        pthread_cond_broadcast(tmp->mysys_var->current_cond);
 
635
        pthread_mutex_unlock(tmp->mysys_var->current_mutex);
 
636
      }
 
637
      pthread_mutex_unlock(&tmp->mysys_var->mutex);
457
638
    }
458
639
  }
459
 
 
460
 
  if (session::Cache::singleton().count())
461
 
    sleep(2);                                   // Give threads time to die
 
640
  (void) pthread_mutex_unlock(&LOCK_thread_count); // For unlink from list
 
641
 
 
642
  end_slave();
 
643
 
 
644
  if (thread_count)
 
645
    sleep(2);                                   // Give threads time to die
462
646
 
463
647
  /*
464
648
    Force remaining threads to die by closing the connection to the client
465
649
    This will ensure that threads that are waiting for a command from the
466
650
    client on a blocking read call are aborted.
467
651
  */
 
652
 
468
653
  for (;;)
469
654
  {
470
 
    boost::mutex::scoped_lock scopedLock(session::Cache::singleton().mutex());
471
 
    session::Cache::list list= session::Cache::singleton().getCache();
472
 
 
473
 
    if (list.empty())
 
655
    DBUG_PRINT("quit",("Locking LOCK_thread_count"));
 
656
    (void) pthread_mutex_lock(&LOCK_thread_count); // For unlink from list
 
657
    if (!(tmp=threads.get()))
474
658
    {
 
659
      DBUG_PRINT("quit",("Unlocking LOCK_thread_count"));
 
660
      (void) pthread_mutex_unlock(&LOCK_thread_count);
475
661
      break;
476
662
    }
477
 
    /* Close before unlock, avoiding crash. See LP bug#436685 */
478
 
    list.front()->client->close();
479
 
  }
480
 
}
481
 
 
482
 
 
483
 
void unireg_abort(int exit_code)
484
 
{
 
663
    if (tmp->vio_ok())
 
664
    {
 
665
      if (global_system_variables.log_warnings)
 
666
        sql_print_warning(ER(ER_FORCING_CLOSE),my_progname,
 
667
                          tmp->thread_id,
 
668
                          (tmp->main_security_ctx.user ?
 
669
                           tmp->main_security_ctx.user : ""));
 
670
      close_connection(tmp,0,0);
 
671
    }
 
672
    DBUG_PRINT("quit",("Unlocking LOCK_thread_count"));
 
673
    (void) pthread_mutex_unlock(&LOCK_thread_count);
 
674
  }
 
675
  /* All threads has now been aborted */
 
676
  DBUG_PRINT("quit",("Waiting for threads to die (count=%u)",thread_count));
 
677
  (void) pthread_mutex_lock(&LOCK_thread_count);
 
678
  while (thread_count)
 
679
  {
 
680
    (void) pthread_cond_wait(&COND_thread_count,&LOCK_thread_count);
 
681
    DBUG_PRINT("quit",("One thread died (count=%u)",thread_count));
 
682
  }
 
683
  (void) pthread_mutex_unlock(&LOCK_thread_count);
 
684
 
 
685
  DBUG_PRINT("quit",("close_connections thread"));
 
686
  DBUG_VOID_RETURN;
 
687
}
 
688
 
 
689
 
 
690
static void close_server_sock()
 
691
{
 
692
#ifdef HAVE_CLOSE_SERVER_SOCK
 
693
  DBUG_ENTER("close_server_sock");
 
694
  my_socket tmp_sock;
 
695
  tmp_sock=ip_sock;
 
696
  if (tmp_sock != INVALID_SOCKET)
 
697
  {
 
698
    ip_sock=INVALID_SOCKET;
 
699
    DBUG_PRINT("info",("calling shutdown on TCP/IP socket"));
 
700
    VOID(shutdown(tmp_sock, SHUT_RDWR));
 
701
  }
 
702
  DBUG_VOID_RETURN;
 
703
#endif
 
704
}
 
705
 
 
706
 
 
707
void kill_mysql(void)
 
708
{
 
709
  DBUG_ENTER("kill_mysql");
 
710
 
 
711
#if defined(SIGNALS_DONT_BREAK_READ)
 
712
  abort_loop=1;                                 // Break connection loops
 
713
  close_server_sock();                          // Force accept to wake up
 
714
#endif
 
715
 
 
716
#if defined(HAVE_PTHREAD_KILL)
 
717
  if (pthread_kill(signal_thread, MYSQL_KILL_SIGNAL))
 
718
  {
 
719
    DBUG_PRINT("error",("Got error %d from pthread_kill",errno)); /* purecov: inspected */
 
720
  }
 
721
#elif !defined(SIGNALS_DONT_BREAK_READ)
 
722
  kill(current_pid, MYSQL_KILL_SIGNAL);
 
723
#endif
 
724
  DBUG_PRINT("quit",("After pthread_kill"));
 
725
  shutdown_in_progress=1;                       // Safety if kill didn't work
 
726
#ifdef SIGNALS_DONT_BREAK_READ
 
727
  if (!kill_in_progress)
 
728
  {
 
729
    pthread_t tmp;
 
730
    abort_loop=1;
 
731
    if (pthread_create(&tmp,&connection_attrib, kill_server_thread,
 
732
                           (void*) 0))
 
733
      sql_print_error("Can't create thread to kill server");
 
734
  }
 
735
#endif
 
736
  DBUG_VOID_RETURN;
 
737
}
 
738
 
 
739
/**
 
740
  Force server down. Kill all connections and threads and exit.
 
741
 
 
742
  @param  sig_ptr       Signal number that caused kill_server to be called.
 
743
 
 
744
  @note
 
745
    A signal number of 0 mean that the function was not called
 
746
    from a signal handler and there is thus no signal to block
 
747
    or stop, we just want to kill the server.
 
748
*/
 
749
 
 
750
static void *kill_server(void *sig_ptr)
 
751
#define RETURN_FROM_KILL_SERVER DBUG_RETURN(0)
 
752
{
 
753
  DBUG_ENTER("kill_server");
 
754
  int sig=(int) (long) sig_ptr;                 // This is passed a int
 
755
  // if there is a signal during the kill in progress, ignore the other
 
756
  if (kill_in_progress)                         // Safety
 
757
    RETURN_FROM_KILL_SERVER;
 
758
  kill_in_progress=TRUE;
 
759
  abort_loop=1;                                 // This should be set
 
760
  if (sig != 0) // 0 is not a valid signal number
 
761
    my_sigset(sig, SIG_IGN);                    /* purify inspected */
 
762
  if (sig == MYSQL_KILL_SIGNAL || sig == 0)
 
763
    sql_print_information(ER(ER_NORMAL_SHUTDOWN),my_progname);
 
764
  else
 
765
    sql_print_error(ER(ER_GOT_SIGNAL),my_progname,sig); /* purecov: inspected */
 
766
  
 
767
  close_connections();
 
768
  if (sig != MYSQL_KILL_SIGNAL &&
 
769
      sig != 0)
 
770
    unireg_abort(1);                            /* purecov: inspected */
 
771
  else
 
772
    unireg_end();
 
773
 
 
774
  /* purecov: begin deadcode */
 
775
 
 
776
  my_thread_end();
 
777
  pthread_exit(0);
 
778
  /* purecov: end */
 
779
 
 
780
  RETURN_FROM_KILL_SERVER;
 
781
}
 
782
 
 
783
 
 
784
#if defined(USE_ONE_SIGNAL_HAND)
 
785
pthread_handler_t kill_server_thread(void *arg __attribute__((unused)))
 
786
{
 
787
  my_thread_init();                             // Initialize new thread
 
788
  kill_server(0);
 
789
  /* purecov: begin deadcode */
 
790
  my_thread_end();
 
791
  pthread_exit(0);
 
792
  return 0;
 
793
  /* purecov: end */
 
794
}
 
795
#endif
 
796
 
 
797
 
 
798
extern "C" sig_handler print_signal_warning(int sig)
 
799
{
 
800
  if (global_system_variables.log_warnings)
 
801
    sql_print_warning("Got signal %d from thread %ld", sig,my_thread_id());
 
802
#ifdef DONT_REMEMBER_SIGNAL
 
803
  my_sigset(sig,print_signal_warning);          /* int. thread system calls */
 
804
#endif
 
805
  if (sig == SIGALRM)
 
806
    alarm(2);                                   /* reschedule alarm */
 
807
}
 
808
 
 
809
/**
 
810
  cleanup all memory and end program nicely.
 
811
 
 
812
    If SIGNALS_DONT_BREAK_READ is defined, this function is called
 
813
    by the main thread. To get MySQL to shut down nicely in this case
 
814
    (Mac OS X) we have to call exit() instead if pthread_exit().
 
815
 
 
816
  @note
 
817
    This function never returns.
 
818
*/
 
819
void unireg_end(void)
 
820
{
 
821
  clean_up(1);
 
822
  my_thread_end();
 
823
#if defined(SIGNALS_DONT_BREAK_READ)
 
824
  exit(0);
 
825
#else
 
826
  pthread_exit(0);                              // Exit is in main thread
 
827
#endif
 
828
}
 
829
 
 
830
 
 
831
extern "C" void unireg_abort(int exit_code)
 
832
{
 
833
  DBUG_ENTER("unireg_abort");
485
834
 
486
835
  if (exit_code)
487
 
    errmsg_printf(ERRMSG_LVL_ERROR, _("Aborting\n"));
 
836
    sql_print_error("Aborting\n");
488
837
  else if (opt_help)
489
838
    usage();
490
 
  clean_up(!opt_help && (exit_code));
491
 
  internal::my_end();
492
 
  exit(exit_code);
 
839
  clean_up(!opt_help && (exit_code || !opt_bootstrap)); /* purecov: inspected */
 
840
  DBUG_PRINT("quit",("done with cleanup in unireg_abort"));
 
841
  mysqld_exit(exit_code);
 
842
}
 
843
 
 
844
 
 
845
static void mysqld_exit(int exit_code)
 
846
{
 
847
  wait_for_signal_thread_to_end();
 
848
  clean_up_mutexes();
 
849
  my_end(opt_endinfo ? MY_CHECK_ERROR | MY_GIVE_INFO : 0);
 
850
  exit(exit_code); /* purecov: inspected */
493
851
}
494
852
 
495
853
 
496
854
void clean_up(bool print_message)
497
855
{
 
856
  DBUG_PRINT("exit",("clean_up"));
498
857
  if (cleanup_done++)
499
 
    return;
500
 
 
 
858
    return; /* purecov: inspected */
 
859
 
 
860
  /*
 
861
    make sure that handlers finish up
 
862
    what they have that is dependent on the binlog
 
863
  */
 
864
  ha_binlog_end(current_thd);
 
865
 
 
866
  logger.cleanup_base();
 
867
 
 
868
  mysql_bin_log.cleanup();
 
869
 
 
870
  if (use_slave_mask)
 
871
    bitmap_free(&slave_error_mask);
 
872
  my_tz_free();
 
873
  my_database_names_free();
501
874
  table_cache_free();
 
875
  table_def_free();
 
876
  lex_free();                           /* Free some memory */
 
877
  item_create_cleanup();
 
878
  set_var_free();
502
879
  free_charsets();
503
 
  module::Registry &modules= module::Registry::singleton();
504
 
  modules.shutdownModules();
 
880
  udf_free();
 
881
  plugin_shutdown();
 
882
  ha_end();
 
883
  if (tc_log)
 
884
    tc_log->close();
505
885
  xid_cache_free();
506
 
 
507
 
  deinit_temporal_formats();
508
 
 
509
 
#if GOOGLE_PROTOBUF_VERSION >= 2001000
510
 
  google::protobuf::ShutdownProtobufLibrary();
511
 
#endif
512
 
 
513
 
  (void) unlink(pid_file.file_string().c_str());        // This may not always exist
514
 
 
515
 
  if (print_message && server_start_time)
516
 
    errmsg_printf(ERRMSG_LVL_INFO, _(ER(ER_SHUTDOWN_COMPLETE)),internal::my_progname);
517
 
  {
518
 
    boost::mutex::scoped_lock scopedLock(session::Cache::singleton().mutex());
519
 
    ready_to_exit= true;
520
 
 
521
 
    /* do the broadcast inside the lock to ensure that my_end() is not called */
522
 
    COND_server_end.notify_all();
523
 
  }
 
886
  delete_elements(&key_caches, (void (*)(const char*, uchar*)) free_key_cache);
 
887
  multi_keycache_free();
 
888
  free_status_vars();
 
889
  end_thr_alarm(1);                     /* Free allocated memory */
 
890
  my_free_open_file_info();
 
891
  my_free((char*) global_system_variables.date_format,
 
892
          MYF(MY_ALLOW_ZERO_PTR));
 
893
  my_free((char*) global_system_variables.time_format,
 
894
          MYF(MY_ALLOW_ZERO_PTR));
 
895
  my_free((char*) global_system_variables.datetime_format,
 
896
          MYF(MY_ALLOW_ZERO_PTR));
 
897
  if (defaults_argv)
 
898
    free_defaults(defaults_argv);
 
899
  my_free(sys_init_connect.value, MYF(MY_ALLOW_ZERO_PTR));
 
900
  my_free(sys_init_slave.value, MYF(MY_ALLOW_ZERO_PTR));
 
901
  my_free(sys_var_general_log_path.value, MYF(MY_ALLOW_ZERO_PTR));
 
902
  my_free(sys_var_slow_log_path.value, MYF(MY_ALLOW_ZERO_PTR));
 
903
  free_tmpdir(&mysql_tmpdir_list);
 
904
  my_free(slave_load_tmpdir,MYF(MY_ALLOW_ZERO_PTR));
 
905
  x_free(opt_bin_logname);
 
906
  x_free(opt_relay_logname);
 
907
  x_free(opt_secure_file_priv);
 
908
  bitmap_free(&temp_pool);
 
909
  end_slave_list();
 
910
  delete binlog_filter;
 
911
  delete rpl_filter;
 
912
  vio_end();
 
913
 
 
914
  if (!opt_bootstrap)
 
915
    (void) my_delete(pidfile_name,MYF(0));      // This may not always exist
 
916
  if (print_message && errmesg && server_start_time)
 
917
    sql_print_information(ER(ER_SHUTDOWN_COMPLETE),my_progname);
 
918
  thread_scheduler.end();
 
919
  finish_client_errs();
 
920
  my_free((uchar*) my_error_unregister(ER_ERROR_FIRST, ER_ERROR_LAST),
 
921
          MYF(MY_WME | MY_FAE | MY_ALLOW_ZERO_PTR));
 
922
  DBUG_PRINT("quit", ("Error messages freed"));
 
923
  /* Tell main we are ready */
 
924
  logger.cleanup_end();
 
925
  (void) pthread_mutex_lock(&LOCK_thread_count);
 
926
  DBUG_PRINT("quit", ("got thread count lock"));
 
927
  ready_to_exit=1;
 
928
  /* do the broadcast inside the lock to ensure that my_end() is not called */
 
929
  (void) pthread_cond_broadcast(&COND_thread_count);
 
930
  (void) pthread_mutex_unlock(&LOCK_thread_count);
524
931
 
525
932
  /*
526
933
    The following lines may never be executed as the main thread may have
527
934
    killed us
528
935
  */
 
936
  DBUG_PRINT("quit", ("done with cleanup"));
529
937
} /* clean_up */
530
938
 
531
939
 
 
940
/**
 
941
  This is mainly needed when running with purify, but it's still nice to
 
942
  know that all child threads have died when mysqld exits.
 
943
*/
 
944
static void wait_for_signal_thread_to_end()
 
945
{
 
946
  uint i;
 
947
  /*
 
948
    Wait up to 10 seconds for signal thread to die. We use this mainly to
 
949
    avoid getting warnings that my_thread_end has not been called
 
950
  */
 
951
  for (i= 0 ; i < 100 && signal_thread_in_use; i++)
 
952
  {
 
953
    if (pthread_kill(signal_thread, MYSQL_KILL_SIGNAL) != ESRCH)
 
954
      break;
 
955
    my_sleep(100);                              // Give it time to die
 
956
  }
 
957
}
 
958
 
 
959
 
 
960
static void clean_up_mutexes()
 
961
{
 
962
  (void) pthread_mutex_destroy(&LOCK_mysql_create_db);
 
963
  (void) pthread_mutex_destroy(&LOCK_lock_db);
 
964
  (void) pthread_mutex_destroy(&LOCK_open);
 
965
  (void) pthread_mutex_destroy(&LOCK_thread_count);
 
966
  (void) pthread_mutex_destroy(&LOCK_mapped_file);
 
967
  (void) pthread_mutex_destroy(&LOCK_status);
 
968
  (void) pthread_mutex_destroy(&LOCK_error_log);
 
969
  (void) pthread_mutex_destroy(&LOCK_manager);
 
970
  (void) pthread_mutex_destroy(&LOCK_crypt);
 
971
  (void) pthread_mutex_destroy(&LOCK_user_conn);
 
972
  (void) pthread_mutex_destroy(&LOCK_connection_count);
 
973
  (void) pthread_mutex_destroy(&LOCK_rpl_status);
 
974
  (void) pthread_cond_destroy(&COND_rpl_status);
 
975
  (void) pthread_mutex_destroy(&LOCK_active_mi);
 
976
  (void) rwlock_destroy(&LOCK_sys_init_connect);
 
977
  (void) rwlock_destroy(&LOCK_sys_init_slave);
 
978
  (void) pthread_mutex_destroy(&LOCK_global_system_variables);
 
979
  (void) rwlock_destroy(&LOCK_system_variables_hash);
 
980
  (void) pthread_mutex_destroy(&LOCK_global_read_lock);
 
981
  (void) pthread_mutex_destroy(&LOCK_uuid_generator);
 
982
  (void) pthread_cond_destroy(&COND_thread_count);
 
983
  (void) pthread_cond_destroy(&COND_refresh);
 
984
  (void) pthread_cond_destroy(&COND_global_read_lock);
 
985
  (void) pthread_cond_destroy(&COND_thread_cache);
 
986
  (void) pthread_cond_destroy(&COND_flush_thread_cache);
 
987
  (void) pthread_cond_destroy(&COND_manager);
 
988
}
 
989
 
 
990
 
 
991
/****************************************************************************
 
992
** Init IP and UNIX socket
 
993
****************************************************************************/
 
994
 
 
995
static void set_ports()
 
996
{
 
997
  char  *env;
 
998
  if (!mysqld_port && !opt_disable_networking)
 
999
  {                                     // Get port if not from commandline
 
1000
    mysqld_port= MYSQL_PORT;
 
1001
 
 
1002
    /*
 
1003
      if builder specifically requested a default port, use that
 
1004
      (even if it coincides with our factory default).
 
1005
      only if they didn't do we check /etc/services (and, failing
 
1006
      on that, fall back to the factory default of 3306).
 
1007
      either default can be overridden by the environment variable
 
1008
      MYSQL_TCP_PORT, which in turn can be overridden with command
 
1009
      line options.
 
1010
    */
 
1011
 
 
1012
#if MYSQL_PORT_DEFAULT == 0
 
1013
    struct  servent *serv_ptr;
 
1014
    if ((serv_ptr= getservbyname("mysql", "tcp")))
 
1015
      mysqld_port= ntohs((u_short) serv_ptr->s_port); /* purecov: inspected */
 
1016
#endif
 
1017
    if ((env = getenv("MYSQL_TCP_PORT")))
 
1018
      mysqld_port= (uint) atoi(env);            /* purecov: inspected */
 
1019
  }
 
1020
}
 
1021
 
532
1022
/* Change to run as another user if started with --user */
533
1023
 
534
 
passwd *check_user(const char *user)
 
1024
static struct passwd *check_user(const char *user)
535
1025
{
536
 
  passwd *tmp_user_info;
 
1026
  struct passwd *tmp_user_info;
537
1027
  uid_t user_id= geteuid();
538
1028
 
539
1029
  // Don't bother if we aren't superuser
542
1032
    if (user)
543
1033
    {
544
1034
      /* Don't give a warning, if real user is same as given with --user */
 
1035
      /* purecov: begin tested */
545
1036
      tmp_user_info= getpwnam(user);
546
1037
      if ((!tmp_user_info || user_id != tmp_user_info->pw_uid) &&
547
 
          global_system_variables.log_warnings)
548
 
            errmsg_printf(ERRMSG_LVL_WARN, _("One can only use the --user switch "
549
 
                            "if running as root\n"));
 
1038
          global_system_variables.log_warnings)
 
1039
        sql_print_warning(
 
1040
                    "One can only use the --user switch if running as root\n");
 
1041
      /* purecov: end */
550
1042
    }
551
1043
    return NULL;
552
1044
  }
553
 
  if (not user)
 
1045
  if (!user)
554
1046
  {
555
 
      errmsg_printf(ERRMSG_LVL_ERROR, _("Fatal error: Please read \"Security\" section of "
556
 
                      "the manual to find out how to run drizzled as root!\n"));
557
 
    unireg_abort(1);
 
1047
    if (!opt_bootstrap)
 
1048
    {
 
1049
      sql_print_error("Fatal error: Please read \"Security\" section of the manual to find out how to run mysqld as root!\n");
 
1050
      unireg_abort(1);
 
1051
    }
 
1052
    return NULL;
558
1053
  }
 
1054
  /* purecov: begin tested */
559
1055
  if (!strcmp(user,"root"))
560
1056
    return NULL;                        // Avoid problem with dynamic libraries
561
1057
 
570
1066
      goto err;
571
1067
  }
572
1068
  return tmp_user_info;
 
1069
  /* purecov: end */
573
1070
 
574
1071
err:
575
 
  errmsg_printf(ERRMSG_LVL_ERROR, _("Fatal error: Can't change to run as user '%s' ;  "
576
 
                    "Please check that the user exists!\n"),user);
 
1072
  sql_print_error("Fatal error: Can't change to run as user '%s' ;  Please check that the user exists!\n",user);
577
1073
  unireg_abort(1);
578
1074
 
579
1075
#ifdef PR_SET_DUMPABLE
580
 
  if (test_flags.test(TEST_CORE_ON_SIGNAL))
 
1076
  if (test_flags & TEST_CORE_ON_SIGNAL)
581
1077
  {
582
1078
    /* inform kernel that process is dumpable */
583
1079
    (void) prctl(PR_SET_DUMPABLE, 1);
584
1080
  }
585
1081
#endif
586
1082
 
587
 
/* Sun Studio 5.10 doesn't like this line.  5.9 requires it */
588
 
#if defined(__SUNPRO_CC) && (__SUNPRO_CC <= 0x590)
589
1083
  return NULL;
590
 
#endif
591
 
 
592
1084
}
593
1085
 
594
 
void set_user(const char *user, passwd *user_info_arg)
 
1086
static void set_user(const char *user, struct passwd *user_info_arg)
595
1087
{
596
 
  assert(user_info_arg != 0);
 
1088
  /* purecov: begin tested */
 
1089
  DBUG_ASSERT(user_info_arg != 0);
 
1090
#ifdef HAVE_INITGROUPS
 
1091
  /*
 
1092
    We can get a SIGSEGV when calling initgroups() on some systems when NSS
 
1093
    is configured to use LDAP and the server is statically linked.  We set
 
1094
    calling_initgroups as a flag to the SIGSEGV handler that is then used to
 
1095
    output a specific message to help the user resolve this problem.
 
1096
  */
 
1097
  calling_initgroups= TRUE;
597
1098
  initgroups((char*) user, user_info_arg->pw_gid);
 
1099
  calling_initgroups= FALSE;
 
1100
#endif
598
1101
  if (setgid(user_info_arg->pw_gid) == -1)
599
1102
  {
600
 
    sql_perror(N_("Set process group ID failed"));
 
1103
    sql_perror("setgid");
601
1104
    unireg_abort(1);
602
1105
  }
603
1106
  if (setuid(user_info_arg->pw_uid) == -1)
604
1107
  {
605
 
    sql_perror(N_("Set process user ID failed"));
606
 
    unireg_abort(1);
607
 
  }
608
 
}
609
 
 
 
1108
    sql_perror("setuid");
 
1109
    unireg_abort(1);
 
1110
  }
 
1111
  /* purecov: end */
 
1112
}
 
1113
 
 
1114
 
 
1115
static void set_effective_user(struct passwd *user_info_arg)
 
1116
{
 
1117
  DBUG_ASSERT(user_info_arg != 0);
 
1118
  if (setregid((gid_t)-1, user_info_arg->pw_gid) == -1)
 
1119
  {
 
1120
    sql_perror("setregid");
 
1121
    unireg_abort(1);
 
1122
  }
 
1123
  if (setreuid((uid_t)-1, user_info_arg->pw_uid) == -1)
 
1124
  {
 
1125
    sql_perror("setreuid");
 
1126
    unireg_abort(1);
 
1127
  }
 
1128
}
610
1129
 
611
1130
 
612
1131
/** Change root user if started with @c --chroot . */
613
1132
static void set_root(const char *path)
614
1133
{
615
 
  if ((chroot(path) == -1) || !chdir("/"))
 
1134
  if (chroot(path) == -1)
616
1135
  {
617
 
    sql_perror(N_("Process chroot failed"));
 
1136
    sql_perror("chroot");
618
1137
    unireg_abort(1);
619
1138
  }
620
 
}
621
 
 
622
 
 
623
 
/*
624
 
  Unlink session from global list of available connections and free session
625
 
 
626
 
  SYNOPSIS
627
 
    Session::unlink()
628
 
    session              Thread handler
629
 
*/
630
 
 
631
 
void drizzled::Session::unlink(Session::shared_ptr &session)
632
 
{
633
 
  connection_count.decrement();
634
 
 
635
 
  session->cleanup();
636
 
 
637
 
  boost::mutex::scoped_lock scopedLock(session::Cache::singleton().mutex());
638
 
 
639
 
  if (unlikely(plugin::EventObserver::disconnectSession(*session)))
640
 
  {
641
 
    // We should do something about an error...
642
 
  }
643
 
  session::Cache::singleton().erase(session);
644
 
}
645
 
 
 
1139
  my_setwd("/", MYF(0));
 
1140
}
 
1141
 
 
1142
 
 
1143
static void network_init(void)
 
1144
{
 
1145
  int   arg;
 
1146
  int   ret;
 
1147
  uint  waited;
 
1148
  uint  this_wait;
 
1149
  uint  retry;
 
1150
  char port_buf[NI_MAXSERV];
 
1151
  DBUG_ENTER("network_init");
 
1152
 
 
1153
  if (thread_scheduler.init())
 
1154
    unireg_abort(1);                    /* purecov: inspected */
 
1155
 
 
1156
  set_ports();
 
1157
 
 
1158
  if (mysqld_port != 0 && !opt_disable_networking && !opt_bootstrap)
 
1159
  {
 
1160
    struct addrinfo *ai;
 
1161
    struct addrinfo hints;
 
1162
    int error;
 
1163
    DBUG_PRINT("general",("IP Socket is %d",mysqld_port));
 
1164
 
 
1165
    bzero(&hints, sizeof (hints));
 
1166
    hints.ai_flags= AI_PASSIVE;
 
1167
    hints.ai_socktype= SOCK_STREAM;
 
1168
    hints.ai_family= AF_UNSPEC;
 
1169
 
 
1170
    my_snprintf(port_buf, NI_MAXSERV, "%d", mysqld_port);
 
1171
    error= getaddrinfo(my_bind_addr_str, port_buf, &hints, &ai);
 
1172
    if (error != 0)
 
1173
    {
 
1174
      DBUG_PRINT("error",("Got error: %d from getaddrinfo()", error));
 
1175
      sql_perror(ER(ER_IPSOCK_ERROR));          /* purecov: tested */
 
1176
      unireg_abort(1);                          /* purecov: tested */
 
1177
    }
 
1178
 
 
1179
 
 
1180
    ip_sock= socket(ai->ai_family, ai->ai_socktype,
 
1181
                    ai->ai_protocol);
 
1182
 
 
1183
    if (ip_sock == INVALID_SOCKET)
 
1184
    {
 
1185
      DBUG_PRINT("error",("Got error: %d from socket()",socket_errno));
 
1186
      sql_perror(ER(ER_IPSOCK_ERROR));          /* purecov: tested */
 
1187
      unireg_abort(1);                          /* purecov: tested */
 
1188
    }
 
1189
 
 
1190
    /*
 
1191
      We should not use SO_REUSEADDR on windows as this would enable a
 
1192
      user to open two mysqld servers with the same TCP/IP port.
 
1193
    */
 
1194
    arg= 1;
 
1195
    (void) setsockopt(ip_sock,SOL_SOCKET,SO_REUSEADDR,(char*)&arg,sizeof(arg));
 
1196
 
 
1197
#ifdef IPV6_V6ONLY
 
1198
     /*
 
1199
       For interoperability with older clients, IPv6 socket should
 
1200
       listen on both IPv6 and IPv4 wildcard addresses.
 
1201
       Turn off IPV6_V6ONLY option.
 
1202
     */
 
1203
    if (ai->ai_family == AF_INET6)
 
1204
    {
 
1205
      arg= 0;      
 
1206
      (void) setsockopt(ip_sock, IPPROTO_IPV6, IPV6_V6ONLY, (char*)&arg,
 
1207
                sizeof(arg));
 
1208
    }
 
1209
#endif
 
1210
    /*
 
1211
      Sometimes the port is not released fast enough when stopping and
 
1212
      restarting the server. This happens quite often with the test suite
 
1213
      on busy Linux systems. Retry to bind the address at these intervals:
 
1214
      Sleep intervals: 1, 2, 4,  6,  9, 13, 17, 22, ...
 
1215
      Retry at second: 1, 3, 7, 13, 22, 35, 52, 74, ...
 
1216
      Limit the sequence by mysqld_port_timeout (set --port-open-timeout=#).
 
1217
    */
 
1218
    for (waited= 0, retry= 1; ; retry++, waited+= this_wait)
 
1219
    {
 
1220
      if (((ret= bind(ip_sock, ai->ai_addr, ai->ai_addrlen)) >= 0 ) ||
 
1221
          (socket_errno != SOCKET_EADDRINUSE) ||
 
1222
          (waited >= mysqld_port_timeout))
 
1223
        break;
 
1224
      sql_print_information("Retrying bind on TCP/IP port %u", mysqld_port);
 
1225
      this_wait= retry * retry / 3 + 1;
 
1226
      sleep(this_wait);
 
1227
    }
 
1228
    freeaddrinfo(ai);
 
1229
    if (ret < 0)
 
1230
    {
 
1231
      DBUG_PRINT("error",("Got error: %d from bind",socket_errno));
 
1232
      sql_perror("Can't start server: Bind on TCP/IP port");
 
1233
      sql_print_error("Do you already have another mysqld server running on port: %d ?",mysqld_port);
 
1234
      unireg_abort(1);
 
1235
    }
 
1236
    if (listen(ip_sock,(int) back_log) < 0)
 
1237
    {
 
1238
      sql_perror("Can't start server: listen() on TCP/IP port");
 
1239
      sql_print_error("listen() on TCP/IP failed with error %d",
 
1240
                      socket_errno);
 
1241
      unireg_abort(1);
 
1242
    }
 
1243
  }
 
1244
 
 
1245
  DBUG_PRINT("info",("server started"));
 
1246
  DBUG_VOID_RETURN;
 
1247
}
 
1248
 
 
1249
/**
 
1250
  Close a connection.
 
1251
 
 
1252
  @param thd            Thread handle
 
1253
  @param errcode        Error code to print to console
 
1254
  @param lock           1 if we have have to lock LOCK_thread_count
 
1255
 
 
1256
  @note
 
1257
    For the connection that is doing shutdown, this is called twice
 
1258
*/
 
1259
void close_connection(THD *thd, uint errcode, bool lock)
 
1260
{
 
1261
  st_vio *vio;
 
1262
  DBUG_ENTER("close_connection");
 
1263
  DBUG_PRINT("enter",("fd: %s  error: '%s'",
 
1264
                      thd->net.vio ? vio_description(thd->net.vio) :
 
1265
                      "(not connected)",
 
1266
                      errcode ? ER(errcode) : ""));
 
1267
  if (lock)
 
1268
    (void) pthread_mutex_lock(&LOCK_thread_count);
 
1269
  thd->killed= THD::KILL_CONNECTION;
 
1270
  if ((vio= thd->net.vio) != 0)
 
1271
  {
 
1272
    if (errcode)
 
1273
      net_send_error(thd, errcode, ER(errcode)); /* purecov: inspected */
 
1274
    vio_close(vio);                     /* vio is freed in delete thd */
 
1275
  }
 
1276
  if (lock)
 
1277
    (void) pthread_mutex_unlock(&LOCK_thread_count);
 
1278
  DBUG_VOID_RETURN;
 
1279
}
 
1280
 
 
1281
 
 
1282
/** Called when a thread is aborted. */
 
1283
/* ARGSUSED */
 
1284
extern "C" sig_handler end_thread_signal(int sig __attribute__((unused)))
 
1285
{
 
1286
  THD *thd=current_thd;
 
1287
  DBUG_ENTER("end_thread_signal");
 
1288
  if (thd && ! thd->bootstrap)
 
1289
  {
 
1290
    statistic_increment(killed_threads, &LOCK_status);
 
1291
    thread_scheduler.end_thread(thd,0);         /* purecov: inspected */
 
1292
  }
 
1293
  DBUG_VOID_RETURN;                             /* purecov: deadcode */
 
1294
}
 
1295
 
 
1296
 
 
1297
/*
 
1298
  Unlink thd from global list of available connections and free thd
 
1299
 
 
1300
  SYNOPSIS
 
1301
    unlink_thd()
 
1302
    thd          Thread handler
 
1303
 
 
1304
  NOTES
 
1305
    LOCK_thread_count is locked and left locked
 
1306
*/
 
1307
 
 
1308
void unlink_thd(THD *thd)
 
1309
{
 
1310
  DBUG_ENTER("unlink_thd");
 
1311
  DBUG_PRINT("enter", ("thd: 0x%lx", (long) thd));
 
1312
  thd->cleanup();
 
1313
 
 
1314
  pthread_mutex_lock(&LOCK_connection_count);
 
1315
  --connection_count;
 
1316
  pthread_mutex_unlock(&LOCK_connection_count);
 
1317
 
 
1318
  (void) pthread_mutex_lock(&LOCK_thread_count);
 
1319
  thread_count--;
 
1320
  delete thd;
 
1321
  DBUG_VOID_RETURN;
 
1322
}
 
1323
 
 
1324
 
 
1325
/*
 
1326
  Store thread in cache for reuse by new connections
 
1327
 
 
1328
  SYNOPSIS
 
1329
    cache_thread()
 
1330
 
 
1331
  NOTES
 
1332
    LOCK_thread_count has to be locked
 
1333
 
 
1334
  RETURN
 
1335
    0  Thread was not put in cache
 
1336
    1  Thread is to be reused by new connection.
 
1337
       (ie, caller should return, not abort with pthread_exit())
 
1338
*/
 
1339
 
 
1340
 
 
1341
static bool cache_thread()
 
1342
{
 
1343
  safe_mutex_assert_owner(&LOCK_thread_count);
 
1344
  if (cached_thread_count < thread_cache_size &&
 
1345
      ! abort_loop && !kill_cached_threads)
 
1346
  {
 
1347
    /* Don't kill the thread, just put it in cache for reuse */
 
1348
    DBUG_PRINT("info", ("Adding thread to cache"));
 
1349
    cached_thread_count++;
 
1350
    while (!abort_loop && ! wake_thread && ! kill_cached_threads)
 
1351
      (void) pthread_cond_wait(&COND_thread_cache, &LOCK_thread_count);
 
1352
    cached_thread_count--;
 
1353
    if (kill_cached_threads)
 
1354
      pthread_cond_signal(&COND_flush_thread_cache);
 
1355
    if (wake_thread)
 
1356
    {
 
1357
      THD *thd;
 
1358
      wake_thread--;
 
1359
      thd= thread_cache.get();
 
1360
      thd->thread_stack= (char*) &thd;          // For store_globals
 
1361
      (void) thd->store_globals();
 
1362
      /*
 
1363
        THD::mysys_var::abort is associated with physical thread rather
 
1364
        than with THD object. So we need to reset this flag before using
 
1365
        this thread for handling of new THD object/connection.
 
1366
      */
 
1367
      thd->mysys_var->abort= 0;
 
1368
      thd->thr_create_utime= my_micro_time();
 
1369
      threads.append(thd);
 
1370
      return(1);
 
1371
    }
 
1372
  }
 
1373
  return(0);
 
1374
}
 
1375
 
 
1376
 
 
1377
/*
 
1378
  End thread for the current connection
 
1379
 
 
1380
  SYNOPSIS
 
1381
    one_thread_per_connection_end()
 
1382
    thd           Thread handler
 
1383
    put_in_cache  Store thread in cache, if there is room in it
 
1384
                  Normally this is true in all cases except when we got
 
1385
                  out of resources initializing the current thread
 
1386
 
 
1387
  NOTES
 
1388
    If thread is cached, we will wait until thread is scheduled to be
 
1389
    reused and then we will return.
 
1390
    If thread is not cached, we end the thread.
 
1391
 
 
1392
  RETURN
 
1393
    0    Signal to handle_one_connection to reuse connection
 
1394
*/
 
1395
 
 
1396
bool one_thread_per_connection_end(THD *thd, bool put_in_cache)
 
1397
{
 
1398
  DBUG_ENTER("one_thread_per_connection_end");
 
1399
  unlink_thd(thd);
 
1400
  if (put_in_cache)
 
1401
    put_in_cache= cache_thread();
 
1402
  pthread_mutex_unlock(&LOCK_thread_count);
 
1403
  if (put_in_cache)
 
1404
    DBUG_RETURN(0);                             // Thread is reused
 
1405
 
 
1406
  /* It's safe to broadcast outside a lock (COND... is not deleted here) */
 
1407
  DBUG_PRINT("signal", ("Broadcasting COND_thread_count"));
 
1408
  my_thread_end();
 
1409
  (void) pthread_cond_broadcast(&COND_thread_count);
 
1410
 
 
1411
  pthread_exit(0);
 
1412
  DBUG_RETURN(0);                               // Impossible
 
1413
}
 
1414
 
 
1415
 
 
1416
void flush_thread_cache()
 
1417
{
 
1418
  (void) pthread_mutex_lock(&LOCK_thread_count);
 
1419
  kill_cached_threads++;
 
1420
  while (cached_thread_count)
 
1421
  {
 
1422
    pthread_cond_broadcast(&COND_thread_cache);
 
1423
    pthread_cond_wait(&COND_flush_thread_cache,&LOCK_thread_count);
 
1424
  }
 
1425
  kill_cached_threads--;
 
1426
  (void) pthread_mutex_unlock(&LOCK_thread_count);
 
1427
}
 
1428
 
 
1429
 
 
1430
#ifdef THREAD_SPECIFIC_SIGPIPE
 
1431
/**
 
1432
  Aborts a thread nicely. Comes here on SIGPIPE.
 
1433
 
 
1434
  @todo
 
1435
    One should have to fix that thr_alarm know about this thread too.
 
1436
*/
 
1437
extern "C" sig_handler abort_thread(int sig __attribute__((unused)))
 
1438
{
 
1439
  THD *thd=current_thd;
 
1440
  DBUG_ENTER("abort_thread");
 
1441
  if (thd)
 
1442
    thd->killed= THD::KILL_CONNECTION;
 
1443
  DBUG_VOID_RETURN;
 
1444
}
 
1445
#endif
 
1446
 
 
1447
#if BACKTRACE_DEMANGLE
 
1448
#include <cxxabi.h>
 
1449
extern "C" char *my_demangle(const char *mangled_name, int *status)
 
1450
{
 
1451
  return abi::__cxa_demangle(mangled_name, NULL, NULL, status);
 
1452
}
 
1453
#endif
 
1454
 
 
1455
 
 
1456
extern "C" sig_handler handle_segfault(int sig)
 
1457
{
 
1458
  time_t curr_time;
 
1459
  struct tm tm;
 
1460
  THD *thd=current_thd;
 
1461
 
 
1462
  /*
 
1463
    Strictly speaking, one needs a mutex here
 
1464
    but since we have got SIGSEGV already, things are a mess
 
1465
    so not having the mutex is not as bad as possibly using a buggy
 
1466
    mutex - so we keep things simple
 
1467
  */
 
1468
  if (segfaulted)
 
1469
  {
 
1470
    fprintf(stderr, "Fatal " SIGNAL_FMT " while backtracing\n", sig);
 
1471
    exit(1);
 
1472
  }
 
1473
 
 
1474
  segfaulted = 1;
 
1475
 
 
1476
  curr_time= my_time(0);
 
1477
  localtime_r(&curr_time, &tm);
 
1478
 
 
1479
  fprintf(stderr,"\
 
1480
%02d%02d%02d %2d:%02d:%02d - mysqld got " SIGNAL_FMT " ;\n\
 
1481
This could be because you hit a bug. It is also possible that this binary\n\
 
1482
or one of the libraries it was linked against is corrupt, improperly built,\n\
 
1483
or misconfigured. This error can also be caused by malfunctioning hardware.\n",
 
1484
          tm.tm_year % 100, tm.tm_mon+1, tm.tm_mday,
 
1485
          tm.tm_hour, tm.tm_min, tm.tm_sec,
 
1486
          sig);
 
1487
  fprintf(stderr, "\
 
1488
We will try our best to scrape up some info that will hopefully help diagnose\n\
 
1489
the problem, but since we have already crashed, something is definitely wrong\n\
 
1490
and this may fail.\n\n");
 
1491
  fprintf(stderr, "key_buffer_size=%lu\n",
 
1492
          (ulong) dflt_key_cache->key_cache_mem_size);
 
1493
  fprintf(stderr, "read_buffer_size=%ld\n", (long) global_system_variables.read_buff_size);
 
1494
  fprintf(stderr, "max_used_connections=%lu\n", max_used_connections);
 
1495
  fprintf(stderr, "max_threads=%u\n", thread_scheduler.max_threads);
 
1496
  fprintf(stderr, "thread_count=%u\n", thread_count);
 
1497
  fprintf(stderr, "connection_count=%u\n", connection_count);
 
1498
  fprintf(stderr, "It is possible that mysqld could use up to \n\
 
1499
key_buffer_size + (read_buffer_size + sort_buffer_size)*max_threads = %lu K\n\
 
1500
bytes of memory\n", ((ulong) dflt_key_cache->key_cache_mem_size +
 
1501
                     (global_system_variables.read_buff_size +
 
1502
                      global_system_variables.sortbuff_size) *
 
1503
                     thread_scheduler.max_threads +
 
1504
                     max_connections * sizeof(THD)) / 1024);
 
1505
  fprintf(stderr, "Hope that's ok; if not, decrease some variables in the equation.\n\n");
 
1506
 
 
1507
#ifdef HAVE_STACKTRACE
 
1508
  if (!(test_flags & TEST_NO_STACKTRACE))
 
1509
  {
 
1510
    fprintf(stderr,"thd: 0x%lx\n",(long) thd);
 
1511
    fprintf(stderr,"\
 
1512
Attempting backtrace. You can use the following information to find out\n\
 
1513
where mysqld died. If you see no messages after this, something went\n\
 
1514
terribly wrong...\n");  
 
1515
    print_stacktrace(thd ? (uchar*) thd->thread_stack : (uchar*) 0,
 
1516
                     my_thread_stack_size);
 
1517
  }
 
1518
  if (thd)
 
1519
  {
 
1520
    const char *kreason= "UNKNOWN";
 
1521
    switch (thd->killed) {
 
1522
    case THD::NOT_KILLED:
 
1523
      kreason= "NOT_KILLED";
 
1524
      break;
 
1525
    case THD::KILL_BAD_DATA:
 
1526
      kreason= "KILL_BAD_DATA";
 
1527
      break;
 
1528
    case THD::KILL_CONNECTION:
 
1529
      kreason= "KILL_CONNECTION";
 
1530
      break;
 
1531
    case THD::KILL_QUERY:
 
1532
      kreason= "KILL_QUERY";
 
1533
      break;
 
1534
    case THD::KILLED_NO_VALUE:
 
1535
      kreason= "KILLED_NO_VALUE";
 
1536
      break;
 
1537
    }
 
1538
    fprintf(stderr, "Trying to get some variables.\n\
 
1539
Some pointers may be invalid and cause the dump to abort...\n");
 
1540
    safe_print_str("thd->query", thd->query, 1024);
 
1541
    fprintf(stderr, "thd->thread_id=%lu\n", (ulong) thd->thread_id);
 
1542
    fprintf(stderr, "thd->killed=%s\n", kreason);
 
1543
  }
 
1544
  fprintf(stderr, "\
 
1545
The manual page at http://dev.mysql.com/doc/mysql/en/crashing.html contains\n\
 
1546
information that should help you find out what is causing the crash.\n");
 
1547
  fflush(stderr);
 
1548
#endif /* HAVE_STACKTRACE */
 
1549
 
 
1550
#ifdef HAVE_INITGROUPS
 
1551
  if (calling_initgroups)
 
1552
    fprintf(stderr, "\n\
 
1553
This crash occured while the server was calling initgroups(). This is\n\
 
1554
often due to the use of a mysqld that is statically linked against glibc\n\
 
1555
and configured to use LDAP in /etc/nsswitch.conf. You will need to either\n\
 
1556
upgrade to a version of glibc that does not have this problem (2.3.4 or\n\
 
1557
later when used with nscd), disable LDAP in your nsswitch.conf, or use a\n\
 
1558
mysqld that is not statically linked.\n");
 
1559
#endif
 
1560
 
 
1561
  if (thd_lib_detected == THD_LIB_LT && !getenv("LD_ASSUME_KERNEL"))
 
1562
    fprintf(stderr,"\n\
 
1563
You are running a statically-linked LinuxThreads binary on an NPTL system.\n\
 
1564
This can result in crashes on some distributions due to LT/NPTL conflicts.\n\
 
1565
You should either build a dynamically-linked binary, or force LinuxThreads\n\
 
1566
to be used with the LD_ASSUME_KERNEL environment variable. Please consult\n\
 
1567
the documentation for your distribution on how to do that.\n");
 
1568
  
 
1569
  if (locked_in_memory)
 
1570
  {
 
1571
    fprintf(stderr, "\n\
 
1572
The \"--memlock\" argument, which was enabled, uses system calls that are\n\
 
1573
unreliable and unstable on some operating systems and operating-system\n\
 
1574
versions (notably, some versions of Linux).  This crash could be due to use\n\
 
1575
of those buggy OS calls.  You should consider whether you really need the\n\
 
1576
\"--memlock\" parameter and/or consult the OS distributer about \"mlockall\"\n\
 
1577
bugs.\n");
 
1578
  }
 
1579
 
 
1580
#ifdef HAVE_WRITE_CORE
 
1581
  if (test_flags & TEST_CORE_ON_SIGNAL)
 
1582
  {
 
1583
    fprintf(stderr, "Writing a core file\n");
 
1584
    fflush(stderr);
 
1585
    write_core(sig);
 
1586
  }
 
1587
#endif
 
1588
 
 
1589
  exit(1);
 
1590
}
646
1591
 
647
1592
#ifndef SA_RESETHAND
648
1593
#define SA_RESETHAND 0
651
1596
#define SA_NODEFER 0
652
1597
#endif
653
1598
 
654
 
 
655
 
 
656
 
 
657
 
const char *load_default_groups[]= 
658
 
{
659
 
  DRIZZLE_CONFIG_NAME, "server", 0, 0
660
 
};
661
 
 
662
 
static void find_plugin_dir(string progname)
663
 
{
664
 
  if (progname[0] != FN_LIBCHAR)
665
 
  {
666
 
    /* We have a relative path and need to find the absolute */
667
 
    char working_dir[FN_REFLEN];
668
 
    char *working_dir_ptr= working_dir;
669
 
    working_dir_ptr= getcwd(working_dir_ptr, FN_REFLEN);
670
 
    string new_path(working_dir);
671
 
    if (*(new_path.end()-1) != '/')
672
 
      new_path.push_back('/');
673
 
    if (progname[0] == '.' && progname[1] == '/')
674
 
      new_path.append(progname.substr(2));
 
1599
static void init_signals(void)
 
1600
{
 
1601
  sigset_t set;
 
1602
  struct sigaction sa;
 
1603
  DBUG_ENTER("init_signals");
 
1604
 
 
1605
  my_sigset(THR_SERVER_ALARM,print_signal_warning); // Should never be called!
 
1606
 
 
1607
  if (!(test_flags & TEST_NO_STACKTRACE) || (test_flags & TEST_CORE_ON_SIGNAL))
 
1608
  {
 
1609
    sa.sa_flags = SA_RESETHAND | SA_NODEFER;
 
1610
    sigemptyset(&sa.sa_mask);
 
1611
    sigprocmask(SIG_SETMASK,&sa.sa_mask,NULL);
 
1612
 
 
1613
    init_stacktrace();
 
1614
    sa.sa_handler=handle_segfault;
 
1615
    sigaction(SIGSEGV, &sa, NULL);
 
1616
    sigaction(SIGABRT, &sa, NULL);
 
1617
#ifdef SIGBUS
 
1618
    sigaction(SIGBUS, &sa, NULL);
 
1619
#endif
 
1620
    sigaction(SIGILL, &sa, NULL);
 
1621
    sigaction(SIGFPE, &sa, NULL);
 
1622
  }
 
1623
 
 
1624
#ifdef HAVE_GETRLIMIT
 
1625
  if (test_flags & TEST_CORE_ON_SIGNAL)
 
1626
  {
 
1627
    /* Change limits so that we will get a core file */
 
1628
    STRUCT_RLIMIT rl;
 
1629
    rl.rlim_cur = rl.rlim_max = RLIM_INFINITY;
 
1630
    if (setrlimit(RLIMIT_CORE, &rl) && global_system_variables.log_warnings)
 
1631
      sql_print_warning("setrlimit could not change the size of core files to 'infinity';  We may not be able to generate a core file on signals");
 
1632
  }
 
1633
#endif
 
1634
  (void) sigemptyset(&set);
 
1635
  my_sigset(SIGPIPE,SIG_IGN);
 
1636
  sigaddset(&set,SIGPIPE);
 
1637
#ifndef IGNORE_SIGHUP_SIGQUIT
 
1638
  sigaddset(&set,SIGQUIT);
 
1639
  sigaddset(&set,SIGHUP);
 
1640
#endif
 
1641
  sigaddset(&set,SIGTERM);
 
1642
 
 
1643
  /* Fix signals if blocked by parents (can happen on Mac OS X) */
 
1644
  sigemptyset(&sa.sa_mask);
 
1645
  sa.sa_flags = 0;
 
1646
  sa.sa_handler = print_signal_warning;
 
1647
  sigaction(SIGTERM, &sa, (struct sigaction*) 0);
 
1648
  sa.sa_flags = 0;
 
1649
  sa.sa_handler = print_signal_warning;
 
1650
  sigaction(SIGHUP, &sa, (struct sigaction*) 0);
 
1651
#ifdef SIGTSTP
 
1652
  sigaddset(&set,SIGTSTP);
 
1653
#endif
 
1654
  if (thd_lib_detected != THD_LIB_LT)
 
1655
    sigaddset(&set,THR_SERVER_ALARM);
 
1656
  if (test_flags & TEST_SIGINT)
 
1657
  {
 
1658
    my_sigset(thr_kill_signal, end_thread_signal);
 
1659
    // May be SIGINT
 
1660
    sigdelset(&set, thr_kill_signal);
 
1661
  }
 
1662
  else
 
1663
    sigaddset(&set,SIGINT);
 
1664
  sigprocmask(SIG_SETMASK,&set,NULL);
 
1665
  pthread_sigmask(SIG_SETMASK,&set,NULL);
 
1666
  DBUG_VOID_RETURN;
 
1667
}
 
1668
 
 
1669
 
 
1670
static void start_signal_handler(void)
 
1671
{
 
1672
  int error;
 
1673
  pthread_attr_t thr_attr;
 
1674
  DBUG_ENTER("start_signal_handler");
 
1675
 
 
1676
  (void) pthread_attr_init(&thr_attr);
 
1677
  pthread_attr_setscope(&thr_attr, PTHREAD_SCOPE_SYSTEM);
 
1678
  (void) pthread_attr_setdetachstate(&thr_attr, PTHREAD_CREATE_DETACHED);
 
1679
  if (!(opt_specialflag & SPECIAL_NO_PRIOR))
 
1680
  {
 
1681
    struct sched_param tmp_sched_param;
 
1682
 
 
1683
    memset(&tmp_sched_param, 0, sizeof(tmp_sched_param));
 
1684
    tmp_sched_param.sched_priority= INTERRUPT_PRIOR;
 
1685
    (void)pthread_attr_setschedparam(&thr_attr, &tmp_sched_param);
 
1686
  }
 
1687
#if defined(__ia64__) || defined(__ia64)
 
1688
  /*
 
1689
    Peculiar things with ia64 platforms - it seems we only have half the
 
1690
    stack size in reality, so we have to double it here
 
1691
  */
 
1692
  pthread_attr_setstacksize(&thr_attr,my_thread_stack_size*2);
 
1693
#else
 
1694
  pthread_attr_setstacksize(&thr_attr,my_thread_stack_size);
 
1695
 
 
1696
  (void) pthread_mutex_lock(&LOCK_thread_count);
 
1697
  if ((error=pthread_create(&signal_thread,&thr_attr,signal_hand,0)))
 
1698
  {
 
1699
    sql_print_error("Can't create interrupt-thread (error %d, errno: %d)",
 
1700
                    error,errno);
 
1701
    exit(1);
 
1702
  }
 
1703
  (void) pthread_cond_wait(&COND_thread_count,&LOCK_thread_count);
 
1704
  pthread_mutex_unlock(&LOCK_thread_count);
 
1705
 
 
1706
  (void) pthread_attr_destroy(&thr_attr);
 
1707
  DBUG_VOID_RETURN;
 
1708
}
 
1709
 
 
1710
 
 
1711
/** This threads handles all signals and alarms. */
 
1712
/* ARGSUSED */
 
1713
pthread_handler_t signal_hand(void *arg __attribute__((unused)))
 
1714
{
 
1715
  sigset_t set;
 
1716
  int sig;
 
1717
  my_thread_init();                             // Init new thread
 
1718
  DBUG_ENTER("signal_hand");
 
1719
  signal_thread_in_use= 1;
 
1720
 
 
1721
  /*
 
1722
    Setup alarm handler
 
1723
    This should actually be '+ max_number_of_slaves' instead of +10,
 
1724
    but the +10 should be quite safe.
 
1725
  */
 
1726
  init_thr_alarm(thread_scheduler.max_threads + 10);
 
1727
  if (thd_lib_detected != THD_LIB_LT && (test_flags & TEST_SIGINT))
 
1728
  {
 
1729
    (void) sigemptyset(&set);                   // Setup up SIGINT for debug
 
1730
    (void) sigaddset(&set,SIGINT);              // For debugging
 
1731
    (void) pthread_sigmask(SIG_UNBLOCK,&set,NULL);
 
1732
  }
 
1733
  (void) sigemptyset(&set);                     // Setup up SIGINT for debug
 
1734
#ifdef USE_ONE_SIGNAL_HAND
 
1735
  (void) sigaddset(&set,THR_SERVER_ALARM);      // For alarms
 
1736
#endif
 
1737
#ifndef IGNORE_SIGHUP_SIGQUIT
 
1738
  (void) sigaddset(&set,SIGQUIT);
 
1739
  (void) sigaddset(&set,SIGHUP);
 
1740
#endif
 
1741
  (void) sigaddset(&set,SIGTERM);
 
1742
  (void) sigaddset(&set,SIGTSTP);
 
1743
 
 
1744
  /* Save pid to this process (or thread on Linux) */
 
1745
  if (!opt_bootstrap)
 
1746
    create_pid_file();
 
1747
 
 
1748
#ifdef HAVE_STACK_TRACE_ON_SEGV
 
1749
  if (opt_do_pstack)
 
1750
  {
 
1751
    sprintf(pstack_file_name,"mysqld-%lu-%%d-%%d.backtrace", (ulong)getpid());
 
1752
    pstack_install_segv_action(pstack_file_name);
 
1753
  }
 
1754
#endif /* HAVE_STACK_TRACE_ON_SEGV */
 
1755
 
 
1756
  /*
 
1757
    signal to start_signal_handler that we are ready
 
1758
    This works by waiting for start_signal_handler to free mutex,
 
1759
    after which we signal it that we are ready.
 
1760
    At this pointer there is no other threads running, so there
 
1761
    should not be any other pthread_cond_signal() calls.
 
1762
  */
 
1763
  (void) pthread_mutex_lock(&LOCK_thread_count);
 
1764
  (void) pthread_mutex_unlock(&LOCK_thread_count);
 
1765
  (void) pthread_cond_broadcast(&COND_thread_count);
 
1766
 
 
1767
  (void) pthread_sigmask(SIG_BLOCK,&set,NULL);
 
1768
  for (;;)
 
1769
  {
 
1770
    int error;                                  // Used when debugging
 
1771
    if (shutdown_in_progress && !abort_loop)
 
1772
    {
 
1773
      sig= SIGTERM;
 
1774
      error=0;
 
1775
    }
675
1776
    else
676
 
      new_path.append(progname);
677
 
    progname.swap(new_path);
678
 
  }
679
 
 
680
 
  /* Now, trim off the exe name */
681
 
  string progdir(progname.substr(0, progname.rfind(FN_LIBCHAR)+1));
682
 
  if (progdir.rfind(".libs/") != string::npos)
683
 
  {
684
 
    progdir.assign(progdir.substr(0, progdir.rfind(".libs/")));
685
 
  }
686
 
  string testlofile(progdir);
687
 
  testlofile.append("drizzled.lo");
688
 
  string testofile(progdir);
689
 
  testofile.append("drizzled.o");
690
 
  struct stat testfile_stat;
691
 
  if (not (stat(testlofile.c_str(), &testfile_stat) && stat(testofile.c_str(), &testfile_stat)))
692
 
  {
693
 
    /* We are in a source dir! Plugin dir is ../plugin/.libs */
694
 
    size_t last_libchar_pos= progdir.rfind(FN_LIBCHAR,progdir.size()-2)+1;
695
 
    base_plugin_dir= progdir.substr(0,last_libchar_pos);
696
 
    base_plugin_dir /= "plugin";
697
 
    base_plugin_dir /= ".libs";
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
 
 
708
 
static 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
 
 
719
 
static 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
 
 
724
 
static 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
 
    cout << N_("Error: Invalid Value for auto_increment_increment");
730
 
    exit(-1);
731
 
  }
732
 
  global_system_variables.auto_increment_increment= in_auto_increment_increment;
733
 
}
734
 
 
735
 
static void check_limits_aio(uint64_t in_auto_increment_offset)
736
 
{
737
 
  global_system_variables.auto_increment_offset= 1;
738
 
  if (in_auto_increment_offset < 1 || in_auto_increment_offset > UINT64_MAX)
739
 
  {
740
 
    cout << N_("Error: Invalid Value for auto_increment_offset");
741
 
    exit(-1);
742
 
  }
743
 
  global_system_variables.auto_increment_offset= in_auto_increment_offset;
744
 
}
745
 
 
746
 
static void check_limits_completion_type(uint32_t in_completion_type)
747
 
{
748
 
  global_system_variables.completion_type= 0;
749
 
  if (in_completion_type > 2)
750
 
  {
751
 
    cout << N_("Error: Invalid Value for completion_type");
752
 
    exit(-1);
753
 
  }
754
 
  global_system_variables.completion_type= in_completion_type;
755
 
}
756
 
 
757
 
 
758
 
static void check_limits_dpi(uint32_t in_div_precincrement)
759
 
{
760
 
  global_system_variables.div_precincrement= 4;
761
 
  if (in_div_precincrement > DECIMAL_MAX_SCALE)
762
 
  {
763
 
    cout << N_("Error: Invalid Value for div-precision-increment");
764
 
    exit(-1);
765
 
  }
766
 
  global_system_variables.div_precincrement= in_div_precincrement;
767
 
}
768
 
 
769
 
static void check_limits_gcml(uint64_t in_group_concat_max_len)
770
 
{
771
 
  global_system_variables.group_concat_max_len= 1024;
772
 
  if (in_group_concat_max_len > ULONG_MAX || in_group_concat_max_len < 4)
773
 
  {
774
 
    cout << N_("Error: Invalid Value for group_concat_max_len");
775
 
    exit(-1);
776
 
  }
777
 
  global_system_variables.group_concat_max_len= in_group_concat_max_len;
778
 
}
779
 
 
780
 
static void check_limits_join_buffer_size(uint64_t in_join_buffer_size)
781
 
{
782
 
  global_system_variables.join_buff_size= (128*1024L);
783
 
  if (in_join_buffer_size < IO_SIZE*2 || in_join_buffer_size > ULONG_MAX)
784
 
  {
785
 
    cout << N_("Error: Invalid Value for join_buffer_size");
786
 
    exit(-1);
787
 
  }
788
 
  in_join_buffer_size-= in_join_buffer_size % IO_SIZE;
789
 
  global_system_variables.join_buff_size= in_join_buffer_size;
790
 
}
791
 
 
792
 
static void check_limits_map(uint32_t in_max_allowed_packet)
793
 
{
794
 
  global_system_variables.max_allowed_packet= (64*1024*1024L);
795
 
  if (in_max_allowed_packet < 1024 || in_max_allowed_packet > 1024*1024L*1024L)
796
 
  {
797
 
    cout << N_("Error: Invalid Value for max_allowed_packet");
798
 
    exit(-1);
799
 
  }
800
 
  in_max_allowed_packet-= in_max_allowed_packet % 1024;
801
 
  global_system_variables.max_allowed_packet= in_max_allowed_packet;
802
 
}
803
 
 
804
 
static void check_limits_mce(uint64_t in_max_connect_errors)
805
 
{
806
 
  max_connect_errors= MAX_CONNECT_ERRORS;
807
 
  if (in_max_connect_errors < 1 || in_max_connect_errors > ULONG_MAX)
808
 
  {
809
 
    cout << N_("Error: Invalid Value for max_connect_errors");
810
 
    exit(-1);
811
 
  }
812
 
  max_connect_errors= in_max_connect_errors;
813
 
}
814
 
 
815
 
static void check_limits_max_err_cnt(uint64_t in_max_error_count)
816
 
{
817
 
  global_system_variables.max_error_count= DEFAULT_ERROR_COUNT;
818
 
  if (in_max_error_count > 65535)
819
 
  {
820
 
    cout << N_("Error: Invalid Value for max_error_count");
821
 
    exit(-1);
822
 
  }
823
 
  global_system_variables.max_error_count= in_max_error_count;
824
 
}
825
 
 
826
 
static void check_limits_mhts(uint64_t in_max_heap_table_size)
827
 
{
828
 
  global_system_variables.max_heap_table_size= (16*1024*1024L);
829
 
  if (in_max_heap_table_size < 16384 || in_max_heap_table_size > MAX_MEM_TABLE_SIZE)
830
 
  {
831
 
    cout << N_("Error: Invalid Value for max_heap_table_size");
832
 
    exit(-1);
833
 
  }
834
 
  in_max_heap_table_size-= in_max_heap_table_size % 1024;
835
 
  global_system_variables.max_heap_table_size= in_max_heap_table_size;
836
 
}
837
 
 
838
 
static void check_limits_merl(uint64_t in_min_examined_row_limit)
839
 
{
840
 
  global_system_variables.min_examined_row_limit= 0;
841
 
  if (in_min_examined_row_limit > ULONG_MAX)
842
 
  {
843
 
    cout << N_("Error: Invalid Value for min_examined_row_limit");
844
 
    exit(-1);
845
 
  }
846
 
  global_system_variables.min_examined_row_limit= in_min_examined_row_limit;
847
 
}
848
 
 
849
 
static void check_limits_max_join_size(drizzled::ha_rows in_max_join_size)
850
 
{
851
 
  global_system_variables.max_join_size= INT32_MAX;
852
 
  if ((uint64_t)in_max_join_size < 1 || (uint64_t)in_max_join_size > INT32_MAX)
853
 
  {
854
 
    cout << N_("Error: Invalid Value for max_join_size");
855
 
    exit(-1);
856
 
  }
857
 
  global_system_variables.max_join_size= in_max_join_size;
858
 
}
859
 
 
860
 
static void check_limits_mlfsd(int64_t in_max_length_for_sort_data)
861
 
{
862
 
  global_system_variables.max_length_for_sort_data= 1024;
863
 
  if (in_max_length_for_sort_data < 4 || in_max_length_for_sort_data > 8192*1024L)
864
 
  {
865
 
    cout << N_("Error: Invalid Value for max_length_for_sort_data");
866
 
    exit(-1);
867
 
  }
868
 
  global_system_variables.max_length_for_sort_data= in_max_length_for_sort_data;
869
 
}
870
 
 
871
 
static void check_limits_msfk(uint64_t in_max_seeks_for_key)
872
 
{
873
 
  global_system_variables.max_seeks_for_key= ULONG_MAX;
874
 
  if (in_max_seeks_for_key < 1 || in_max_seeks_for_key > ULONG_MAX)
875
 
  {
876
 
    cout << N_("Error: Invalid Value for max_seeks_for_key");
877
 
    exit(-1);
878
 
  }
879
 
  global_system_variables.max_seeks_for_key= in_max_seeks_for_key;
880
 
}
881
 
 
882
 
static void check_limits_max_sort_length(size_t in_max_sort_length)
883
 
{
884
 
  global_system_variables.max_sort_length= 1024;
885
 
  if ((int64_t)in_max_sort_length < 4 || (int64_t)in_max_sort_length > 8192*1024L)
886
 
  {
887
 
    cout << N_("Error: Invalid Value for max_sort_length");
888
 
    exit(-1);
889
 
  }
890
 
  global_system_variables.max_sort_length= in_max_sort_length;
891
 
}
892
 
 
893
 
static void check_limits_osd(uint32_t in_optimizer_search_depth)
894
 
{
895
 
  global_system_variables.optimizer_search_depth= 0;
896
 
  if (in_optimizer_search_depth > MAX_TABLES + 2)
897
 
  {
898
 
    cout << N_("Error: Invalid Value for optimizer_search_depth");
899
 
    exit(-1);
900
 
  }
901
 
  global_system_variables.optimizer_search_depth= in_optimizer_search_depth;
902
 
}
903
 
 
904
 
static void check_limits_pbs(uint64_t in_preload_buff_size)
905
 
{
906
 
  global_system_variables.preload_buff_size= (32*1024L);
907
 
  if (in_preload_buff_size < 1024 || in_preload_buff_size > 1024*1024*1024L)
908
 
  {
909
 
    cout << N_("Error: Invalid Value for preload_buff_size");
910
 
    exit(-1);
911
 
  }
912
 
  global_system_variables.preload_buff_size= in_preload_buff_size;
913
 
}
914
 
 
915
 
static void check_limits_qabs(uint32_t in_query_alloc_block_size)
916
 
{
917
 
  global_system_variables.query_alloc_block_size= QUERY_ALLOC_BLOCK_SIZE;
918
 
  if (in_query_alloc_block_size < 1024)
919
 
  {
920
 
    cout << N_("Error: Invalid Value for query_alloc_block_size");
921
 
    exit(-1);
922
 
  }
923
 
  in_query_alloc_block_size-= in_query_alloc_block_size % 1024;
924
 
  global_system_variables.query_alloc_block_size= in_query_alloc_block_size;
925
 
}
926
 
 
927
 
static void check_limits_qps(uint32_t in_query_prealloc_size)
928
 
{
929
 
  global_system_variables.query_prealloc_size= QUERY_ALLOC_PREALLOC_SIZE;
930
 
  if (in_query_prealloc_size < QUERY_ALLOC_PREALLOC_SIZE)
931
 
  {
932
 
    cout << N_("Error: Invalid Value for query_prealloc_size");
933
 
    exit(-1);
934
 
  }
935
 
  in_query_prealloc_size-= in_query_prealloc_size % 1024;
936
 
  global_system_variables.query_prealloc_size= in_query_prealloc_size;
937
 
}
938
 
 
939
 
static void check_limits_rabs(size_t in_range_alloc_block_size)
940
 
{
941
 
  global_system_variables.range_alloc_block_size= RANGE_ALLOC_BLOCK_SIZE;
942
 
  if (in_range_alloc_block_size < RANGE_ALLOC_BLOCK_SIZE)
943
 
  {
944
 
    cout << N_("Error: Invalid Value for range_alloc_block_size");
945
 
    exit(-1);
946
 
  }
947
 
  in_range_alloc_block_size-= in_range_alloc_block_size % 1024;
948
 
  global_system_variables.range_alloc_block_size= in_range_alloc_block_size;
949
 
}
950
 
 
951
 
static void check_limits_read_buffer_size(int32_t in_read_buff_size)
952
 
{
953
 
  global_system_variables.read_buff_size= (128*1024L);
954
 
  if (in_read_buff_size < IO_SIZE*2 || in_read_buff_size > INT32_MAX)
955
 
  {
956
 
    cout << N_("Error: Invalid Value for read_buff_size");
957
 
    exit(-1);
958
 
  }
959
 
  in_read_buff_size-= in_read_buff_size % IO_SIZE;
960
 
  global_system_variables.read_buff_size= in_read_buff_size;
961
 
}
962
 
 
963
 
static void check_limits_read_rnd_buffer_size(uint32_t in_read_rnd_buff_size)
964
 
{
965
 
  global_system_variables.read_rnd_buff_size= (256*1024L);
966
 
  if (in_read_rnd_buff_size < 64 || in_read_rnd_buff_size > UINT32_MAX)
967
 
  {
968
 
    cout << N_("Error: Invalid Value for read_rnd_buff_size");
969
 
    exit(-1);
970
 
  }
971
 
  global_system_variables.read_rnd_buff_size= in_read_rnd_buff_size;
972
 
}
973
 
 
974
 
static void check_limits_sort_buffer_size(size_t in_sortbuff_size)
975
 
{
976
 
  global_system_variables.sortbuff_size= MAX_SORT_MEMORY;
977
 
  if ((uint32_t)in_sortbuff_size < MIN_SORT_MEMORY)
978
 
  {
979
 
    cout << N_("Error: Invalid Value for sort_buff_size");
980
 
    exit(-1);
981
 
  }
982
 
  global_system_variables.sortbuff_size= in_sortbuff_size;
983
 
}
984
 
 
985
 
static void check_limits_tdc(uint32_t in_table_def_size)
986
 
{
987
 
  table_def_size= 128;
988
 
  if (in_table_def_size < 1 || in_table_def_size > 512*1024L)
989
 
  {
990
 
    cout << N_("Error: Invalid Value for table_def_size");
991
 
    exit(-1);
992
 
  }
993
 
  table_def_size= in_table_def_size;
994
 
}
995
 
 
996
 
static void check_limits_toc(uint32_t in_table_cache_size)
997
 
{
998
 
  table_cache_size= TABLE_OPEN_CACHE_DEFAULT;
999
 
  if (in_table_cache_size < TABLE_OPEN_CACHE_MIN || in_table_cache_size > 512*1024L)
1000
 
  {
1001
 
    cout << N_("Error: Invalid Value for table_cache_size");
1002
 
    exit(-1);
1003
 
  }
1004
 
  table_cache_size= in_table_cache_size;
1005
 
}
1006
 
 
1007
 
static void check_limits_tlwt(uint64_t in_table_lock_wait_timeout)
1008
 
{
1009
 
  table_lock_wait_timeout= 50;
1010
 
  if (in_table_lock_wait_timeout < 1 || in_table_lock_wait_timeout > 1024*1024*1024)
1011
 
  {
1012
 
    cout << N_("Error: Invalid Value for table_lock_wait_timeout");
1013
 
    exit(-1);
1014
 
  }
1015
 
  table_lock_wait_timeout= in_table_lock_wait_timeout;
1016
 
}
1017
 
 
1018
 
static void check_limits_thread_stack(uint32_t in_my_thread_stack_size)
1019
 
{
1020
 
  my_thread_stack_size= in_my_thread_stack_size - (in_my_thread_stack_size % 1024);
1021
 
}
1022
 
 
1023
 
static void check_limits_tmp_table_size(uint64_t in_tmp_table_size)
1024
 
{
1025
 
  global_system_variables.tmp_table_size= 16*1024*1024L;
1026
 
  if (in_tmp_table_size < 1024 || in_tmp_table_size > MAX_MEM_TABLE_SIZE)
1027
 
  {
1028
 
    cout << N_("Error: Invalid Value for table_lock_wait_timeout");
1029
 
    exit(-1);
1030
 
  }
1031
 
  global_system_variables.tmp_table_size= in_tmp_table_size;
1032
 
}
1033
 
 
1034
 
static void check_limits_transaction_message_threshold(size_t in_transaction_message_threshold)
1035
 
{
1036
 
  global_system_variables.transaction_message_threshold= 1024*1024;
1037
 
  if ((int64_t) in_transaction_message_threshold < 128*1024 || (int64_t)in_transaction_message_threshold > 1024*1024)
1038
 
  {
1039
 
    cout << N_("Error: Invalid Value for transaction_message_threshold valid values are between 131072 - 1048576 bytes");
1040
 
    exit(-1);
1041
 
  }
1042
 
  global_system_variables.transaction_message_threshold= in_transaction_message_threshold;
1043
 
}
1044
 
 
1045
 
static void process_defaults_files()
1046
 
{
1047
 
  for (vector<string>::iterator iter= defaults_file_list.begin();
1048
 
       iter != defaults_file_list.end();
1049
 
       ++iter)
1050
 
  {
1051
 
    fs::path file_location= *iter;
1052
 
 
1053
 
    ifstream input_defaults_file(file_location.file_string().c_str());
1054
 
    
1055
 
    po::parsed_options file_parsed=
1056
 
      dpo::parse_config_file(input_defaults_file, full_options, true);
1057
 
    vector<string> file_unknown= 
1058
 
      po::collect_unrecognized(file_parsed.options, po::include_positional);
1059
 
 
1060
 
    for (vector<string>::iterator it= file_unknown.begin();
1061
 
         it != file_unknown.end();
1062
 
         ++it)
 
1777
      while ((error=my_sigwait(&set,&sig)) == EINTR) ;
 
1778
    if (cleanup_done)
1063
1779
    {
1064
 
      string new_unknown_opt("--");
1065
 
      new_unknown_opt.append(*it);
1066
 
      ++it;
1067
 
      if (it != file_unknown.end())
 
1780
      DBUG_PRINT("quit",("signal_handler: calling my_thread_end()"));
 
1781
      my_thread_end();
 
1782
      signal_thread_in_use= 0;
 
1783
      pthread_exit(0);                          // Safety
 
1784
    }
 
1785
    switch (sig) {
 
1786
    case SIGTERM:
 
1787
    case SIGQUIT:
 
1788
    case SIGKILL:
 
1789
#ifdef EXTRA_DEBUG
 
1790
      sql_print_information("Got signal %d to shutdown mysqld",sig);
 
1791
#endif
 
1792
      /* switch to the old log message processing */
 
1793
      logger.set_handlers(LOG_FILE, opt_slow_log ? LOG_FILE:LOG_NONE,
 
1794
                          opt_log ? LOG_FILE:LOG_NONE);
 
1795
      DBUG_PRINT("info",("Got signal: %d  abort_loop: %d",sig,abort_loop));
 
1796
      if (!abort_loop)
1068
1797
      {
1069
 
        if ((*it) != "true")
 
1798
        abort_loop=1;                           // mark abort for threads
 
1799
#ifdef USE_ONE_SIGNAL_HAND
 
1800
        pthread_t tmp;
 
1801
        if (!(opt_specialflag & SPECIAL_NO_PRIOR))
1070
1802
        {
1071
 
          new_unknown_opt.push_back('=');
1072
 
          new_unknown_opt.append(*it);
 
1803
          struct sched_param tmp_sched_param;
 
1804
 
 
1805
          memset(&tmp_sched_param, 0, sizeof(tmp_sched_param));
 
1806
          tmp_sched_param.sched_priority= INTERRUPT_PRIOR;
 
1807
          (void)pthread_attr_setschedparam(&connection_attrib, &tmp_sched_param);
1073
1808
        }
 
1809
        if (pthread_create(&tmp,&connection_attrib, kill_server_thread,
 
1810
                           (void*) &sig))
 
1811
          sql_print_error("Can't create thread to kill server");
 
1812
#else
 
1813
        kill_server((void*) sig);       // MIT THREAD has a alarm thread
 
1814
#endif
 
1815
      }
 
1816
      break;
 
1817
    case SIGHUP:
 
1818
      if (!abort_loop)
 
1819
      {
 
1820
        bool not_used;
 
1821
        mysql_print_status();           // Print some debug info
 
1822
        reload_cache((THD*) 0,
 
1823
                     (REFRESH_LOG | REFRESH_TABLES | REFRESH_FAST |
 
1824
                      REFRESH_GRANT |
 
1825
                      REFRESH_THREADS | REFRESH_HOSTS),
 
1826
                     (TABLE_LIST*) 0, &not_used); // Flush logs
 
1827
      }
 
1828
      /* reenable logs after the options were reloaded */
 
1829
      if (log_output_options & LOG_NONE)
 
1830
      {
 
1831
        logger.set_handlers(LOG_FILE,
 
1832
                            opt_slow_log ? LOG_TABLE : LOG_NONE,
 
1833
                            opt_log ? LOG_TABLE : LOG_NONE);
1074
1834
      }
1075
1835
      else
1076
1836
      {
1077
 
        break;
 
1837
        logger.set_handlers(LOG_FILE,
 
1838
                            opt_slow_log ? log_output_options : LOG_NONE,
 
1839
                            opt_log ? log_output_options : LOG_NONE);
1078
1840
      }
1079
 
      unknown_options.push_back(new_unknown_opt);
 
1841
      break;
 
1842
#ifdef USE_ONE_SIGNAL_HAND
 
1843
    case THR_SERVER_ALARM:
 
1844
      process_alarm(sig);                       // Trigger alarms.
 
1845
      break;
 
1846
#endif
 
1847
    default:
 
1848
#ifdef EXTRA_DEBUG
 
1849
      sql_print_warning("Got signal: %d  error: %d",sig,error); /* purecov: tested */
 
1850
#endif
 
1851
      break;                                    /* purecov: tested */
1080
1852
    }
1081
 
    store(file_parsed, vm);
1082
1853
  }
 
1854
  return(0);                                    /* purecov: deadcode */
1083
1855
}
1084
1856
 
1085
 
static void compose_defaults_file_list(vector<string> in_options)
 
1857
static void check_data_home(const char *path)
 
1858
{}
 
1859
 
 
1860
#endif  /* __WIN__*/
 
1861
 
 
1862
 
 
1863
/**
 
1864
  All global error messages are sent here where the first one is stored
 
1865
  for the client.
 
1866
*/
 
1867
/* ARGSUSED */
 
1868
extern "C" void my_message_sql(uint error, const char *str, myf MyFlags);
 
1869
 
 
1870
void my_message_sql(uint error, const char *str, myf MyFlags)
1086
1871
{
1087
 
  for (vector<string>::iterator it= in_options.begin();
1088
 
       it != in_options.end();
1089
 
       ++it)
 
1872
  THD *thd;
 
1873
  DBUG_ENTER("my_message_sql");
 
1874
  DBUG_PRINT("error", ("error: %u  message: '%s'", error, str));
 
1875
  /*
 
1876
    Put here following assertion when situation with EE_* error codes
 
1877
    will be fixed
 
1878
    DBUG_ASSERT(error != 0);
 
1879
  */
 
1880
  if ((thd= current_thd))
1090
1881
  {
1091
 
    fs::path p(*it);
1092
 
    if (fs::is_regular_file(p))
1093
 
      defaults_file_list.push_back(*it);
 
1882
    if (MyFlags & ME_FATALERROR)
 
1883
      thd->is_fatal_error= 1;
 
1884
 
 
1885
#ifdef BUG_36098_FIXED
 
1886
    mysql_audit_general(thd,MYSQL_AUDIT_GENERAL_ERROR,error,my_time(0),
 
1887
                        0,0,str,str ? strlen(str) : 0,
 
1888
                        thd->query,thd->query_length,
 
1889
                        thd->variables.character_set_client,
 
1890
                        thd->row_count);
 
1891
#endif
 
1892
 
 
1893
 
 
1894
    /*
 
1895
      TODO: There are two exceptions mechanism (THD and sp_rcontext),
 
1896
      this could be improved by having a common stack of handlers.
 
1897
    */
 
1898
    if (thd->handle_error(error, str,
 
1899
                          MYSQL_ERROR::WARN_LEVEL_ERROR))
 
1900
      DBUG_VOID_RETURN;
 
1901
 
 
1902
    thd->is_slave_error=  1; // needed to catch query errors during replication
 
1903
 
 
1904
    /*
 
1905
      thd->lex->current_select == 0 if lex structure is not inited
 
1906
      (not query command (COM_QUERY))
 
1907
    */
 
1908
    if (thd->lex->current_select &&
 
1909
        thd->lex->current_select->no_error && !thd->is_fatal_error)
 
1910
    {
 
1911
      DBUG_PRINT("error",
 
1912
                 ("Error converted to warning: current_select: no_error %d  "
 
1913
                  "fatal_error: %d",
 
1914
                  (thd->lex->current_select ?
 
1915
                   thd->lex->current_select->no_error : 0),
 
1916
                  (int) thd->is_fatal_error));
 
1917
    }
1094
1918
    else
1095
1919
    {
1096
 
      errmsg_printf(ERRMSG_LVL_ERROR,
1097
 
                  _("Defaults file '%s' not found\n"), (*it).c_str());
1098
 
      unireg_abort(1);
1099
 
    }
1100
 
 
1101
 
  }
1102
 
}
1103
 
 
1104
 
int init_common_variables(int argc, char **argv, module::Registry &plugins)
1105
 
{
1106
 
  time_t curr_time;
1107
 
  umask(((~internal::my_umask) & 0666));
 
1920
      if (! thd->main_da.is_error())            // Return only first message
 
1921
      {
 
1922
        if (error == 0)
 
1923
          error= ER_UNKNOWN_ERROR;
 
1924
        if (str == NULL)
 
1925
          str= ER(error);
 
1926
        thd->main_da.set_error_status(thd, error, str);
 
1927
      }
 
1928
    }
 
1929
 
 
1930
    if (!thd->no_warnings_for_error && !thd->is_fatal_error)
 
1931
    {
 
1932
      /*
 
1933
        Suppress infinite recursion if there a memory allocation error
 
1934
        inside push_warning.
 
1935
      */
 
1936
      thd->no_warnings_for_error= TRUE;
 
1937
      push_warning(thd, MYSQL_ERROR::WARN_LEVEL_ERROR, error, str);
 
1938
      thd->no_warnings_for_error= FALSE;
 
1939
    }
 
1940
  }
 
1941
  if (!thd || MyFlags & ME_NOREFRESH)
 
1942
    sql_print_error("%s: %s",my_progname,str); /* purecov: inspected */
 
1943
  DBUG_VOID_RETURN;
 
1944
}
 
1945
 
 
1946
 
 
1947
extern "C" void *my_str_malloc_mysqld(size_t size);
 
1948
extern "C" void my_str_free_mysqld(void *ptr);
 
1949
 
 
1950
void *my_str_malloc_mysqld(size_t size)
 
1951
{
 
1952
  return my_malloc(size, MYF(MY_FAE));
 
1953
}
 
1954
 
 
1955
 
 
1956
void my_str_free_mysqld(void *ptr)
 
1957
{
 
1958
  my_free((uchar*)ptr, MYF(MY_FAE));
 
1959
}
 
1960
 
 
1961
 
 
1962
static const char *load_default_groups[]= {
 
1963
"mysqld","server", MYSQL_BASE_VERSION, 0, 0};
 
1964
 
 
1965
 
 
1966
/**
 
1967
  Initialize one of the global date/time format variables.
 
1968
 
 
1969
  @param format_type            What kind of format should be supported
 
1970
  @param var_ptr                Pointer to variable that should be updated
 
1971
 
 
1972
  @note
 
1973
    The default value is taken from either opt_date_time_formats[] or
 
1974
    the ISO format (ANSI SQL)
 
1975
 
 
1976
  @retval
 
1977
    0 ok
 
1978
  @retval
 
1979
    1 error
 
1980
*/
 
1981
 
 
1982
static bool init_global_datetime_format(timestamp_type format_type,
 
1983
                                        DATE_TIME_FORMAT **var_ptr)
 
1984
{
 
1985
  /* Get command line option */
 
1986
  const char *str= opt_date_time_formats[format_type];
 
1987
 
 
1988
  if (!str)                                     // No specified format
 
1989
  {
 
1990
    str= get_date_time_format_str(&known_date_time_formats[ISO_FORMAT],
 
1991
                                  format_type);
 
1992
    /*
 
1993
      Set the "command line" option to point to the generated string so
 
1994
      that we can set global formats back to default
 
1995
    */
 
1996
    opt_date_time_formats[format_type]= str;
 
1997
  }
 
1998
  if (!(*var_ptr= date_time_format_make(format_type, str, strlen(str))))
 
1999
  {
 
2000
    fprintf(stderr, "Wrong date/time format specifier: %s\n", str);
 
2001
    return 1;
 
2002
  }
 
2003
  return 0;
 
2004
}
 
2005
 
 
2006
SHOW_VAR com_status_vars[]= {
 
2007
  {"admin_commands",       (char*) offsetof(STATUS_VAR, com_other), SHOW_LONG_STATUS},
 
2008
  {"assign_to_keycache",   (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_ASSIGN_TO_KEYCACHE]), SHOW_LONG_STATUS},
 
2009
  {"alter_db",             (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_ALTER_DB]), SHOW_LONG_STATUS},
 
2010
  {"alter_db_upgrade",     (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_ALTER_DB_UPGRADE]), SHOW_LONG_STATUS},
 
2011
  {"alter_table",          (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_ALTER_TABLE]), SHOW_LONG_STATUS},
 
2012
  {"alter_tablespace",     (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_ALTER_TABLESPACE]), SHOW_LONG_STATUS},
 
2013
  {"analyze",              (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_ANALYZE]), SHOW_LONG_STATUS},
 
2014
  {"begin",                (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_BEGIN]), SHOW_LONG_STATUS},
 
2015
  {"binlog",               (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_BINLOG_BASE64_EVENT]), SHOW_LONG_STATUS},
 
2016
  {"change_db",            (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_CHANGE_DB]), SHOW_LONG_STATUS},
 
2017
  {"change_master",        (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_CHANGE_MASTER]), SHOW_LONG_STATUS},
 
2018
  {"check",                (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_CHECK]), SHOW_LONG_STATUS},
 
2019
  {"checksum",             (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_CHECKSUM]), SHOW_LONG_STATUS},
 
2020
  {"commit",               (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_COMMIT]), SHOW_LONG_STATUS},
 
2021
  {"create_db",            (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_CREATE_DB]), SHOW_LONG_STATUS},
 
2022
  {"create_index",         (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_CREATE_INDEX]), SHOW_LONG_STATUS},
 
2023
  {"create_table",         (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_CREATE_TABLE]), SHOW_LONG_STATUS},
 
2024
  {"create_udf",           (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_CREATE_FUNCTION]), SHOW_LONG_STATUS},
 
2025
  {"dealloc_sql",          (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_DEALLOCATE_PREPARE]), SHOW_LONG_STATUS},
 
2026
  {"delete",               (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_DELETE]), SHOW_LONG_STATUS},
 
2027
  {"delete_multi",         (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_DELETE_MULTI]), SHOW_LONG_STATUS},
 
2028
  {"drop_db",              (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_DROP_DB]), SHOW_LONG_STATUS},
 
2029
  {"drop_function",        (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_DROP_FUNCTION]), SHOW_LONG_STATUS},
 
2030
  {"drop_index",           (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_DROP_INDEX]), SHOW_LONG_STATUS},
 
2031
  {"drop_table",           (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_DROP_TABLE]), SHOW_LONG_STATUS},
 
2032
  {"empty_query",          (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_EMPTY_QUERY]), SHOW_LONG_STATUS},
 
2033
  {"execute_sql",          (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_EXECUTE]), SHOW_LONG_STATUS},
 
2034
  {"flush",                (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_FLUSH]), SHOW_LONG_STATUS},
 
2035
  {"insert",               (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_INSERT]), SHOW_LONG_STATUS},
 
2036
  {"insert_select",        (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_INSERT_SELECT]), SHOW_LONG_STATUS},
 
2037
  {"kill",                 (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_KILL]), SHOW_LONG_STATUS},
 
2038
  {"load",                 (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_LOAD]), SHOW_LONG_STATUS},
 
2039
  {"lock_tables",          (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_LOCK_TABLES]), SHOW_LONG_STATUS},
 
2040
  {"optimize",             (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_OPTIMIZE]), SHOW_LONG_STATUS},
 
2041
  {"preload_keys",         (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_PRELOAD_KEYS]), SHOW_LONG_STATUS},
 
2042
  {"prepare_sql",          (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_PREPARE]), SHOW_LONG_STATUS},
 
2043
  {"purge",                (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_PURGE]), SHOW_LONG_STATUS},
 
2044
  {"purge_before_date",    (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_PURGE_BEFORE]), SHOW_LONG_STATUS},
 
2045
  {"release_savepoint",    (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_RELEASE_SAVEPOINT]), SHOW_LONG_STATUS},
 
2046
  {"rename_table",         (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_RENAME_TABLE]), SHOW_LONG_STATUS},
 
2047
  {"repair",               (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_REPAIR]), SHOW_LONG_STATUS},
 
2048
  {"replace",              (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_REPLACE]), SHOW_LONG_STATUS},
 
2049
  {"replace_select",       (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_REPLACE_SELECT]), SHOW_LONG_STATUS},
 
2050
  {"reset",                (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_RESET]), SHOW_LONG_STATUS},
 
2051
  {"rollback",             (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_ROLLBACK]), SHOW_LONG_STATUS},
 
2052
  {"rollback_to_savepoint",(char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_ROLLBACK_TO_SAVEPOINT]), SHOW_LONG_STATUS},
 
2053
  {"savepoint",            (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_SAVEPOINT]), SHOW_LONG_STATUS},
 
2054
  {"select",               (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_SELECT]), SHOW_LONG_STATUS},
 
2055
  {"set_option",           (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_SET_OPTION]), SHOW_LONG_STATUS},
 
2056
  {"show_archive",         (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_SHOW_ARCHIVE]), SHOW_LONG_STATUS},
 
2057
  {"show_authors",         (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_SHOW_AUTHORS]), SHOW_LONG_STATUS},
 
2058
  {"show_binlog_events",   (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_SHOW_BINLOG_EVENTS]), SHOW_LONG_STATUS},
 
2059
  {"show_binlogs",         (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_SHOW_BINLOGS]), SHOW_LONG_STATUS},
 
2060
  {"show_charsets",        (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_SHOW_CHARSETS]), SHOW_LONG_STATUS},
 
2061
  {"show_collations",      (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_SHOW_COLLATIONS]), SHOW_LONG_STATUS},
 
2062
  {"show_contributors",    (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_SHOW_CONTRIBUTORS]), SHOW_LONG_STATUS},
 
2063
  {"show_create_db",       (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_SHOW_CREATE_DB]), SHOW_LONG_STATUS},
 
2064
  {"show_create_table",    (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_SHOW_CREATE]), SHOW_LONG_STATUS},
 
2065
  {"show_databases",       (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_SHOW_DATABASES]), SHOW_LONG_STATUS},
 
2066
  {"show_engine_status",   (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_SHOW_ENGINE_STATUS]), SHOW_LONG_STATUS},
 
2067
  {"show_errors",          (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_SHOW_ERRORS]), SHOW_LONG_STATUS},
 
2068
  {"show_fields",          (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_SHOW_FIELDS]), SHOW_LONG_STATUS},
 
2069
  {"show_keys",            (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_SHOW_KEYS]), SHOW_LONG_STATUS},
 
2070
  {"show_master_status",   (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_SHOW_MASTER_STAT]), SHOW_LONG_STATUS},
 
2071
  {"show_open_tables",     (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_SHOW_OPEN_TABLES]), SHOW_LONG_STATUS},
 
2072
  {"show_plugins",         (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_SHOW_PLUGINS]), SHOW_LONG_STATUS},
 
2073
  {"show_processlist",     (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_SHOW_PROCESSLIST]), SHOW_LONG_STATUS},
 
2074
  {"show_slave_hosts",     (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_SHOW_SLAVE_HOSTS]), SHOW_LONG_STATUS},
 
2075
  {"show_slave_status",    (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_SHOW_SLAVE_STAT]), SHOW_LONG_STATUS},
 
2076
  {"show_status",          (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_SHOW_STATUS]), SHOW_LONG_STATUS},
 
2077
  {"show_table_status",    (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_SHOW_TABLE_STATUS]), SHOW_LONG_STATUS},
 
2078
  {"show_tables",          (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_SHOW_TABLES]), SHOW_LONG_STATUS},
 
2079
  {"show_variables",       (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_SHOW_VARIABLES]), SHOW_LONG_STATUS},
 
2080
  {"show_warnings",        (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_SHOW_WARNS]), SHOW_LONG_STATUS},
 
2081
  {"slave_start",          (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_SLAVE_START]), SHOW_LONG_STATUS},
 
2082
  {"slave_stop",           (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_SLAVE_STOP]), SHOW_LONG_STATUS},
 
2083
  {"stmt_close",           (char*) offsetof(STATUS_VAR, com_stmt_close), SHOW_LONG_STATUS},
 
2084
  {"stmt_execute",         (char*) offsetof(STATUS_VAR, com_stmt_execute), SHOW_LONG_STATUS},
 
2085
  {"stmt_fetch",           (char*) offsetof(STATUS_VAR, com_stmt_fetch), SHOW_LONG_STATUS},
 
2086
  {"stmt_prepare",         (char*) offsetof(STATUS_VAR, com_stmt_prepare), SHOW_LONG_STATUS},
 
2087
  {"stmt_reset",           (char*) offsetof(STATUS_VAR, com_stmt_reset), SHOW_LONG_STATUS},
 
2088
  {"stmt_send_long_data",  (char*) offsetof(STATUS_VAR, com_stmt_send_long_data), SHOW_LONG_STATUS},
 
2089
  {"truncate",             (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_TRUNCATE]), SHOW_LONG_STATUS},
 
2090
  {"unlock_tables",        (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_UNLOCK_TABLES]), SHOW_LONG_STATUS},
 
2091
  {"update",               (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_UPDATE]), SHOW_LONG_STATUS},
 
2092
  {"update_multi",         (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_UPDATE_MULTI]), SHOW_LONG_STATUS},
 
2093
  {"xa_commit",            (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_XA_COMMIT]),SHOW_LONG_STATUS},
 
2094
  {"xa_end",               (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_XA_END]),SHOW_LONG_STATUS},
 
2095
  {"xa_prepare",           (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_XA_PREPARE]),SHOW_LONG_STATUS},
 
2096
  {"xa_recover",           (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_XA_RECOVER]),SHOW_LONG_STATUS},
 
2097
  {"xa_rollback",          (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_XA_ROLLBACK]),SHOW_LONG_STATUS},
 
2098
  {"xa_start",             (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_XA_START]),SHOW_LONG_STATUS},
 
2099
  {NullS, NullS, SHOW_LONG}
 
2100
};
 
2101
 
 
2102
static int init_common_variables(const char *conf_file_name, int argc,
 
2103
                                 char **argv, const char **groups)
 
2104
{
 
2105
  char buff[FN_REFLEN], *s;
 
2106
  umask(((~my_umask) & 0666));
1108
2107
  my_decimal_set_zero(&decimal_zero); // set decimal_zero constant;
1109
2108
  tzset();                      // Set tzname
1110
2109
 
1111
 
  curr_time= time(NULL);
1112
 
  if (curr_time == (time_t)-1)
 
2110
  max_system_variables.pseudo_thread_id= (ulong)~0;
 
2111
  server_start_time= flush_status_time= my_time(0);
 
2112
  rpl_filter= new Rpl_filter;
 
2113
  binlog_filter= new Rpl_filter;
 
2114
  if (!rpl_filter || !binlog_filter) 
 
2115
  {
 
2116
    sql_perror("Could not allocate replication and binlog filters");
 
2117
    exit(1);
 
2118
  }
 
2119
 
 
2120
  if (init_thread_environment())
1113
2121
    return 1;
1114
 
 
1115
 
  max_system_variables.pseudo_thread_id= UINT32_MAX;
1116
 
  server_start_time= flush_status_time= curr_time;
1117
 
 
1118
 
  drizzle_init_variables();
1119
 
 
1120
 
  find_plugin_dir(argv[0]);
 
2122
  mysql_init_variables();
 
2123
 
 
2124
#ifdef HAVE_TZNAME
1121
2125
  {
1122
2126
    struct tm tm_tmp;
1123
2127
    localtime_r(&server_start_time,&tm_tmp);
1124
 
    strncpy(system_time_zone, tzname[tm_tmp.tm_isdst != 0 ? 1 : 0],
 
2128
    strmake(system_time_zone, tzname[tm_tmp.tm_isdst != 0 ? 1 : 0],
1125
2129
            sizeof(system_time_zone)-1);
1126
2130
 
1127
 
  }
 
2131
 }
 
2132
#endif
1128
2133
  /*
1129
2134
    We set SYSTEM time zone as reasonable default and
1130
2135
    also for failure of my_tz_init() and bootstrap mode.
1133
2138
  */
1134
2139
  global_system_variables.time_zone= my_tz_SYSTEM;
1135
2140
 
 
2141
  /*
 
2142
    Init mutexes for the global MYSQL_BIN_LOG objects.
 
2143
    As safe_mutex depends on what MY_INIT() does, we can't init the mutexes of
 
2144
    global MYSQL_BIN_LOGs in their constructors, because then they would be
 
2145
    inited before MY_INIT(). So we do it here.
 
2146
  */
 
2147
  mysql_bin_log.init_pthread_objects();
 
2148
 
1136
2149
  if (gethostname(glob_hostname,sizeof(glob_hostname)) < 0)
1137
2150
  {
1138
 
    strncpy(glob_hostname, STRING_WITH_LEN("localhost"));
1139
 
    errmsg_printf(ERRMSG_LVL_WARN, _("gethostname failed, using '%s' as hostname"),
1140
 
                  glob_hostname);
1141
 
    pid_file= "drizzle";
 
2151
    strmake(glob_hostname, STRING_WITH_LEN("localhost"));
 
2152
    sql_print_warning("gethostname failed, using '%s' as hostname",
 
2153
                      glob_hostname);
 
2154
    strmake(pidfile_name, STRING_WITH_LEN("mysql"));
1142
2155
  }
1143
2156
  else
1144
 
  {
1145
 
    pid_file= glob_hostname;
1146
 
  }
1147
 
  pid_file.replace_extension(".pid");
1148
 
 
1149
 
  system_config_dir /= "drizzle";
1150
 
 
1151
 
  config_options.add_options()
1152
 
  ("help,?", po::value<bool>(&opt_help)->default_value(false)->zero_tokens(),
1153
 
  N_("Display this help and exit."))
1154
 
  ("no-defaults", po::value<bool>()->default_value(false)->zero_tokens(),
1155
 
  N_("Configuration file defaults are not used if no-defaults is set"))
1156
 
  ("defaults-file", po::value<vector<string> >()->composing()->notifier(&compose_defaults_file_list),
1157
 
   N_("Configuration file to use"))
1158
 
  ("config-dir", po::value<fs::path>(&system_config_dir),
1159
 
   N_("Base location for config files"))
1160
 
  ("plugin-dir", po::value<fs::path>(&plugin_dir)->notifier(&notify_plugin_dir),
1161
 
  N_("Directory for plugins."))
1162
 
  ;
1163
 
 
1164
 
  plugin_load_options.add_options()
1165
 
  ("plugin-add", po::value<vector<string> >()->composing()->notifier(&compose_plugin_add),
1166
 
  N_("Optional comma separated list of plugins to load at startup in addition "
1167
 
     "to the default list of plugins. "
1168
 
     "[for example: --plugin_add=crc32,logger_gearman]"))    
1169
 
  ("plugin-remove", po::value<vector<string> >()->composing()->notifier(&compose_plugin_remove),
1170
 
  N_("Optional comma separated list of plugins to not load at startup. Effectively "
1171
 
     "removes a plugin from the list of plugins to be loaded. "
1172
 
     "[for example: --plugin_remove=crc32,logger_gearman]"))
1173
 
  ("plugin-load", po::value<string>()->notifier(&notify_plugin_load)->default_value(PANDORA_PLUGIN_LIST),
1174
 
  N_("Optional comma separated list of plugins to load at starup instead of "
1175
 
     "the default plugin load list. "
1176
 
     "[for example: --plugin_load=crc32,logger_gearman]"))
1177
 
  ;
1178
 
 
1179
 
  long_options.add_options()
1180
 
  ("auto-increment-increment", po::value<uint64_t>(&global_system_variables.auto_increment_increment)->default_value(1)->notifier(&check_limits_aii),
1181
 
  N_("Auto-increment columns are incremented by this"))
1182
 
  ("auto-increment-offset", po::value<uint64_t>(&global_system_variables.auto_increment_offset)->default_value(1)->notifier(&check_limits_aio),
1183
 
  N_("Offset added to Auto-increment columns. Used when auto-increment-increment != 1"))
1184
 
  ("basedir,b", po::value<fs::path>(&basedir),
1185
 
  N_("Path to installation directory. All paths are usually resolved "
1186
 
     "relative to this."))
1187
 
  ("chroot,r", po::value<string>(),
1188
 
  N_("Chroot drizzled daemon during startup."))
1189
 
  ("collation-server", po::value<string>(),
1190
 
  N_("Set the default collation."))      
1191
 
  ("completion-type", po::value<uint32_t>(&global_system_variables.completion_type)->default_value(0)->notifier(&check_limits_completion_type),
1192
 
  N_("Default completion type."))
1193
 
  ("core-file",  N_("Write core on errors."))
1194
 
  ("datadir", po::value<fs::path>(&data_home),
1195
 
  N_("Path to the database root."))
1196
 
  ("default-storage-engine", po::value<string>(),
1197
 
  N_("Set the default storage engine for tables."))
1198
 
  ("default-time-zone", po::value<string>(),
1199
 
  N_("Set the default time zone."))
1200
 
  ("exit-info,T", po::value<long>(),
1201
 
  N_("Used for debugging;  Use at your own risk!"))
1202
 
  ("gdb", po::value<bool>(&opt_debugging)->default_value(false)->zero_tokens(),
1203
 
  N_("Set up signals usable for debugging"))
1204
 
  ("lc-time-name", po::value<string>(),
1205
 
  N_("Set the language used for the month names and the days of the week."))
1206
 
  ("log-warnings,W", po::value<bool>(&global_system_variables.log_warnings)->default_value(false)->zero_tokens(),
1207
 
  N_("Log some not critical warnings to the log file."))  
1208
 
  ("pid-file", po::value<fs::path>(&pid_file),
1209
 
  N_("Pid file used by drizzled."))
1210
 
  ("port-open-timeout", po::value<uint32_t>(&drizzled_bind_timeout)->default_value(0),
1211
 
  N_("Maximum time in seconds to wait for the port to become free. "))
1212
 
  ("replicate-query", po::value<bool>(&global_system_variables.replicate_query)->default_value(false)->zero_tokens(),
1213
 
  N_("Include the SQL query in replicated protobuf messages."))
1214
 
  ("secure-file-priv", po::value<fs::path>(&secure_file_priv)->notifier(expand_secure_file_priv),
1215
 
  N_("Limit LOAD DATA, SELECT ... OUTFILE, and LOAD_FILE() to files "
1216
 
     "within specified directory"))
1217
 
  ("server-id", po::value<uint32_t>(&server_id)->default_value(0),
1218
 
  N_("Uniquely identifies the server instance in the community of "
1219
 
     "replication partners."))
1220
 
  ("skip-stack-trace",  
1221
 
  N_("Don't print a stack trace on failure."))
1222
 
  ("symbolic-links,s", po::value<bool>(&internal::my_use_symdir)->default_value(IF_PURIFY(false,true))->zero_tokens(),
1223
 
  N_("Enable symbolic link support."))
1224
 
  ("timed-mutexes", po::value<bool>(&internal::timed_mutexes)->default_value(false)->zero_tokens(),
1225
 
  N_("Specify whether to time mutexes (only InnoDB mutexes are currently "
1226
 
     "supported)")) 
1227
 
  ("tmpdir,t", po::value<string>(),
1228
 
  N_("Path for temporary files."))
1229
 
  ("transaction-isolation", po::value<string>(),
1230
 
  N_("Default transaction isolation level."))
1231
 
  ("transaction-message-threshold", po::value<size_t>(&global_system_variables.transaction_message_threshold)->default_value(1024*1024)->notifier(&check_limits_transaction_message_threshold),
1232
 
  N_("Max message size written to transaction log, valid values 131072 - 1048576 bytes."))
1233
 
  ("user,u", po::value<string>(),
1234
 
  N_("Run drizzled daemon as user."))  
1235
 
  ("version,V", 
1236
 
  N_("Output version information and exit."))
1237
 
  ("back-log", po::value<back_log_constraints>(&back_log),
1238
 
  N_("The number of outstanding connection requests Drizzle can have. This "
1239
 
     "comes into play when the main Drizzle thread gets very many connection "
1240
 
     "requests in a very short time."))
1241
 
  ("bulk-insert-buffer-size", 
1242
 
  po::value<uint64_t>(&global_system_variables.bulk_insert_buff_size)->default_value(8192*1024),
1243
 
  N_("Size of tree cache used in bulk insert optimization. Note that this is "
1244
 
     "a limit per thread!"))
1245
 
  ("div-precision-increment",  po::value<uint32_t>(&global_system_variables.div_precincrement)->default_value(4)->notifier(&check_limits_dpi),
1246
 
  N_("Precision of the result of '/' operator will be increased on that "
1247
 
     "value."))
1248
 
  ("group-concat-max-len", po::value<uint64_t>(&global_system_variables.group_concat_max_len)->default_value(1024)->notifier(&check_limits_gcml),
1249
 
  N_("The maximum length of the result of function  group_concat."))
1250
 
  ("join-buffer-size", po::value<uint64_t>(&global_system_variables.join_buff_size)->default_value(128*1024L)->notifier(&check_limits_join_buffer_size),
1251
 
  N_("The size of the buffer that is used for full joins."))
1252
 
  ("join-heap-threshold",
1253
 
  po::value<uint64_t>()->default_value(0),
1254
 
  N_("A global cap on the amount of memory that can be allocated by session join buffers (0 means unlimited)"))
1255
 
  ("max-allowed-packet", po::value<uint32_t>(&global_system_variables.max_allowed_packet)->default_value(64*1024*1024L)->notifier(&check_limits_map),
1256
 
  N_("Max packetlength to send/receive from to server."))
1257
 
  ("max-connect-errors", po::value<uint64_t>(&max_connect_errors)->default_value(MAX_CONNECT_ERRORS)->notifier(&check_limits_mce),
1258
 
  N_("If there is more than this number of interrupted connections from a "
1259
 
     "host this host will be blocked from further connections."))
1260
 
  ("max-error-count", po::value<uint64_t>(&global_system_variables.max_error_count)->default_value(DEFAULT_ERROR_COUNT)->notifier(&check_limits_max_err_cnt),
1261
 
  N_("Max number of errors/warnings to store for a statement."))
1262
 
  ("max-heap-table-size", po::value<uint64_t>(&global_system_variables.max_heap_table_size)->default_value(16*1024*1024L)->notifier(&check_limits_mhts),
1263
 
  N_("Don't allow creation of heap tables bigger than this."))
1264
 
  ("max-join-size", po::value<drizzled::ha_rows>(&global_system_variables.max_join_size)->default_value(INT32_MAX)->notifier(&check_limits_max_join_size),
1265
 
  N_("Joins that are probably going to read more than max_join_size records "
1266
 
     "return an error."))
1267
 
  ("max-length-for-sort-data", po::value<uint64_t>(&global_system_variables.max_length_for_sort_data)->default_value(1024)->notifier(&check_limits_mlfsd),
1268
 
  N_("Max number of bytes in sorted records."))
1269
 
  ("max-seeks-for-key", po::value<uint64_t>(&global_system_variables.max_seeks_for_key)->default_value(ULONG_MAX)->notifier(&check_limits_msfk),
1270
 
  N_("Limit assumed max number of seeks when looking up rows based on a key"))
1271
 
  ("max-sort-length", po::value<size_t>(&global_system_variables.max_sort_length)->default_value(1024)->notifier(&check_limits_max_sort_length),  
1272
 
  N_("The number of bytes to use when sorting BLOB or TEXT values "
1273
 
     "(only the first max_sort_length bytes of each value are used; the "
1274
 
     "rest are ignored)."))
1275
 
  ("max-write-lock-count", po::value<uint64_t>(&max_write_lock_count)->default_value(UINT64_MAX),
1276
 
  N_("After this many write locks, allow some read locks to run in between."))
1277
 
  ("min-examined-row-limit", po::value<uint64_t>(&global_system_variables.min_examined_row_limit)->default_value(0)->notifier(&check_limits_merl),
1278
 
  N_("Don't log queries which examine less than min_examined_row_limit "
1279
 
     "rows to file."))
1280
 
  ("disable-optimizer-prune",
1281
 
  N_("Do not apply any heuristic(s) during query optimization to prune, "
1282
 
     "thus perform an exhaustive search from the optimizer search space."))
1283
 
  ("optimizer-search-depth", po::value<uint32_t>(&global_system_variables.optimizer_search_depth)->default_value(0)->notifier(&check_limits_osd),
1284
 
  N_("Maximum depth of search performed by the query optimizer. Values "
1285
 
     "larger than the number of relations in a query result in better query "
1286
 
     "plans, but take longer to compile a query. Smaller values than the "
1287
 
     "number of tables in a relation result in faster optimization, but may "
1288
 
     "produce very bad query plans. If set to 0, the system will "
1289
 
     "automatically pick a reasonable value; if set to MAX_TABLES+2, the "
1290
 
     "optimizer will switch to the original find_best (used for "
1291
 
     "testing/comparison)."))
1292
 
  ("preload-buffer-size", po::value<uint64_t>(&global_system_variables.preload_buff_size)->default_value(32*1024L)->notifier(&check_limits_pbs),
1293
 
  N_("The size of the buffer that is allocated when preloading indexes"))
1294
 
  ("query-alloc-block-size", 
1295
 
  po::value<uint32_t>(&global_system_variables.query_alloc_block_size)->default_value(QUERY_ALLOC_BLOCK_SIZE)->notifier(&check_limits_qabs),
1296
 
  N_("Allocation block size for query parsing and execution"))
1297
 
  ("query-prealloc-size",
1298
 
  po::value<uint32_t>(&global_system_variables.query_prealloc_size)->default_value(QUERY_ALLOC_PREALLOC_SIZE)->notifier(&check_limits_qps),
1299
 
  N_("Persistent buffer for query parsing and execution"))
1300
 
  ("range-alloc-block-size",
1301
 
  po::value<size_t>(&global_system_variables.range_alloc_block_size)->default_value(RANGE_ALLOC_BLOCK_SIZE)->notifier(&check_limits_rabs),
1302
 
  N_("Allocation block size for storing ranges during optimization"))
1303
 
  ("read-buffer-size",
1304
 
  po::value<uint32_t>(&global_system_variables.read_buff_size)->default_value(128*1024L)->notifier(&check_limits_read_buffer_size),
1305
 
  N_("Each thread that does a sequential scan allocates a buffer of this "
1306
 
      "size for each table it scans. If you do many sequential scans, you may "
1307
 
      "want to increase this value."))
1308
 
  ("read-buffer-threshold",
1309
 
  po::value<uint64_t>()->default_value(0),
1310
 
  N_("A global cap on the size of read-buffer-size (0 means unlimited)"))
1311
 
  ("read-rnd-buffer-size",
1312
 
  po::value<uint32_t>(&global_system_variables.read_rnd_buff_size)->default_value(256*1024L)->notifier(&check_limits_read_rnd_buffer_size),
1313
 
  N_("When reading rows in sorted order after a sort, the rows are read "
1314
 
     "through this buffer to avoid a disk seeks. If not set, then it's set "
1315
 
     "to the value of record_buffer."))
1316
 
  ("read-rnd-threshold",
1317
 
  po::value<uint64_t>()->default_value(0),
1318
 
  N_("A global cap on the size of read-rnd-buffer-size (0 means unlimited)"))
1319
 
  ("scheduler", po::value<string>(),
1320
 
  N_("Select scheduler to be used (by default multi-thread)."))
1321
 
  ("sort-buffer-size",
1322
 
  po::value<size_t>(&global_system_variables.sortbuff_size)->default_value(MAX_SORT_MEMORY)->notifier(&check_limits_sort_buffer_size),
1323
 
  N_("Each thread that needs to do a sort allocates a buffer of this size."))
1324
 
  ("sort-heap-threshold",
1325
 
  po::value<uint64_t>()->default_value(0),
1326
 
  N_("A global cap on the amount of memory that can be allocated by session sort buffers (0 means unlimited)"))
1327
 
  ("table-definition-cache", po::value<size_t>(&table_def_size)->default_value(128)->notifier(&check_limits_tdc),
1328
 
  N_("The number of cached table definitions."))
1329
 
  ("table-open-cache", po::value<uint64_t>(&table_cache_size)->default_value(TABLE_OPEN_CACHE_DEFAULT)->notifier(&check_limits_toc),
1330
 
  N_("The number of cached open tables."))
1331
 
  ("table-lock-wait-timeout", po::value<uint64_t>(&table_lock_wait_timeout)->default_value(50)->notifier(&check_limits_tlwt),
1332
 
  N_("Timeout in seconds to wait for a table level lock before returning an "
1333
 
     "error. Used only if the connection has active cursors."))
1334
 
  ("thread-stack", po::value<size_t>(&my_thread_stack_size)->default_value(DEFAULT_THREAD_STACK)->notifier(&check_limits_thread_stack),
1335
 
  N_("The stack size for each thread."))
1336
 
  ("tmp-table-size", 
1337
 
  po::value<uint64_t>(&global_system_variables.tmp_table_size)->default_value(16*1024*1024L)->notifier(&check_limits_tmp_table_size),
1338
 
  N_("If an internal in-memory temporary table exceeds this size, Drizzle will"
1339
 
     " automatically convert it to an on-disk MyISAM table."))
1340
 
  ;
1341
 
 
1342
 
  full_options.add(long_options);
1343
 
  full_options.add(plugin_load_options);
1344
 
 
1345
 
  initial_options.add(config_options);
1346
 
  initial_options.add(plugin_load_options);
1347
 
 
1348
 
  int style = po::command_line_style::default_style & ~po::command_line_style::allow_guessing;
1349
 
  /* Get options about where config files and the like are */
1350
 
  po::parsed_options parsed= po::command_line_parser(argc, argv).style(style).
1351
 
    options(initial_options).allow_unregistered().run();
1352
 
  unknown_options=
1353
 
    po::collect_unrecognized(parsed.options, po::include_positional);
1354
 
 
1355
 
  try
1356
 
  {
1357
 
    po::store(parsed, vm);
1358
 
  }
1359
 
  catch (std::exception&)
1360
 
  {
1361
 
    errmsg_printf(ERRMSG_LVL_ERROR, _("Duplicate entry for command line option\n"));
1362
 
    unireg_abort(1);
1363
 
  }
1364
 
 
1365
 
  if (not vm["no-defaults"].as<bool>())
1366
 
  {
1367
 
    fs::path system_config_file_drizzle(system_config_dir);
1368
 
    system_config_file_drizzle /= "drizzled.cnf";
1369
 
    defaults_file_list.insert(defaults_file_list.begin(),
1370
 
                              system_config_file_drizzle.file_string());
1371
 
 
1372
 
    fs::path config_conf_d_location(system_config_dir);
1373
 
    config_conf_d_location /= "conf.d";
1374
 
 
1375
 
 
1376
 
    CachedDirectory config_conf_d(config_conf_d_location.file_string());
1377
 
    if (not config_conf_d.fail())
 
2157
  strmake(pidfile_name, glob_hostname, sizeof(pidfile_name)-5);
 
2158
  strmov(fn_ext(pidfile_name),".pid");          // Add proper extension
 
2159
 
 
2160
  /*
 
2161
    Add server status variables to the dynamic list of
 
2162
    status variables that is shown by SHOW STATUS.
 
2163
    Later, in plugin_init, and mysql_install_plugin
 
2164
    new entries could be added to that list.
 
2165
  */
 
2166
  if (add_status_vars(status_vars))
 
2167
    return 1; // an error was already reported
 
2168
 
 
2169
#ifndef DBUG_OFF
 
2170
  /*
 
2171
    We have few debug-only commands in com_status_vars, only visible in debug
 
2172
    builds. for simplicity we enable the assert only in debug builds
 
2173
 
 
2174
    There are 7 Com_ variables which don't have corresponding SQLCOM_ values:
 
2175
    (TODO strictly speaking they shouldn't be here, should not have Com_ prefix
 
2176
    that is. Perhaps Stmt_ ? Comstmt_ ? Prepstmt_ ?)
 
2177
 
 
2178
      Com_admin_commands       => com_other
 
2179
      Com_stmt_close           => com_stmt_close
 
2180
      Com_stmt_execute         => com_stmt_execute
 
2181
      Com_stmt_fetch           => com_stmt_fetch
 
2182
      Com_stmt_prepare         => com_stmt_prepare
 
2183
      Com_stmt_reset           => com_stmt_reset
 
2184
      Com_stmt_send_long_data  => com_stmt_send_long_data
 
2185
 
 
2186
    With this correction the number of Com_ variables (number of elements in
 
2187
    the array, excluding the last element - terminator) must match the number
 
2188
    of SQLCOM_ constants.
 
2189
  */
 
2190
  compile_time_assert(sizeof(com_status_vars)/sizeof(com_status_vars[0]) - 1 ==
 
2191
                     SQLCOM_END + 7);
 
2192
#endif
 
2193
 
 
2194
  load_defaults(conf_file_name, groups, &argc, &argv);
 
2195
  defaults_argv=argv;
 
2196
  defaults_argc=argc;
 
2197
  get_options(&defaults_argc, defaults_argv);
 
2198
  set_server_version();
 
2199
 
 
2200
  DBUG_PRINT("info",("%s  Ver %s for %s on %s\n",my_progname,
 
2201
                     server_version, SYSTEM_TYPE,MACHINE_TYPE));
 
2202
 
 
2203
#ifdef HAVE_LARGE_PAGES
 
2204
  /* Initialize large page size */
 
2205
  if (opt_large_pages && (opt_large_page_size= my_get_large_page_size()))
 
2206
  {
 
2207
      my_use_large_pages= 1;
 
2208
      my_large_page_size= opt_large_page_size;
 
2209
  }
 
2210
#endif /* HAVE_LARGE_PAGES */
 
2211
 
 
2212
  /* connections and databases needs lots of files */
 
2213
  {
 
2214
    uint files, wanted_files, max_open_files;
 
2215
 
 
2216
    /* MyISAM requires two file handles per table. */
 
2217
    wanted_files= 10+max_connections+table_cache_size*2;
 
2218
    /*
 
2219
      We are trying to allocate no less than max_connections*5 file
 
2220
      handles (i.e. we are trying to set the limit so that they will
 
2221
      be available).  In addition, we allocate no less than how much
 
2222
      was already allocated.  However below we report a warning and
 
2223
      recompute values only if we got less file handles than were
 
2224
      explicitly requested.  No warning and re-computation occur if we
 
2225
      can't get max_connections*5 but still got no less than was
 
2226
      requested (value of wanted_files).
 
2227
    */
 
2228
    max_open_files= max(max(wanted_files, max_connections*5),
 
2229
                        open_files_limit);
 
2230
    files= my_set_max_open_files(max_open_files);
 
2231
 
 
2232
    if (files < wanted_files)
1378
2233
    {
1379
 
 
1380
 
      for (CachedDirectory::Entries::const_iterator iter= config_conf_d.getEntries().begin();
1381
 
           iter != config_conf_d.getEntries().end();
1382
 
           ++iter)
 
2234
      if (!open_files_limit)
1383
2235
      {
1384
 
        string file_entry((*iter)->filename);
1385
 
 
1386
 
        if (not file_entry.empty()
1387
 
            && file_entry != "."
1388
 
            && file_entry != "..")
1389
 
        {
1390
 
          fs::path the_entry(config_conf_d_location);
1391
 
          the_entry /= file_entry;
1392
 
          defaults_file_list.push_back(the_entry.file_string());
1393
 
        }
 
2236
        /*
 
2237
          If we have requested too much file handles than we bring
 
2238
          max_connections in supported bounds.
 
2239
        */
 
2240
        max_connections= (ulong) min(files-10-TABLE_OPEN_CACHE_MIN*2,
 
2241
                                     max_connections);
 
2242
        /*
 
2243
          Decrease table_cache_size according to max_connections, but
 
2244
          not below TABLE_OPEN_CACHE_MIN.  Outer min() ensures that we
 
2245
          never increase table_cache_size automatically (that could
 
2246
          happen if max_connections is decreased above).
 
2247
        */
 
2248
        table_cache_size= (ulong) min(max((files-10-max_connections)/2,
 
2249
                                          TABLE_OPEN_CACHE_MIN),
 
2250
                                      table_cache_size);
 
2251
        DBUG_PRINT("warning",
 
2252
                   ("Changed limits: max_open_files: %u  max_connections: %ld  table_cache: %ld",
 
2253
                    files, max_connections, table_cache_size));
 
2254
        if (global_system_variables.log_warnings)
 
2255
          sql_print_warning("Changed limits: max_open_files: %u  max_connections: %ld  table_cache: %ld",
 
2256
                        files, max_connections, table_cache_size);
1394
2257
      }
1395
 
    }
1396
 
  }
1397
 
 
1398
 
  /* TODO: here is where we should add a process_env_vars */
1399
 
 
1400
 
  /* We need a notify here so that plugin_init will work properly */
1401
 
  try
1402
 
  {
1403
 
    po::notify(vm);
1404
 
  }
1405
 
  catch (po::validation_error &err)
1406
 
  {
1407
 
    errmsg_printf(ERRMSG_LVL_ERROR,  
1408
 
                  _("%s: %s.\n"
1409
 
                    "Use --help to get a list of available options\n"),
1410
 
                  internal::my_progname, err.what());
1411
 
    unireg_abort(1);
1412
 
  }
1413
 
 
1414
 
  process_defaults_files();
1415
 
 
1416
 
  /* Process with notify a second time because a config file may contain
1417
 
     plugin loader options */
1418
 
 
1419
 
  try
1420
 
  {
1421
 
    po::notify(vm);
1422
 
  }
1423
 
  catch (po::validation_error &err)
1424
 
  {
1425
 
    errmsg_printf(ERRMSG_LVL_ERROR,
1426
 
                  _("%s: %s.\n"
1427
 
                    "Use --help to get a list of available options\n"),
1428
 
                  internal::my_progname, err.what());
1429
 
    unireg_abort(1);
1430
 
  }
1431
 
 
1432
 
  /* At this point, we've read all the options we need to read from files and
1433
 
     collected most of them into unknown options - now let's load everything
1434
 
  */
1435
 
 
1436
 
  if (plugin_init(plugins, plugin_options))
1437
 
  {
1438
 
    errmsg_printf(ERRMSG_LVL_ERROR, _("Failed to initialize plugins\n"));
1439
 
    unireg_abort(1);
1440
 
  }
1441
 
 
1442
 
  full_options.add(plugin_options);
1443
 
 
1444
 
  vector<string> final_unknown_options;
1445
 
  try
1446
 
  {
1447
 
    po::parsed_options final_parsed=
1448
 
      po::command_line_parser(unknown_options).style(style).
1449
 
      options(full_options).extra_parser(dpo::parse_size_arg).run();
1450
 
 
1451
 
    final_unknown_options=
1452
 
      po::collect_unrecognized(final_parsed.options, po::include_positional);
1453
 
 
1454
 
    po::store(final_parsed, vm);
1455
 
 
1456
 
  }
1457
 
  catch (po::validation_error &err)
1458
 
  {
1459
 
    errmsg_printf(ERRMSG_LVL_ERROR,
1460
 
                  _("%s: %s.\n"
1461
 
                    "Use --help to get a list of available options\n"),
1462
 
                  internal::my_progname, err.what());
1463
 
    unireg_abort(1);
1464
 
  }
1465
 
  catch (po::invalid_command_line_syntax &err)
1466
 
  {
1467
 
    errmsg_printf(ERRMSG_LVL_ERROR,
1468
 
                  _("%s: %s.\n"
1469
 
                    "Use --help to get a list of available options\n"),
1470
 
                  internal::my_progname, err.what());
1471
 
    unireg_abort(1);
1472
 
  }
1473
 
  catch (po::unknown_option &err)
1474
 
  {
1475
 
    errmsg_printf(ERRMSG_LVL_ERROR,
1476
 
                  _("%s\nUse --help to get a list of available options\n"),
1477
 
                  err.what());
1478
 
    unireg_abort(1);
1479
 
  }
1480
 
 
1481
 
  try
1482
 
  {
1483
 
    po::notify(vm);
1484
 
  }
1485
 
  catch (po::validation_error &err)
1486
 
  {
1487
 
    errmsg_printf(ERRMSG_LVL_ERROR,  
1488
 
                  _("%s: %s.\n"
1489
 
                    "Use --help to get a list of available options\n"),
1490
 
                  internal::my_progname, err.what());
1491
 
    unireg_abort(1);
1492
 
  }
1493
 
 
1494
 
  get_options();
1495
 
 
1496
 
  /* Inverted Booleans */
1497
 
 
1498
 
  global_system_variables.optimizer_prune_level=
1499
 
    vm.count("disable-optimizer-prune") ? false : true;
1500
 
 
1501
 
  if (vm.count("help") == 0 && vm.count("help-extended") == 0)
1502
 
  {
1503
 
    if ((user_info= check_user(drizzled_user)))
1504
 
    {
1505
 
      set_user(drizzled_user, user_info);
1506
 
    }
1507
 
  }
1508
 
 
1509
 
  fix_paths();
1510
 
 
1511
 
  current_pid= getpid();                /* Save for later ref */
1512
 
  init_time();                          /* Init time-functions (read zone) */
1513
 
 
 
2258
      else if (global_system_variables.log_warnings)
 
2259
        sql_print_warning("Could not increase number of max_open_files to more than %u (request: %u)", files, wanted_files);
 
2260
    }
 
2261
    open_files_limit= files;
 
2262
  }
 
2263
  unireg_init(opt_specialflag); /* Set up extern variabels */
 
2264
  if (init_errmessage())        /* Read error messages from file */
 
2265
    return 1;
 
2266
  init_client_errs();
 
2267
  lex_init();
1514
2268
  if (item_create_init())
1515
2269
    return 1;
1516
 
  if (sys_var_init())
1517
 
    return 1;
1518
 
  /* Creates static regex matching for temporal values */
1519
 
  if (! init_temporal_formats())
1520
 
    return 1;
1521
 
 
1522
 
  if (!(default_charset_info=
1523
 
        get_charset_by_csname(default_character_set_name, MY_CS_PRIMARY)))
 
2270
  item_init();
 
2271
  if (set_var_init())
 
2272
    return 1;
 
2273
  if (init_replication_sys_vars())
 
2274
    return 1;
 
2275
  mysys_uses_curses=0;
 
2276
  /*
 
2277
    Process a comma-separated character set list and choose
 
2278
    the first available character set. This is mostly for
 
2279
    test purposes, to be able to start "mysqld" even if
 
2280
    the requested character set is not available (see bug#18743).
 
2281
  */
 
2282
  for (;;)
1524
2283
  {
1525
 
    errmsg_printf(ERRMSG_LVL_ERROR, _("Error getting default charset"));
1526
 
    return 1;                           // Eof of the list
 
2284
    char *next_character_set_name= strchr(default_character_set_name, ',');
 
2285
    if (next_character_set_name)
 
2286
      *next_character_set_name++= '\0';
 
2287
    if (!(default_charset_info=
 
2288
          get_charset_by_csname(default_character_set_name,
 
2289
                                MY_CS_PRIMARY, MYF(MY_WME))))
 
2290
    {
 
2291
      if (next_character_set_name)
 
2292
      {
 
2293
        default_character_set_name= next_character_set_name;
 
2294
        default_collation_name= 0;          // Ignore collation
 
2295
      }
 
2296
      else
 
2297
        return 1;                           // Eof of the list
 
2298
    }
 
2299
    else
 
2300
      break;
1527
2301
  }
1528
2302
 
1529
 
  if (vm.count("scheduler"))
1530
 
    opt_scheduler= vm["scheduler"].as<string>().c_str();
1531
 
 
1532
2303
  if (default_collation_name)
1533
2304
  {
1534
 
    const CHARSET_INFO * const default_collation= get_charset_by_name(default_collation_name);
1535
 
    if (not default_collation)
 
2305
    CHARSET_INFO *default_collation;
 
2306
    default_collation= get_charset_by_name(default_collation_name, MYF(0));
 
2307
    if (!default_collation)
1536
2308
    {
1537
 
      errmsg_printf(ERRMSG_LVL_ERROR, _(ER(ER_UNKNOWN_COLLATION)), default_collation_name);
 
2309
      sql_print_error(ER(ER_UNKNOWN_COLLATION), default_collation_name);
1538
2310
      return 1;
1539
2311
    }
1540
 
    if (not my_charset_same(default_charset_info, default_collation))
 
2312
    if (!my_charset_same(default_charset_info, default_collation))
1541
2313
    {
1542
 
      errmsg_printf(ERRMSG_LVL_ERROR, _(ER(ER_COLLATION_CHARSET_MISMATCH)),
1543
 
                    default_collation_name,
1544
 
                    default_charset_info->csname);
 
2314
      sql_print_error(ER(ER_COLLATION_CHARSET_MISMATCH),
 
2315
                      default_collation_name,
 
2316
                      default_charset_info->csname);
1545
2317
      return 1;
1546
2318
    }
1547
2319
    default_charset_info= default_collation;
1548
2320
  }
1549
2321
  /* Set collactions that depends on the default collation */
1550
2322
  global_system_variables.collation_server=      default_charset_info;
1551
 
 
1552
 
  if (not (character_set_filesystem=
1553
 
           get_charset_by_csname(character_set_filesystem_name, MY_CS_PRIMARY)))
1554
 
  {
1555
 
    errmsg_printf(ERRMSG_LVL_ERROR, _("Error setting collation"));
 
2323
  global_system_variables.collation_database=    default_charset_info;
 
2324
  global_system_variables.collation_connection=  default_charset_info;
 
2325
  global_system_variables.character_set_results= default_charset_info;
 
2326
  global_system_variables.character_set_client= default_charset_info;
 
2327
 
 
2328
  global_system_variables.optimizer_use_mrr= 1;
 
2329
  global_system_variables.optimizer_switch= 0;
 
2330
 
 
2331
  if (!(character_set_filesystem= 
 
2332
        get_charset_by_csname(character_set_filesystem_name,
 
2333
                              MY_CS_PRIMARY, MYF(MY_WME))))
1556
2334
    return 1;
1557
 
  }
1558
2335
  global_system_variables.character_set_filesystem= character_set_filesystem;
1559
2336
 
1560
2337
  if (!(my_default_lc_time_names=
1561
2338
        my_locale_by_name(lc_time_names_name)))
1562
2339
  {
1563
 
    errmsg_printf(ERRMSG_LVL_ERROR, _("Unknown locale: '%s'"), lc_time_names_name);
 
2340
    sql_print_error("Unknown locale: '%s'", lc_time_names_name);
1564
2341
    return 1;
1565
2342
  }
1566
2343
  global_system_variables.lc_time_names= my_default_lc_time_names;
1567
 
 
1568
 
  /* Reset table_alias_charset */
1569
 
  table_alias_charset= files_charset_info;
1570
 
 
1571
 
  return 0;
1572
 
}
1573
 
 
1574
 
 
1575
 
int init_server_components(module::Registry &plugins)
1576
 
{
 
2344
  
 
2345
  sys_init_connect.value_length= 0;
 
2346
  if ((sys_init_connect.value= opt_init_connect))
 
2347
    sys_init_connect.value_length= strlen(opt_init_connect);
 
2348
  else
 
2349
    sys_init_connect.value=my_strdup("",MYF(0));
 
2350
 
 
2351
  sys_init_slave.value_length= 0;
 
2352
  if ((sys_init_slave.value= opt_init_slave))
 
2353
    sys_init_slave.value_length= strlen(opt_init_slave);
 
2354
  else
 
2355
    sys_init_slave.value=my_strdup("",MYF(0));
 
2356
 
 
2357
  /* check log options and issue warnings if needed */
 
2358
  if (opt_log && opt_logname && !(log_output_options & LOG_FILE) &&
 
2359
      !(log_output_options & LOG_NONE))
 
2360
    sql_print_warning("Although a path was specified for the "
 
2361
                      "--log option, log tables are used. "
 
2362
                      "To enable logging to files use the --log-output option.");
 
2363
 
 
2364
  if (opt_slow_log && opt_slow_logname && !(log_output_options & LOG_FILE)
 
2365
      && !(log_output_options & LOG_NONE))
 
2366
    sql_print_warning("Although a path was specified for the "
 
2367
                      "--log-slow-queries option, log tables are used. "
 
2368
                      "To enable logging to files use the --log-output=file option.");
 
2369
 
 
2370
  s= opt_logname ? opt_logname : make_default_log_name(buff, ".log");
 
2371
  sys_var_general_log_path.value= my_strdup(s, MYF(0));
 
2372
  sys_var_general_log_path.value_length= strlen(s);
 
2373
 
 
2374
  s= opt_slow_logname ? opt_slow_logname : make_default_log_name(buff, "-slow.log");
 
2375
  sys_var_slow_log_path.value= my_strdup(s, MYF(0));
 
2376
  sys_var_slow_log_path.value_length= strlen(s);
 
2377
 
 
2378
  if (use_temp_pool && bitmap_init(&temp_pool,0,1024,1))
 
2379
    return 1;
 
2380
  if (my_database_names_init())
 
2381
    return 1;
 
2382
 
 
2383
  /*
 
2384
    Ensure that lower_case_table_names is set on system where we have case
 
2385
    insensitive names.  If this is not done the users MyISAM tables will
 
2386
    get corrupted if accesses with names of different case.
 
2387
  */
 
2388
  DBUG_PRINT("info", ("lower_case_table_names: %d", lower_case_table_names));
 
2389
  lower_case_file_system= test_if_case_insensitive(mysql_real_data_home);
 
2390
  if (!lower_case_table_names && lower_case_file_system == 1)
 
2391
  {
 
2392
    if (lower_case_table_names_used)
 
2393
    {
 
2394
      if (global_system_variables.log_warnings)
 
2395
        sql_print_warning("\
 
2396
You have forced lower_case_table_names to 0 through a command-line \
 
2397
option, even though your file system '%s' is case insensitive.  This means \
 
2398
that you can corrupt a MyISAM table by accessing it with different cases. \
 
2399
You should consider changing lower_case_table_names to 1 or 2",
 
2400
                        mysql_real_data_home);
 
2401
    }
 
2402
    else
 
2403
    {
 
2404
      if (global_system_variables.log_warnings)
 
2405
        sql_print_warning("Setting lower_case_table_names=2 because file system for %s is case insensitive", mysql_real_data_home);
 
2406
      lower_case_table_names= 2;
 
2407
    }
 
2408
  }
 
2409
  else if (lower_case_table_names == 2 &&
 
2410
           !(lower_case_file_system=
 
2411
             (test_if_case_insensitive(mysql_real_data_home) == 1)))
 
2412
  {
 
2413
    if (global_system_variables.log_warnings)
 
2414
      sql_print_warning("lower_case_table_names was set to 2, even though your "
 
2415
                        "the file system '%s' is case sensitive.  Now setting "
 
2416
                        "lower_case_table_names to 0 to avoid future problems.",
 
2417
                        mysql_real_data_home);
 
2418
    lower_case_table_names= 0;
 
2419
  }
 
2420
  else
 
2421
  {
 
2422
    lower_case_file_system=
 
2423
      (test_if_case_insensitive(mysql_real_data_home) == 1);
 
2424
  }
 
2425
 
 
2426
  /* Reset table_alias_charset, now that lower_case_table_names is set. */
 
2427
  table_alias_charset= (lower_case_table_names ?
 
2428
                        files_charset_info :
 
2429
                        &my_charset_bin);
 
2430
 
 
2431
  return 0;
 
2432
}
 
2433
 
 
2434
 
 
2435
static int init_thread_environment()
 
2436
{
 
2437
  (void) pthread_mutex_init(&LOCK_mysql_create_db,MY_MUTEX_INIT_SLOW);
 
2438
  (void) pthread_mutex_init(&LOCK_lock_db,MY_MUTEX_INIT_SLOW);
 
2439
  (void) pthread_mutex_init(&LOCK_open, NULL);
 
2440
  (void) pthread_mutex_init(&LOCK_thread_count,MY_MUTEX_INIT_FAST);
 
2441
  (void) pthread_mutex_init(&LOCK_mapped_file,MY_MUTEX_INIT_SLOW);
 
2442
  (void) pthread_mutex_init(&LOCK_status,MY_MUTEX_INIT_FAST);
 
2443
  (void) pthread_mutex_init(&LOCK_error_log,MY_MUTEX_INIT_FAST);
 
2444
  (void) pthread_mutex_init(&LOCK_manager,MY_MUTEX_INIT_FAST);
 
2445
  (void) pthread_mutex_init(&LOCK_crypt,MY_MUTEX_INIT_FAST);
 
2446
  (void) pthread_mutex_init(&LOCK_user_conn, MY_MUTEX_INIT_FAST);
 
2447
  (void) pthread_mutex_init(&LOCK_active_mi, MY_MUTEX_INIT_FAST);
 
2448
  (void) pthread_mutex_init(&LOCK_global_system_variables, MY_MUTEX_INIT_FAST);
 
2449
  (void) my_rwlock_init(&LOCK_system_variables_hash, NULL);
 
2450
  (void) pthread_mutex_init(&LOCK_global_read_lock, MY_MUTEX_INIT_FAST);
 
2451
  (void) pthread_mutex_init(&LOCK_uuid_generator, MY_MUTEX_INIT_FAST);
 
2452
  (void) pthread_mutex_init(&LOCK_connection_count, MY_MUTEX_INIT_FAST);
 
2453
  (void) my_rwlock_init(&LOCK_sys_init_connect, NULL);
 
2454
  (void) my_rwlock_init(&LOCK_sys_init_slave, NULL);
 
2455
  (void) pthread_cond_init(&COND_thread_count,NULL);
 
2456
  (void) pthread_cond_init(&COND_refresh,NULL);
 
2457
  (void) pthread_cond_init(&COND_global_read_lock,NULL);
 
2458
  (void) pthread_cond_init(&COND_thread_cache,NULL);
 
2459
  (void) pthread_cond_init(&COND_flush_thread_cache,NULL);
 
2460
  (void) pthread_cond_init(&COND_manager,NULL);
 
2461
  (void) pthread_mutex_init(&LOCK_rpl_status, MY_MUTEX_INIT_FAST);
 
2462
  (void) pthread_cond_init(&COND_rpl_status, NULL);
 
2463
 
 
2464
  /* Parameter for threads created for connections */
 
2465
  (void) pthread_attr_init(&connection_attrib);
 
2466
  (void) pthread_attr_setdetachstate(&connection_attrib,
 
2467
                                     PTHREAD_CREATE_DETACHED);
 
2468
  pthread_attr_setscope(&connection_attrib, PTHREAD_SCOPE_SYSTEM);
 
2469
  if (!(opt_specialflag & SPECIAL_NO_PRIOR))
 
2470
  {
 
2471
    struct sched_param tmp_sched_param;
 
2472
 
 
2473
    memset(&tmp_sched_param, 0, sizeof(tmp_sched_param));
 
2474
    tmp_sched_param.sched_priority= WAIT_PRIOR;
 
2475
    (void)pthread_attr_setschedparam(&connection_attrib, &tmp_sched_param);
 
2476
  }
 
2477
 
 
2478
  if (pthread_key_create(&THR_THD,NULL) ||
 
2479
      pthread_key_create(&THR_MALLOC,NULL))
 
2480
  {
 
2481
    sql_print_error("Can't create thread-keys");
 
2482
    return 1;
 
2483
  }
 
2484
  return 0;
 
2485
}
 
2486
 
 
2487
 
 
2488
static int init_server_components()
 
2489
{
 
2490
  DBUG_ENTER("init_server_components");
1577
2491
  /*
1578
2492
    We need to call each of these following functions to ensure that
1579
2493
    all things are initialized so that unireg_abort() doesn't fail
1580
2494
  */
1581
 
  if (table_cache_init())
1582
 
  {
1583
 
    errmsg_printf(ERRMSG_LVL_ERROR, _("Could not initialize table cache\n"));
 
2495
  if (table_cache_init() | table_def_init())
1584
2496
    unireg_abort(1);
1585
 
  }
1586
 
 
1587
 
  // Resize the definition Cache at startup
1588
 
  table::Cache::singleton().rehash(table_def_size);
1589
 
  definition::Cache::singleton().rehash(table_def_size);
1590
 
  message::Cache::singleton().rehash(table_def_size);
1591
 
 
 
2497
 
 
2498
  randominit(&sql_rand,(ulong) server_start_time,(ulong) server_start_time/2);
1592
2499
  setup_fpu();
 
2500
  init_thr_lock();
 
2501
  init_slave_list();
1593
2502
 
1594
2503
  /* Setup logs */
1595
2504
 
 
2505
  /*
 
2506
    Enable old-fashioned error log, except when the user has requested
 
2507
    help information. Since the implementation of plugin server
 
2508
    variables the help output is now written much later.
 
2509
  */
 
2510
  if (opt_error_log && !opt_help)
 
2511
  {
 
2512
    if (!log_error_file_ptr[0])
 
2513
      fn_format(log_error_file, pidfile_name, mysql_data_home, ".err",
 
2514
                MY_REPLACE_EXT); /* replace '.<domain>' by '.err', bug#4997 */
 
2515
    else
 
2516
      fn_format(log_error_file, log_error_file_ptr, mysql_data_home, ".err",
 
2517
                MY_UNPACK_FILENAME | MY_SAFE_PATH);
 
2518
    if (!log_error_file[0])
 
2519
      opt_error_log= 1;                         // Too long file name
 
2520
    else
 
2521
    {
 
2522
      if (freopen(log_error_file, "a+", stdout))
 
2523
        freopen(log_error_file, "a+", stderr);
 
2524
    }
 
2525
  }
 
2526
 
1596
2527
  if (xid_cache_init())
1597
2528
  {
1598
 
    errmsg_printf(ERRMSG_LVL_ERROR, _("XA cache initialization failed: Out of memory\n"));
1599
 
    unireg_abort(1);
1600
 
  }
 
2529
    sql_print_error("Out of memory");
 
2530
    unireg_abort(1);
 
2531
  }
 
2532
 
 
2533
  /* need to configure logging before initializing storage engines */
 
2534
  if (opt_update_log)
 
2535
  {
 
2536
    /*
 
2537
      Update log is removed since 5.0. But we still accept the option.
 
2538
      The idea is if the user already uses the binlog and the update log,
 
2539
      we completely ignore any option/variable related to the update log, like
 
2540
      if the update log did not exist. But if the user uses only the update
 
2541
      log, then we translate everything into binlog for him (with warnings).
 
2542
      Implementation of the above :
 
2543
      - If mysqld is started with --log-update and --log-bin,
 
2544
      ignore --log-update (print a warning), push a warning when SQL_LOG_UPDATE
 
2545
      is used, and turn off --sql-bin-update-same.
 
2546
      This will completely ignore SQL_LOG_UPDATE
 
2547
      - If mysqld is started with --log-update only,
 
2548
      change it to --log-bin (with the filename passed to log-update,
 
2549
      plus '-bin') (print a warning), push a warning when SQL_LOG_UPDATE is
 
2550
      used, and turn on --sql-bin-update-same.
 
2551
      This will translate SQL_LOG_UPDATE to SQL_LOG_BIN.
 
2552
 
 
2553
      Note that we tell the user that --sql-bin-update-same is deprecated and
 
2554
      does nothing, and we don't take into account if he used this option or
 
2555
      not; but internally we give this variable a value to have the behaviour
 
2556
      we want (i.e. have SQL_LOG_UPDATE influence SQL_LOG_BIN or not).
 
2557
      As sql-bin-update-same, log-update and log-bin cannot be changed by the
 
2558
      user after starting the server (they are not variables), the user will
 
2559
      not later interfere with the settings we do here.
 
2560
    */
 
2561
    if (opt_bin_log)
 
2562
    {
 
2563
      opt_sql_bin_update= 0;
 
2564
      sql_print_error("The update log is no longer supported by MySQL in \
 
2565
version 5.0 and above. It is replaced by the binary log.");
 
2566
    }
 
2567
    else
 
2568
    {
 
2569
      opt_sql_bin_update= 1;
 
2570
      opt_bin_log= 1;
 
2571
      if (opt_update_logname)
 
2572
      {
 
2573
        /* as opt_bin_log==0, no need to free opt_bin_logname */
 
2574
        if (!(opt_bin_logname= my_strdup(opt_update_logname, MYF(MY_WME))))
 
2575
          exit(EXIT_OUT_OF_MEMORY);
 
2576
        sql_print_error("The update log is no longer supported by MySQL in \
 
2577
version 5.0 and above. It is replaced by the binary log. Now starting MySQL \
 
2578
with --log-bin='%s' instead.",opt_bin_logname);
 
2579
      }
 
2580
      else
 
2581
        sql_print_error("The update log is no longer supported by MySQL in \
 
2582
version 5.0 and above. It is replaced by the binary log. Now starting MySQL \
 
2583
with --log-bin instead.");
 
2584
    }
 
2585
  }
 
2586
  if (opt_log_slave_updates && !opt_bin_log)
 
2587
  {
 
2588
    sql_print_error("You need to use --log-bin to make "
 
2589
                    "--log-slave-updates work.");
 
2590
    unireg_abort(1);
 
2591
  }
 
2592
  if (!opt_bin_log)
 
2593
    if (opt_binlog_format_id != BINLOG_FORMAT_UNSPEC)
 
2594
  {
 
2595
    sql_print_error("You need to use --log-bin to make "
 
2596
                    "--binlog-format work.");
 
2597
    unireg_abort(1);
 
2598
  }
 
2599
    else
 
2600
  {
 
2601
      global_system_variables.binlog_format= BINLOG_FORMAT_MIXED;
 
2602
    }
 
2603
  else
 
2604
    if (opt_binlog_format_id == BINLOG_FORMAT_UNSPEC)
 
2605
      global_system_variables.binlog_format= BINLOG_FORMAT_MIXED;
 
2606
    else
 
2607
    { 
 
2608
      DBUG_ASSERT(global_system_variables.binlog_format != BINLOG_FORMAT_UNSPEC);
 
2609
  }
 
2610
 
 
2611
  /* Check that we have not let the format to unspecified at this point */
 
2612
  DBUG_ASSERT((uint)global_system_variables.binlog_format <=
 
2613
              array_elements(binlog_format_names)-1);
 
2614
 
 
2615
  if (opt_log_slave_updates && replicate_same_server_id)
 
2616
  {
 
2617
    sql_print_error("\
 
2618
using --replicate-same-server-id in conjunction with \
 
2619
--log-slave-updates is impossible, it would lead to infinite loops in this \
 
2620
server.");
 
2621
    unireg_abort(1);
 
2622
  }
 
2623
 
 
2624
  if (opt_bin_log)
 
2625
  {
 
2626
    char buf[FN_REFLEN];
 
2627
    const char *ln;
 
2628
    ln= mysql_bin_log.generate_name(opt_bin_logname, "-bin", 1, buf);
 
2629
    if (!opt_bin_logname && !opt_binlog_index_name)
 
2630
    {
 
2631
      /*
 
2632
        User didn't give us info to name the binlog index file.
 
2633
        Picking `hostname`-bin.index like did in 4.x, causes replication to
 
2634
        fail if the hostname is changed later. So, we would like to instead
 
2635
        require a name. But as we don't want to break many existing setups, we
 
2636
        only give warning, not error.
 
2637
      */
 
2638
      sql_print_warning("No argument was provided to --log-bin, and "
 
2639
                        "--log-bin-index was not used; so replication "
 
2640
                        "may break when this MySQL server acts as a "
 
2641
                        "master and has his hostname changed!! Please "
 
2642
                        "use '--log-bin=%s' to avoid this problem.", ln);
 
2643
    }
 
2644
    if (ln == buf)
 
2645
    {
 
2646
      my_free(opt_bin_logname, MYF(MY_ALLOW_ZERO_PTR));
 
2647
      opt_bin_logname=my_strdup(buf, MYF(0));
 
2648
    }
 
2649
    if (mysql_bin_log.open_index_file(opt_binlog_index_name, ln))
 
2650
    {
 
2651
      unireg_abort(1);
 
2652
    }
 
2653
 
 
2654
    /*
 
2655
      Used to specify which type of lock we need to use for queries of type
 
2656
      INSERT ... SELECT. This will change when we have row level logging.
 
2657
    */
 
2658
    using_update_log=1;
 
2659
  }
 
2660
 
 
2661
  /* call ha_init_key_cache() on all key caches to init them */
 
2662
  process_key_caches(&ha_init_key_cache);
1601
2663
 
1602
2664
  /* Allow storage engine to give real error messages */
1603
 
  ha_init_errors();
 
2665
  if (ha_init_errors())
 
2666
    DBUG_RETURN(1);
1604
2667
 
 
2668
  if (plugin_init(&defaults_argc, defaults_argv,
 
2669
                  (opt_noacl ? PLUGIN_INIT_SKIP_PLUGIN_TABLE : 0) |
 
2670
                  (opt_help ? PLUGIN_INIT_SKIP_INITIALIZATION : 0)))
 
2671
  {
 
2672
    sql_print_error("Failed to initialize plugins.");
 
2673
    unireg_abort(1);
 
2674
  }
1605
2675
 
1606
2676
  if (opt_help)
1607
2677
    unireg_abort(0);
1608
2678
 
1609
 
  if (plugin_finalize(plugins))
1610
 
  {
1611
 
    unireg_abort(1);
1612
 
  }
1613
 
 
1614
 
  string scheduler_name;
1615
 
  if (opt_scheduler)
1616
 
  {
1617
 
    scheduler_name= opt_scheduler;
1618
 
  }
1619
 
  else
1620
 
  {
1621
 
    scheduler_name= opt_scheduler_default;
1622
 
    opt_scheduler= opt_scheduler_default; 
1623
 
  }
1624
 
 
1625
 
  if (plugin::Scheduler::setPlugin(scheduler_name))
1626
 
  {
1627
 
      errmsg_printf(ERRMSG_LVL_ERROR,
1628
 
                   _("No scheduler found, cannot continue!\n"));
 
2679
  /* we do want to exit if there are any other unknown options */
 
2680
  if (defaults_argc > 1)
 
2681
  {
 
2682
    int ho_error;
 
2683
    char **tmp_argv= defaults_argv;
 
2684
    struct my_option no_opts[]=
 
2685
    {
 
2686
      {0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}
 
2687
    };
 
2688
    /*
 
2689
      We need to eat any 'loose' arguments first before we conclude
 
2690
      that there are unprocessed options.
 
2691
      But we need to preserve defaults_argv pointer intact for
 
2692
      free_defaults() to work. Thus we use a copy here.
 
2693
    */
 
2694
    my_getopt_skip_unknown= 0;
 
2695
 
 
2696
    if ((ho_error= handle_options(&defaults_argc, &tmp_argv, no_opts,
 
2697
                                  mysqld_get_one_option)))
 
2698
      unireg_abort(ho_error);
 
2699
 
 
2700
    if (defaults_argc)
 
2701
    {
 
2702
      fprintf(stderr, "%s: Too many arguments (first extra is '%s').\n"
 
2703
              "Use --verbose --help to get a list of available options\n",
 
2704
              my_progname, *tmp_argv);
1629
2705
      unireg_abort(1);
1630
 
  }
1631
 
 
1632
 
  /*
1633
 
    This is entirely for legacy. We will create a new "disk based" engine and a
1634
 
    "memory" engine which will be configurable longterm.
1635
 
  */
1636
 
  const std::string myisam_engine_name("MyISAM");
1637
 
  const std::string heap_engine_name("MEMORY");
1638
 
  myisam_engine= plugin::StorageEngine::findByName(myisam_engine_name);
1639
 
  heap_engine= plugin::StorageEngine::findByName(heap_engine_name);
 
2706
    }
 
2707
  }
 
2708
 
 
2709
  /* if the errmsg.sys is not loaded, terminate to maintain behaviour */
 
2710
  if (!errmesg[0][0])
 
2711
    unireg_abort(1);
 
2712
 
 
2713
  /* We have to initialize the storage engines before CSV logging */
 
2714
  if (ha_init())
 
2715
  {
 
2716
    sql_print_error("Can't init databases");
 
2717
    unireg_abort(1);
 
2718
  }
 
2719
 
 
2720
  logger.set_handlers(LOG_FILE, opt_slow_log ? LOG_FILE:LOG_NONE,
 
2721
                      opt_log ? LOG_FILE:LOG_NONE);
1640
2722
 
1641
2723
  /*
1642
2724
    Check that the default storage engine is actually available.
1643
2725
  */
1644
2726
  if (default_storage_engine_str)
1645
2727
  {
1646
 
    const std::string name(default_storage_engine_str);
1647
 
    plugin::StorageEngine *engine;
1648
 
 
1649
 
    engine= plugin::StorageEngine::findByName(name);
1650
 
    if (engine == NULL)
1651
 
    {
1652
 
      errmsg_printf(ERRMSG_LVL_ERROR, _("Unknown/unsupported storage engine: %s\n"),
1653
 
                    default_storage_engine_str);
1654
 
      unireg_abort(1);
1655
 
    }
1656
 
    global_system_variables.storage_engine= engine;
1657
 
  }
1658
 
 
1659
 
  if (plugin::XaResourceManager::recoverAllXids())
1660
 
  {
1661
 
    /* This function alredy generates error messages */
1662
 
    unireg_abort(1);
1663
 
  }
 
2728
    LEX_STRING name= { default_storage_engine_str,
 
2729
                       strlen(default_storage_engine_str) };
 
2730
    plugin_ref plugin;
 
2731
    handlerton *hton;
 
2732
    
 
2733
    if ((plugin= ha_resolve_by_name(0, &name)))
 
2734
      hton= plugin_data(plugin, handlerton*);
 
2735
    else
 
2736
    {
 
2737
      sql_print_error("Unknown/unsupported table type: %s",
 
2738
                      default_storage_engine_str);
 
2739
      unireg_abort(1);
 
2740
    }
 
2741
    if (!ha_storage_engine_is_enabled(hton))
 
2742
    {
 
2743
      if (!opt_bootstrap)
 
2744
      {
 
2745
        sql_print_error("Default storage engine (%s) is not available",
 
2746
                        default_storage_engine_str);
 
2747
        unireg_abort(1);
 
2748
      }
 
2749
      DBUG_ASSERT(global_system_variables.table_plugin);
 
2750
    }
 
2751
    else
 
2752
    {
 
2753
      /*
 
2754
        Need to unlock as global_system_variables.table_plugin 
 
2755
        was acquired during plugin_init()
 
2756
      */
 
2757
      plugin_unlock(0, global_system_variables.table_plugin);
 
2758
      global_system_variables.table_plugin= plugin;
 
2759
    }
 
2760
  }
 
2761
 
 
2762
  tc_log= (total_ha_2pc > 1 ? (opt_bin_log  ?
 
2763
                               (TC_LOG *) &mysql_bin_log :
 
2764
                               (TC_LOG *) &tc_log_mmap) :
 
2765
           (TC_LOG *) &tc_log_dummy);
 
2766
 
 
2767
  if (tc_log->open(opt_bin_log ? opt_bin_logname : opt_tc_log_file))
 
2768
  {
 
2769
    sql_print_error("Can't init tc log");
 
2770
    unireg_abort(1);
 
2771
  }
 
2772
 
 
2773
  if (ha_recover(0))
 
2774
  {
 
2775
    unireg_abort(1);
 
2776
  }
 
2777
 
 
2778
  if (opt_bin_log && mysql_bin_log.open(opt_bin_logname, LOG_BIN, 0,
 
2779
                                        WRITE_CACHE, 0, max_binlog_size, 0))
 
2780
    unireg_abort(1);
 
2781
 
 
2782
  if (opt_bin_log && expire_logs_days)
 
2783
  {
 
2784
    time_t purge_time= server_start_time - expire_logs_days*24*60*60;
 
2785
    if (purge_time >= 0)
 
2786
      mysql_bin_log.purge_logs_before_date(purge_time);
 
2787
  }
 
2788
 
 
2789
  if (opt_myisam_log)
 
2790
    (void) mi_log(1);
 
2791
 
 
2792
#if defined(HAVE_MLOCKALL) && defined(MCL_CURRENT)
 
2793
  if (locked_in_memory && !getuid())
 
2794
  {
 
2795
    if (setreuid((uid_t)-1, 0) == -1)
 
2796
    {                        // this should never happen
 
2797
      sql_perror("setreuid");
 
2798
      unireg_abort(1);
 
2799
    }
 
2800
    if (mlockall(MCL_CURRENT))
 
2801
    {
 
2802
      if (global_system_variables.log_warnings)
 
2803
        sql_print_warning("Failed to lock memory. Errno: %d\n",errno);
 
2804
      locked_in_memory= 0;
 
2805
    }
 
2806
    if (user_info)
 
2807
      set_user(mysqld_user, user_info);
 
2808
  }
 
2809
  else
 
2810
#endif
 
2811
    locked_in_memory=0;
 
2812
 
 
2813
  ft_init_stopwords();
1664
2814
 
1665
2815
  init_update_queries();
1666
 
 
1667
 
  return(0);
 
2816
  DBUG_RETURN(0);
 
2817
}
 
2818
 
 
2819
 
 
2820
static void create_maintenance_thread()
 
2821
{
 
2822
  if (flush_time && flush_time != ~(ulong) 0L)
 
2823
  {
 
2824
    pthread_t hThread;
 
2825
    if (pthread_create(&hThread,&connection_attrib,handle_manager,0))
 
2826
      sql_print_warning("Can't create thread to manage maintenance");
 
2827
  }
 
2828
}
 
2829
 
 
2830
 
 
2831
int main(int argc, char **argv)
 
2832
{
 
2833
  MY_INIT(argv[0]);             // init my_sys library & pthreads
 
2834
  /* nothing should come before this line ^^^ */
 
2835
 
 
2836
  /* Set signal used to kill MySQL */
 
2837
#if defined(SIGUSR2)
 
2838
  thr_kill_signal= thd_lib_detected == THD_LIB_LT ? SIGINT : SIGUSR2;
 
2839
#else
 
2840
  thr_kill_signal= SIGINT;
 
2841
#endif
 
2842
 
 
2843
  /*
 
2844
    Perform basic logger initialization logger. Should be called after
 
2845
    MY_INIT, as it initializes mutexes. Log tables are inited later.
 
2846
  */
 
2847
  logger.init_base();
 
2848
 
 
2849
#ifdef _CUSTOMSTARTUPCONFIG_
 
2850
  if (_cust_check_startup())
 
2851
  {
 
2852
    / * _cust_check_startup will report startup failure error * /
 
2853
    exit(1);
 
2854
  }
 
2855
#endif
 
2856
 
 
2857
  if (init_common_variables(MYSQL_CONFIG_NAME,
 
2858
                            argc, argv, load_default_groups))
 
2859
    unireg_abort(1);                            // Will do exit
 
2860
 
 
2861
  init_signals();
 
2862
  if (!(opt_specialflag & SPECIAL_NO_PRIOR))
 
2863
  {
 
2864
    struct sched_param tmp_sched_param;
 
2865
 
 
2866
    memset(&tmp_sched_param, 0, sizeof(tmp_sched_param));
 
2867
    tmp_sched_param.sched_priority= my_thread_stack_size*2;
 
2868
    (void)pthread_setschedparam(pthread_self(), SCHED_OTHER, &tmp_sched_param);
 
2869
  }
 
2870
  pthread_attr_setstacksize(&connection_attrib,my_thread_stack_size);
 
2871
#ifdef HAVE_PTHREAD_ATTR_GETSTACKSIZE
 
2872
  {
 
2873
    /* Retrieve used stack size;  Needed for checking stack overflows */
 
2874
    size_t stack_size= 0;
 
2875
    pthread_attr_getstacksize(&connection_attrib, &stack_size);
 
2876
    /* We must check if stack_size = 0 as Solaris 2.9 can return 0 here */
 
2877
    if (stack_size && stack_size < my_thread_stack_size)
 
2878
    {
 
2879
      if (global_system_variables.log_warnings)
 
2880
        sql_print_warning("Asked for %lu thread stack, but got %ld",
 
2881
                          my_thread_stack_size, (long) stack_size);
 
2882
      my_thread_stack_size= stack_size;
 
2883
    }
 
2884
  }
 
2885
#endif
 
2886
 
 
2887
  select_thread=pthread_self();
 
2888
  select_thread_in_use=1;
 
2889
 
 
2890
  /*
 
2891
    We have enough space for fiddling with the argv, continue
 
2892
  */
 
2893
  check_data_home(mysql_real_data_home);
 
2894
  if (my_setwd(mysql_real_data_home,MYF(MY_WME)) && !opt_help)
 
2895
    unireg_abort(1);                            /* purecov: inspected */
 
2896
  mysql_data_home= mysql_data_home_buff;
 
2897
  mysql_data_home[0]=FN_CURLIB;         // all paths are relative from here
 
2898
  mysql_data_home[1]=0;
 
2899
  mysql_data_home_len= 2;
 
2900
 
 
2901
  if ((user_info= check_user(mysqld_user)))
 
2902
  {
 
2903
#if defined(HAVE_MLOCKALL) && defined(MCL_CURRENT)
 
2904
    if (locked_in_memory) // getuid() == 0 here
 
2905
      set_effective_user(user_info);
 
2906
    else
 
2907
#endif
 
2908
      set_user(mysqld_user, user_info);
 
2909
  }
 
2910
 
 
2911
  if (opt_bin_log && !server_id)
 
2912
  {
 
2913
    server_id= 1;
 
2914
#ifdef EXTRA_DEBUG
 
2915
    sql_print_warning("You have enabled the binary log, but you haven't set "
 
2916
                      "server-id to a non-zero value: we force server id to 1; "
 
2917
                      "updates will be logged to the binary log, but "
 
2918
                      "connections from slaves will not be accepted.");
 
2919
#endif
 
2920
  }
 
2921
 
 
2922
  if (init_server_components())
 
2923
    unireg_abort(1);
 
2924
 
 
2925
  network_init();
 
2926
 
 
2927
  /*
 
2928
   Initialize my_str_malloc() and my_str_free()
 
2929
  */
 
2930
  my_str_malloc= &my_str_malloc_mysqld;
 
2931
  my_str_free= &my_str_free_mysqld;
 
2932
 
 
2933
  /*
 
2934
    init signals & alarm
 
2935
    After this we can't quit by a simple unireg_abort
 
2936
  */
 
2937
  error_handler_hook= my_message_sql;
 
2938
  start_signal_handler();                               // Creates pidfile
 
2939
 
 
2940
  if (mysql_rm_tmp_tables() || my_tz_init((THD *)0, default_tz_name, opt_bootstrap))
 
2941
  {
 
2942
    abort_loop=1;
 
2943
    select_thread_in_use=0;
 
2944
    (void) pthread_kill(signal_thread, MYSQL_KILL_SIGNAL);
 
2945
 
 
2946
    if (!opt_bootstrap)
 
2947
      (void) my_delete(pidfile_name,MYF(MY_WME));       // Not needed anymore
 
2948
 
 
2949
    exit(1);
 
2950
  }
 
2951
 
 
2952
  udf_init();
 
2953
 
 
2954
  init_status_vars();
 
2955
  if (opt_bootstrap) /* If running with bootstrap, do not start replication. */
 
2956
    opt_skip_slave_start= 1;
 
2957
  /*
 
2958
    init_slave() must be called after the thread keys are created.
 
2959
    Some parts of the code (e.g. SHOW STATUS LIKE 'slave_running' and other
 
2960
    places) assume that active_mi != 0, so let's fail if it's 0 (out of
 
2961
    memory); a message has already been printed.
 
2962
  */
 
2963
  if (init_slave() && !active_mi)
 
2964
  {
 
2965
    unireg_abort(1);
 
2966
  }
 
2967
 
 
2968
  if (opt_bootstrap)
 
2969
  {
 
2970
    select_thread_in_use= 0;                    // Allow 'kill' to work
 
2971
    bootstrap(stdin);
 
2972
    unireg_abort(bootstrap_error ? 1 : 0);
 
2973
  }
 
2974
  if (opt_init_file)
 
2975
  {
 
2976
    if (read_init_file(opt_init_file))
 
2977
      unireg_abort(1);
 
2978
  }
 
2979
 
 
2980
  create_maintenance_thread();
 
2981
 
 
2982
  sql_print_information(ER(ER_STARTUP),my_progname,server_version,
 
2983
                        "", mysqld_port, MYSQL_COMPILATION_COMMENT);
 
2984
 
 
2985
 
 
2986
  handle_connections_sockets();
 
2987
 
 
2988
  /* (void) pthread_attr_destroy(&connection_attrib); */
 
2989
  
 
2990
  DBUG_PRINT("quit",("Exiting main thread"));
 
2991
 
 
2992
#ifdef EXTRA_DEBUG2
 
2993
  sql_print_error("Before Lock_thread_count");
 
2994
#endif
 
2995
  (void) pthread_mutex_lock(&LOCK_thread_count);
 
2996
  DBUG_PRINT("quit", ("Got thread_count mutex"));
 
2997
  select_thread_in_use=0;                       // For close_connections
 
2998
  (void) pthread_mutex_unlock(&LOCK_thread_count);
 
2999
  (void) pthread_cond_broadcast(&COND_thread_count);
 
3000
#ifdef EXTRA_DEBUG2
 
3001
  sql_print_error("After lock_thread_count");
 
3002
#endif
 
3003
 
 
3004
  /* Wait until cleanup is done */
 
3005
  (void) pthread_mutex_lock(&LOCK_thread_count);
 
3006
  while (!ready_to_exit)
 
3007
    pthread_cond_wait(&COND_thread_count,&LOCK_thread_count);
 
3008
  (void) pthread_mutex_unlock(&LOCK_thread_count);
 
3009
 
 
3010
  clean_up(1);
 
3011
  mysqld_exit(0);
 
3012
}
 
3013
 
 
3014
 
 
3015
/**
 
3016
  Execute all commands from a file. Used by the mysql_install_db script to
 
3017
  create MySQL privilege tables without having to start a full MySQL server.
 
3018
*/
 
3019
 
 
3020
static void bootstrap(FILE *file)
 
3021
{
 
3022
  DBUG_ENTER("bootstrap");
 
3023
 
 
3024
  THD *thd= new THD;
 
3025
  thd->bootstrap=1;
 
3026
  my_net_init(&thd->net,(st_vio*) 0);
 
3027
  thd->max_client_packet_length= thd->net.max_packet;
 
3028
  thd->thread_id= thd->variables.pseudo_thread_id= thread_id++;
 
3029
  thread_count++;
 
3030
 
 
3031
  bootstrap_file=file;
 
3032
  if (pthread_create(&thd->real_id,&connection_attrib,handle_bootstrap,
 
3033
                     (void*) thd))
 
3034
  {
 
3035
    sql_print_warning("Can't create thread to handle bootstrap");
 
3036
    bootstrap_error=-1;
 
3037
    DBUG_VOID_RETURN;
 
3038
  }
 
3039
  /* Wait for thread to die */
 
3040
  (void) pthread_mutex_lock(&LOCK_thread_count);
 
3041
  while (thread_count)
 
3042
  {
 
3043
    (void) pthread_cond_wait(&COND_thread_count,&LOCK_thread_count);
 
3044
    DBUG_PRINT("quit",("One thread died (count=%u)",thread_count));
 
3045
  }
 
3046
  (void) pthread_mutex_unlock(&LOCK_thread_count);
 
3047
 
 
3048
  DBUG_VOID_RETURN;
 
3049
}
 
3050
 
 
3051
 
 
3052
static bool read_init_file(char *file_name)
 
3053
{
 
3054
  FILE *file;
 
3055
  DBUG_ENTER("read_init_file");
 
3056
  DBUG_PRINT("enter",("name: %s",file_name));
 
3057
  if (!(file=my_fopen(file_name,O_RDONLY,MYF(MY_WME))))
 
3058
    return(1);
 
3059
  bootstrap(file);
 
3060
  (void) my_fclose(file,MYF(MY_WME));
 
3061
  return 0;
 
3062
}
 
3063
 
 
3064
 
 
3065
/*
 
3066
   Simple scheduler that use the main thread to handle the request
 
3067
 
 
3068
   NOTES
 
3069
     This is only used for debugging, when starting mysqld with
 
3070
     --thread-handling=no-threads or --one-thread
 
3071
 
 
3072
     When we enter this function, LOCK_thread_count is hold!
 
3073
*/
 
3074
   
 
3075
void handle_connection_in_main_thread(THD *thd)
 
3076
{
 
3077
  safe_mutex_assert_owner(&LOCK_thread_count);
 
3078
  thread_cache_size=0;                  // Safety
 
3079
  threads.append(thd);
 
3080
  (void) pthread_mutex_unlock(&LOCK_thread_count);
 
3081
  handle_one_connection((void*) thd);
 
3082
}
 
3083
 
 
3084
 
 
3085
/*
 
3086
  Scheduler that uses one thread per connection
 
3087
*/
 
3088
 
 
3089
void create_thread_to_handle_connection(THD *thd)
 
3090
{
 
3091
  if (cached_thread_count > wake_thread)
 
3092
  {
 
3093
    /* Get thread from cache */
 
3094
    thread_cache.append(thd);
 
3095
    wake_thread++;
 
3096
    pthread_cond_signal(&COND_thread_cache);
 
3097
  }
 
3098
  else
 
3099
  {
 
3100
    char error_message_buff[MYSQL_ERRMSG_SIZE];
 
3101
    /* Create new thread to handle connection */
 
3102
    int error;
 
3103
    thread_created++;
 
3104
    threads.append(thd);
 
3105
    DBUG_PRINT("info",(("creating thread %lu"), thd->thread_id));
 
3106
    thd->connect_utime= thd->start_utime= my_micro_time();
 
3107
    if ((error=pthread_create(&thd->real_id,&connection_attrib,
 
3108
                              handle_one_connection,
 
3109
                              (void*) thd)))
 
3110
    {
 
3111
      /* purify: begin inspected */
 
3112
      DBUG_PRINT("error",
 
3113
                 ("Can't create thread to handle request (error %d)",
 
3114
                  error));
 
3115
      thread_count--;
 
3116
      thd->killed= THD::KILL_CONNECTION;                        // Safety
 
3117
      (void) pthread_mutex_unlock(&LOCK_thread_count);
 
3118
 
 
3119
      pthread_mutex_lock(&LOCK_connection_count);
 
3120
      --connection_count;
 
3121
      pthread_mutex_unlock(&LOCK_connection_count);
 
3122
 
 
3123
      statistic_increment(aborted_connects,&LOCK_status);
 
3124
      /* Can't use my_error() since store_globals has not been called. */
 
3125
      my_snprintf(error_message_buff, sizeof(error_message_buff),
 
3126
                  ER(ER_CANT_CREATE_THREAD), error);
 
3127
      net_send_error(thd, ER_CANT_CREATE_THREAD, error_message_buff);
 
3128
      (void) pthread_mutex_lock(&LOCK_thread_count);
 
3129
      close_connection(thd,0,0);
 
3130
      delete thd;
 
3131
      (void) pthread_mutex_unlock(&LOCK_thread_count);
 
3132
      return;
 
3133
      /* purecov: end */
 
3134
    }
 
3135
  }
 
3136
  (void) pthread_mutex_unlock(&LOCK_thread_count);
 
3137
  DBUG_PRINT("info",("Thread created"));
 
3138
}
 
3139
 
 
3140
 
 
3141
/**
 
3142
  Create new thread to handle incoming connection.
 
3143
 
 
3144
    This function will create new thread to handle the incoming
 
3145
    connection.  If there are idle cached threads one will be used.
 
3146
    'thd' will be pushed into 'threads'.
 
3147
 
 
3148
    In single-threaded mode (\#define ONE_THREAD) connection will be
 
3149
    handled inside this function.
 
3150
 
 
3151
  @param[in,out] thd    Thread handle of future thread.
 
3152
*/
 
3153
 
 
3154
static void create_new_thread(THD *thd)
 
3155
{
 
3156
  DBUG_ENTER("create_new_thread");
 
3157
 
 
3158
  /*
 
3159
    Don't allow too many connections. We roughly check here that we allow
 
3160
    only (max_connections + 1) connections.
 
3161
  */
 
3162
 
 
3163
  pthread_mutex_lock(&LOCK_connection_count);
 
3164
 
 
3165
  if (connection_count >= max_connections + 1 || abort_loop)
 
3166
  {
 
3167
    pthread_mutex_unlock(&LOCK_connection_count);
 
3168
 
 
3169
    DBUG_PRINT("error",("Too many connections"));
 
3170
    close_connection(thd, ER_CON_COUNT_ERROR, 1);
 
3171
    delete thd;
 
3172
    DBUG_VOID_RETURN;
 
3173
  }
 
3174
 
 
3175
  ++connection_count;
 
3176
 
 
3177
  if (connection_count > max_used_connections)
 
3178
    max_used_connections= connection_count;
 
3179
 
 
3180
  pthread_mutex_unlock(&LOCK_connection_count);
 
3181
 
 
3182
  /* Start a new thread to handle connection. */
 
3183
 
 
3184
  pthread_mutex_lock(&LOCK_thread_count);
 
3185
 
 
3186
  /*
 
3187
    The initialization of thread_id is done in create_embedded_thd() for
 
3188
    the embedded library.
 
3189
    TODO: refactor this to avoid code duplication there
 
3190
  */
 
3191
  thd->thread_id= thd->variables.pseudo_thread_id= thread_id++;
 
3192
 
 
3193
  thread_count++;
 
3194
 
 
3195
  thread_scheduler.add_connection(thd);
 
3196
 
 
3197
  DBUG_VOID_RETURN;
 
3198
}
 
3199
 
 
3200
 
 
3201
#ifdef SIGNALS_DONT_BREAK_READ
 
3202
inline void kill_broken_server()
 
3203
{
 
3204
  /* hack to get around signals ignored in syscalls for problem OS's */
 
3205
  if ((!opt_disable_networking && ip_sock == INVALID_SOCKET))
 
3206
  {
 
3207
    select_thread_in_use = 0;
 
3208
    /* The following call will never return */
 
3209
    kill_server((void*) MYSQL_KILL_SIGNAL);
 
3210
  }
 
3211
}
 
3212
#define MAYBE_BROKEN_SYSCALL kill_broken_server();
 
3213
#else
 
3214
#define MAYBE_BROKEN_SYSCALL
 
3215
#endif
 
3216
 
 
3217
        /* Handle new connections and spawn new process to handle them */
 
3218
 
 
3219
void handle_connections_sockets()
 
3220
{
 
3221
  my_socket sock,new_sock;
 
3222
  uint error_count=0;
 
3223
  uint max_used_connection= (uint)ip_sock+1;
 
3224
  fd_set readFDs,clientFDs;
 
3225
  THD *thd;
 
3226
  struct sockaddr_storage cAddr;
 
3227
  int ip_flags=0, flags;
 
3228
  st_vio *vio_tmp;
 
3229
 
 
3230
  FD_ZERO(&clientFDs);
 
3231
  if (ip_sock != INVALID_SOCKET)
 
3232
  {
 
3233
    FD_SET(ip_sock,&clientFDs);
 
3234
#ifdef HAVE_FCNTL
 
3235
    ip_flags = fcntl(ip_sock, F_GETFL, 0);
 
3236
#endif
 
3237
  }
 
3238
  DBUG_PRINT("general",("Waiting for connections."));
 
3239
  MAYBE_BROKEN_SYSCALL;
 
3240
  while (!abort_loop)
 
3241
  {
 
3242
    readFDs=clientFDs;
 
3243
    if (select((int) max_used_connection,&readFDs,0,0,0) < 0)
 
3244
    {
 
3245
      if (socket_errno != SOCKET_EINTR)
 
3246
      {
 
3247
        if (!select_errors++ && !abort_loop)    /* purecov: inspected */
 
3248
          sql_print_error("mysqld: Got error %d from select",socket_errno); /* purecov: inspected */
 
3249
      }
 
3250
      MAYBE_BROKEN_SYSCALL
 
3251
      continue;
 
3252
    }
 
3253
    if (abort_loop)
 
3254
    {
 
3255
      MAYBE_BROKEN_SYSCALL;
 
3256
      break;
 
3257
    }
 
3258
 
 
3259
    /* Is this a new connection request ? */
 
3260
    {
 
3261
      sock = ip_sock;
 
3262
      flags= ip_flags;
 
3263
    }
 
3264
 
 
3265
#if !defined(NO_FCNTL_NONBLOCK)
 
3266
    if (!(test_flags & TEST_BLOCKING))
 
3267
    {
 
3268
#if defined(O_NONBLOCK)
 
3269
      fcntl(sock, F_SETFL, flags | O_NONBLOCK);
 
3270
#elif defined(O_NDELAY)
 
3271
      fcntl(sock, F_SETFL, flags | O_NDELAY);
 
3272
#endif
 
3273
    }
 
3274
#endif /* NO_FCNTL_NONBLOCK */
 
3275
    for (uint retry=0; retry < MAX_ACCEPT_RETRY; retry++)
 
3276
    {
 
3277
      size_socket length= sizeof(struct sockaddr_storage);
 
3278
      new_sock= accept(sock, (struct sockaddr *)(&cAddr),
 
3279
                       &length);
 
3280
      if (new_sock != INVALID_SOCKET ||
 
3281
          (socket_errno != SOCKET_EINTR && socket_errno != SOCKET_EAGAIN))
 
3282
        break;
 
3283
      MAYBE_BROKEN_SYSCALL;
 
3284
#if !defined(NO_FCNTL_NONBLOCK)
 
3285
      if (!(test_flags & TEST_BLOCKING))
 
3286
      {
 
3287
        if (retry == MAX_ACCEPT_RETRY - 1)
 
3288
          fcntl(sock, F_SETFL, flags);          // Try without O_NONBLOCK
 
3289
      }
 
3290
#endif
 
3291
    }
 
3292
#if !defined(NO_FCNTL_NONBLOCK)
 
3293
    if (!(test_flags & TEST_BLOCKING))
 
3294
      fcntl(sock, F_SETFL, flags);
 
3295
#endif
 
3296
    if (new_sock == INVALID_SOCKET)
 
3297
    {
 
3298
      if ((error_count++ & 255) == 0)           // This can happen often
 
3299
        sql_perror("Error in accept");
 
3300
      MAYBE_BROKEN_SYSCALL;
 
3301
      if (socket_errno == SOCKET_ENFILE || socket_errno == SOCKET_EMFILE)
 
3302
        sleep(1);                               // Give other threads some time
 
3303
      continue;
 
3304
    }
 
3305
 
 
3306
    {
 
3307
      size_socket dummyLen;
 
3308
      struct sockaddr_storage dummy;
 
3309
      dummyLen = sizeof(dummy);
 
3310
      if (  getsockname(new_sock,(struct sockaddr *)&dummy, 
 
3311
                  (socklen_t *)&dummyLen) < 0  )
 
3312
      {
 
3313
        sql_perror("Error on new connection socket");
 
3314
        (void) shutdown(new_sock, SHUT_RDWR);
 
3315
        (void) closesocket(new_sock);
 
3316
        continue;
 
3317
      }
 
3318
    }
 
3319
 
 
3320
    /*
 
3321
    ** Don't allow too many connections
 
3322
    */
 
3323
 
 
3324
    if (!(thd= new THD))
 
3325
    {
 
3326
      (void) shutdown(new_sock, SHUT_RDWR);
 
3327
      VOID(closesocket(new_sock));
 
3328
      continue;
 
3329
    }
 
3330
    if (!(vio_tmp=vio_new(new_sock, VIO_TYPE_TCPIP, sock == 0)) ||
 
3331
        my_net_init(&thd->net,vio_tmp))
 
3332
    {
 
3333
      /*
 
3334
        Only delete the temporary vio if we didn't already attach it to the
 
3335
        NET object. The destructor in THD will delete any initialized net
 
3336
        structure.
 
3337
      */
 
3338
      if (vio_tmp && thd->net.vio != vio_tmp)
 
3339
        vio_delete(vio_tmp);
 
3340
      else
 
3341
      {
 
3342
        (void) shutdown(new_sock, SHUT_RDWR);
 
3343
        (void) closesocket(new_sock);
 
3344
      }
 
3345
      delete thd;
 
3346
      continue;
 
3347
    }
 
3348
 
 
3349
    create_new_thread(thd);
 
3350
  }
1668
3351
}
1669
3352
 
1670
3353
 
1672
3355
  Handle start options
1673
3356
******************************************************************************/
1674
3357
 
1675
 
enum options_drizzled
 
3358
enum options_mysqld
1676
3359
{
1677
 
  OPT_SOCKET=256,
1678
 
  OPT_BIND_ADDRESS,            
1679
 
  OPT_PID_FILE,
1680
 
  OPT_STORAGE_ENGINE,          
1681
 
  OPT_INIT_FILE,
 
3360
  OPT_ISAM_LOG=256,            OPT_SKIP_NEW, 
 
3361
  OPT_SKIP_GRANT,              OPT_SKIP_LOCK, 
 
3362
  OPT_ENABLE_LOCK,             OPT_USE_LOCKING,
 
3363
  OPT_SOCKET,                  OPT_UPDATE_LOG,
 
3364
  OPT_BIN_LOG,                 
 
3365
  OPT_BIN_LOG_INDEX,
 
3366
  OPT_BIND_ADDRESS,            OPT_PID_FILE,
 
3367
  OPT_SKIP_PRIOR,              OPT_BIG_TABLES,
 
3368
  OPT_STANDALONE,              OPT_ONE_THREAD,
 
3369
  OPT_CONSOLE,                 OPT_LOW_PRIORITY_UPDATES,
 
3370
  OPT_SHORT_LOG_FORMAT,
 
3371
  OPT_FLUSH,                   OPT_SAFE,
 
3372
  OPT_BOOTSTRAP,               OPT_SKIP_SHOW_DB,
 
3373
  OPT_STORAGE_ENGINE,          OPT_INIT_FILE,
 
3374
  OPT_DELAY_KEY_WRITE_ALL,     OPT_SLOW_QUERY_LOG,
 
3375
  OPT_DELAY_KEY_WRITE,         OPT_CHARSETS_DIR,
 
3376
  OPT_MASTER_INFO_FILE,
 
3377
  OPT_MASTER_RETRY_COUNT,      OPT_LOG_TC, OPT_LOG_TC_SIZE,
 
3378
  OPT_SQL_BIN_UPDATE_SAME,     OPT_REPLICATE_DO_DB,
 
3379
  OPT_REPLICATE_IGNORE_DB,     OPT_LOG_SLAVE_UPDATES,
 
3380
  OPT_BINLOG_DO_DB,            OPT_BINLOG_IGNORE_DB,
 
3381
  OPT_BINLOG_FORMAT,
 
3382
#ifndef DBUG_OFF
 
3383
  OPT_BINLOG_SHOW_XID,
 
3384
#endif
 
3385
  OPT_BINLOG_ROWS_EVENT_MAX_SIZE, 
1682
3386
  OPT_WANT_CORE,
1683
 
  OPT_MEMLOCK,
1684
 
  OPT_SERVER_ID,
1685
 
  OPT_TC_HEURISTIC_RECOVER,
 
3387
  OPT_MEMLOCK,                 OPT_MYISAM_RECOVER,
 
3388
  OPT_REPLICATE_REWRITE_DB,    OPT_SERVER_ID,
 
3389
  OPT_SKIP_SLAVE_START,
 
3390
  OPT_REPLICATE_DO_TABLE,
 
3391
  OPT_REPLICATE_IGNORE_TABLE,  OPT_REPLICATE_WILD_DO_TABLE,
 
3392
  OPT_REPLICATE_WILD_IGNORE_TABLE, OPT_REPLICATE_SAME_SERVER_ID,
 
3393
  OPT_DISCONNECT_SLAVE_EVENT_COUNT, OPT_TC_HEURISTIC_RECOVER,
 
3394
  OPT_ABORT_SLAVE_EVENT_COUNT,
 
3395
  OPT_LOG_BIN_TRUST_FUNCTION_CREATORS,
 
3396
  OPT_ENGINE_CONDITION_PUSHDOWN, 
1686
3397
  OPT_TEMP_POOL, OPT_TX_ISOLATION, OPT_COMPLETION_TYPE,
1687
3398
  OPT_SKIP_STACK_TRACE, OPT_SKIP_SYMLINKS,
1688
 
  OPT_DO_PSTACK,
1689
 
  OPT_LOCAL_INFILE,
1690
 
  OPT_BACK_LOG,
1691
 
  OPT_JOIN_BUFF_SIZE,
1692
 
  OPT_MAX_ALLOWED_PACKET,
1693
 
  OPT_MAX_CONNECT_ERRORS,
 
3399
  OPT_MAX_BINLOG_DUMP_EVENTS, OPT_SPORADIC_BINLOG_DUMP_FAIL,
 
3400
  OPT_SAFE_USER_CREATE,
 
3401
  OPT_DO_PSTACK, OPT_REPORT_HOST,
 
3402
  OPT_REPORT_USER, OPT_REPORT_PASSWORD, OPT_REPORT_PORT,
 
3403
  OPT_SHOW_SLAVE_AUTH_INFO,
 
3404
  OPT_SLAVE_LOAD_TMPDIR, OPT_NO_MIX_TYPE,
 
3405
  OPT_RPL_RECOVERY_RANK,
 
3406
  OPT_RELAY_LOG, OPT_RELAY_LOG_INDEX, OPT_RELAY_LOG_INFO_FILE,
 
3407
  OPT_SLAVE_SKIP_ERRORS, OPT_SLAVE_ALLOW_BATCHING, OPT_DES_KEY_FILE, OPT_LOCAL_INFILE,
 
3408
  OPT_SSL_SSL, OPT_SSL_KEY, OPT_SSL_CERT, OPT_SSL_CA,
 
3409
  OPT_SSL_CAPATH, OPT_SSL_CIPHER,
 
3410
  OPT_BACK_LOG, OPT_BINLOG_CACHE_SIZE,
 
3411
  OPT_CONNECT_TIMEOUT,
 
3412
  OPT_FLUSH_TIME, OPT_FT_MIN_WORD_LEN, OPT_FT_BOOLEAN_SYNTAX,
 
3413
  OPT_FT_MAX_WORD_LEN, OPT_FT_QUERY_EXPANSION_LIMIT, OPT_FT_STOPWORD_FILE,
 
3414
  OPT_INTERACTIVE_TIMEOUT, OPT_JOIN_BUFF_SIZE,
 
3415
  OPT_KEY_BUFFER_SIZE, OPT_KEY_CACHE_BLOCK_SIZE,
 
3416
  OPT_KEY_CACHE_DIVISION_LIMIT, OPT_KEY_CACHE_AGE_THRESHOLD,
 
3417
  OPT_LONG_QUERY_TIME,
 
3418
  OPT_LOWER_CASE_TABLE_NAMES, OPT_MAX_ALLOWED_PACKET,
 
3419
  OPT_MAX_BINLOG_CACHE_SIZE, OPT_MAX_BINLOG_SIZE,
 
3420
  OPT_MAX_CONNECTIONS, OPT_MAX_CONNECT_ERRORS,
1694
3421
  OPT_MAX_HEP_TABLE_SIZE,
1695
 
  OPT_MAX_JOIN_SIZE,
1696
 
  OPT_MAX_SORT_LENGTH,
 
3422
  OPT_MAX_JOIN_SIZE, OPT_MAX_PREPARED_STMT_COUNT,
 
3423
  OPT_MAX_RELAY_LOG_SIZE, OPT_MAX_SORT_LENGTH,
1697
3424
  OPT_MAX_SEEKS_FOR_KEY, OPT_MAX_TMP_TABLES, OPT_MAX_USER_CONNECTIONS,
1698
3425
  OPT_MAX_LENGTH_FOR_SORT_DATA,
1699
3426
  OPT_MAX_WRITE_LOCK_COUNT, OPT_BULK_INSERT_BUFFER_SIZE,
1701
3428
  OPT_MYISAM_BLOCK_SIZE, OPT_MYISAM_MAX_EXTRA_SORT_FILE_SIZE,
1702
3429
  OPT_MYISAM_MAX_SORT_FILE_SIZE, OPT_MYISAM_SORT_BUFFER_SIZE,
1703
3430
  OPT_MYISAM_USE_MMAP, OPT_MYISAM_REPAIR_THREADS,
1704
 
  OPT_NET_BUFFER_LENGTH,
 
3431
  OPT_MYISAM_STATS_METHOD,
 
3432
  OPT_NET_BUFFER_LENGTH, OPT_NET_RETRY_COUNT,
 
3433
  OPT_NET_READ_TIMEOUT, OPT_NET_WRITE_TIMEOUT,
 
3434
  OPT_OPEN_FILES_LIMIT,
1705
3435
  OPT_PRELOAD_BUFFER_SIZE,
1706
 
  OPT_RECORD_BUFFER,
1707
 
  OPT_RECORD_RND_BUFFER, OPT_DIV_PRECINCREMENT,
1708
 
  OPT_DEBUGGING,
 
3436
  OPT_QUERY_CACHE_LIMIT, OPT_QUERY_CACHE_MIN_RES_UNIT, OPT_QUERY_CACHE_SIZE,
 
3437
  OPT_QUERY_CACHE_TYPE, OPT_QUERY_CACHE_WLOCK_INVALIDATE, OPT_RECORD_BUFFER,
 
3438
  OPT_RECORD_RND_BUFFER, OPT_DIV_PRECINCREMENT, OPT_RELAY_LOG_SPACE_LIMIT,
 
3439
  OPT_RELAY_LOG_PURGE,
 
3440
  OPT_SLAVE_NET_TIMEOUT, OPT_SLAVE_COMPRESSED_PROTOCOL, OPT_SLOW_LAUNCH_TIME,
 
3441
  OPT_SLAVE_TRANS_RETRIES, OPT_READONLY, OPT_DEBUGGING,
1709
3442
  OPT_SORT_BUFFER, OPT_TABLE_OPEN_CACHE, OPT_TABLE_DEF_CACHE,
 
3443
  OPT_THREAD_CONCURRENCY, OPT_THREAD_CACHE_SIZE,
1710
3444
  OPT_TMP_TABLE_SIZE, OPT_THREAD_STACK,
1711
3445
  OPT_WAIT_TIMEOUT,
1712
 
  OPT_RANGE_ALLOC_BLOCK_SIZE,
 
3446
  OPT_ERROR_LOG_FILE,
 
3447
  OPT_DEFAULT_WEEK_FORMAT,
 
3448
  OPT_RANGE_ALLOC_BLOCK_SIZE, OPT_ALLOW_SUSPICIOUS_UDFS,
1713
3449
  OPT_QUERY_ALLOC_BLOCK_SIZE, OPT_QUERY_PREALLOC_SIZE,
1714
3450
  OPT_TRANS_ALLOC_BLOCK_SIZE, OPT_TRANS_PREALLOC_SIZE,
 
3451
  OPT_SYNC_FRM, OPT_SYNC_BINLOG,
 
3452
  OPT_SYNC_REPLICATION,
 
3453
  OPT_SYNC_REPLICATION_SLAVE_ID,
 
3454
  OPT_SYNC_REPLICATION_TIMEOUT,
 
3455
  OPT_ENABLE_SHARED_MEMORY,
 
3456
  OPT_SHARED_MEMORY_BASE_NAME,
 
3457
  OPT_OLD_PASSWORDS,
1715
3458
  OPT_OLD_ALTER_TABLE,
 
3459
  OPT_EXPIRE_LOGS_DAYS,
1716
3460
  OPT_GROUP_CONCAT_MAX_LEN,
1717
3461
  OPT_DEFAULT_COLLATION,
 
3462
  OPT_CHARACTER_SET_CLIENT_HANDSHAKE,
1718
3463
  OPT_CHARACTER_SET_FILESYSTEM,
1719
3464
  OPT_LC_TIME_NAMES,
1720
3465
  OPT_INIT_CONNECT,
 
3466
  OPT_INIT_SLAVE,
 
3467
  OPT_SECURE_AUTH,
 
3468
  OPT_DATE_FORMAT,
 
3469
  OPT_TIME_FORMAT,
 
3470
  OPT_DATETIME_FORMAT,
 
3471
  OPT_LOG_QUERIES_NOT_USING_INDEXES,
1721
3472
  OPT_DEFAULT_TIME_ZONE,
 
3473
  OPT_SYSDATE_IS_NOW,
1722
3474
  OPT_OPTIMIZER_SEARCH_DEPTH,
1723
 
  OPT_SCHEDULER,
1724
 
  OPT_PROTOCOL,
1725
3475
  OPT_OPTIMIZER_PRUNE_LEVEL,
 
3476
  OPT_UPDATABLE_VIEWS_WITH_LIMIT,
1726
3477
  OPT_AUTO_INCREMENT, OPT_AUTO_INCREMENT_OFFSET,
1727
3478
  OPT_ENABLE_LARGE_PAGES,
1728
3479
  OPT_TIMED_MUTEXES,
 
3480
  OPT_OLD_STYLE_USER_LIMITS,
 
3481
  OPT_LOG_SLOW_ADMIN_STATEMENTS,
1729
3482
  OPT_TABLE_LOCK_WAIT_TIMEOUT,
1730
 
  OPT_PLUGIN_ADD,
1731
 
  OPT_PLUGIN_REMOVE,
1732
3483
  OPT_PLUGIN_LOAD,
1733
3484
  OPT_PLUGIN_DIR,
 
3485
  OPT_LOG_OUTPUT,
1734
3486
  OPT_PORT_OPEN_TIMEOUT,
 
3487
  OPT_PROFILING,
 
3488
  OPT_KEEP_FILES_ON_CREATE,
 
3489
  OPT_GENERAL_LOG,
 
3490
  OPT_SLOW_LOG,
 
3491
  OPT_THREAD_HANDLING,
 
3492
  OPT_INNODB_ROLLBACK_ON_TIMEOUT,
1735
3493
  OPT_SECURE_FILE_PRIV,
1736
3494
  OPT_MIN_EXAMINED_ROW_LIMIT,
1737
 
  OPT_PRINT_DEFAULTS
 
3495
  OPT_LOG_SLOW_SLAVE_STATEMENTS,
 
3496
  OPT_OLD_MODE,
 
3497
  OPT_POOL_OF_THREADS,
 
3498
  OPT_SLAVE_EXEC_MODE
1738
3499
};
1739
3500
 
1740
3501
 
1741
 
struct option my_long_options[] =
 
3502
#define LONG_TIMEOUT ((ulong) 3600L*24L*365L)
 
3503
 
 
3504
struct my_option my_long_options[] =
1742
3505
{
1743
 
 
1744
 
  {"help", '?', N_("Display this help and exit."),
1745
 
   (char**) &opt_help, (char**) &opt_help, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0,
 
3506
  {"help", '?', "Display this help and exit.", 
 
3507
   (uchar**) &opt_help, (uchar**) &opt_help, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0,
1746
3508
   0, 0},
 
3509
  {"abort-slave-event-count", OPT_ABORT_SLAVE_EVENT_COUNT,
 
3510
   "Option used by mysql-test for debugging and testing of replication.",
 
3511
   (uchar**) &abort_slave_event_count,  (uchar**) &abort_slave_event_count,
 
3512
   0, GET_INT, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
3513
  {"allow-suspicious-udfs", OPT_ALLOW_SUSPICIOUS_UDFS,
 
3514
   "Allows use of UDFs consisting of only one symbol xxx() "
 
3515
   "without corresponding xxx_init() or xxx_deinit(). That also means "
 
3516
   "that one can load any function from any library, for example exit() "
 
3517
   "from libc.so",
 
3518
   (uchar**) &opt_allow_suspicious_udfs, (uchar**) &opt_allow_suspicious_udfs,
 
3519
   0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
 
3520
  {"ansi", 'a', "Use ANSI SQL syntax instead of MySQL syntax. This mode will also set transaction isolation level 'serializable'.", 0, 0, 0,
 
3521
   GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
1747
3522
  {"auto-increment-increment", OPT_AUTO_INCREMENT,
1748
 
   N_("Auto-increment columns are incremented by this"),
1749
 
   (char**) &global_system_variables.auto_increment_increment,
1750
 
   (char**) &max_system_variables.auto_increment_increment, 0, GET_ULL,
1751
 
   OPT_ARG, 1, 1, INT64_MAX, 0, 1, 0 },
 
3523
   "Auto-increment columns are incremented by this",
 
3524
   (uchar**) &global_system_variables.auto_increment_increment,
 
3525
   (uchar**) &max_system_variables.auto_increment_increment, 0, GET_ULONG,
 
3526
   OPT_ARG, 1, 1, 65535, 0, 1, 0 },
1752
3527
  {"auto-increment-offset", OPT_AUTO_INCREMENT_OFFSET,
1753
 
   N_("Offset added to Auto-increment columns. Used when "
1754
 
      "auto-increment-increment != 1"),
1755
 
   (char**) &global_system_variables.auto_increment_offset,
1756
 
   (char**) &max_system_variables.auto_increment_offset, 0, GET_ULL, OPT_ARG,
1757
 
   1, 1, INT64_MAX, 0, 1, 0 },
 
3528
   "Offset added to Auto-increment columns. Used when auto-increment-increment != 1",
 
3529
   (uchar**) &global_system_variables.auto_increment_offset,
 
3530
   (uchar**) &max_system_variables.auto_increment_offset, 0, GET_ULONG, OPT_ARG,
 
3531
   1, 1, 65535, 0, 1, 0 },
1758
3532
  {"basedir", 'b',
1759
 
   N_("Path to installation directory. All paths are usually resolved "
1760
 
      "relative to this."),
1761
 
   NULL, NULL, 0, GET_STR, REQUIRED_ARG,
1762
 
   0, 0, 0, 0, 0, 0},
1763
 
  {"chroot", 'r',
1764
 
   N_("Chroot drizzled daemon during startup."),
1765
 
   (char**) &drizzled_chroot, (char**) &drizzled_chroot, 0, GET_STR, REQUIRED_ARG,
1766
 
   0, 0, 0, 0, 0, 0},
1767
 
  {"collation-server", OPT_DEFAULT_COLLATION,
1768
 
   N_("Set the default collation."),
1769
 
   (char**) &default_collation_name, (char**) &default_collation_name,
1770
 
   0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0 },
1771
 
  {"completion-type", OPT_COMPLETION_TYPE,
1772
 
   N_("Default completion type."),
1773
 
   (char**) &global_system_variables.completion_type,
1774
 
   (char**) &max_system_variables.completion_type, 0, GET_UINT,
 
3533
   "Path to installation directory. All paths are usually resolved relative to this.",
 
3534
   (uchar**) &mysql_home_ptr, (uchar**) &mysql_home_ptr, 0, GET_STR, REQUIRED_ARG,
 
3535
   0, 0, 0, 0, 0, 0},
 
3536
  {"big-tables", OPT_BIG_TABLES,
 
3537
   "Allow big result sets by saving all temporary sets on file (Solves most 'table full' errors).",
 
3538
   0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
 
3539
  {"bind-address", OPT_BIND_ADDRESS, "IP address to bind to.",
 
3540
   (uchar**) &my_bind_addr_str, (uchar**) &my_bind_addr_str, 0, GET_STR,
 
3541
   REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
3542
  {"binlog_format", OPT_BINLOG_FORMAT,
 
3543
   "Does not have any effect without '--log-bin'. "
 
3544
   "Tell the master the form of binary logging to use: either 'row' for "
 
3545
   "row-based binary logging, or 'statement' for statement-based binary "
 
3546
   "logging, or 'mixed'. 'mixed' is statement-based binary logging except "
 
3547
   "for those statements where only row-based is correct: those which "
 
3548
   "involve user-defined functions (i.e. UDFs) or the UUID() function; for "
 
3549
   "those, row-based binary logging is automatically used. "
 
3550
   ,(uchar**) &opt_binlog_format, (uchar**) &opt_binlog_format,
 
3551
   0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
3552
  {"binlog-do-db", OPT_BINLOG_DO_DB,
 
3553
   "Tells the master it should log updates for the specified database, and exclude all others not explicitly mentioned.",
 
3554
   0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
3555
  {"binlog-ignore-db", OPT_BINLOG_IGNORE_DB,
 
3556
   "Tells the master that updates to the given database should not be logged tothe binary log.",
 
3557
   0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
3558
  {"binlog-row-event-max-size", OPT_BINLOG_ROWS_EVENT_MAX_SIZE,
 
3559
   "The maximum size of a row-based binary log event in bytes. Rows will be "
 
3560
   "grouped into events smaller than this size if possible. "
 
3561
   "The value has to be a multiple of 256.",
 
3562
   (uchar**) &opt_binlog_rows_event_max_size, 
 
3563
   (uchar**) &opt_binlog_rows_event_max_size, 0, 
 
3564
   GET_ULONG, REQUIRED_ARG, 
 
3565
   /* def_value */ 1024, /* min_value */  256, /* max_value */ ULONG_MAX, 
 
3566
   /* sub_size */     0, /* block_size */ 256, 
 
3567
   /* app_type */ 0
 
3568
  },
 
3569
#ifndef DISABLE_GRANT_OPTIONS
 
3570
  {"bootstrap", OPT_BOOTSTRAP, "Used by mysql installation scripts.", 0, 0, 0,
 
3571
   GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
 
3572
#endif
 
3573
  {"character-set-client-handshake", OPT_CHARACTER_SET_CLIENT_HANDSHAKE,
 
3574
   "Don't ignore client side character set value sent during handshake.",
 
3575
   (uchar**) &opt_character_set_client_handshake,
 
3576
   (uchar**) &opt_character_set_client_handshake,
 
3577
    0, GET_BOOL, NO_ARG, 1, 0, 0, 0, 0, 0},
 
3578
  {"character-set-filesystem", OPT_CHARACTER_SET_FILESYSTEM,
 
3579
   "Set the filesystem character set.",
 
3580
   (uchar**) &character_set_filesystem_name,
 
3581
   (uchar**) &character_set_filesystem_name,
 
3582
   0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0 },
 
3583
  {"character-set-server", 'C', "Set the default character set.",
 
3584
   (uchar**) &default_character_set_name, (uchar**) &default_character_set_name,
 
3585
   0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0 },
 
3586
  {"character-sets-dir", OPT_CHARSETS_DIR,
 
3587
   "Directory where character sets are.", (uchar**) &charsets_dir,
 
3588
   (uchar**) &charsets_dir, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
3589
  {"chroot", 'r', "Chroot mysqld daemon during startup.",
 
3590
   (uchar**) &mysqld_chroot, (uchar**) &mysqld_chroot, 0, GET_STR, REQUIRED_ARG,
 
3591
   0, 0, 0, 0, 0, 0},
 
3592
  {"collation-server", OPT_DEFAULT_COLLATION, "Set the default collation.",
 
3593
   (uchar**) &default_collation_name, (uchar**) &default_collation_name,
 
3594
   0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0 },
 
3595
  {"completion-type", OPT_COMPLETION_TYPE, "Default completion type.",
 
3596
   (uchar**) &global_system_variables.completion_type,
 
3597
   (uchar**) &max_system_variables.completion_type, 0, GET_ULONG,
1775
3598
   REQUIRED_ARG, 0, 0, 2, 0, 1, 0},
1776
 
  {"core-file", OPT_WANT_CORE,
1777
 
   N_("Write core on errors."),
1778
 
   0, 0, 0, GET_NO_ARG,
 
3599
  {"console", OPT_CONSOLE, "Write error output on screen; Don't remove the console window on windows.",
 
3600
   (uchar**) &opt_console, (uchar**) &opt_console, 0, GET_BOOL, NO_ARG, 0, 0, 0,
 
3601
   0, 0, 0},
 
3602
  {"core-file", OPT_WANT_CORE, "Write core on errors.", 0, 0, 0, GET_NO_ARG,
1779
3603
   NO_ARG, 0, 0, 0, 0, 0, 0},
1780
 
  {"datadir", 'h',
1781
 
   N_("Path to the database root."),
1782
 
   NULL, NULL, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
3604
  {"datadir", 'h', "Path to the database root.", (uchar**) &mysql_data_home,
 
3605
   (uchar**) &mysql_data_home, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
3606
#ifndef DBUG_OFF
 
3607
  {"debug", '#', "Debug log.", (uchar**) &default_dbug_option,
 
3608
   (uchar**) &default_dbug_option, 0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0},
 
3609
#endif
 
3610
  {"default-character-set", 'C', "Set the default character set (deprecated option, use --character-set-server instead).",
 
3611
   (uchar**) &default_character_set_name, (uchar**) &default_character_set_name,
 
3612
   0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0 },
 
3613
  {"default-collation", OPT_DEFAULT_COLLATION, "Set the default collation (deprecated option, use --collation-server instead).",
 
3614
   (uchar**) &default_collation_name, (uchar**) &default_collation_name,
 
3615
   0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0 },
1783
3616
  {"default-storage-engine", OPT_STORAGE_ENGINE,
1784
 
   N_("Set the default storage engine (table type) for tables."),
1785
 
   (char**)&default_storage_engine_str, (char**)&default_storage_engine_str,
1786
 
   0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
1787
 
  {"default-time-zone", OPT_DEFAULT_TIME_ZONE,
1788
 
   N_("Set the default time zone."),
1789
 
   (char**) &default_tz_name, (char**) &default_tz_name,
 
3617
   "Set the default storage engine (table type) for tables.",
 
3618
   (uchar**)&default_storage_engine_str, (uchar**)&default_storage_engine_str,
 
3619
   0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
3620
  {"default-table-type", OPT_STORAGE_ENGINE,
 
3621
   "(deprecated) Use --default-storage-engine.",
 
3622
   (uchar**)&default_storage_engine_str, (uchar**)&default_storage_engine_str,
 
3623
   0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
3624
  {"default-time-zone", OPT_DEFAULT_TIME_ZONE, "Set the default time zone.",
 
3625
   (uchar**) &default_tz_name, (uchar**) &default_tz_name,
1790
3626
   0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0 },
 
3627
  {"delay-key-write", OPT_DELAY_KEY_WRITE, "Type of DELAY_KEY_WRITE.",
 
3628
   0,0,0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0},
 
3629
  {"delay-key-write-for-all-tables", OPT_DELAY_KEY_WRITE_ALL,
 
3630
   "Don't flush key buffers between writes for any MyISAM table (Deprecated option, use --delay-key-write=all instead).",
 
3631
   0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
 
3632
  {"disconnect-slave-event-count", OPT_DISCONNECT_SLAVE_EVENT_COUNT,
 
3633
   "Option used by mysql-test for debugging and testing of replication.",
 
3634
   (uchar**) &disconnect_slave_event_count,
 
3635
   (uchar**) &disconnect_slave_event_count, 0, GET_INT, REQUIRED_ARG, 0, 0, 0,
 
3636
   0, 0, 0},
 
3637
#ifdef HAVE_STACK_TRACE_ON_SEGV
 
3638
  {"enable-pstack", OPT_DO_PSTACK, "Print a symbolic stack trace on failure.",
 
3639
   (uchar**) &opt_do_pstack, (uchar**) &opt_do_pstack, 0, GET_BOOL, NO_ARG, 0, 0,
 
3640
   0, 0, 0, 0},
 
3641
#endif /* HAVE_STACK_TRACE_ON_SEGV */
 
3642
  {"engine-condition-pushdown",
 
3643
   OPT_ENGINE_CONDITION_PUSHDOWN,
 
3644
   "Push supported query conditions to the storage engine.",
 
3645
   (uchar**) &global_system_variables.engine_condition_pushdown,
 
3646
   (uchar**) &global_system_variables.engine_condition_pushdown,
 
3647
   0, GET_BOOL, NO_ARG, 1, 0, 0, 0, 0, 0},
1791
3648
  /* See how it's handled in get_one_option() */
1792
 
  {"exit-info", 'T',
1793
 
   N_("Used for debugging;  Use at your own risk!"),
1794
 
   0, 0, 0, GET_LONG, OPT_ARG, 0, 0, 0, 0, 0, 0},
 
3649
  {"exit-info", 'T', "Used for debugging;  Use at your own risk!", 0, 0, 0,
 
3650
   GET_LONG, OPT_ARG, 0, 0, 0, 0, 0, 0},
 
3651
  {"flush", OPT_FLUSH, "Flush tables to disk between SQL commands.", 0, 0, 0,
 
3652
   GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
1795
3653
  /* We must always support the next option to make scripts like mysqltest
1796
3654
     easier to do */
1797
3655
  {"gdb", OPT_DEBUGGING,
1798
 
   N_("Set up signals usable for debugging"),
1799
 
   (char**) &opt_debugging, (char**) &opt_debugging,
 
3656
   "Set up signals usable for debugging",
 
3657
   (uchar**) &opt_debugging, (uchar**) &opt_debugging,
1800
3658
   0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
 
3659
  {"general-log", OPT_GENERAL_LOG,
 
3660
   "Enable|disable general log", (uchar**) &opt_log,
 
3661
   (uchar**) &opt_log, 0, GET_BOOL, OPT_ARG, 0, 0, 0, 0, 0, 0},
 
3662
#ifdef HAVE_LARGE_PAGES
 
3663
  {"large-pages", OPT_ENABLE_LARGE_PAGES, "Enable support for large pages. \
 
3664
Disable with --skip-large-pages.",
 
3665
   (uchar**) &opt_large_pages, (uchar**) &opt_large_pages, 0, GET_BOOL, NO_ARG, 0, 0, 0,
 
3666
   0, 0, 0},
 
3667
#endif
 
3668
  {"init-connect", OPT_INIT_CONNECT, "Command(s) that are executed for each new connection",
 
3669
   (uchar**) &opt_init_connect, (uchar**) &opt_init_connect, 0, GET_STR_ALLOC,
 
3670
   REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
3671
  {"init-file", OPT_INIT_FILE, "Read SQL commands from this file at startup.",
 
3672
   (uchar**) &opt_init_file, (uchar**) &opt_init_file, 0, GET_STR, REQUIRED_ARG,
 
3673
   0, 0, 0, 0, 0, 0},
 
3674
  {"init-slave", OPT_INIT_SLAVE, "Command(s) that are executed when a slave connects to this master",
 
3675
   (uchar**) &opt_init_slave, (uchar**) &opt_init_slave, 0, GET_STR_ALLOC,
 
3676
   REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
3677
  {"language", 'L',
 
3678
   "Client error messages in given language. May be given as a full path.",
 
3679
   (uchar**) &language_ptr, (uchar**) &language_ptr, 0, GET_STR, REQUIRED_ARG,
 
3680
   0, 0, 0, 0, 0, 0},
1801
3681
  {"lc-time-names", OPT_LC_TIME_NAMES,
1802
 
   N_("Set the language used for the month names and the days of the week."),
1803
 
   (char**) &lc_time_names_name,
1804
 
   (char**) &lc_time_names_name,
 
3682
   "Set the language used for the month names and the days of the week.",
 
3683
   (uchar**) &lc_time_names_name,
 
3684
   (uchar**) &lc_time_names_name,
1805
3685
   0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0 },
1806
 
  {"log-warnings", 'W',
1807
 
   N_("Log some not critical warnings to the log file."),
1808
 
   (char**) &global_system_variables.log_warnings,
1809
 
   (char**) &max_system_variables.log_warnings, 0, GET_BOOL, OPT_ARG, 1, 0, 0,
 
3686
  {"local-infile", OPT_LOCAL_INFILE,
 
3687
   "Enable/disable LOAD DATA LOCAL INFILE (takes values 1|0).",
 
3688
   (uchar**) &opt_local_infile,
 
3689
   (uchar**) &opt_local_infile, 0, GET_BOOL, OPT_ARG,
 
3690
   1, 0, 0, 0, 0, 0},
 
3691
  {"log", 'l', "Log connections and queries to file.", (uchar**) &opt_logname,
 
3692
   (uchar**) &opt_logname, 0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0},
 
3693
  {"log-bin", OPT_BIN_LOG,
 
3694
   "Log update queries in binary format. Optional (but strongly recommended "
 
3695
   "to avoid replication problems if server's hostname changes) argument "
 
3696
   "should be the chosen location for the binary log files.",
 
3697
   (uchar**) &opt_bin_logname, (uchar**) &opt_bin_logname, 0, GET_STR_ALLOC,
 
3698
   OPT_ARG, 0, 0, 0, 0, 0, 0},
 
3699
  {"log-bin-index", OPT_BIN_LOG_INDEX,
 
3700
   "File that holds the names for last binary log files.",
 
3701
   (uchar**) &opt_binlog_index_name, (uchar**) &opt_binlog_index_name, 0, GET_STR,
 
3702
   REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
3703
#ifndef TO_BE_REMOVED_IN_5_1_OR_6_0
 
3704
  /*
 
3705
    In 5.0.6 we introduced the below option, then in 5.0.16 we renamed it to
 
3706
    log-bin-trust-function-creators but kept also the old name for
 
3707
    compatibility; the behaviour was also changed to apply only to functions
 
3708
    (and triggers). In a future release this old name could be removed.
 
3709
  */
 
3710
  {"log-bin-trust-routine-creators", OPT_LOG_BIN_TRUST_FUNCTION_CREATORS,
 
3711
   "(deprecated) Use log-bin-trust-function-creators.",
 
3712
   (uchar**) &trust_function_creators, (uchar**) &trust_function_creators, 0,
 
3713
   GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
 
3714
#endif
 
3715
  /*
 
3716
    This option starts with "log-bin" to emphasize that it is specific of
 
3717
    binary logging.
 
3718
  */
 
3719
  {"log-bin-trust-function-creators", OPT_LOG_BIN_TRUST_FUNCTION_CREATORS,
 
3720
   "If equal to 0 (the default), then when --log-bin is used, creation of "
 
3721
   "a stored function (or trigger) is allowed only to users having the SUPER privilege "
 
3722
   "and only if this stored function (trigger) may not break binary logging."
 
3723
   "Note that if ALL connections to this server ALWAYS use row-based binary "
 
3724
   "logging, the security issues do not exist and the binary logging cannot "
 
3725
   "break, so you can safely set this to 1."
 
3726
   ,(uchar**) &trust_function_creators, (uchar**) &trust_function_creators, 0,
 
3727
   GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
 
3728
  {"log-error", OPT_ERROR_LOG_FILE, "Error log file.",
 
3729
   (uchar**) &log_error_file_ptr, (uchar**) &log_error_file_ptr, 0, GET_STR,
 
3730
   OPT_ARG, 0, 0, 0, 0, 0, 0},
 
3731
  {"log-isam", OPT_ISAM_LOG, "Log all MyISAM changes to file.",
 
3732
   (uchar**) &myisam_log_filename, (uchar**) &myisam_log_filename, 0, GET_STR,
 
3733
   OPT_ARG, 0, 0, 0, 0, 0, 0},
 
3734
  {"log-long-format", '0',
 
3735
   "Log some extra information to update log. Please note that this option is deprecated; see --log-short-format option.", 
 
3736
   0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
 
3737
#ifdef WITH_CSV_STORAGE_ENGINE
 
3738
  {"log-output", OPT_LOG_OUTPUT,
 
3739
   "Syntax: log-output[=value[,value...]], where \"value\" could be TABLE, "
 
3740
   "FILE or NONE.",
 
3741
   (uchar**) &log_output_str, (uchar**) &log_output_str, 0,
 
3742
   GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0},
 
3743
#endif
 
3744
  {"log-queries-not-using-indexes", OPT_LOG_QUERIES_NOT_USING_INDEXES,
 
3745
   "Log queries that are executed without benefit of any index to the slow log if it is open.",
 
3746
   (uchar**) &opt_log_queries_not_using_indexes, (uchar**) &opt_log_queries_not_using_indexes,
 
3747
   0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
 
3748
  {"log-short-format", OPT_SHORT_LOG_FORMAT,
 
3749
   "Don't log extra information to update and slow-query logs.",
 
3750
   (uchar**) &opt_short_log_format, (uchar**) &opt_short_log_format,
 
3751
   0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
 
3752
  {"log-slave-updates", OPT_LOG_SLAVE_UPDATES,
 
3753
   "Tells the slave to log the updates from the slave thread to the binary log. You will need to turn it on if you plan to daisy-chain the slaves.",
 
3754
   (uchar**) &opt_log_slave_updates, (uchar**) &opt_log_slave_updates, 0, GET_BOOL,
 
3755
   NO_ARG, 0, 0, 0, 0, 0, 0},
 
3756
  {"log-slow-admin-statements", OPT_LOG_SLOW_ADMIN_STATEMENTS,
 
3757
   "Log slow OPTIMIZE, ANALYZE, ALTER and other administrative statements to the slow log if it is open.",
 
3758
   (uchar**) &opt_log_slow_admin_statements,
 
3759
   (uchar**) &opt_log_slow_admin_statements,
 
3760
   0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
 
3761
 {"log-slow-slave-statements", OPT_LOG_SLOW_SLAVE_STATEMENTS,
 
3762
  "Log slow statements executed by slave thread to the slow log if it is open.",
 
3763
  (uchar**) &opt_log_slow_slave_statements,
 
3764
  (uchar**) &opt_log_slow_slave_statements,
 
3765
  0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
 
3766
  {"log-slow-queries", OPT_SLOW_QUERY_LOG,
 
3767
    "Log slow queries to a table or log file. Defaults logging to table mysql.slow_log or hostname-slow.log if --log-output=file is used. Must be enabled to activate other slow log options.",
 
3768
   (uchar**) &opt_slow_logname, (uchar**) &opt_slow_logname, 0, GET_STR, OPT_ARG,
 
3769
   0, 0, 0, 0, 0, 0},
 
3770
  {"log-tc", OPT_LOG_TC,
 
3771
   "Path to transaction coordinator log (used for transactions that affect "
 
3772
   "more than one storage engine, when binary log is disabled)",
 
3773
   (uchar**) &opt_tc_log_file, (uchar**) &opt_tc_log_file, 0, GET_STR,
 
3774
   REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
3775
#ifdef HAVE_MMAP
 
3776
  {"log-tc-size", OPT_LOG_TC_SIZE, "Size of transaction coordinator log.",
 
3777
   (uchar**) &opt_tc_log_size, (uchar**) &opt_tc_log_size, 0, GET_ULONG,
 
3778
   REQUIRED_ARG, TC_LOG_MIN_SIZE, TC_LOG_MIN_SIZE, ULONG_MAX, 0,
 
3779
   TC_LOG_PAGE_SIZE, 0},
 
3780
#endif
 
3781
  {"log-update", OPT_UPDATE_LOG,
 
3782
   "The update log is deprecated since version 5.0, is replaced by the binary \
 
3783
log and this option justs turns on --log-bin instead.",
 
3784
   (uchar**) &opt_update_logname, (uchar**) &opt_update_logname, 0, GET_STR,
 
3785
   OPT_ARG, 0, 0, 0, 0, 0, 0},
 
3786
  {"log-warnings", 'W', "Log some not critical warnings to the log file.",
 
3787
   (uchar**) &global_system_variables.log_warnings,
 
3788
   (uchar**) &max_system_variables.log_warnings, 0, GET_ULONG, OPT_ARG, 1, 0, 0,
1810
3789
   0, 0, 0},
1811
 
  {"pid-file", OPT_PID_FILE,
1812
 
   N_("Pid file used by drizzled."),
1813
 
   NULL, NULL, 0, GET_STR,
1814
 
   REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
3790
  {"low-priority-updates", OPT_LOW_PRIORITY_UPDATES,
 
3791
   "INSERT/DELETE/UPDATE has lower priority than selects.",
 
3792
   (uchar**) &global_system_variables.low_priority_updates,
 
3793
   (uchar**) &max_system_variables.low_priority_updates,
 
3794
   0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
 
3795
  {"master-info-file", OPT_MASTER_INFO_FILE,
 
3796
   "The location and name of the file that remembers the master and where the I/O replication \
 
3797
thread is in the master's binlogs.",
 
3798
   (uchar**) &master_info_file, (uchar**) &master_info_file, 0, GET_STR,
 
3799
   REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
3800
  {"master-retry-count", OPT_MASTER_RETRY_COUNT,
 
3801
   "The number of tries the slave will make to connect to the master before giving up.",
 
3802
   (uchar**) &master_retry_count, (uchar**) &master_retry_count, 0, GET_ULONG,
 
3803
   REQUIRED_ARG, 3600*24, 0, 0, 0, 0, 0},
 
3804
  {"max-binlog-dump-events", OPT_MAX_BINLOG_DUMP_EVENTS,
 
3805
   "Option used by mysql-test for debugging and testing of replication.",
 
3806
   (uchar**) &max_binlog_dump_events, (uchar**) &max_binlog_dump_events, 0,
 
3807
   GET_INT, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
3808
  {"memlock", OPT_MEMLOCK, "Lock mysqld in memory.", (uchar**) &locked_in_memory,
 
3809
   (uchar**) &locked_in_memory, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
 
3810
  {"myisam-recover", OPT_MYISAM_RECOVER,
 
3811
   "Syntax: myisam-recover[=option[,option...]], where option can be DEFAULT, BACKUP, FORCE or QUICK.",
 
3812
   (uchar**) &myisam_recover_options_str, (uchar**) &myisam_recover_options_str, 0,
 
3813
   GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0},
 
3814
  {"new", 'n', "Use very new possible 'unsafe' functions.",
 
3815
   (uchar**) &global_system_variables.new_mode,
 
3816
   (uchar**) &max_system_variables.new_mode,
 
3817
   0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
 
3818
  {"old-alter-table", OPT_OLD_ALTER_TABLE,
 
3819
   "Use old, non-optimized alter table.",
 
3820
   (uchar**) &global_system_variables.old_alter_table,
 
3821
   (uchar**) &max_system_variables.old_alter_table, 0, GET_BOOL, NO_ARG,
 
3822
   0, 0, 0, 0, 0, 0},
 
3823
  {"old-passwords", OPT_OLD_PASSWORDS, "Use old password encryption method (needed for 4.0 and older clients).",
 
3824
   (uchar**) &global_system_variables.old_passwords,
 
3825
   (uchar**) &max_system_variables.old_passwords, 0, GET_BOOL, NO_ARG,
 
3826
   0, 0, 0, 0, 0, 0},
 
3827
  {"one-thread", OPT_ONE_THREAD,
 
3828
   "(deprecated): Only use one thread (for debugging under Linux). Use thread-handling=no-threads instead",
 
3829
   0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
 
3830
  {"pool-of-threads", OPT_POOL_OF_THREADS,
 
3831
   "Use pool of threads during testing. NOTE: Use thread-handling=pool-of-threads instead",
 
3832
   0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
 
3833
  {"old-style-user-limits", OPT_OLD_STYLE_USER_LIMITS,
 
3834
   "Enable old-style user limits (before 5.0.3 user resources were counted per each user+host vs. per account)",
 
3835
   (uchar**) &opt_old_style_user_limits, (uchar**) &opt_old_style_user_limits,
 
3836
   0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
 
3837
  {"pid-file", OPT_PID_FILE, "Pid file used by safe_mysqld.",
 
3838
   (uchar**) &pidfile_name_ptr, (uchar**) &pidfile_name_ptr, 0, GET_STR,
 
3839
   REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
3840
  {"port", 'P', "Port number to use for connection or 0 for default to, in "
 
3841
   "order of preference, my.cnf, $MYSQL_TCP_PORT, "
 
3842
#if MYSQL_PORT_DEFAULT == 0
 
3843
   "/etc/services, "
 
3844
#endif
 
3845
   "built-in default (" STRINGIFY_ARG(MYSQL_PORT) ").",
 
3846
   (uchar**) &mysqld_port,
 
3847
   (uchar**) &mysqld_port, 0, GET_UINT, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
1815
3848
  {"port-open-timeout", OPT_PORT_OPEN_TIMEOUT,
1816
 
   N_("Maximum time in seconds to wait for the port to become free. "
1817
 
      "(Default: no wait)"),
1818
 
   (char**) &drizzled_bind_timeout,
1819
 
   (char**) &drizzled_bind_timeout, 0, GET_UINT, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
3849
   "Maximum time in seconds to wait for the port to become free. "
 
3850
   "(Default: no wait)", (uchar**) &mysqld_port_timeout,
 
3851
   (uchar**) &mysqld_port_timeout, 0, GET_UINT, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
3852
  {"relay-log", OPT_RELAY_LOG,
 
3853
   "The location and name to use for relay logs.",
 
3854
   (uchar**) &opt_relay_logname, (uchar**) &opt_relay_logname, 0,
 
3855
   GET_STR_ALLOC, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
3856
  {"relay-log-index", OPT_RELAY_LOG_INDEX,
 
3857
   "The location and name to use for the file that keeps a list of the last \
 
3858
relay logs.",
 
3859
   (uchar**) &opt_relaylog_index_name, (uchar**) &opt_relaylog_index_name, 0,
 
3860
   GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
3861
  {"relay-log-info-file", OPT_RELAY_LOG_INFO_FILE,
 
3862
   "The location and name of the file that remembers where the SQL replication \
 
3863
thread is in the relay logs.",
 
3864
   (uchar**) &relay_log_info_file, (uchar**) &relay_log_info_file, 0, GET_STR,
 
3865
   REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
3866
  {"replicate-do-db", OPT_REPLICATE_DO_DB,
 
3867
   "Tells the slave thread to restrict replication to the specified database. To specify more than one database, use the directive multiple times, once for each database. Note that this will only work if you do not use cross-database queries such as UPDATE some_db.some_table SET foo='bar' while having selected a different or no database. If you need cross database updates to work, make sure you have 3.23.28 or later, and use replicate-wild-do-table=db_name.%.",
 
3868
   0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
3869
  {"replicate-do-table", OPT_REPLICATE_DO_TABLE,
 
3870
   "Tells the slave thread to restrict replication to the specified table. To specify more than one table, use the directive multiple times, once for each table. This will work for cross-database updates, in contrast to replicate-do-db.",
 
3871
   0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
3872
  {"replicate-ignore-db", OPT_REPLICATE_IGNORE_DB,
 
3873
   "Tells the slave thread to not replicate to the specified database. To specify more than one database to ignore, use the directive multiple times, once for each database. This option will not work if you use cross database updates. If you need cross database updates to work, make sure you have 3.23.28 or later, and use replicate-wild-ignore-table=db_name.%. ",
 
3874
   0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
3875
  {"replicate-ignore-table", OPT_REPLICATE_IGNORE_TABLE,
 
3876
   "Tells the slave thread to not replicate to the specified table. To specify more than one table to ignore, use the directive multiple times, once for each table. This will work for cross-datbase updates, in contrast to replicate-ignore-db.",
 
3877
   0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
3878
  {"replicate-rewrite-db", OPT_REPLICATE_REWRITE_DB,
 
3879
   "Updates to a database with a different name than the original. Example: replicate-rewrite-db=master_db_name->slave_db_name.",
 
3880
   0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
3881
  {"replicate-same-server-id", OPT_REPLICATE_SAME_SERVER_ID,
 
3882
   "In replication, if set to 1, do not skip events having our server id. \
 
3883
Default value is 0 (to break infinite loops in circular replication). \
 
3884
Can't be set to 1 if --log-slave-updates is used.",
 
3885
   (uchar**) &replicate_same_server_id,
 
3886
   (uchar**) &replicate_same_server_id,
 
3887
   0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
 
3888
  {"replicate-wild-do-table", OPT_REPLICATE_WILD_DO_TABLE,
 
3889
   "Tells the slave thread to restrict replication to the tables that match the specified wildcard pattern. To specify more than one table, use the directive multiple times, once for each table. This will work for cross-database updates. Example: replicate-wild-do-table=foo%.bar% will replicate only updates to tables in all databases that start with foo and whose table names start with bar.",
 
3890
   0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
3891
  {"replicate-wild-ignore-table", OPT_REPLICATE_WILD_IGNORE_TABLE,
 
3892
   "Tells the slave thread to not replicate to the tables that match the given wildcard pattern. To specify more than one table to ignore, use the directive multiple times, once for each table. This will work for cross-database updates. Example: replicate-wild-ignore-table=foo%.bar% will not do updates to tables in databases that start with foo and whose table names start with bar.",
 
3893
   0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
3894
  // In replication, we may need to tell the other servers how to connect
 
3895
  {"report-host", OPT_REPORT_HOST,
 
3896
   "Hostname or IP of the slave to be reported to to the master during slave registration. Will appear in the output of SHOW SLAVE HOSTS. Leave unset if you do not want the slave to register itself with the master. Note that it is not sufficient for the master to simply read the IP of the slave off the socket once the slave connects. Due to NAT and other routing issues, that IP may not be valid for connecting to the slave from the master or other hosts.",
 
3897
   (uchar**) &report_host, (uchar**) &report_host, 0, GET_STR, REQUIRED_ARG, 0, 0,
 
3898
   0, 0, 0, 0},
 
3899
  {"report-password", OPT_REPORT_PASSWORD, "Undocumented.",
 
3900
   (uchar**) &report_password, (uchar**) &report_password, 0, GET_STR,
 
3901
   REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
3902
  {"report-port", OPT_REPORT_PORT,
 
3903
   "Port for connecting to slave reported to the master during slave registration. Set it only if the slave is listening on a non-default port or if you have a special tunnel from the master or other clients to the slave. If not sure, leave this option unset.",
 
3904
   (uchar**) &report_port, (uchar**) &report_port, 0, GET_UINT, REQUIRED_ARG,
 
3905
   MYSQL_PORT, 0, 0, 0, 0, 0},
 
3906
  {"safe-mode", OPT_SAFE, "Skip some optimize stages (for testing).",
 
3907
   0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
1820
3908
  {"secure-file-priv", OPT_SECURE_FILE_PRIV,
1821
 
   N_("Limit LOAD DATA, SELECT ... OUTFILE, and LOAD_FILE() to files "
1822
 
      "within specified directory"),
1823
 
   NULL, NULL, 0,
 
3909
   "Limit LOAD DATA, SELECT ... OUTFILE, and LOAD_FILE() to files within specified directory",
 
3910
   (uchar**) &opt_secure_file_priv, (uchar**) &opt_secure_file_priv, 0,
1824
3911
   GET_STR_ALLOC, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
1825
3912
  {"server-id", OPT_SERVER_ID,
1826
 
   N_("Uniquely identifies the server instance in the community of "
1827
 
      "replication partners."),
1828
 
   (char**) &server_id, (char**) &server_id, 0, GET_UINT32, REQUIRED_ARG, 0, 0, 0,
 
3913
   "Uniquely identifies the server instance in the community of replication partners.",
 
3914
   (uchar**) &server_id, (uchar**) &server_id, 0, GET_ULONG, REQUIRED_ARG, 0, 0, 0,
1829
3915
   0, 0, 0},
 
3916
  {"set-variable", 'O',
 
3917
   "Change the value of a variable. Please note that this option is deprecated;you can set variables directly with --variable-name=value.",
 
3918
   0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
3919
  {"skip-new", OPT_SKIP_NEW, "Don't use new, possible wrong routines.",
 
3920
   0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
 
3921
  {"skip-slave-start", OPT_SKIP_SLAVE_START,
 
3922
   "If set, slave is not autostarted.", (uchar**) &opt_skip_slave_start,
 
3923
   (uchar**) &opt_skip_slave_start, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
1830
3924
  {"skip-stack-trace", OPT_SKIP_STACK_TRACE,
1831
 
   N_("Don't print a stack trace on failure."),
1832
 
   0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0,
 
3925
   "Don't print a stack trace on failure.", 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0,
1833
3926
   0, 0, 0, 0},
1834
 
  {"symbolic-links", 's',
1835
 
   N_("Enable symbolic link support."),
1836
 
   (char**) &internal::my_use_symdir, (char**) &internal::my_use_symdir, 0, GET_BOOL, NO_ARG,
 
3927
  {"skip-symlink", OPT_SKIP_SYMLINKS, "Don't allow symlinking of tables. Deprecated option.  Use --skip-symbolic-links instead.",
 
3928
   0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
 
3929
  {"skip-thread-priority", OPT_SKIP_PRIOR,
 
3930
   "Don't give threads different priorities.", 0, 0, 0, GET_NO_ARG, NO_ARG,
 
3931
   DEFAULT_SKIP_THREAD_PRIORITY, 0, 0, 0, 0, 0},
 
3932
  {"slave-load-tmpdir", OPT_SLAVE_LOAD_TMPDIR,
 
3933
   "The location where the slave should put its temporary files when \
 
3934
replicating a LOAD DATA INFILE command.",
 
3935
   (uchar**) &slave_load_tmpdir, (uchar**) &slave_load_tmpdir, 0, GET_STR_ALLOC,
 
3936
   REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
3937
  {"slave-skip-errors", OPT_SLAVE_SKIP_ERRORS,
 
3938
   "Tells the slave thread to continue replication when a query event returns an error from the provided list.",
 
3939
   0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
3940
  {"slave-exec-mode", OPT_SLAVE_EXEC_MODE,
 
3941
   "Modes for how replication events should be executed.  Legal values are STRICT (default) and IDEMPOTENT. In IDEMPOTENT mode, replication will not stop for operations that are idempotent. In STRICT mode, replication will stop on any unexpected difference between the master and the slave.",
 
3942
   (uchar**) &slave_exec_mode_str, (uchar**) &slave_exec_mode_str, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
3943
  {"slow-query-log", OPT_SLOW_LOG,
 
3944
   "Enable|disable slow query log", (uchar**) &opt_slow_log,
 
3945
   (uchar**) &opt_slow_log, 0, GET_BOOL, OPT_ARG, 0, 0, 0, 0, 0, 0},
 
3946
  {"sporadic-binlog-dump-fail", OPT_SPORADIC_BINLOG_DUMP_FAIL,
 
3947
   "Option used by mysql-test for debugging and testing of replication.",
 
3948
   (uchar**) &opt_sporadic_binlog_dump_fail,
 
3949
   (uchar**) &opt_sporadic_binlog_dump_fail, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0,
 
3950
   0},
 
3951
  {"sql-bin-update-same", OPT_SQL_BIN_UPDATE_SAME,
 
3952
   "The update log is deprecated since version 5.0, is replaced by the binary \
 
3953
log and this option does nothing anymore.",
 
3954
   0, 0, 0, GET_DISABLED, NO_ARG, 0, 0, 0, 0, 0, 0},
 
3955
  {"symbolic-links", 's', "Enable symbolic link support.",
 
3956
   (uchar**) &my_use_symdir, (uchar**) &my_use_symdir, 0, GET_BOOL, NO_ARG,
1837
3957
   /*
1838
3958
     The system call realpath() produces warnings under valgrind and
1839
3959
     purify. These are not suppressed: instead we disable symlinks
1840
3960
     option if compiled with valgrind support.
1841
3961
   */
1842
3962
   IF_PURIFY(0,1), 0, 0, 0, 0, 0},
 
3963
  {"sysdate-is-now", OPT_SYSDATE_IS_NOW,
 
3964
   "Non-default option to alias SYSDATE() to NOW() to make it safe-replicable. Since 5.0, SYSDATE() returns a `dynamic' value different for different invocations, even within the same statement.",
 
3965
   (uchar**) &global_system_variables.sysdate_is_now,
 
3966
   0, 0, GET_BOOL, NO_ARG, 0, 0, 1, 0, 1, 0},
 
3967
  {"tc-heuristic-recover", OPT_TC_HEURISTIC_RECOVER,
 
3968
   "Decision to use in heuristic recover process. Possible values are COMMIT or ROLLBACK.",
 
3969
   (uchar**) &opt_tc_heuristic_recover, (uchar**) &opt_tc_heuristic_recover,
 
3970
   0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
3971
  {"temp-pool", OPT_TEMP_POOL,
 
3972
   "Using this option will cause most temporary files created to use a small set of names, rather than a unique name for each new file.",
 
3973
   (uchar**) &use_temp_pool, (uchar**) &use_temp_pool, 0, GET_BOOL, NO_ARG, 1,
 
3974
   0, 0, 0, 0, 0},
1843
3975
  {"timed_mutexes", OPT_TIMED_MUTEXES,
1844
 
   N_("Specify whether to time mutexes (only InnoDB mutexes are currently "
1845
 
      "supported)"),
1846
 
   (char**) &internal::timed_mutexes, (char**) &internal::timed_mutexes, 0, GET_BOOL, NO_ARG, 0,
 
3976
   "Specify whether to time mutexes (only InnoDB mutexes are currently supported)",
 
3977
   (uchar**) &timed_mutexes, (uchar**) &timed_mutexes, 0, GET_BOOL, NO_ARG, 0, 
1847
3978
    0, 0, 0, 0, 0},
1848
3979
  {"tmpdir", 't',
1849
 
   N_("Path for temporary files."),
1850
 
   (char**) &opt_drizzle_tmpdir,
1851
 
   (char**) &opt_drizzle_tmpdir, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
3980
   "Path for temporary files. Several paths may be specified, separated by a "
 
3981
   "colon (:)"
 
3982
   ", in this case they are used in a round-robin fashion.",
 
3983
   (uchar**) &opt_mysql_tmpdir,
 
3984
   (uchar**) &opt_mysql_tmpdir, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
1852
3985
  {"transaction-isolation", OPT_TX_ISOLATION,
1853
 
   N_("Default transaction isolation level."),
1854
 
   0, 0, 0, GET_STR, REQUIRED_ARG, 0,
 
3986
   "Default transaction isolation level.", 0, 0, 0, GET_STR, REQUIRED_ARG, 0,
1855
3987
   0, 0, 0, 0, 0},
1856
 
  {"user", 'u',
1857
 
   N_("Run drizzled daemon as user."),
1858
 
   0, 0, 0, GET_STR, REQUIRED_ARG,
 
3988
  {"use-symbolic-links", 's', "Enable symbolic link support. Deprecated option; use --symbolic-links instead.",
 
3989
   (uchar**) &my_use_symdir, (uchar**) &my_use_symdir, 0, GET_BOOL, NO_ARG,
 
3990
   IF_PURIFY(0,1), 0, 0, 0, 0, 0},
 
3991
  {"user", 'u', "Run mysqld daemon as user.", 0, 0, 0, GET_STR, REQUIRED_ARG,
1859
3992
   0, 0, 0, 0, 0, 0},
1860
 
  {"version", 'V',
1861
 
   N_("Output version information and exit."),
1862
 
   0, 0, 0, GET_NO_ARG,
 
3993
  {"verbose", 'v', "Used with --help option for detailed help",
 
3994
   (uchar**) &opt_verbose, (uchar**) &opt_verbose, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0,
 
3995
   0, 0},
 
3996
  {"version", 'V', "Output version information and exit.", 0, 0, 0, GET_NO_ARG,
1863
3997
   NO_ARG, 0, 0, 0, 0, 0, 0},
1864
 
  {"back_log", OPT_BACK_LOG,
1865
 
   N_("The number of outstanding connection requests Drizzle can have. This "
1866
 
      "comes into play when the main Drizzle thread gets very many connection "
1867
 
      "requests in a very short time."),
1868
 
    (char**) &back_log, (char**) &back_log, 0, GET_UINT,
 
3998
  {"warnings", 'W', "Deprecated; use --log-warnings instead.",
 
3999
   (uchar**) &global_system_variables.log_warnings,
 
4000
   (uchar**) &max_system_variables.log_warnings, 0, GET_ULONG, OPT_ARG,
 
4001
   1, 0, ULONG_MAX, 0, 0, 0},
 
4002
  { "back_log", OPT_BACK_LOG,
 
4003
    "The number of outstanding connection requests MySQL can have. This comes into play when the main MySQL thread gets very many connection requests in a very short time.",
 
4004
    (uchar**) &back_log, (uchar**) &back_log, 0, GET_ULONG,
1869
4005
    REQUIRED_ARG, 50, 1, 65535, 0, 1, 0 },
1870
 
  { "bulk_insert_buffer_size", OPT_BULK_INSERT_BUFFER_SIZE,
1871
 
    N_("Size of tree cache used in bulk insert optimization. Note that this is "
1872
 
       "a limit per thread!"),
1873
 
    (char**) &global_system_variables.bulk_insert_buff_size,
1874
 
    (char**) &max_system_variables.bulk_insert_buff_size,
1875
 
    0, GET_ULL, REQUIRED_ARG, 8192*1024, 0, ULONG_MAX, 0, 1, 0},
1876
 
  { "div_precision_increment", OPT_DIV_PRECINCREMENT,
1877
 
   N_("Precision of the result of '/' operator will be increased on that "
1878
 
      "value."),
1879
 
   (char**) &global_system_variables.div_precincrement,
1880
 
   (char**) &max_system_variables.div_precincrement, 0, GET_UINT,
 
4006
  {"binlog_cache_size", OPT_BINLOG_CACHE_SIZE,
 
4007
   "The size of the cache to hold the SQL statements for the binary log during a transaction. If you often use big, multi-statement transactions you can increase this to get more performance.",
 
4008
   (uchar**) &binlog_cache_size, (uchar**) &binlog_cache_size, 0, GET_ULONG,
 
4009
   REQUIRED_ARG, 32*1024L, IO_SIZE, ULONG_MAX, 0, IO_SIZE, 0},
 
4010
  {"bulk_insert_buffer_size", OPT_BULK_INSERT_BUFFER_SIZE,
 
4011
   "Size of tree cache used in bulk insert optimisation. Note that this is a limit per thread!",
 
4012
   (uchar**) &global_system_variables.bulk_insert_buff_size,
 
4013
   (uchar**) &max_system_variables.bulk_insert_buff_size,
 
4014
   0, GET_ULONG, REQUIRED_ARG, 8192*1024, 0, ULONG_MAX, 0, 1, 0},
 
4015
  {"connect_timeout", OPT_CONNECT_TIMEOUT,
 
4016
   "The number of seconds the mysqld server is waiting for a connect packet before responding with 'Bad handshake'.",
 
4017
    (uchar**) &connect_timeout, (uchar**) &connect_timeout,
 
4018
   0, GET_ULONG, REQUIRED_ARG, CONNECT_TIMEOUT, 2, LONG_TIMEOUT, 0, 1, 0 },
 
4019
  { "date_format", OPT_DATE_FORMAT,
 
4020
    "The DATE format (For future).",
 
4021
    (uchar**) &opt_date_time_formats[MYSQL_TIMESTAMP_DATE],
 
4022
    (uchar**) &opt_date_time_formats[MYSQL_TIMESTAMP_DATE],
 
4023
    0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
4024
  { "datetime_format", OPT_DATETIME_FORMAT,
 
4025
    "The DATETIME/TIMESTAMP format (for future).",
 
4026
    (uchar**) &opt_date_time_formats[MYSQL_TIMESTAMP_DATETIME],
 
4027
    (uchar**) &opt_date_time_formats[MYSQL_TIMESTAMP_DATETIME],
 
4028
    0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
4029
  { "default_week_format", OPT_DEFAULT_WEEK_FORMAT,
 
4030
    "The default week format used by WEEK() functions.",
 
4031
    (uchar**) &global_system_variables.default_week_format,
 
4032
    (uchar**) &max_system_variables.default_week_format,
 
4033
    0, GET_ULONG, REQUIRED_ARG, 0, 0, 7L, 0, 1, 0},
 
4034
  {"div_precision_increment", OPT_DIV_PRECINCREMENT,
 
4035
   "Precision of the result of '/' operator will be increased on that value.",
 
4036
   (uchar**) &global_system_variables.div_precincrement,
 
4037
   (uchar**) &max_system_variables.div_precincrement, 0, GET_ULONG,
1881
4038
   REQUIRED_ARG, 4, 0, DECIMAL_MAX_SCALE, 0, 0, 0},
 
4039
  {"expire_logs_days", OPT_EXPIRE_LOGS_DAYS,
 
4040
   "If non-zero, binary logs will be purged after expire_logs_days "
 
4041
   "days; possible purges happen at startup and at binary log rotation.",
 
4042
   (uchar**) &expire_logs_days,
 
4043
   (uchar**) &expire_logs_days, 0, GET_ULONG,
 
4044
   REQUIRED_ARG, 0, 0, 99, 0, 1, 0},
 
4045
  { "flush_time", OPT_FLUSH_TIME,
 
4046
    "A dedicated thread is created to flush all tables at the given interval.",
 
4047
    (uchar**) &flush_time, (uchar**) &flush_time, 0, GET_ULONG, REQUIRED_ARG,
 
4048
    FLUSH_TIME, 0, LONG_TIMEOUT, 0, 1, 0},
1882
4049
  { "group_concat_max_len", OPT_GROUP_CONCAT_MAX_LEN,
1883
 
    N_("The maximum length of the result of function  group_concat."),
1884
 
    (char**) &global_system_variables.group_concat_max_len,
1885
 
    (char**) &max_system_variables.group_concat_max_len, 0, GET_UINT64,
 
4050
    "The maximum length of the result of function  group_concat.",
 
4051
    (uchar**) &global_system_variables.group_concat_max_len,
 
4052
    (uchar**) &max_system_variables.group_concat_max_len, 0, GET_ULONG,
1886
4053
    REQUIRED_ARG, 1024, 4, ULONG_MAX, 0, 1, 0},
1887
 
  { "join_buffer_size", OPT_JOIN_BUFF_SIZE,
1888
 
    N_("The size of the buffer that is used for full joins."),
1889
 
   (char**) &global_system_variables.join_buff_size,
1890
 
   (char**) &max_system_variables.join_buff_size, 0, GET_UINT64,
 
4054
  {"interactive_timeout", OPT_INTERACTIVE_TIMEOUT,
 
4055
   "The number of seconds the server waits for activity on an interactive connection before closing it.",
 
4056
   (uchar**) &global_system_variables.net_interactive_timeout,
 
4057
   (uchar**) &max_system_variables.net_interactive_timeout, 0,
 
4058
   GET_ULONG, REQUIRED_ARG, NET_WAIT_TIMEOUT, 1, LONG_TIMEOUT, 0, 1, 0},
 
4059
  {"join_buffer_size", OPT_JOIN_BUFF_SIZE,
 
4060
   "The size of the buffer that is used for full joins.",
 
4061
   (uchar**) &global_system_variables.join_buff_size,
 
4062
   (uchar**) &max_system_variables.join_buff_size, 0, GET_ULONG,
1891
4063
   REQUIRED_ARG, 128*1024L, IO_SIZE*2+MALLOC_OVERHEAD, ULONG_MAX,
1892
4064
   MALLOC_OVERHEAD, IO_SIZE, 0},
 
4065
  {"keep_files_on_create", OPT_KEEP_FILES_ON_CREATE,
 
4066
   "Don't overwrite stale .MYD and .MYI even if no directory is specified.",
 
4067
   (uchar**) &global_system_variables.keep_files_on_create,
 
4068
   (uchar**) &max_system_variables.keep_files_on_create,
 
4069
   0, GET_BOOL, OPT_ARG, 0, 0, 0, 0, 0, 0},
 
4070
  {"key_buffer_size", OPT_KEY_BUFFER_SIZE,
 
4071
   "The size of the buffer used for index blocks for MyISAM tables. Increase this to get better index handling (for all reads and multiple writes) to as much as you can afford; 64M on a 256M machine that mainly runs MySQL is quite common.",
 
4072
   (uchar**) &dflt_key_cache_var.param_buff_size,
 
4073
   (uchar**) 0,
 
4074
   0, (GET_ULL | GET_ASK_ADDR),
 
4075
   REQUIRED_ARG, KEY_CACHE_SIZE, MALLOC_OVERHEAD, SIZE_T_MAX, MALLOC_OVERHEAD,
 
4076
   IO_SIZE, 0},
 
4077
  {"key_cache_age_threshold", OPT_KEY_CACHE_AGE_THRESHOLD,
 
4078
   "This characterizes the number of hits a hot block has to be untouched until it is considered aged enough to be downgraded to a warm block. This specifies the percentage ratio of that number of hits to the total number of blocks in key cache",
 
4079
   (uchar**) &dflt_key_cache_var.param_age_threshold,
 
4080
   (uchar**) 0,
 
4081
   0, (GET_ULONG | GET_ASK_ADDR), REQUIRED_ARG, 
 
4082
   300, 100, ULONG_MAX, 0, 100, 0},
 
4083
  {"key_cache_block_size", OPT_KEY_CACHE_BLOCK_SIZE,
 
4084
   "The default size of key cache blocks",
 
4085
   (uchar**) &dflt_key_cache_var.param_block_size,
 
4086
   (uchar**) 0,
 
4087
   0, (GET_ULONG | GET_ASK_ADDR), REQUIRED_ARG,
 
4088
   KEY_CACHE_BLOCK_SIZE, 512, 1024 * 16, 0, 512, 0},
 
4089
  {"key_cache_division_limit", OPT_KEY_CACHE_DIVISION_LIMIT,
 
4090
   "The minimum percentage of warm blocks in key cache",
 
4091
   (uchar**) &dflt_key_cache_var.param_division_limit,
 
4092
   (uchar**) 0,
 
4093
   0, (GET_ULONG | GET_ASK_ADDR) , REQUIRED_ARG, 100,
 
4094
   1, 100, 0, 1, 0},
 
4095
  {"long_query_time", OPT_LONG_QUERY_TIME,
 
4096
   "Log all queries that have taken more than long_query_time seconds to execute to file. "
 
4097
   "The argument will be treated as a decimal value with microsecond precission.",
 
4098
   (uchar**) &long_query_time, (uchar**) &long_query_time, 0, GET_DOUBLE,
 
4099
   REQUIRED_ARG, 10, 0, LONG_TIMEOUT, 0, 0, 0},
 
4100
  {"lower_case_table_names", OPT_LOWER_CASE_TABLE_NAMES,
 
4101
   "If set to 1 table names are stored in lowercase on disk and table names will be case-insensitive.  Should be set to 2 if you are using a case insensitive file system",
 
4102
   (uchar**) &lower_case_table_names,
 
4103
   (uchar**) &lower_case_table_names, 0, GET_UINT, OPT_ARG,
 
4104
#ifdef FN_NO_CASE_SENCE
 
4105
    1
 
4106
#else
 
4107
    0
 
4108
#endif
 
4109
   , 0, 2, 0, 1, 0},
1893
4110
  {"max_allowed_packet", OPT_MAX_ALLOWED_PACKET,
1894
 
   N_("Max packetlength to send/receive from to server."),
1895
 
   (char**) &global_system_variables.max_allowed_packet,
1896
 
   (char**) &max_system_variables.max_allowed_packet, 0, GET_UINT32,
1897
 
   REQUIRED_ARG, 64*1024*1024L, 1024, 1024L*1024L*1024L, MALLOC_OVERHEAD, 1024, 0},
 
4111
   "Max packetlength to send/receive from to server.",
 
4112
   (uchar**) &global_system_variables.max_allowed_packet,
 
4113
   (uchar**) &max_system_variables.max_allowed_packet, 0, GET_ULONG,
 
4114
   REQUIRED_ARG, 1024*1024L, 1024, 1024L*1024L*1024L, MALLOC_OVERHEAD, 1024, 0},
 
4115
  {"max_binlog_cache_size", OPT_MAX_BINLOG_CACHE_SIZE,
 
4116
   "Can be used to restrict the total size used to cache a multi-transaction query.",
 
4117
   (uchar**) &max_binlog_cache_size, (uchar**) &max_binlog_cache_size, 0,
 
4118
   GET_ULONG, REQUIRED_ARG, ULONG_MAX, IO_SIZE, ULONG_MAX, 0, IO_SIZE, 0},
 
4119
  {"max_binlog_size", OPT_MAX_BINLOG_SIZE,
 
4120
   "Binary log will be rotated automatically when the size exceeds this \
 
4121
value. Will also apply to relay logs if max_relay_log_size is 0. \
 
4122
The minimum value for this variable is 4096.",
 
4123
   (uchar**) &max_binlog_size, (uchar**) &max_binlog_size, 0, GET_ULONG,
 
4124
   REQUIRED_ARG, 1024*1024L*1024L, IO_SIZE, 1024*1024L*1024L, 0, IO_SIZE, 0},
1898
4125
  {"max_connect_errors", OPT_MAX_CONNECT_ERRORS,
1899
 
   N_("If there is more than this number of interrupted connections from a "
1900
 
      "host this host will be blocked from further connections."),
1901
 
   (char**) &max_connect_errors, (char**) &max_connect_errors, 0, GET_UINT64,
1902
 
   REQUIRED_ARG, MAX_CONNECT_ERRORS, 1, ULONG_MAX, 0, 1, 0},
 
4126
   "If there is more than this number of interrupted connections from a host this host will be blocked from further connections.",
 
4127
   (uchar**) &max_connect_errors, (uchar**) &max_connect_errors, 0, GET_ULONG,
 
4128
    REQUIRED_ARG, MAX_CONNECT_ERRORS, 1, ULONG_MAX, 0, 1, 0},
 
4129
  // Default max_connections of 151 is larger than Apache's default max
 
4130
  // children, to avoid "too many connections" error in a common setup
 
4131
  {"max_connections", OPT_MAX_CONNECTIONS,
 
4132
   "The number of simultaneous clients allowed.", (uchar**) &max_connections,
 
4133
   (uchar**) &max_connections, 0, GET_ULONG, REQUIRED_ARG, 151, 1, 100000, 0, 1,
 
4134
   0},
1903
4135
  {"max_error_count", OPT_MAX_ERROR_COUNT,
1904
 
   N_("Max number of errors/warnings to store for a statement."),
1905
 
   (char**) &global_system_variables.max_error_count,
1906
 
   (char**) &max_system_variables.max_error_count,
1907
 
   0, GET_UINT64, REQUIRED_ARG, DEFAULT_ERROR_COUNT, 0, 65535, 0, 1, 0},
 
4136
   "Max number of errors/warnings to store for a statement.",
 
4137
   (uchar**) &global_system_variables.max_error_count,
 
4138
   (uchar**) &max_system_variables.max_error_count,
 
4139
   0, GET_ULONG, REQUIRED_ARG, DEFAULT_ERROR_COUNT, 0, 65535, 0, 1, 0},
1908
4140
  {"max_heap_table_size", OPT_MAX_HEP_TABLE_SIZE,
1909
 
   N_("Don't allow creation of heap tables bigger than this."),
1910
 
   (char**) &global_system_variables.max_heap_table_size,
1911
 
   (char**) &max_system_variables.max_heap_table_size, 0, GET_ULL,
1912
 
   REQUIRED_ARG, 16*1024*1024L, 16384, (int64_t)MAX_MEM_TABLE_SIZE,
 
4141
   "Don't allow creation of heap tables bigger than this.",
 
4142
   (uchar**) &global_system_variables.max_heap_table_size,
 
4143
   (uchar**) &max_system_variables.max_heap_table_size, 0, GET_ULL,
 
4144
   REQUIRED_ARG, 16*1024*1024L, 16384, MAX_MEM_TABLE_SIZE,
1913
4145
   MALLOC_OVERHEAD, 1024, 0},
1914
4146
  {"max_join_size", OPT_MAX_JOIN_SIZE,
1915
 
   N_("Joins that are probably going to read more than max_join_size records "
1916
 
      "return an error."),
1917
 
   (char**) &global_system_variables.max_join_size,
1918
 
   (char**) &max_system_variables.max_join_size, 0, GET_HA_ROWS, REQUIRED_ARG,
1919
 
   INT32_MAX, 1, INT32_MAX, 0, 1, 0},
1920
 
  {"max_length_for_sort_data", OPT_MAX_LENGTH_FOR_SORT_DATA,
1921
 
   N_("Max number of bytes in sorted records."),
1922
 
   (char**) &global_system_variables.max_length_for_sort_data,
1923
 
   (char**) &max_system_variables.max_length_for_sort_data, 0, GET_ULL,
1924
 
   REQUIRED_ARG, 1024, 4, 8192*1024L, 0, 1, 0},
 
4147
   "Joins that are probably going to read more than max_join_size records return an error.",
 
4148
   (uchar**) &global_system_variables.max_join_size,
 
4149
   (uchar**) &max_system_variables.max_join_size, 0, GET_HA_ROWS, REQUIRED_ARG,
 
4150
   ~0L, 1, ~0L, 0, 1, 0},
 
4151
   {"max_length_for_sort_data", OPT_MAX_LENGTH_FOR_SORT_DATA,
 
4152
    "Max number of bytes in sorted records.",
 
4153
    (uchar**) &global_system_variables.max_length_for_sort_data,
 
4154
    (uchar**) &max_system_variables.max_length_for_sort_data, 0, GET_ULONG,
 
4155
    REQUIRED_ARG, 1024, 4, 8192*1024L, 0, 1, 0},
 
4156
  {"max_relay_log_size", OPT_MAX_RELAY_LOG_SIZE,
 
4157
   "If non-zero: relay log will be rotated automatically when the size exceeds this value; if zero (the default): when the size exceeds max_binlog_size. 0 excepted, the minimum value for this variable is 4096.",
 
4158
   (uchar**) &max_relay_log_size, (uchar**) &max_relay_log_size, 0, GET_ULONG,
 
4159
   REQUIRED_ARG, 0L, 0L, 1024*1024L*1024L, 0, IO_SIZE, 0},
1925
4160
  { "max_seeks_for_key", OPT_MAX_SEEKS_FOR_KEY,
1926
 
    N_("Limit assumed max number of seeks when looking up rows based on a key"),
1927
 
    (char**) &global_system_variables.max_seeks_for_key,
1928
 
    (char**) &max_system_variables.max_seeks_for_key, 0, GET_UINT64,
 
4161
    "Limit assumed max number of seeks when looking up rows based on a key",
 
4162
    (uchar**) &global_system_variables.max_seeks_for_key,
 
4163
    (uchar**) &max_system_variables.max_seeks_for_key, 0, GET_ULONG,
1929
4164
    REQUIRED_ARG, ULONG_MAX, 1, ULONG_MAX, 0, 1, 0 },
1930
4165
  {"max_sort_length", OPT_MAX_SORT_LENGTH,
1931
 
   N_("The number of bytes to use when sorting BLOB or TEXT values "
1932
 
      "(only the first max_sort_length bytes of each value are used; the "
1933
 
      "rest are ignored)."),
1934
 
   (char**) &global_system_variables.max_sort_length,
1935
 
   (char**) &max_system_variables.max_sort_length, 0, GET_SIZE,
 
4166
   "The number of bytes to use when sorting BLOB or TEXT values (only the first max_sort_length bytes of each value are used; the rest are ignored).",
 
4167
   (uchar**) &global_system_variables.max_sort_length,
 
4168
   (uchar**) &max_system_variables.max_sort_length, 0, GET_ULONG,
1936
4169
   REQUIRED_ARG, 1024, 4, 8192*1024L, 0, 1, 0},
 
4170
  {"max_tmp_tables", OPT_MAX_TMP_TABLES,
 
4171
   "Maximum number of temporary tables a client can keep open at a time.",
 
4172
   (uchar**) &global_system_variables.max_tmp_tables,
 
4173
   (uchar**) &max_system_variables.max_tmp_tables, 0, GET_ULONG,
 
4174
   REQUIRED_ARG, 32, 1, ULONG_MAX, 0, 1, 0},
1937
4175
  {"max_write_lock_count", OPT_MAX_WRITE_LOCK_COUNT,
1938
 
   N_("After this many write locks, allow some read locks to run in between."),
1939
 
   (char**) &max_write_lock_count, (char**) &max_write_lock_count, 0, GET_ULL,
 
4176
   "After this many write locks, allow some read locks to run in between.",
 
4177
   (uchar**) &max_write_lock_count, (uchar**) &max_write_lock_count, 0, GET_ULONG,
1940
4178
   REQUIRED_ARG, ULONG_MAX, 1, ULONG_MAX, 0, 1, 0},
1941
4179
  {"min_examined_row_limit", OPT_MIN_EXAMINED_ROW_LIMIT,
1942
 
   N_("Don't log queries which examine less than min_examined_row_limit "
1943
 
      "rows to file."),
1944
 
   (char**) &global_system_variables.min_examined_row_limit,
1945
 
   (char**) &max_system_variables.min_examined_row_limit, 0, GET_ULL,
1946
 
   REQUIRED_ARG, 0, 0, ULONG_MAX, 0, 1L, 0},
 
4180
   "Don't log queries which examine less than min_examined_row_limit rows to file.",
 
4181
   (uchar**) &global_system_variables.min_examined_row_limit,
 
4182
   (uchar**) &max_system_variables.min_examined_row_limit, 0, GET_ULONG,
 
4183
  REQUIRED_ARG, 0, 0, ULONG_MAX, 0, 1L, 0},
 
4184
  {"myisam_block_size", OPT_MYISAM_BLOCK_SIZE,
 
4185
   "Block size to be used for MyISAM index pages.",
 
4186
   (uchar**) &opt_myisam_block_size,
 
4187
   (uchar**) &opt_myisam_block_size, 0, GET_ULONG, REQUIRED_ARG,
 
4188
   MI_KEY_BLOCK_LENGTH, MI_MIN_KEY_BLOCK_LENGTH, MI_MAX_KEY_BLOCK_LENGTH,
 
4189
   0, MI_MIN_KEY_BLOCK_LENGTH, 0},
 
4190
  {"myisam_data_pointer_size", OPT_MYISAM_DATA_POINTER_SIZE,
 
4191
   "Default pointer size to be used for MyISAM tables.",
 
4192
   (uchar**) &myisam_data_pointer_size,
 
4193
   (uchar**) &myisam_data_pointer_size, 0, GET_ULONG, REQUIRED_ARG,
 
4194
   6, 2, 7, 0, 1, 0},
 
4195
  {"myisam_max_extra_sort_file_size", OPT_MYISAM_MAX_EXTRA_SORT_FILE_SIZE,
 
4196
   "Deprecated option",
 
4197
   (uchar**) &global_system_variables.myisam_max_extra_sort_file_size,
 
4198
   (uchar**) &max_system_variables.myisam_max_extra_sort_file_size,
 
4199
   0, GET_ULL, REQUIRED_ARG, (ulonglong) MI_MAX_TEMP_LENGTH,
 
4200
   0, (ulonglong) MAX_FILE_SIZE, 0, 1, 0},
 
4201
  {"myisam_max_sort_file_size", OPT_MYISAM_MAX_SORT_FILE_SIZE,
 
4202
   "Don't use the fast sort index method to created index if the temporary file would get bigger than this.",
 
4203
   (uchar**) &global_system_variables.myisam_max_sort_file_size,
 
4204
   (uchar**) &max_system_variables.myisam_max_sort_file_size, 0,
 
4205
   GET_ULL, REQUIRED_ARG, (longlong) LONG_MAX, 0, (ulonglong) MAX_FILE_SIZE,
 
4206
   0, 1024*1024, 0},
 
4207
  {"myisam_repair_threads", OPT_MYISAM_REPAIR_THREADS,
 
4208
   "Number of threads to use when repairing MyISAM tables. The value of 1 disables parallel repair.",
 
4209
   (uchar**) &global_system_variables.myisam_repair_threads,
 
4210
   (uchar**) &max_system_variables.myisam_repair_threads, 0,
 
4211
   GET_ULONG, REQUIRED_ARG, 1, 1, ULONG_MAX, 0, 1, 0},
 
4212
  {"myisam_sort_buffer_size", OPT_MYISAM_SORT_BUFFER_SIZE,
 
4213
   "The buffer that is allocated when sorting the index when doing a REPAIR or when creating indexes with CREATE INDEX or ALTER TABLE.",
 
4214
   (uchar**) &global_system_variables.myisam_sort_buff_size,
 
4215
   (uchar**) &max_system_variables.myisam_sort_buff_size, 0,
 
4216
   GET_ULONG, REQUIRED_ARG, 8192*1024, 4, ~0L, 0, 1, 0},
 
4217
  {"myisam_stats_method", OPT_MYISAM_STATS_METHOD,
 
4218
   "Specifies how MyISAM index statistics collection code should threat NULLs. "
 
4219
   "Possible values of name are \"nulls_unequal\" (default behavior for 4.1/5.0), "
 
4220
   "\"nulls_equal\" (emulate 4.0 behavior), and \"nulls_ignored\".",
 
4221
   (uchar**) &myisam_stats_method_str, (uchar**) &myisam_stats_method_str, 0,
 
4222
    GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
4223
  {"net_buffer_length", OPT_NET_BUFFER_LENGTH,
 
4224
   "Buffer length for TCP/IP and socket communication.",
 
4225
   (uchar**) &global_system_variables.net_buffer_length,
 
4226
   (uchar**) &max_system_variables.net_buffer_length, 0, GET_ULONG,
 
4227
   REQUIRED_ARG, 16384, 1024, 1024*1024L, 0, 1024, 0},
 
4228
  {"net_read_timeout", OPT_NET_READ_TIMEOUT,
 
4229
   "Number of seconds to wait for more data from a connection before aborting the read.",
 
4230
   (uchar**) &global_system_variables.net_read_timeout,
 
4231
   (uchar**) &max_system_variables.net_read_timeout, 0, GET_ULONG,
 
4232
   REQUIRED_ARG, NET_READ_TIMEOUT, 1, LONG_TIMEOUT, 0, 1, 0},
 
4233
  {"net_retry_count", OPT_NET_RETRY_COUNT,
 
4234
   "If a read on a communication port is interrupted, retry this many times before giving up.",
 
4235
   (uchar**) &global_system_variables.net_retry_count,
 
4236
   (uchar**) &max_system_variables.net_retry_count,0,
 
4237
   GET_ULONG, REQUIRED_ARG, MYSQLD_NET_RETRY_COUNT, 1, ULONG_MAX, 0, 1, 0},
 
4238
  {"net_write_timeout", OPT_NET_WRITE_TIMEOUT,
 
4239
   "Number of seconds to wait for a block to be written to a connection  before aborting the write.",
 
4240
   (uchar**) &global_system_variables.net_write_timeout,
 
4241
   (uchar**) &max_system_variables.net_write_timeout, 0, GET_ULONG,
 
4242
   REQUIRED_ARG, NET_WRITE_TIMEOUT, 1, LONG_TIMEOUT, 0, 1, 0},
 
4243
  { "old", OPT_OLD_MODE, "Use compatible behavior.", 
 
4244
    (uchar**) &global_system_variables.old_mode,
 
4245
    (uchar**) &max_system_variables.old_mode, 0, GET_BOOL, NO_ARG, 
 
4246
    0, 0, 0, 0, 0, 0},
 
4247
  {"open_files_limit", OPT_OPEN_FILES_LIMIT,
 
4248
   "If this is not 0, then mysqld will use this value to reserve file descriptors to use with setrlimit(). If this value is 0 then mysqld will reserve max_connections*5 or max_connections + table_cache*2 (whichever is larger) number of files.",
 
4249
   (uchar**) &open_files_limit, (uchar**) &open_files_limit, 0, GET_ULONG,
 
4250
   REQUIRED_ARG, 0, 0, OS_FILE_LIMIT, 0, 1, 0},
1947
4251
  {"optimizer_prune_level", OPT_OPTIMIZER_PRUNE_LEVEL,
1948
 
    N_("Controls the heuristic(s) applied during query optimization to prune "
1949
 
       "less-promising partial plans from the optimizer search space. Meaning: "
1950
 
       "false - do not apply any heuristic, thus perform exhaustive search; "
1951
 
       "true - prune plans based on number of retrieved rows."),
1952
 
    (char**) &global_system_variables.optimizer_prune_level,
1953
 
    (char**) &max_system_variables.optimizer_prune_level,
1954
 
    0, GET_BOOL, OPT_ARG, 1, 0, 1, 0, 1, 0},
 
4252
   "Controls the heuristic(s) applied during query optimization to prune less-promising partial plans from the optimizer search space. Meaning: 0 - do not apply any heuristic, thus perform exhaustive search; 1 - prune plans based on number of retrieved rows.",
 
4253
   (uchar**) &global_system_variables.optimizer_prune_level,
 
4254
   (uchar**) &max_system_variables.optimizer_prune_level,
 
4255
   0, GET_ULONG, OPT_ARG, 1, 0, 1, 0, 1, 0},
1955
4256
  {"optimizer_search_depth", OPT_OPTIMIZER_SEARCH_DEPTH,
1956
 
   N_("Maximum depth of search performed by the query optimizer. Values "
1957
 
      "larger than the number of relations in a query result in better query "
1958
 
      "plans, but take longer to compile a query. Smaller values than the "
1959
 
      "number of tables in a relation result in faster optimization, but may "
1960
 
      "produce very bad query plans. If set to 0, the system will "
1961
 
      "automatically pick a reasonable value; if set to MAX_TABLES+2, the "
1962
 
      "optimizer will switch to the original find_best (used for "
1963
 
      "testing/comparison)."),
1964
 
   (char**) &global_system_variables.optimizer_search_depth,
1965
 
   (char**) &max_system_variables.optimizer_search_depth,
1966
 
   0, GET_UINT, OPT_ARG, 0, 0, MAX_TABLES+2, 0, 1, 0},
 
4257
   "Maximum depth of search performed by the query optimizer. Values larger than the number of relations in a query result in better query plans, but take longer to compile a query. Smaller values than the number of tables in a relation result in faster optimization, but may produce very bad query plans. If set to 0, the system will automatically pick a reasonable value; if set to MAX_TABLES+2, the optimizer will switch to the original find_best (used for testing/comparison).",
 
4258
   (uchar**) &global_system_variables.optimizer_search_depth,
 
4259
   (uchar**) &max_system_variables.optimizer_search_depth,
 
4260
   0, GET_ULONG, OPT_ARG, MAX_TABLES+1, 0, MAX_TABLES+2, 0, 1, 0},
1967
4261
  {"plugin_dir", OPT_PLUGIN_DIR,
1968
 
   N_("Directory for plugins."),
1969
 
   NULL, NULL, 0,
1970
 
   GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
1971
 
  {"plugin_add", OPT_PLUGIN_ADD,
1972
 
   N_("Optional comma separated list of plugins to load at startup in addition "
1973
 
      "to the default list of plugins. "
1974
 
      "[for example: --plugin_add=crc32,logger_gearman]"),
1975
 
   NULL, NULL, 0,
1976
 
   GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
1977
 
  {"plugin_remove", OPT_PLUGIN_ADD,
1978
 
   N_("Optional comma separated list of plugins to not load at startup. Effectively "
1979
 
      "removes a plugin from the list of plugins to be loaded. "
1980
 
      "[for example: --plugin_remove=crc32,logger_gearman]"),
1981
 
   NULL, NULL, 0,
 
4262
   "Directory for plugins.",
 
4263
   (uchar**) &opt_plugin_dir_ptr, (uchar**) &opt_plugin_dir_ptr, 0,
1982
4264
   GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
1983
4265
  {"plugin_load", OPT_PLUGIN_LOAD,
1984
 
   N_("Optional comma separated list of plugins to load at starup instead of "
1985
 
      "the default plugin load list. "
1986
 
      "[for example: --plugin_load=crc32,logger_gearman]"),
1987
 
   NULL, NULL, 0,
 
4266
   "Optional colon separated list of plugins to load, where each plugin is "
 
4267
   "identified by name and path to library seperated by an equals.",
 
4268
   (uchar**) &opt_plugin_load, (uchar**) &opt_plugin_load, 0,
1988
4269
   GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
1989
4270
  {"preload_buffer_size", OPT_PRELOAD_BUFFER_SIZE,
1990
 
   N_("The size of the buffer that is allocated when preloading indexes"),
1991
 
   (char**) &global_system_variables.preload_buff_size,
1992
 
   (char**) &max_system_variables.preload_buff_size, 0, GET_ULL,
 
4271
   "The size of the buffer that is allocated when preloading indexes",
 
4272
   (uchar**) &global_system_variables.preload_buff_size,
 
4273
   (uchar**) &max_system_variables.preload_buff_size, 0, GET_ULONG,
1993
4274
   REQUIRED_ARG, 32*1024L, 1024, 1024*1024*1024L, 0, 1, 0},
1994
4275
  {"query_alloc_block_size", OPT_QUERY_ALLOC_BLOCK_SIZE,
1995
 
   N_("Allocation block size for query parsing and execution"),
1996
 
   (char**) &global_system_variables.query_alloc_block_size,
1997
 
   (char**) &max_system_variables.query_alloc_block_size, 0, GET_UINT,
 
4276
   "Allocation block size for query parsing and execution",
 
4277
   (uchar**) &global_system_variables.query_alloc_block_size,
 
4278
   (uchar**) &max_system_variables.query_alloc_block_size, 0, GET_ULONG,
1998
4279
   REQUIRED_ARG, QUERY_ALLOC_BLOCK_SIZE, 1024, ULONG_MAX, 0, 1024, 0},
1999
4280
  {"query_prealloc_size", OPT_QUERY_PREALLOC_SIZE,
2000
 
   N_("Persistent buffer for query parsing and execution"),
2001
 
   (char**) &global_system_variables.query_prealloc_size,
2002
 
   (char**) &max_system_variables.query_prealloc_size, 0, GET_UINT,
 
4281
   "Persistent buffer for query parsing and execution",
 
4282
   (uchar**) &global_system_variables.query_prealloc_size,
 
4283
   (uchar**) &max_system_variables.query_prealloc_size, 0, GET_ULONG,
2003
4284
   REQUIRED_ARG, QUERY_ALLOC_PREALLOC_SIZE, QUERY_ALLOC_PREALLOC_SIZE,
2004
4285
   ULONG_MAX, 0, 1024, 0},
2005
4286
  {"range_alloc_block_size", OPT_RANGE_ALLOC_BLOCK_SIZE,
2006
 
   N_("Allocation block size for storing ranges during optimization"),
2007
 
   (char**) &global_system_variables.range_alloc_block_size,
2008
 
   (char**) &max_system_variables.range_alloc_block_size, 0, GET_SIZE,
2009
 
   REQUIRED_ARG, RANGE_ALLOC_BLOCK_SIZE, RANGE_ALLOC_BLOCK_SIZE, (int64_t)SIZE_MAX,
 
4287
   "Allocation block size for storing ranges during optimization",
 
4288
   (uchar**) &global_system_variables.range_alloc_block_size,
 
4289
   (uchar**) &max_system_variables.range_alloc_block_size, 0, GET_ULONG,
 
4290
   REQUIRED_ARG, RANGE_ALLOC_BLOCK_SIZE, RANGE_ALLOC_BLOCK_SIZE, ULONG_MAX,
2010
4291
   0, 1024, 0},
2011
4292
  {"read_buffer_size", OPT_RECORD_BUFFER,
2012
 
    N_("Each thread that does a sequential scan allocates a buffer of this "
2013
 
       "size for each table it scans. If you do many sequential scans, you may "
2014
 
       "want to increase this value."),
2015
 
    (char**) &global_system_variables.read_buff_size,
2016
 
    (char**) &max_system_variables.read_buff_size,0, GET_UINT, REQUIRED_ARG,
2017
 
    128*1024L, IO_SIZE*2+MALLOC_OVERHEAD, INT32_MAX, MALLOC_OVERHEAD, IO_SIZE,
2018
 
    0},
 
4293
   "Each thread that does a sequential scan allocates a buffer of this size for each table it scans. If you do many sequential scans, you may want to increase this value.",
 
4294
   (uchar**) &global_system_variables.read_buff_size,
 
4295
   (uchar**) &max_system_variables.read_buff_size,0, GET_ULONG, REQUIRED_ARG,
 
4296
   128*1024L, IO_SIZE*2+MALLOC_OVERHEAD, INT_MAX32, MALLOC_OVERHEAD, IO_SIZE,
 
4297
   0},
 
4298
  {"read_only", OPT_READONLY,
 
4299
   "Make all non-temporary tables read-only, with the exception for replication (slave) threads and users with the SUPER privilege",
 
4300
   (uchar**) &opt_readonly,
 
4301
   (uchar**) &opt_readonly,
 
4302
   0, GET_BOOL, NO_ARG, 0, 0, 1, 0, 1, 0},
2019
4303
  {"read_rnd_buffer_size", OPT_RECORD_RND_BUFFER,
2020
 
   N_("When reading rows in sorted order after a sort, the rows are read "
2021
 
      "through this buffer to avoid a disk seeks. If not set, then it's set "
2022
 
      "to the value of record_buffer."),
2023
 
   (char**) &global_system_variables.read_rnd_buff_size,
2024
 
   (char**) &max_system_variables.read_rnd_buff_size, 0,
2025
 
   GET_UINT, REQUIRED_ARG, 256*1024L, 64 /*IO_SIZE*2+MALLOC_OVERHEAD*/ ,
2026
 
   UINT32_MAX, MALLOC_OVERHEAD, 1 /* Small lower limit to be able to test MRR */, 0},
2027
 
  {"scheduler", OPT_SCHEDULER,
2028
 
   N_("Select scheduler to be used (by default multi-thread)."),
2029
 
   (char**)&opt_scheduler, (char**)&opt_scheduler,
2030
 
   0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
2031
 
  /* x8 compared to MySQL's x2. We have UTF8 to consider. */
 
4304
   "When reading rows in sorted order after a sort, the rows are read through this buffer to avoid a disk seeks. If not set, then it's set to the value of record_buffer.",
 
4305
   (uchar**) &global_system_variables.read_rnd_buff_size,
 
4306
   (uchar**) &max_system_variables.read_rnd_buff_size, 0,
 
4307
   GET_ULONG, REQUIRED_ARG, 256*1024L, 64 /*IO_SIZE*2+MALLOC_OVERHEAD*/ ,
 
4308
   INT_MAX32, MALLOC_OVERHEAD, 1 /* Small lower limit to be able to test MRR */, 0},
 
4309
  {"record_buffer", OPT_RECORD_BUFFER,
 
4310
   "Alias for read_buffer_size",
 
4311
   (uchar**) &global_system_variables.read_buff_size,
 
4312
   (uchar**) &max_system_variables.read_buff_size,0, GET_ULONG, REQUIRED_ARG,
 
4313
   128*1024L, IO_SIZE*2+MALLOC_OVERHEAD, INT_MAX32, MALLOC_OVERHEAD, IO_SIZE, 0},
 
4314
  {"relay_log_purge", OPT_RELAY_LOG_PURGE,
 
4315
   "0 = do not purge relay logs. 1 = purge them as soon as they are no more needed.",
 
4316
   (uchar**) &relay_log_purge,
 
4317
   (uchar**) &relay_log_purge, 0, GET_BOOL, NO_ARG,
 
4318
   1, 0, 1, 0, 1, 0},
 
4319
  {"relay_log_space_limit", OPT_RELAY_LOG_SPACE_LIMIT,
 
4320
   "Maximum space to use for all relay logs.",
 
4321
   (uchar**) &relay_log_space_limit,
 
4322
   (uchar**) &relay_log_space_limit, 0, GET_ULL, REQUIRED_ARG, 0L, 0L,
 
4323
   (longlong) ULONG_MAX, 0, 1, 0},
 
4324
  {"slave_compressed_protocol", OPT_SLAVE_COMPRESSED_PROTOCOL,
 
4325
   "Use compression on master/slave protocol.",
 
4326
   (uchar**) &opt_slave_compressed_protocol,
 
4327
   (uchar**) &opt_slave_compressed_protocol,
 
4328
   0, GET_BOOL, NO_ARG, 0, 0, 1, 0, 1, 0},
 
4329
  {"slave_net_timeout", OPT_SLAVE_NET_TIMEOUT,
 
4330
   "Number of seconds to wait for more data from a master/slave connection before aborting the read.",
 
4331
   (uchar**) &slave_net_timeout, (uchar**) &slave_net_timeout, 0,
 
4332
   GET_ULONG, REQUIRED_ARG, SLAVE_NET_TIMEOUT, 1, LONG_TIMEOUT, 0, 1, 0},
 
4333
  {"slave_transaction_retries", OPT_SLAVE_TRANS_RETRIES,
 
4334
   "Number of times the slave SQL thread will retry a transaction in case "
 
4335
   "it failed with a deadlock or elapsed lock wait timeout, "
 
4336
   "before giving up and stopping.",
 
4337
   (uchar**) &slave_trans_retries, (uchar**) &slave_trans_retries, 0,
 
4338
   GET_ULONG, REQUIRED_ARG, 10L, 0L, (longlong) ULONG_MAX, 0, 1, 0},
 
4339
  {"slave-allow-batching", OPT_SLAVE_ALLOW_BATCHING,
 
4340
   "Allow slave to batch requests.",
 
4341
   (uchar**) &slave_allow_batching, (uchar**) &slave_allow_batching,
 
4342
   0, GET_BOOL, NO_ARG, 0, 0, 1, 0, 1, 0},
 
4343
  {"slow_launch_time", OPT_SLOW_LAUNCH_TIME,
 
4344
   "If creating the thread takes longer than this value (in seconds), the Slow_launch_threads counter will be incremented.",
 
4345
   (uchar**) &slow_launch_time, (uchar**) &slow_launch_time, 0, GET_ULONG,
 
4346
   REQUIRED_ARG, 2L, 0L, LONG_TIMEOUT, 0, 1, 0},
2032
4347
  {"sort_buffer_size", OPT_SORT_BUFFER,
2033
 
   N_("Each thread that needs to do a sort allocates a buffer of this size."),
2034
 
   (char**) &global_system_variables.sortbuff_size,
2035
 
   (char**) &max_system_variables.sortbuff_size, 0, GET_SIZE, REQUIRED_ARG,
2036
 
   MAX_SORT_MEMORY, MIN_SORT_MEMORY+MALLOC_OVERHEAD*8, (int64_t)SIZE_MAX,
 
4348
   "Each thread that needs to do a sort allocates a buffer of this size.",
 
4349
   (uchar**) &global_system_variables.sortbuff_size,
 
4350
   (uchar**) &max_system_variables.sortbuff_size, 0, GET_ULONG, REQUIRED_ARG,
 
4351
   MAX_SORT_MEMORY, MIN_SORT_MEMORY+MALLOC_OVERHEAD*2, ULONG_MAX,
2037
4352
   MALLOC_OVERHEAD, 1, 0},
 
4353
  {"sync-binlog", OPT_SYNC_BINLOG,
 
4354
   "Synchronously flush binary log to disk after every #th event. "
 
4355
   "Use 0 (default) to disable synchronous flushing.",
 
4356
   (uchar**) &sync_binlog_period, (uchar**) &sync_binlog_period, 0, GET_ULONG,
 
4357
   REQUIRED_ARG, 0, 0, ULONG_MAX, 0, 1, 0},
 
4358
  {"sync-frm", OPT_SYNC_FRM, "Sync .frm to disk on create. Enabled by default.",
 
4359
   (uchar**) &opt_sync_frm, (uchar**) &opt_sync_frm, 0, GET_BOOL, NO_ARG, 1, 0,
 
4360
   0, 0, 0, 0},
 
4361
  {"table_cache", OPT_TABLE_OPEN_CACHE,
 
4362
   "Deprecated; use --table_open_cache instead.",
 
4363
   (uchar**) &table_cache_size, (uchar**) &table_cache_size, 0, GET_ULONG,
 
4364
   REQUIRED_ARG, TABLE_OPEN_CACHE_DEFAULT, 1, 512*1024L, 0, 1, 0},
2038
4365
  {"table_definition_cache", OPT_TABLE_DEF_CACHE,
2039
 
   N_("The number of cached table definitions."),
2040
 
   (char**) &table_def_size, (char**) &table_def_size,
2041
 
   0, GET_SIZE, REQUIRED_ARG, 128, 1, 512*1024L, 0, 1, 0},
 
4366
   "The number of cached table definitions.",
 
4367
   (uchar**) &table_def_size, (uchar**) &table_def_size,
 
4368
   0, GET_ULONG, REQUIRED_ARG, 128, 1, 512*1024L, 0, 1, 0},
2042
4369
  {"table_open_cache", OPT_TABLE_OPEN_CACHE,
2043
 
   N_("The number of cached open tables."),
2044
 
   (char**) &table_cache_size, (char**) &table_cache_size, 0, GET_UINT64,
2045
 
   REQUIRED_ARG, TABLE_OPEN_CACHE_DEFAULT, TABLE_OPEN_CACHE_MIN, 512*1024L, 0, 1, 0},
 
4370
   "The number of cached open tables.",
 
4371
   (uchar**) &table_cache_size, (uchar**) &table_cache_size, 0, GET_ULONG,
 
4372
   REQUIRED_ARG, TABLE_OPEN_CACHE_DEFAULT, 1, 512*1024L, 0, 1, 0},
2046
4373
  {"table_lock_wait_timeout", OPT_TABLE_LOCK_WAIT_TIMEOUT,
2047
 
   N_("Timeout in seconds to wait for a table level lock before returning an "
2048
 
      "error. Used only if the connection has active cursors."),
2049
 
   (char**) &table_lock_wait_timeout, (char**) &table_lock_wait_timeout,
2050
 
   0, GET_ULL, REQUIRED_ARG, 50, 1, 1024 * 1024 * 1024, 0, 1, 0},
 
4374
   "Timeout in seconds to wait for a table level lock before returning an "
 
4375
   "error. Used only if the connection has active cursors.",
 
4376
   (uchar**) &table_lock_wait_timeout, (uchar**) &table_lock_wait_timeout,
 
4377
   0, GET_ULONG, REQUIRED_ARG, 50, 1, 1024 * 1024 * 1024, 0, 1, 0},
 
4378
  {"thread_cache_size", OPT_THREAD_CACHE_SIZE,
 
4379
   "How many threads we should keep in a cache for reuse.",
 
4380
   (uchar**) &thread_cache_size, (uchar**) &thread_cache_size, 0, GET_ULONG,
 
4381
   REQUIRED_ARG, 0, 0, 16384, 0, 1, 0},
 
4382
  {"thread_pool_size", OPT_THREAD_CACHE_SIZE,
 
4383
   "How many threads we should create to handle query requests in case of 'thread_handling=pool-of-threads'",
 
4384
   (uchar**) &thread_pool_size, (uchar**) &thread_pool_size, 0, GET_ULONG,
 
4385
   REQUIRED_ARG, 20, 1, 16384, 0, 1, 0},
2051
4386
  {"thread_stack", OPT_THREAD_STACK,
2052
 
   N_("The stack size for each thread."),
2053
 
   (char**) &my_thread_stack_size,
2054
 
   (char**) &my_thread_stack_size, 0, GET_SIZE,
2055
 
   REQUIRED_ARG,DEFAULT_THREAD_STACK,
2056
 
   UINT32_C(1024*512), (int64_t)SIZE_MAX, 0, 1024, 0},
 
4387
   "The stack size for each thread.", (uchar**) &my_thread_stack_size,
 
4388
   (uchar**) &my_thread_stack_size, 0, GET_ULONG, REQUIRED_ARG,DEFAULT_THREAD_STACK,
 
4389
   1024L*128L, ULONG_MAX, 0, 1024, 0},
 
4390
  { "time_format", OPT_TIME_FORMAT,
 
4391
    "The TIME format (for future).",
 
4392
    (uchar**) &opt_date_time_formats[MYSQL_TIMESTAMP_TIME],
 
4393
    (uchar**) &opt_date_time_formats[MYSQL_TIMESTAMP_TIME],
 
4394
    0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
2057
4395
  {"tmp_table_size", OPT_TMP_TABLE_SIZE,
2058
 
   N_("If an internal in-memory temporary table exceeds this size, Drizzle will"
2059
 
      " automatically convert it to an on-disk MyISAM table."),
2060
 
   (char**) &global_system_variables.tmp_table_size,
2061
 
   (char**) &max_system_variables.tmp_table_size, 0, GET_ULL,
2062
 
   REQUIRED_ARG, 16*1024*1024L, 1024, (int64_t)MAX_MEM_TABLE_SIZE, 0, 1, 0},
 
4396
   "If an internal in-memory temporary table exceeds this size, MySQL will"
 
4397
   " automatically convert it to an on-disk MyISAM table.",
 
4398
   (uchar**) &global_system_variables.tmp_table_size,
 
4399
   (uchar**) &max_system_variables.tmp_table_size, 0, GET_ULL,
 
4400
   REQUIRED_ARG, 16*1024*1024L, 1024, MAX_MEM_TABLE_SIZE, 0, 1, 0},
 
4401
  {"transaction_alloc_block_size", OPT_TRANS_ALLOC_BLOCK_SIZE,
 
4402
   "Allocation block size for transactions to be stored in binary log",
 
4403
   (uchar**) &global_system_variables.trans_alloc_block_size,
 
4404
   (uchar**) &max_system_variables.trans_alloc_block_size, 0, GET_ULONG,
 
4405
   REQUIRED_ARG, QUERY_ALLOC_BLOCK_SIZE, 1024, ULONG_MAX, 0, 1024, 0},
 
4406
  {"transaction_prealloc_size", OPT_TRANS_PREALLOC_SIZE,
 
4407
   "Persistent buffer for transactions to be stored in binary log",
 
4408
   (uchar**) &global_system_variables.trans_prealloc_size,
 
4409
   (uchar**) &max_system_variables.trans_prealloc_size, 0, GET_ULONG,
 
4410
   REQUIRED_ARG, TRANS_ALLOC_PREALLOC_SIZE, 1024, ULONG_MAX, 0, 1024, 0},
 
4411
  {"thread_handling", OPT_THREAD_HANDLING,
 
4412
   "Define threads usage for handling queries:  "
 
4413
   "one-thread-per-connection or no-threads", 0, 0,
 
4414
   0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
4415
  {"wait_timeout", OPT_WAIT_TIMEOUT,
 
4416
   "The number of seconds the server waits for activity on a connection before closing it.",
 
4417
   (uchar**) &global_system_variables.net_wait_timeout,
 
4418
   (uchar**) &max_system_variables.net_wait_timeout, 0, GET_ULONG,
 
4419
   REQUIRED_ARG, NET_WAIT_TIMEOUT, 1, IF_WIN(INT_MAX32/1000, LONG_TIMEOUT),
 
4420
   0, 1, 0},
2063
4421
  {0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}
2064
4422
};
2065
4423
 
 
4424
static int show_net_compression(THD *thd, SHOW_VAR *var, char *buff)
 
4425
{
 
4426
  var->type= SHOW_MY_BOOL;
 
4427
  var->value= (char *)&thd->net.compress;
 
4428
  return 0;
 
4429
}
 
4430
 
 
4431
static int show_starttime(THD *thd, SHOW_VAR *var, char *buff)
 
4432
{
 
4433
  var->type= SHOW_LONG;
 
4434
  var->value= buff;
 
4435
  *((long *)buff)= (long) (thd->query_start() - server_start_time);
 
4436
  return 0;
 
4437
}
 
4438
 
 
4439
static int show_flushstatustime(THD *thd, SHOW_VAR *var, char *buff)
 
4440
{
 
4441
  var->type= SHOW_LONG;
 
4442
  var->value= buff;
 
4443
  *((long *)buff)= (long) (thd->query_start() - flush_status_time);
 
4444
  return 0;
 
4445
}
 
4446
 
 
4447
static int show_slave_running(THD *thd, SHOW_VAR *var, char *buff)
 
4448
{
 
4449
  var->type= SHOW_MY_BOOL;
 
4450
  pthread_mutex_lock(&LOCK_active_mi);
 
4451
  var->value= buff;
 
4452
  *((my_bool *)buff)= (my_bool) (active_mi && active_mi->slave_running &&
 
4453
                                 active_mi->rli.slave_running);
 
4454
  pthread_mutex_unlock(&LOCK_active_mi);
 
4455
  return 0;
 
4456
}
 
4457
 
 
4458
static int show_slave_retried_trans(THD *thd, SHOW_VAR *var, char *buff)
 
4459
{
 
4460
  /*
 
4461
    TODO: with multimaster, have one such counter per line in
 
4462
    SHOW SLAVE STATUS, and have the sum over all lines here.
 
4463
  */
 
4464
  pthread_mutex_lock(&LOCK_active_mi);
 
4465
  if (active_mi)
 
4466
  {
 
4467
    var->type= SHOW_LONG;
 
4468
    var->value= buff;
 
4469
    pthread_mutex_lock(&active_mi->rli.data_lock);
 
4470
    *((long *)buff)= (long)active_mi->rli.retried_trans;
 
4471
    pthread_mutex_unlock(&active_mi->rli.data_lock);
 
4472
  }
 
4473
  else
 
4474
    var->type= SHOW_UNDEF;
 
4475
  pthread_mutex_unlock(&LOCK_active_mi);
 
4476
  return 0;
 
4477
}
 
4478
 
 
4479
static int show_slave_received_heartbeats(THD *thd, SHOW_VAR *var, char *buff)
 
4480
{
 
4481
  pthread_mutex_lock(&LOCK_active_mi);
 
4482
  if (active_mi)
 
4483
  {
 
4484
    var->type= SHOW_LONGLONG;
 
4485
    var->value= buff;
 
4486
    pthread_mutex_lock(&active_mi->rli.data_lock);
 
4487
    *((longlong *)buff)= active_mi->received_heartbeats;
 
4488
    pthread_mutex_unlock(&active_mi->rli.data_lock);
 
4489
  }
 
4490
  else
 
4491
    var->type= SHOW_UNDEF;
 
4492
  pthread_mutex_unlock(&LOCK_active_mi);
 
4493
  return 0;
 
4494
}
 
4495
 
 
4496
static int show_heartbeat_period(THD *thd, SHOW_VAR *var, char *buff)
 
4497
{
 
4498
  pthread_mutex_lock(&LOCK_active_mi);
 
4499
  if (active_mi)
 
4500
  {
 
4501
    var->type= SHOW_CHAR;
 
4502
    var->value= buff;
 
4503
    my_sprintf(buff, (buff, "%.3f",active_mi->heartbeat_period));
 
4504
  }
 
4505
  else
 
4506
    var->type= SHOW_UNDEF;
 
4507
  pthread_mutex_unlock(&LOCK_active_mi);
 
4508
  return 0;
 
4509
}
 
4510
 
 
4511
 
 
4512
static int show_open_tables(THD *thd, SHOW_VAR *var, char *buff)
 
4513
{
 
4514
  var->type= SHOW_LONG;
 
4515
  var->value= buff;
 
4516
  *((long *)buff)= (long)cached_open_tables();
 
4517
  return 0;
 
4518
}
 
4519
 
 
4520
static int show_table_definitions(THD *thd, SHOW_VAR *var, char *buff)
 
4521
{
 
4522
  var->type= SHOW_LONG;
 
4523
  var->value= buff;
 
4524
  *((long *)buff)= (long)cached_table_definitions();
 
4525
  return 0;
 
4526
}
 
4527
 
 
4528
/*
 
4529
  Variables shown by SHOW STATUS in alphabetical order
 
4530
*/
 
4531
 
 
4532
SHOW_VAR status_vars[]= {
 
4533
  {"Aborted_clients",          (char*) &aborted_threads,        SHOW_LONG},
 
4534
  {"Aborted_connects",         (char*) &aborted_connects,       SHOW_LONG},
 
4535
  {"Binlog_cache_disk_use",    (char*) &binlog_cache_disk_use,  SHOW_LONG},
 
4536
  {"Binlog_cache_use",         (char*) &binlog_cache_use,       SHOW_LONG},
 
4537
  {"Bytes_received",           (char*) offsetof(STATUS_VAR, bytes_received), SHOW_LONGLONG_STATUS},
 
4538
  {"Bytes_sent",               (char*) offsetof(STATUS_VAR, bytes_sent), SHOW_LONGLONG_STATUS},
 
4539
  {"Com",                      (char*) com_status_vars, SHOW_ARRAY},
 
4540
  {"Compression",              (char*) &show_net_compression, SHOW_FUNC},
 
4541
  {"Connections",              (char*) &thread_id,              SHOW_LONG_NOFLUSH},
 
4542
  {"Created_tmp_disk_tables",  (char*) offsetof(STATUS_VAR, created_tmp_disk_tables), SHOW_LONG_STATUS},
 
4543
  {"Created_tmp_files",        (char*) &my_tmp_file_created,    SHOW_LONG},
 
4544
  {"Created_tmp_tables",       (char*) offsetof(STATUS_VAR, created_tmp_tables), SHOW_LONG_STATUS},
 
4545
  {"Flush_commands",           (char*) &refresh_version,        SHOW_LONG_NOFLUSH},
 
4546
  {"Handler_commit",           (char*) offsetof(STATUS_VAR, ha_commit_count), SHOW_LONG_STATUS},
 
4547
  {"Handler_delete",           (char*) offsetof(STATUS_VAR, ha_delete_count), SHOW_LONG_STATUS},
 
4548
  {"Handler_discover",         (char*) offsetof(STATUS_VAR, ha_discover_count), SHOW_LONG_STATUS},
 
4549
  {"Handler_prepare",          (char*) offsetof(STATUS_VAR, ha_prepare_count),  SHOW_LONG_STATUS},
 
4550
  {"Handler_read_first",       (char*) offsetof(STATUS_VAR, ha_read_first_count), SHOW_LONG_STATUS},
 
4551
  {"Handler_read_key",         (char*) offsetof(STATUS_VAR, ha_read_key_count), SHOW_LONG_STATUS},
 
4552
  {"Handler_read_next",        (char*) offsetof(STATUS_VAR, ha_read_next_count), SHOW_LONG_STATUS},
 
4553
  {"Handler_read_prev",        (char*) offsetof(STATUS_VAR, ha_read_prev_count), SHOW_LONG_STATUS},
 
4554
  {"Handler_read_rnd",         (char*) offsetof(STATUS_VAR, ha_read_rnd_count), SHOW_LONG_STATUS},
 
4555
  {"Handler_read_rnd_next",    (char*) offsetof(STATUS_VAR, ha_read_rnd_next_count), SHOW_LONG_STATUS},
 
4556
  {"Handler_rollback",         (char*) offsetof(STATUS_VAR, ha_rollback_count), SHOW_LONG_STATUS},
 
4557
  {"Handler_savepoint",        (char*) offsetof(STATUS_VAR, ha_savepoint_count), SHOW_LONG_STATUS},
 
4558
  {"Handler_savepoint_rollback",(char*) offsetof(STATUS_VAR, ha_savepoint_rollback_count), SHOW_LONG_STATUS},
 
4559
  {"Handler_update",           (char*) offsetof(STATUS_VAR, ha_update_count), SHOW_LONG_STATUS},
 
4560
  {"Handler_write",            (char*) offsetof(STATUS_VAR, ha_write_count), SHOW_LONG_STATUS},
 
4561
  {"Key_blocks_not_flushed",   (char*) offsetof(KEY_CACHE, global_blocks_changed), SHOW_KEY_CACHE_LONG},
 
4562
  {"Key_blocks_unused",        (char*) offsetof(KEY_CACHE, blocks_unused), SHOW_KEY_CACHE_LONG},
 
4563
  {"Key_blocks_used",          (char*) offsetof(KEY_CACHE, blocks_used), SHOW_KEY_CACHE_LONG},
 
4564
  {"Key_read_requests",        (char*) offsetof(KEY_CACHE, global_cache_r_requests), SHOW_KEY_CACHE_LONGLONG},
 
4565
  {"Key_reads",                (char*) offsetof(KEY_CACHE, global_cache_read), SHOW_KEY_CACHE_LONGLONG},
 
4566
  {"Key_write_requests",       (char*) offsetof(KEY_CACHE, global_cache_w_requests), SHOW_KEY_CACHE_LONGLONG},
 
4567
  {"Key_writes",               (char*) offsetof(KEY_CACHE, global_cache_write), SHOW_KEY_CACHE_LONGLONG},
 
4568
  {"Last_query_cost",          (char*) offsetof(STATUS_VAR, last_query_cost), SHOW_DOUBLE_STATUS},
 
4569
  {"Max_used_connections",     (char*) &max_used_connections,  SHOW_LONG},
 
4570
  {"Open_files",               (char*) &my_file_opened,         SHOW_LONG_NOFLUSH},
 
4571
  {"Open_streams",             (char*) &my_stream_opened,       SHOW_LONG_NOFLUSH},
 
4572
  {"Open_table_definitions",   (char*) &show_table_definitions, SHOW_FUNC},
 
4573
  {"Open_tables",              (char*) &show_open_tables,       SHOW_FUNC},
 
4574
  {"Opened_files",             (char*) &my_file_total_opened, SHOW_LONG_NOFLUSH},
 
4575
  {"Opened_tables",            (char*) offsetof(STATUS_VAR, opened_tables), SHOW_LONG_STATUS},
 
4576
  {"Opened_table_definitions", (char*) offsetof(STATUS_VAR, opened_shares), SHOW_LONG_STATUS},
 
4577
  {"Questions",                (char*) offsetof(STATUS_VAR, questions), SHOW_LONG_STATUS},
 
4578
  {"Select_full_join",         (char*) offsetof(STATUS_VAR, select_full_join_count), SHOW_LONG_STATUS},
 
4579
  {"Select_full_range_join",   (char*) offsetof(STATUS_VAR, select_full_range_join_count), SHOW_LONG_STATUS},
 
4580
  {"Select_range",             (char*) offsetof(STATUS_VAR, select_range_count), SHOW_LONG_STATUS},
 
4581
  {"Select_range_check",       (char*) offsetof(STATUS_VAR, select_range_check_count), SHOW_LONG_STATUS},
 
4582
  {"Select_scan",              (char*) offsetof(STATUS_VAR, select_scan_count), SHOW_LONG_STATUS},
 
4583
  {"Slave_open_temp_tables",   (char*) &slave_open_temp_tables, SHOW_LONG},
 
4584
  {"Slave_retried_transactions",(char*) &show_slave_retried_trans, SHOW_FUNC},
 
4585
  {"Slave_heartbeat_period",   (char*) &show_heartbeat_period, SHOW_FUNC},
 
4586
  {"Slave_received_heartbeats",(char*) &show_slave_received_heartbeats, SHOW_FUNC},
 
4587
  {"Slave_running",            (char*) &show_slave_running,     SHOW_FUNC},
 
4588
  {"Slow_launch_threads",      (char*) &slow_launch_threads,    SHOW_LONG},
 
4589
  {"Slow_queries",             (char*) offsetof(STATUS_VAR, long_query_count), SHOW_LONG_STATUS},
 
4590
  {"Sort_merge_passes",        (char*) offsetof(STATUS_VAR, filesort_merge_passes), SHOW_LONG_STATUS},
 
4591
  {"Sort_range",               (char*) offsetof(STATUS_VAR, filesort_range_count), SHOW_LONG_STATUS},
 
4592
  {"Sort_rows",                (char*) offsetof(STATUS_VAR, filesort_rows), SHOW_LONG_STATUS},
 
4593
  {"Sort_scan",                (char*) offsetof(STATUS_VAR, filesort_scan_count), SHOW_LONG_STATUS},
 
4594
  {"Table_locks_immediate",    (char*) &locks_immediate,        SHOW_LONG},
 
4595
  {"Table_locks_waited",       (char*) &locks_waited,           SHOW_LONG},
 
4596
#ifdef HAVE_MMAP
 
4597
  {"Tc_log_max_pages_used",    (char*) &tc_log_max_pages_used,  SHOW_LONG},
 
4598
  {"Tc_log_page_size",         (char*) &tc_log_page_size,       SHOW_LONG},
 
4599
  {"Tc_log_page_waits",        (char*) &tc_log_page_waits,      SHOW_LONG},
 
4600
#endif
 
4601
  {"Threads_cached",           (char*) &cached_thread_count,    SHOW_LONG_NOFLUSH},
 
4602
  {"Threads_connected",        (char*) &connection_count,       SHOW_INT},
 
4603
  {"Threads_created",          (char*) &thread_created,         SHOW_LONG_NOFLUSH},
 
4604
  {"Threads_running",          (char*) &thread_running,         SHOW_INT},
 
4605
  {"Uptime",                   (char*) &show_starttime,         SHOW_FUNC},
 
4606
  {"Uptime_since_flush_status",(char*) &show_flushstatustime,   SHOW_FUNC},
 
4607
  {NullS, NullS, SHOW_LONG}
 
4608
};
 
4609
 
2066
4610
static void print_version(void)
2067
4611
{
 
4612
  set_server_version();
2068
4613
  /*
2069
4614
    Note: the instance manager keys off the string 'Ver' so it can find the
2070
 
    version from the output of 'drizzled --version', so don't change it!
 
4615
    version from the output of 'mysqld --version', so don't change it!
2071
4616
  */
2072
 
  printf("%s  Ver %s for %s-%s on %s (%s)\n",internal::my_progname,
2073
 
         PANDORA_RELEASE_VERSION, HOST_VENDOR, HOST_OS, HOST_CPU,
2074
 
         COMPILATION_COMMENT);
 
4617
  printf("%s  Ver %s for %s on %s (%s)\n",my_progname,
 
4618
         server_version,SYSTEM_TYPE,MACHINE_TYPE, MYSQL_COMPILATION_COMMENT);
2075
4619
}
2076
4620
 
2077
4621
static void usage(void)
2078
4622
{
2079
 
  if (!(default_charset_info= get_charset_by_csname(default_character_set_name, MY_CS_PRIMARY)))
 
4623
  if (!(default_charset_info= get_charset_by_csname(default_character_set_name,
 
4624
                                                   MY_CS_PRIMARY,
 
4625
                                                   MYF(MY_WME))))
2080
4626
    exit(1);
2081
4627
  if (!default_collation_name)
2082
4628
    default_collation_name= (char*) default_charset_info->name;
2083
4629
  print_version();
2084
 
  puts(_("Copyright (C) 2008 Sun Microsystems\n"
2085
 
         "This software comes with ABSOLUTELY NO WARRANTY. "
2086
 
         "This is free software,\n"
2087
 
         "and you are welcome to modify and redistribute it under the GPL "
2088
 
         "license\n\n"));
2089
 
 
2090
 
 
2091
 
  printf(_("Usage: %s [OPTIONS]\n"), internal::my_progname);
2092
 
 
2093
 
  po::options_description all_options("Drizzled Options");
2094
 
  all_options.add(config_options);
2095
 
  all_options.add(plugin_load_options);
2096
 
  all_options.add(long_options);
2097
 
  all_options.add(plugin_options);
2098
 
  cout << all_options << endl;
2099
 
 
 
4630
  puts("\
 
4631
Copyright (C) 2000 MySQL AB, by Monty and others\n\
 
4632
This software comes with ABSOLUTELY NO WARRANTY. This is free software,\n\
 
4633
and you are welcome to modify and redistribute it under the GPL license\n\n\
 
4634
Starts the MySQL database server\n");
 
4635
 
 
4636
  printf("Usage: %s [OPTIONS]\n", my_progname);
 
4637
  if (!opt_verbose)
 
4638
    puts("\nFor more help options (several pages), use mysqld --verbose --help");
 
4639
  else
 
4640
  {
 
4641
  print_defaults(MYSQL_CONFIG_NAME,load_default_groups);
 
4642
  puts("");
 
4643
  set_ports();
 
4644
 
 
4645
  /* Print out all the options including plugin supplied options */
 
4646
  my_print_help_inc_plugins(my_long_options, sizeof(my_long_options)/sizeof(my_option));
 
4647
 
 
4648
  puts("\n\
 
4649
To see what values a running MySQL server is using, type\n\
 
4650
'mysqladmin variables' instead of 'mysqld --verbose --help'.");
 
4651
  }
2100
4652
}
2101
4653
 
 
4654
 
2102
4655
/**
2103
 
  Initialize all Drizzle global variables to default values.
 
4656
  Initialize all MySQL global variables to default values.
2104
4657
 
2105
4658
  We don't need to set numeric variables refered to in my_long_options
2106
4659
  as these are initialized by my_getopt.
2115
4668
    as these are initialized by my_getopt.
2116
4669
*/
2117
4670
 
2118
 
static void drizzle_init_variables(void)
 
4671
static void mysql_init_variables(void)
2119
4672
{
2120
4673
  /* Things reset to zero */
 
4674
  opt_skip_slave_start= opt_reckless_slave = 0;
 
4675
  mysql_home[0]= pidfile_name[0]= log_error_file[0]= 0;
 
4676
  opt_log= opt_slow_log= 0;
 
4677
  opt_update_log= 0;
 
4678
  log_output_options= find_bit_type(log_output_str, &log_output_typelib);
 
4679
  opt_bin_log= 0;
 
4680
  opt_disable_networking= opt_skip_show_db=0;
 
4681
  opt_logname= opt_update_logname= opt_binlog_index_name= opt_slow_logname= 0;
2121
4682
  opt_tc_log_file= (char *)"tc.log";      // no hostname in tc_log file name !
 
4683
  opt_secure_auth= 0;
 
4684
  opt_secure_file_priv= 0;
 
4685
  opt_bootstrap= opt_myisam_log= 0;
 
4686
  mqh_used= 0;
 
4687
  segfaulted= kill_in_progress= 0;
2122
4688
  cleanup_done= 0;
2123
 
  dropping_tables= ha_open_options=0;
2124
 
  test_flags.reset();
2125
 
  wake_thread=0;
2126
 
  abort_loop= select_thread_in_use= false;
 
4689
  defaults_argc= 0;
 
4690
  defaults_argv= 0;
 
4691
  server_id_supplied= 0;
 
4692
  test_flags= select_errors= dropping_tables= ha_open_options=0;
 
4693
  thread_count= thread_running= kill_cached_threads= wake_thread=0;
 
4694
  slave_open_temp_tables= 0;
 
4695
  cached_thread_count= 0;
 
4696
  opt_endinfo= using_udf_functions= 0;
 
4697
  opt_using_transactions= using_update_log= 0;
 
4698
  abort_loop= select_thread_in_use= signal_thread_in_use= 0;
2127
4699
  ready_to_exit= shutdown_in_progress= 0;
2128
 
  drizzled_user= drizzled_chroot= 0;
2129
 
  memset(&current_global_counters, 0, sizeof(current_global_counters));
2130
 
  key_map_full.set();
 
4700
  aborted_threads= aborted_connects= 0;
 
4701
  specialflag= 0;
 
4702
  binlog_cache_use=  binlog_cache_disk_use= 0;
 
4703
  max_used_connections= slow_launch_threads = 0;
 
4704
  mysqld_user= mysqld_chroot= opt_init_file= opt_bin_logname = 0;
 
4705
  errmesg= 0;
 
4706
  opt_mysql_tmpdir= my_bind_addr_str= NullS;
 
4707
  bzero((uchar*) &mysql_tmpdir_list, sizeof(mysql_tmpdir_list));
 
4708
  bzero((char *) &global_status_var, sizeof(global_status_var));
 
4709
  opt_large_pages= 0;
 
4710
  key_map_full.set_all();
2131
4711
 
2132
4712
  /* Character sets */
2133
4713
  system_charset_info= &my_charset_utf8_general_ci;
2134
4714
  files_charset_info= &my_charset_utf8_general_ci;
 
4715
  national_charset_info= &my_charset_utf8_general_ci;
2135
4716
  table_alias_charset= &my_charset_bin;
2136
4717
  character_set_filesystem= &my_charset_bin;
2137
4718
 
 
4719
  opt_date_time_formats[0]= opt_date_time_formats[1]= opt_date_time_formats[2]= 0;
 
4720
 
2138
4721
  /* Things with default values that are not zero */
2139
 
  session_startup_options= (OPTION_AUTO_IS_NULL | OPTION_SQL_NOTES);
 
4722
  delay_key_write_options= (uint) DELAY_KEY_WRITE_ON;
 
4723
  slave_exec_mode_options= 0;
 
4724
  slave_exec_mode_options= (uint)
 
4725
    find_bit_type_or_exit(slave_exec_mode_str, &slave_exec_mode_typelib, NULL);
 
4726
  opt_specialflag= SPECIAL_ENGLISH;
 
4727
  ip_sock= INVALID_SOCKET;
 
4728
  mysql_home_ptr= mysql_home;
 
4729
  pidfile_name_ptr= pidfile_name;
 
4730
  log_error_file_ptr= log_error_file;
 
4731
  language_ptr= language;
 
4732
  mysql_data_home= mysql_real_data_home;
 
4733
  thd_startup_options= (OPTION_AUTO_IS_NULL | OPTION_BIN_LOG |
 
4734
                        OPTION_QUOTE_SHOW_CREATE | OPTION_SQL_NOTES);
 
4735
  protocol_version= PROTOCOL_VERSION;
 
4736
  what_to_log= ~ (1L << (uint) COM_TIME);
2140
4737
  refresh_version= 1L;  /* Increments on each reload */
2141
 
  global_thread_id= 1UL;
2142
 
  session::Cache::singleton().getCache().clear();
 
4738
  global_query_id= thread_id= 1L;
 
4739
  strmov(server_version, MYSQL_SERVER_VERSION);
 
4740
  myisam_recover_options_str= "OFF";
 
4741
  myisam_stats_method_str= "nulls_unequal";
 
4742
  threads.empty();
 
4743
  thread_cache.empty();
 
4744
  key_caches.empty();
 
4745
  if (!(dflt_key_cache= get_or_create_key_cache(default_key_cache_base.str,
 
4746
                                                default_key_cache_base.length)))
 
4747
    exit(1);
 
4748
  /* set key_cache_hash.default_value = dflt_key_cache */
 
4749
  multi_keycache_init();
 
4750
 
 
4751
  /* Set directory paths */
 
4752
  strmake(language, LANGUAGE, sizeof(language)-1);
 
4753
  strmake(mysql_real_data_home, get_relative_path(DATADIR),
 
4754
          sizeof(mysql_real_data_home)-1);
 
4755
  mysql_data_home_buff[0]=FN_CURLIB;    // all paths are relative from here
 
4756
  mysql_data_home_buff[1]=0;
 
4757
  mysql_data_home_len= 2;
 
4758
 
 
4759
  /* Replication parameters */
 
4760
  master_info_file= (char*) "master.info",
 
4761
    relay_log_info_file= (char*) "relay-log.info";
 
4762
  report_user= report_password = report_host= 0;        /* TO BE DELETED */
 
4763
  opt_relay_logname= opt_relaylog_index_name= 0;
2143
4764
 
2144
4765
  /* Variables in libraries */
2145
 
  default_character_set_name= "utf8";
2146
 
  default_collation_name= (char *)compiled_default_collation_name;
2147
 
  character_set_filesystem_name= "binary";
 
4766
  charsets_dir= 0;
 
4767
  default_character_set_name= (char*) MYSQL_DEFAULT_CHARSET_NAME;
 
4768
  default_collation_name= compiled_default_collation_name;
 
4769
  sys_charset_system.set((char*) system_charset_info->csname);
 
4770
  character_set_filesystem_name= (char*) "binary";
2148
4771
  lc_time_names_name= (char*) "en_US";
2149
4772
  /* Set default values for some option variables */
2150
 
  default_storage_engine_str= (char*) "innodb";
2151
 
  global_system_variables.storage_engine= NULL;
 
4773
  default_storage_engine_str= (char*) "MyISAM";
 
4774
  global_system_variables.table_plugin= NULL;
2152
4775
  global_system_variables.tx_isolation= ISO_REPEATABLE_READ;
2153
 
  global_system_variables.select_limit= (uint64_t) HA_POS_ERROR;
2154
 
  max_system_variables.select_limit=    (uint64_t) HA_POS_ERROR;
2155
 
  global_system_variables.max_join_size= (uint64_t) HA_POS_ERROR;
2156
 
  max_system_variables.max_join_size=   (uint64_t) HA_POS_ERROR;
2157
 
  max_system_variables.auto_increment_increment= UINT64_MAX;
2158
 
  max_system_variables.auto_increment_offset= UINT64_MAX;
2159
 
  max_system_variables.completion_type= 2;
2160
 
  max_system_variables.log_warnings= true;
2161
 
  max_system_variables.bulk_insert_buff_size= ULONG_MAX;
2162
 
  max_system_variables.div_precincrement= DECIMAL_MAX_SCALE;
2163
 
  max_system_variables.group_concat_max_len= ULONG_MAX;
2164
 
  max_system_variables.join_buff_size= ULONG_MAX;
2165
 
  max_system_variables.max_allowed_packet= 1024L*1024L*1024L;
2166
 
  max_system_variables.max_error_count= 65535;
2167
 
  max_system_variables.max_heap_table_size= MAX_MEM_TABLE_SIZE;
2168
 
  max_system_variables.max_join_size= INT32_MAX;
2169
 
  max_system_variables.max_length_for_sort_data= 8192*1024L;
2170
 
  max_system_variables.max_seeks_for_key= ULONG_MAX;
2171
 
  max_system_variables.max_sort_length= 8192*1024L;
2172
 
  max_system_variables.min_examined_row_limit= ULONG_MAX;
2173
 
  max_system_variables.optimizer_prune_level= 1;
2174
 
  max_system_variables.optimizer_search_depth= MAX_TABLES+2;
2175
 
  max_system_variables.preload_buff_size= 1024*1024*1024L;
2176
 
  max_system_variables.query_alloc_block_size= UINT32_MAX;
2177
 
  max_system_variables.query_prealloc_size= UINT32_MAX;
2178
 
  max_system_variables.range_alloc_block_size= SIZE_MAX;
2179
 
  max_system_variables.read_buff_size= INT32_MAX;
2180
 
  max_system_variables.read_rnd_buff_size= UINT32_MAX;
2181
 
  max_system_variables.sortbuff_size= SIZE_MAX;
2182
 
  max_system_variables.tmp_table_size= MAX_MEM_TABLE_SIZE;
2183
 
 
2184
 
  opt_scheduler_default= (char*) "multi_thread";
 
4776
  global_system_variables.select_limit= (ulonglong) HA_POS_ERROR;
 
4777
  max_system_variables.select_limit=    (ulonglong) HA_POS_ERROR;
 
4778
  global_system_variables.max_join_size= (ulonglong) HA_POS_ERROR;
 
4779
  max_system_variables.max_join_size=   (ulonglong) HA_POS_ERROR;
 
4780
  global_system_variables.old_passwords= 0;
 
4781
  global_system_variables.old_alter_table= 0;
 
4782
  global_system_variables.binlog_format= BINLOG_FORMAT_UNSPEC;
 
4783
  /*
 
4784
    Default behavior for 4.1 and 5.0 is to treat NULL values as unequal
 
4785
    when collecting index statistics for MyISAM tables.
 
4786
  */
 
4787
  global_system_variables.myisam_stats_method= MI_STATS_METHOD_NULLS_NOT_EQUAL;
2185
4788
 
2186
4789
  /* Variables that depends on compile options */
 
4790
#ifndef DBUG_OFF
 
4791
  default_dbug_option=IF_WIN("d:t:i:O,\\mysqld.trace",
 
4792
                             "d:t:i:o,/tmp/mysqld.trace");
 
4793
#endif
 
4794
  opt_error_log= IF_WIN(1,0);
2187
4795
#ifdef HAVE_BROKEN_REALPATH
2188
4796
  have_symlink=SHOW_OPTION_NO;
2189
4797
#else
2190
4798
  have_symlink=SHOW_OPTION_YES;
2191
4799
#endif
 
4800
#ifdef HAVE_DLOPEN
 
4801
  have_dlopen=SHOW_OPTION_YES;
 
4802
#else
 
4803
  have_dlopen=SHOW_OPTION_NO;
 
4804
#endif
 
4805
#ifdef HAVE_CRYPT
 
4806
  have_crypt=SHOW_OPTION_YES;
 
4807
#else
 
4808
  have_crypt=SHOW_OPTION_NO;
 
4809
#endif
 
4810
#ifdef HAVE_COMPRESS
 
4811
  have_compress= SHOW_OPTION_YES;
 
4812
#else
 
4813
  have_compress= SHOW_OPTION_NO;
 
4814
#endif
2192
4815
 
2193
 
  connection_count= 0;
 
4816
  const char *tmpenv;
 
4817
  if (!(tmpenv = getenv("MY_BASEDIR_VERSION")))
 
4818
    tmpenv = DEFAULT_MYSQL_HOME;
 
4819
  (void) strmake(mysql_home, tmpenv, sizeof(mysql_home)-1);
2194
4820
}
2195
4821
 
2196
4822
 
2197
 
/**
2198
 
  @todo
2199
 
  - FIXME add EXIT_TOO_MANY_ARGUMENTS to "drizzled/error.h" and return that code?
2200
 
*/
2201
 
static void get_options()
 
4823
my_bool
 
4824
mysqld_get_one_option(int optid,
 
4825
                      const struct my_option *opt __attribute__((unused)),
 
4826
                      char *argument)
2202
4827
{
2203
 
 
2204
 
  fs::path &data_home_catalog= getDataHomeCatalog();
2205
 
  data_home_catalog= getDataHome();
2206
 
  data_home_catalog /= "local"; 
2207
 
 
2208
 
  if (vm.count("user"))
2209
 
  {
2210
 
    if (! drizzled_user || ! strcmp(drizzled_user, vm["user"].as<string>().c_str()))
2211
 
      drizzled_user= (char *)vm["user"].as<string>().c_str();
2212
 
 
 
4828
  switch(optid) {
 
4829
  case '#':
 
4830
#ifndef DBUG_OFF
 
4831
    DBUG_SET_INITIAL(argument ? argument : default_dbug_option);
 
4832
#endif
 
4833
    opt_endinfo=1;                              /* unireg: memory allocation */
 
4834
    break;
 
4835
  case 'a':
 
4836
    global_system_variables.tx_isolation= ISO_SERIALIZABLE;
 
4837
    break;
 
4838
  case 'b':
 
4839
    strmake(mysql_home,argument,sizeof(mysql_home)-1);
 
4840
    break;
 
4841
  case 'C':
 
4842
    if (default_collation_name == compiled_default_collation_name)
 
4843
      default_collation_name= 0;
 
4844
    break;
 
4845
  case 'l':
 
4846
    opt_log=1;
 
4847
    break;
 
4848
  case 'h':
 
4849
    strmake(mysql_real_data_home,argument, sizeof(mysql_real_data_home)-1);
 
4850
    /* Correct pointer set by my_getopt (for embedded library) */
 
4851
    mysql_data_home= mysql_real_data_home;
 
4852
    mysql_data_home_len= strlen(mysql_data_home);
 
4853
    break;
 
4854
  case 'u':
 
4855
    if (!mysqld_user || !strcmp(mysqld_user, argument))
 
4856
      mysqld_user= argument;
2213
4857
    else
2214
 
      errmsg_printf(ERRMSG_LVL_WARN, _("Ignoring user change to '%s' because the user was "
2215
 
                                       "set to '%s' earlier on the command line\n"),
2216
 
                    vm["user"].as<string>().c_str(), drizzled_user);
2217
 
  }
2218
 
 
2219
 
  if (vm.count("version"))
2220
 
  {
 
4858
      sql_print_warning("Ignoring user change to '%s' because the user was set to '%s' earlier on the command line\n", argument, mysqld_user);
 
4859
    break;
 
4860
  case 'L':
 
4861
    strmake(language, argument, sizeof(language)-1);
 
4862
    break;
 
4863
  case OPT_SLAVE_SKIP_ERRORS:
 
4864
    init_slave_skip_errors(argument);
 
4865
    break;
 
4866
  case OPT_SLAVE_EXEC_MODE:
 
4867
    slave_exec_mode_options= (uint)
 
4868
      find_bit_type_or_exit(argument, &slave_exec_mode_typelib, "");
 
4869
    break;
 
4870
  case 'V':
2221
4871
    print_version();
2222
4872
    exit(0);
2223
 
  }
2224
 
 
2225
 
  if (vm.count("sort-heap-threshold"))
2226
 
  {
2227
 
    if ((vm["sort-heap-threshold"].as<uint64_t>() > 0) and
2228
 
      (vm["sort-heap-threshold"].as<uint64_t>() < 
2229
 
      global_system_variables.sortbuff_size))
2230
 
    {
2231
 
      cout << N_("Error: sort-heap-threshold cannot be less than sort-buffer-size") << endl;
2232
 
      exit(-1);
2233
 
    }
2234
 
 
2235
 
    global_sort_buffer.setMaxSize(vm["sort-heap-threshold"].as<uint64_t>());
2236
 
  }
2237
 
 
2238
 
  if (vm.count("join-heap-threshold"))
2239
 
  {
2240
 
    if ((vm["join-heap-threshold"].as<uint64_t>() > 0) and
2241
 
      (vm["join-heap-threshold"].as<uint64_t>() <
2242
 
      global_system_variables.join_buff_size))
2243
 
    {
2244
 
      cout << N_("Error: join-heap-threshold cannot be less than join-buffer-size") << endl;
2245
 
      exit(-1);
2246
 
    }
2247
 
 
2248
 
    global_join_buffer.setMaxSize(vm["join-heap-threshold"].as<uint64_t>());
2249
 
  }
2250
 
 
2251
 
  if (vm.count("read-rnd-threshold"))
2252
 
  {
2253
 
    if ((vm["read-rnd-threshold"].as<uint64_t>() > 0) and
2254
 
      (vm["read-rnd-threshold"].as<uint64_t>() <
2255
 
      global_system_variables.read_rnd_buff_size))
2256
 
    {
2257
 
      cout << N_("Error: read-rnd-threshold cannot be less than read-rnd-buffer-size") << endl;
2258
 
      exit(-1);
2259
 
    }
2260
 
 
2261
 
    global_read_rnd_buffer.setMaxSize(vm["read-rnd-threshold"].as<uint64_t>());
2262
 
  }
2263
 
 
2264
 
  if (vm.count("read-buffer-threshold"))
2265
 
  {
2266
 
    if ((vm["read-buffer-threshold"].as<uint64_t>() > 0) and
2267
 
      (vm["read-buffer-threshold"].as<uint64_t>() <
2268
 
      global_system_variables.read_buff_size))
2269
 
    {
2270
 
      cout << N_("Error: read-buffer-threshold cannot be less than read-buffer-size") << endl;
2271
 
      exit(-1);
2272
 
    }
2273
 
 
2274
 
    global_read_buffer.setMaxSize(vm["read-buffer-threshold"].as<uint64_t>());
2275
 
  }
2276
 
 
2277
 
  if (vm.count("exit-info"))
2278
 
  {
2279
 
    if (vm["exit-info"].as<long>())
2280
 
    {
2281
 
      test_flags.set((uint32_t) vm["exit-info"].as<long>());
2282
 
    }
2283
 
  }
2284
 
 
2285
 
  if (vm.count("want-core"))
2286
 
  {
2287
 
    test_flags.set(TEST_CORE_ON_SIGNAL);
2288
 
  }
2289
 
 
2290
 
  if (vm.count("skip-stack-trace"))
2291
 
  {
2292
 
    test_flags.set(TEST_NO_STACKTRACE);
2293
 
  }
2294
 
 
2295
 
  if (vm.count("skip-symlinks"))
2296
 
  {
2297
 
    internal::my_use_symdir=0;
2298
 
  }
2299
 
 
2300
 
  if (vm.count("transaction-isolation"))
 
4873
  case 'W':
 
4874
    if (!argument)
 
4875
      global_system_variables.log_warnings++;
 
4876
    else if (argument == disabled_my_option)
 
4877
      global_system_variables.log_warnings= 0L;
 
4878
    else
 
4879
      global_system_variables.log_warnings= atoi(argument);
 
4880
    break;
 
4881
  case 'T':
 
4882
    test_flags= argument ? (uint) atoi(argument) : 0;
 
4883
    opt_endinfo=1;
 
4884
    break;
 
4885
  case (int) OPT_BIG_TABLES:
 
4886
    thd_startup_options|=OPTION_BIG_TABLES;
 
4887
    break;
 
4888
  case (int) OPT_ISAM_LOG:
 
4889
    opt_myisam_log=1;
 
4890
    break;
 
4891
  case (int) OPT_UPDATE_LOG:
 
4892
    opt_update_log=1;
 
4893
    break;
 
4894
  case (int) OPT_BIN_LOG:
 
4895
    opt_bin_log= test(argument != disabled_my_option);
 
4896
    break;
 
4897
  case (int) OPT_ERROR_LOG_FILE:
 
4898
    opt_error_log= 1;
 
4899
    break;
 
4900
  case (int)OPT_REPLICATE_IGNORE_DB:
 
4901
  {
 
4902
    rpl_filter->add_ignore_db(argument);
 
4903
    break;
 
4904
  }
 
4905
  case (int)OPT_REPLICATE_DO_DB:
 
4906
  {
 
4907
    rpl_filter->add_do_db(argument);
 
4908
    break;
 
4909
  }
 
4910
  case (int)OPT_REPLICATE_REWRITE_DB:
 
4911
  {
 
4912
    char* key = argument,*p, *val;
 
4913
 
 
4914
    if (!(p= strstr(argument, "->")))
 
4915
    {
 
4916
      fprintf(stderr,
 
4917
              "Bad syntax in replicate-rewrite-db - missing '->'!\n");
 
4918
      exit(1);
 
4919
    }
 
4920
    val= p--;
 
4921
    while (my_isspace(mysqld_charset, *p) && p > argument)
 
4922
      *p-- = 0;
 
4923
    if (p == argument)
 
4924
    {
 
4925
      fprintf(stderr,
 
4926
              "Bad syntax in replicate-rewrite-db - empty FROM db!\n");
 
4927
      exit(1);
 
4928
    }
 
4929
    *val= 0;
 
4930
    val+= 2;
 
4931
    while (*val && my_isspace(mysqld_charset, *val))
 
4932
      *val++;
 
4933
    if (!*val)
 
4934
    {
 
4935
      fprintf(stderr,
 
4936
              "Bad syntax in replicate-rewrite-db - empty TO db!\n");
 
4937
      exit(1);
 
4938
    }
 
4939
 
 
4940
    rpl_filter->add_db_rewrite(key, val);
 
4941
    break;
 
4942
  }
 
4943
 
 
4944
  case (int)OPT_BINLOG_IGNORE_DB:
 
4945
  {
 
4946
    binlog_filter->add_ignore_db(argument);
 
4947
    break;
 
4948
  }
 
4949
  case OPT_BINLOG_FORMAT:
 
4950
  {
 
4951
    int id;
 
4952
    id= find_type_or_exit(argument, &binlog_format_typelib, opt->name);
 
4953
    global_system_variables.binlog_format= opt_binlog_format_id= id - 1;
 
4954
    break;
 
4955
  }
 
4956
  case (int)OPT_BINLOG_DO_DB:
 
4957
  {
 
4958
    binlog_filter->add_do_db(argument);
 
4959
    break;
 
4960
  }
 
4961
  case (int)OPT_REPLICATE_DO_TABLE:
 
4962
  {
 
4963
    if (rpl_filter->add_do_table(argument))
 
4964
    {
 
4965
      fprintf(stderr, "Could not add do table rule '%s'!\n", argument);
 
4966
      exit(1);
 
4967
    }
 
4968
    break;
 
4969
  }
 
4970
  case (int)OPT_REPLICATE_WILD_DO_TABLE:
 
4971
  {
 
4972
    if (rpl_filter->add_wild_do_table(argument))
 
4973
    {
 
4974
      fprintf(stderr, "Could not add do table rule '%s'!\n", argument);
 
4975
      exit(1);
 
4976
    }
 
4977
    break;
 
4978
  }
 
4979
  case (int)OPT_REPLICATE_WILD_IGNORE_TABLE:
 
4980
  {
 
4981
    if (rpl_filter->add_wild_ignore_table(argument))
 
4982
    {
 
4983
      fprintf(stderr, "Could not add ignore table rule '%s'!\n", argument);
 
4984
      exit(1);
 
4985
    }
 
4986
    break;
 
4987
  }
 
4988
  case (int)OPT_REPLICATE_IGNORE_TABLE:
 
4989
  {
 
4990
    if (rpl_filter->add_ignore_table(argument))
 
4991
    {
 
4992
      fprintf(stderr, "Could not add ignore table rule '%s'!\n", argument);
 
4993
      exit(1);
 
4994
    }
 
4995
    break;
 
4996
  }
 
4997
  case (int) OPT_SLOW_QUERY_LOG:
 
4998
    opt_slow_log= 1;
 
4999
    break;
 
5000
#ifdef WITH_CSV_STORAGE_ENGINE
 
5001
  case  OPT_LOG_OUTPUT:
 
5002
  {
 
5003
    if (!argument || !argument[0])
 
5004
    {
 
5005
      log_output_options= LOG_FILE;
 
5006
      log_output_str= log_output_typelib.type_names[1];
 
5007
    }
 
5008
    else
 
5009
    {
 
5010
      log_output_str= argument;
 
5011
      log_output_options=
 
5012
        find_bit_type_or_exit(argument, &log_output_typelib, opt->name);
 
5013
  }
 
5014
    break;
 
5015
  }
 
5016
#endif
 
5017
  case (int) OPT_SKIP_NEW:
 
5018
    opt_specialflag|= SPECIAL_NO_NEW_FUNC;
 
5019
    delay_key_write_options= (uint) DELAY_KEY_WRITE_NONE;
 
5020
    myisam_concurrent_insert=0;
 
5021
    myisam_recover_options= HA_RECOVER_NONE;
 
5022
    my_use_symdir=0;
 
5023
    ha_open_options&= ~(HA_OPEN_ABORT_IF_CRASHED | HA_OPEN_DELAY_KEY_WRITE);
 
5024
    break;
 
5025
  case (int) OPT_SAFE:
 
5026
    opt_specialflag|= SPECIAL_SAFE_MODE;
 
5027
    delay_key_write_options= (uint) DELAY_KEY_WRITE_NONE;
 
5028
    myisam_recover_options= HA_RECOVER_DEFAULT;
 
5029
    ha_open_options&= ~(HA_OPEN_DELAY_KEY_WRITE);
 
5030
    break;
 
5031
  case (int) OPT_SKIP_PRIOR:
 
5032
    opt_specialflag|= SPECIAL_NO_PRIOR;
 
5033
    break;
 
5034
  case (int) OPT_SKIP_LOCK:
 
5035
    opt_external_locking=0;
 
5036
    break;
 
5037
  case (int) OPT_SKIP_SHOW_DB:
 
5038
    opt_skip_show_db=1;
 
5039
    opt_specialflag|=SPECIAL_SKIP_SHOW_DB;
 
5040
    break;
 
5041
  case (int) OPT_WANT_CORE:
 
5042
    test_flags |= TEST_CORE_ON_SIGNAL;
 
5043
    break;
 
5044
  case (int) OPT_SKIP_STACK_TRACE:
 
5045
    test_flags|=TEST_NO_STACKTRACE;
 
5046
    break;
 
5047
  case (int) OPT_SKIP_SYMLINKS:
 
5048
    my_use_symdir=0;
 
5049
    break;
 
5050
  case (int) OPT_BIND_ADDRESS:
 
5051
    {
 
5052
      struct addrinfo *res_lst, hints;    
 
5053
 
 
5054
      bzero(&hints, sizeof(struct addrinfo));
 
5055
      hints.ai_socktype= SOCK_STREAM;
 
5056
      hints.ai_protocol= IPPROTO_TCP;
 
5057
 
 
5058
      if (getaddrinfo(argument, NULL, &hints, &res_lst) != 0) 
 
5059
      {
 
5060
        sql_print_error("Can't start server: cannot resolve hostname!");
 
5061
        exit(1);
 
5062
      }
 
5063
 
 
5064
      if (res_lst->ai_next)
 
5065
      {
 
5066
        sql_print_error("Can't start server: bind-address refers to multiple interfaces!");
 
5067
        exit(1);
 
5068
      }
 
5069
      freeaddrinfo(res_lst);
 
5070
    }
 
5071
    break;
 
5072
  case (int) OPT_PID_FILE:
 
5073
    strmake(pidfile_name, argument, sizeof(pidfile_name)-1);
 
5074
    break;
 
5075
  case OPT_CONSOLE:
 
5076
    if (opt_console)
 
5077
      opt_error_log= 0;                 // Force logs to stdout
 
5078
    break;
 
5079
  case (int) OPT_FLUSH:
 
5080
    myisam_flush=1;
 
5081
    flush_time=0;                       // No auto flush
 
5082
    break;
 
5083
  case OPT_LOW_PRIORITY_UPDATES:
 
5084
    thr_upgraded_concurrent_insert_lock= TL_WRITE_LOW_PRIORITY;
 
5085
    global_system_variables.low_priority_updates=1;
 
5086
    break;
 
5087
  case OPT_BOOTSTRAP:
 
5088
    opt_noacl=opt_bootstrap=1;
 
5089
    break;
 
5090
  case OPT_SERVER_ID:
 
5091
    server_id_supplied = 1;
 
5092
    break;
 
5093
  case OPT_DELAY_KEY_WRITE_ALL:
 
5094
    if (argument != disabled_my_option)
 
5095
      argument= (char*) "ALL";
 
5096
    /* Fall through */
 
5097
  case OPT_DELAY_KEY_WRITE:
 
5098
    if (argument == disabled_my_option)
 
5099
      delay_key_write_options= (uint) DELAY_KEY_WRITE_NONE;
 
5100
    else if (! argument)
 
5101
      delay_key_write_options= (uint) DELAY_KEY_WRITE_ON;
 
5102
    else
 
5103
    {
 
5104
      int type;
 
5105
      type= find_type_or_exit(argument, &delay_key_write_typelib, opt->name);
 
5106
      delay_key_write_options= (uint) type-1;
 
5107
    }
 
5108
    break;
 
5109
  case OPT_CHARSETS_DIR:
 
5110
    strmake(mysql_charsets_dir, argument, sizeof(mysql_charsets_dir)-1);
 
5111
    charsets_dir = mysql_charsets_dir;
 
5112
    break;
 
5113
  case OPT_TX_ISOLATION:
2301
5114
  {
2302
5115
    int type;
2303
 
    type= find_type_or_exit((char *)vm["transaction-isolation"].as<string>().c_str(), &tx_isolation_typelib, "transaction-isolation");
 
5116
    type= find_type_or_exit(argument, &tx_isolation_typelib, opt->name);
2304
5117
    global_system_variables.tx_isolation= (type-1);
2305
 
  }
2306
 
 
2307
 
  /* @TODO Make this all strings */
2308
 
  if (vm.count("default-storage-engine"))
2309
 
  {
2310
 
    default_storage_engine_str= (char *)vm["default-storage-engine"].as<string>().c_str();
2311
 
  }
 
5118
    break;
 
5119
  }
 
5120
  case OPT_MYISAM_RECOVER:
 
5121
  {
 
5122
    if (!argument)
 
5123
    {
 
5124
      myisam_recover_options=    HA_RECOVER_DEFAULT;
 
5125
      myisam_recover_options_str= myisam_recover_typelib.type_names[0];
 
5126
    }
 
5127
    else if (!argument[0])
 
5128
    {
 
5129
      myisam_recover_options= HA_RECOVER_NONE;
 
5130
      myisam_recover_options_str= "OFF";
 
5131
    }
 
5132
    else
 
5133
    {
 
5134
      myisam_recover_options_str=argument;
 
5135
      myisam_recover_options=
 
5136
        find_bit_type_or_exit(argument, &myisam_recover_typelib, opt->name);
 
5137
    }
 
5138
    ha_open_options|=HA_OPEN_ABORT_IF_CRASHED;
 
5139
    break;
 
5140
  }
 
5141
  case OPT_TC_HEURISTIC_RECOVER:
 
5142
    tc_heuristic_recover= find_type_or_exit(argument,
 
5143
                                            &tc_heuristic_recover_typelib,
 
5144
                                            opt->name);
 
5145
    break;
 
5146
  case OPT_MYISAM_STATS_METHOD:
 
5147
  {
 
5148
    ulong method_conv;
 
5149
    int method;
 
5150
 
 
5151
    myisam_stats_method_str= argument;
 
5152
    method= find_type_or_exit(argument, &myisam_stats_method_typelib,
 
5153
                              opt->name);
 
5154
    switch (method-1) {
 
5155
    case 2:
 
5156
      method_conv= MI_STATS_METHOD_IGNORE_NULLS;
 
5157
      break;
 
5158
    case 1:
 
5159
      method_conv= MI_STATS_METHOD_NULLS_EQUAL;
 
5160
      break;
 
5161
    case 0:
 
5162
    default:
 
5163
      method_conv= MI_STATS_METHOD_NULLS_NOT_EQUAL;
 
5164
      break;
 
5165
    }
 
5166
    global_system_variables.myisam_stats_method= method_conv;
 
5167
    break;
 
5168
  }
 
5169
  case OPT_ONE_THREAD:
 
5170
    global_system_variables.thread_handling=
 
5171
      SCHEDULER_ONE_THREAD_PER_CONNECTION;
 
5172
    break;
 
5173
  case OPT_POOL_OF_THREADS:
 
5174
    global_system_variables.thread_handling=
 
5175
      SCHEDULER_POOL_OF_THREADS;
 
5176
    break;
 
5177
  case OPT_THREAD_HANDLING:
 
5178
  {
 
5179
    global_system_variables.thread_handling=
 
5180
      find_type_or_exit(argument, &thread_handling_typelib, opt->name)-1;
 
5181
    break;
 
5182
  }
 
5183
  case OPT_LOWER_CASE_TABLE_NAMES:
 
5184
    lower_case_table_names= argument ? atoi(argument) : 1;
 
5185
    lower_case_table_names_used= 1;
 
5186
    break;
 
5187
  }
 
5188
  return 0;
 
5189
}
 
5190
 
 
5191
 
 
5192
/** Handle arguments for multiple key caches. */
 
5193
 
 
5194
extern "C" uchar **mysql_getopt_value(const char *keyname, uint key_length,
 
5195
                                      const struct my_option *option);
 
5196
 
 
5197
uchar* *
 
5198
mysql_getopt_value(const char *keyname, uint key_length,
 
5199
                   const struct my_option *option)
 
5200
{
 
5201
  switch (option->id) {
 
5202
  case OPT_KEY_BUFFER_SIZE:
 
5203
  case OPT_KEY_CACHE_BLOCK_SIZE:
 
5204
  case OPT_KEY_CACHE_DIVISION_LIMIT:
 
5205
  case OPT_KEY_CACHE_AGE_THRESHOLD:
 
5206
  {
 
5207
    KEY_CACHE *key_cache;
 
5208
    if (!(key_cache= get_or_create_key_cache(keyname, key_length)))
 
5209
      exit(1);
 
5210
    switch (option->id) {
 
5211
    case OPT_KEY_BUFFER_SIZE:
 
5212
      return (uchar**) &key_cache->param_buff_size;
 
5213
    case OPT_KEY_CACHE_BLOCK_SIZE:
 
5214
      return (uchar**) &key_cache->param_block_size;
 
5215
    case OPT_KEY_CACHE_DIVISION_LIMIT:
 
5216
      return (uchar**) &key_cache->param_division_limit;
 
5217
    case OPT_KEY_CACHE_AGE_THRESHOLD:
 
5218
      return (uchar**) &key_cache->param_age_threshold;
 
5219
    }
 
5220
  }
 
5221
  }
 
5222
  return option->value;
 
5223
}
 
5224
 
 
5225
 
 
5226
extern "C" void option_error_reporter(enum loglevel level, const char *format, ...);
 
5227
 
 
5228
void option_error_reporter(enum loglevel level, const char *format, ...)
 
5229
{
 
5230
  va_list args;
 
5231
  va_start(args, format);
 
5232
 
 
5233
  /* Don't print warnings for --loose options during bootstrap */
 
5234
  if (level == ERROR_LEVEL || !opt_bootstrap ||
 
5235
      global_system_variables.log_warnings)
 
5236
  {
 
5237
    vprint_msg_to_log(level, format, args);
 
5238
  }
 
5239
  va_end(args);
 
5240
}
 
5241
 
 
5242
 
 
5243
/**
 
5244
  @todo
 
5245
  - FIXME add EXIT_TOO_MANY_ARGUMENTS to "mysys_err.h" and return that code?
 
5246
*/
 
5247
static void get_options(int *argc,char **argv)
 
5248
{
 
5249
  int ho_error;
 
5250
 
 
5251
  my_getopt_register_get_addr(mysql_getopt_value);
 
5252
  my_getopt_error_reporter= option_error_reporter;
2312
5253
 
2313
5254
  /* Skip unknown options so that they may be processed later by plugins */
2314
 
  my_getopt_skip_unknown= true;
2315
 
 
 
5255
  my_getopt_skip_unknown= TRUE;
 
5256
 
 
5257
  if ((ho_error= handle_options(argc, &argv, my_long_options,
 
5258
                                mysqld_get_one_option)))
 
5259
    exit(ho_error);
 
5260
  (*argc)++; /* add back one for the progname handle_options removes */
 
5261
             /* no need to do this for argv as we are discarding it. */
 
5262
 
 
5263
  if ((opt_log_slow_admin_statements || opt_log_queries_not_using_indexes ||
 
5264
       opt_log_slow_slave_statements) &&
 
5265
      !opt_slow_log)
 
5266
    sql_print_warning("options --log-slow-admin-statements, --log-queries-not-using-indexes and --log-slow-slave-statements have no effect if --log-slow-queries is not set");
2316
5267
 
2317
5268
#if defined(HAVE_BROKEN_REALPATH)
2318
 
  internal::my_use_symdir=0;
2319
 
  internal::my_disable_symlinks=1;
 
5269
  my_use_symdir=0;
 
5270
  my_disable_symlinks=1;
2320
5271
  have_symlink=SHOW_OPTION_NO;
2321
5272
#else
2322
 
  if (!internal::my_use_symdir)
 
5273
  if (!my_use_symdir)
2323
5274
  {
2324
 
    internal::my_disable_symlinks=1;
 
5275
    my_disable_symlinks=1;
2325
5276
    have_symlink=SHOW_OPTION_DISABLED;
2326
5277
  }
2327
5278
#endif
2328
5279
  if (opt_debugging)
2329
5280
  {
2330
5281
    /* Allow break with SIGINT, no core or stack trace */
2331
 
    test_flags.set(TEST_SIGINT);
2332
 
    test_flags.set(TEST_NO_STACKTRACE);
2333
 
    test_flags.reset(TEST_CORE_ON_SIGNAL);
 
5282
    test_flags|= TEST_SIGINT | TEST_NO_STACKTRACE;
 
5283
    test_flags&= ~TEST_CORE_ON_SIGNAL;
2334
5284
  }
 
5285
  /* Set global MyISAM variables from delay_key_write_options */
 
5286
  fix_delay_key_write((THD*) 0, OPT_GLOBAL);
 
5287
  /* Set global slave_exec_mode from its option */
 
5288
  fix_slave_exec_mode(OPT_GLOBAL);
2335
5289
 
2336
 
  if (drizzled_chroot)
2337
 
    set_root(drizzled_chroot);
 
5290
  if (mysqld_chroot)
 
5291
    set_root(mysqld_chroot);
 
5292
  fix_paths();
2338
5293
 
2339
5294
  /*
2340
5295
    Set some global variables from the global_system_variables
2341
5296
    In most cases the global variables will not be used
2342
5297
  */
2343
 
  internal::my_default_record_cache_size=global_system_variables.read_buff_size;
2344
 
}
2345
 
 
2346
 
 
2347
 
static void fix_paths()
2348
 
{
2349
 
  fs::path pid_file_path(pid_file);
2350
 
  if (pid_file_path.root_path().string() == "")
2351
 
  {
2352
 
    pid_file_path= getDataHome();
2353
 
    pid_file_path /= pid_file;
2354
 
  }
2355
 
  pid_file= fs::system_complete(pid_file_path);
2356
 
 
2357
 
  if (not opt_help)
2358
 
  {
2359
 
    const char *tmp_string= getenv("TMPDIR") ? getenv("TMPDIR") : NULL;
2360
 
    struct stat buf;
2361
 
    drizzle_tmpdir.clear();
2362
 
 
2363
 
    if (vm.count("tmpdir"))
2364
 
    {
2365
 
      drizzle_tmpdir.append(vm["tmpdir"].as<string>());
2366
 
    }
2367
 
    else if (tmp_string == NULL)
2368
 
    {
2369
 
      drizzle_tmpdir.append(getDataHome().file_string());
2370
 
      drizzle_tmpdir.push_back(FN_LIBCHAR);
2371
 
      drizzle_tmpdir.append(GLOBAL_TEMPORARY_EXT);
2372
 
    }
 
5298
  my_disable_locking= myisam_single_user= test(opt_external_locking == 0);
 
5299
  my_default_record_cache_size=global_system_variables.read_buff_size;
 
5300
  myisam_max_temp_length=
 
5301
    (my_off_t) global_system_variables.myisam_max_sort_file_size;
 
5302
 
 
5303
  /* Set global variables based on startup options */
 
5304
  myisam_block_size=(uint) 1 << my_bit_log2(opt_myisam_block_size);
 
5305
 
 
5306
  /* long_query_time is in microseconds */
 
5307
  global_system_variables.long_query_time= max_system_variables.long_query_time=
 
5308
    (longlong) (long_query_time * 1000000.0);
 
5309
 
 
5310
  if (opt_short_log_format)
 
5311
    opt_specialflag|= SPECIAL_SHORT_LOG_FORMAT;
 
5312
 
 
5313
  if (init_global_datetime_format(MYSQL_TIMESTAMP_DATE,
 
5314
                                  &global_system_variables.date_format) ||
 
5315
      init_global_datetime_format(MYSQL_TIMESTAMP_TIME,
 
5316
                                  &global_system_variables.time_format) ||
 
5317
      init_global_datetime_format(MYSQL_TIMESTAMP_DATETIME,
 
5318
                                  &global_system_variables.datetime_format))
 
5319
    exit(1);
 
5320
 
 
5321
  if (global_system_variables.thread_handling <=
 
5322
      SCHEDULER_ONE_THREAD_PER_CONNECTION)
 
5323
    one_thread_per_connection_scheduler(&thread_scheduler);
 
5324
  else if (global_system_variables.thread_handling == SCHEDULER_NO_THREADS)
 
5325
    one_thread_scheduler(&thread_scheduler);
 
5326
  else
 
5327
    pool_of_threads_scheduler(&thread_scheduler);  /* purecov: tested */
 
5328
}
 
5329
 
 
5330
 
 
5331
/*
 
5332
  Create version name for running mysqld version
 
5333
  We automaticly add suffixes -debug, -embedded and -log to the version
 
5334
  name to make the version more descriptive.
 
5335
  (MYSQL_SERVER_SUFFIX is set by the compilation environment)
 
5336
*/
 
5337
 
 
5338
static void set_server_version(void)
 
5339
{
 
5340
  char *end= strxmov(server_version, MYSQL_SERVER_VERSION,
 
5341
                     MYSQL_SERVER_SUFFIX_STR, NullS);
 
5342
#ifndef DBUG_OFF
 
5343
  if (!strstr(MYSQL_SERVER_SUFFIX_STR, "-debug"))
 
5344
    end= strmov(end, "-debug");
 
5345
#endif
 
5346
  if (opt_log || opt_update_log || opt_slow_log || opt_bin_log)
 
5347
    strmov(end, "-log");                        // This may slow down system
 
5348
}
 
5349
 
 
5350
 
 
5351
static char *get_relative_path(const char *path)
 
5352
{
 
5353
  if (test_if_hard_path(path) &&
 
5354
      is_prefix(path,DEFAULT_MYSQL_HOME) &&
 
5355
      strcmp(DEFAULT_MYSQL_HOME,FN_ROOTDIR))
 
5356
  {
 
5357
    path+=(uint) strlen(DEFAULT_MYSQL_HOME);
 
5358
    while (*path == FN_LIBCHAR)
 
5359
      path++;
 
5360
  }
 
5361
  return (char*) path;
 
5362
}
 
5363
 
 
5364
 
 
5365
/**
 
5366
  Fix filename and replace extension where 'dir' is relative to
 
5367
  mysql_real_data_home.
 
5368
  @return
 
5369
    1 if len(path) > FN_REFLEN
 
5370
*/
 
5371
 
 
5372
bool
 
5373
fn_format_relative_to_data_home(char * to, const char *name,
 
5374
                                const char *dir, const char *extension)
 
5375
{
 
5376
  char tmp_path[FN_REFLEN];
 
5377
  if (!test_if_hard_path(dir))
 
5378
  {
 
5379
    strxnmov(tmp_path,sizeof(tmp_path)-1, mysql_real_data_home,
 
5380
             dir, NullS);
 
5381
    dir=tmp_path;
 
5382
  }
 
5383
  return !fn_format(to, name, dir, extension,
 
5384
                    MY_APPEND_EXT | MY_UNPACK_FILENAME | MY_SAFE_PATH);
 
5385
}
 
5386
 
 
5387
 
 
5388
static void fix_paths(void)
 
5389
{
 
5390
  char buff[FN_REFLEN],*pos;
 
5391
  convert_dirname(mysql_home,mysql_home,NullS);
 
5392
  /* Resolve symlinks to allow 'mysql_home' to be a relative symlink */
 
5393
  my_realpath(mysql_home,mysql_home,MYF(0));
 
5394
  /* Ensure that mysql_home ends in FN_LIBCHAR */
 
5395
  pos=strend(mysql_home);
 
5396
  if (pos[-1] != FN_LIBCHAR)
 
5397
  {
 
5398
    pos[0]= FN_LIBCHAR;
 
5399
    pos[1]= 0;
 
5400
  }
 
5401
  convert_dirname(mysql_real_data_home,mysql_real_data_home,NullS);
 
5402
  (void) fn_format(buff, mysql_real_data_home, "", "",
 
5403
                   (MY_RETURN_REAL_PATH|MY_RESOLVE_SYMLINKS));
 
5404
  (void) unpack_dirname(mysql_unpacked_real_data_home, buff);
 
5405
  convert_dirname(language,language,NullS);
 
5406
  (void) my_load_path(mysql_home,mysql_home,""); // Resolve current dir
 
5407
  (void) my_load_path(mysql_real_data_home,mysql_real_data_home,mysql_home);
 
5408
  (void) my_load_path(pidfile_name,pidfile_name,mysql_real_data_home);
 
5409
  (void) my_load_path(opt_plugin_dir, opt_plugin_dir_ptr ? opt_plugin_dir_ptr :
 
5410
                                      get_relative_path(PLUGINDIR), mysql_home);
 
5411
  opt_plugin_dir_ptr= opt_plugin_dir;
 
5412
 
 
5413
  char *sharedir=get_relative_path(SHAREDIR);
 
5414
  if (test_if_hard_path(sharedir))
 
5415
    strmake(buff,sharedir,sizeof(buff)-1);              /* purecov: tested */
 
5416
  else
 
5417
    strxnmov(buff,sizeof(buff)-1,mysql_home,sharedir,NullS);
 
5418
  convert_dirname(buff,buff,NullS);
 
5419
  (void) my_load_path(language,language,buff);
 
5420
 
 
5421
  /* If --character-sets-dir isn't given, use shared library dir */
 
5422
  if (charsets_dir != mysql_charsets_dir)
 
5423
  {
 
5424
    strxnmov(mysql_charsets_dir, sizeof(mysql_charsets_dir)-1, buff,
 
5425
             CHARSET_DIR, NullS);
 
5426
  }
 
5427
  (void) my_load_path(mysql_charsets_dir, mysql_charsets_dir, buff);
 
5428
  convert_dirname(mysql_charsets_dir, mysql_charsets_dir, NullS);
 
5429
  charsets_dir=mysql_charsets_dir;
 
5430
 
 
5431
  if (init_tmpdir(&mysql_tmpdir_list, opt_mysql_tmpdir))
 
5432
    exit(1);
 
5433
  if (!slave_load_tmpdir)
 
5434
  {
 
5435
    if (!(slave_load_tmpdir = (char*) my_strdup(mysql_tmpdir, MYF(MY_FAE))))
 
5436
      exit(1);
 
5437
  }
 
5438
  /*
 
5439
    Convert the secure-file-priv option to system format, allowing
 
5440
    a quick strcmp to check if read or write is in an allowed dir
 
5441
   */
 
5442
  if (opt_secure_file_priv)
 
5443
  {
 
5444
    convert_dirname(buff, opt_secure_file_priv, NullS);
 
5445
    my_free(opt_secure_file_priv, MYF(0));
 
5446
    opt_secure_file_priv= my_strdup(buff, MYF(MY_FAE));
 
5447
  }
 
5448
}
 
5449
 
 
5450
 
 
5451
static ulong find_bit_type_or_exit(const char *x, TYPELIB *bit_lib,
 
5452
                                   const char *option)
 
5453
{
 
5454
  ulong res;
 
5455
 
 
5456
  const char **ptr;
 
5457
  
 
5458
  if ((res= find_bit_type(x, bit_lib)) == ~(ulong) 0)
 
5459
  {
 
5460
    ptr= bit_lib->type_names;
 
5461
    if (!*x)
 
5462
      fprintf(stderr, "No option given to %s\n", option);
2373
5463
    else
2374
 
    {
2375
 
      drizzle_tmpdir.append(tmp_string);
2376
 
    }
2377
 
 
2378
 
    drizzle_tmpdir= fs::path(fs::system_complete(fs::path(drizzle_tmpdir))).file_string();
2379
 
    assert(drizzle_tmpdir.size());
2380
 
 
2381
 
    if (mkdir(drizzle_tmpdir.c_str(), 0777) == -1)
2382
 
    {
2383
 
      if (errno != EEXIST)
2384
 
      {
2385
 
        perror(drizzle_tmpdir.c_str());
2386
 
        exit(1);
2387
 
      }
2388
 
    }
2389
 
 
2390
 
    if (stat(drizzle_tmpdir.c_str(), &buf) || (S_ISDIR(buf.st_mode) == false))
2391
 
    {
2392
 
      perror(drizzle_tmpdir.c_str());
2393
 
      exit(1);
2394
 
    }
2395
 
  }
2396
 
 
2397
 
}
2398
 
 
2399
 
} /* namespace drizzled */
2400
 
 
 
5464
      fprintf(stderr, "Wrong option to %s. Option(s) given: %s\n", option, x);
 
5465
    fprintf(stderr, "Alternatives are: '%s'", *ptr);
 
5466
    while (*++ptr)
 
5467
      fprintf(stderr, ",'%s'", *ptr);
 
5468
    fprintf(stderr, "\n");
 
5469
    exit(1);
 
5470
  }
 
5471
  return res;
 
5472
}
 
5473
 
 
5474
 
 
5475
/**
 
5476
  @return
 
5477
    a bitfield from a string of substrings separated by ','
 
5478
    or
 
5479
    ~(ulong) 0 on error.
 
5480
*/
 
5481
 
 
5482
static ulong find_bit_type(const char *x, TYPELIB *bit_lib)
 
5483
{
 
5484
  bool found_end;
 
5485
  int  found_count;
 
5486
  const char *end,*i,*j;
 
5487
  const char **array, *pos;
 
5488
  ulong found,found_int,bit;
 
5489
  DBUG_ENTER("find_bit_type");
 
5490
  DBUG_PRINT("enter",("x: '%s'",x));
 
5491
 
 
5492
  found=0;
 
5493
  found_end= 0;
 
5494
  pos=(char *) x;
 
5495
  while (*pos == ' ') pos++;
 
5496
  found_end= *pos == 0;
 
5497
  while (!found_end)
 
5498
  {
 
5499
    if (!*(end=strcend(pos,',')))               /* Let end point at fieldend */
 
5500
    {
 
5501
      while (end > pos && end[-1] == ' ')
 
5502
        end--;                                  /* Skip end-space */
 
5503
      found_end=1;
 
5504
    }
 
5505
    found_int=0; found_count=0;
 
5506
    for (array=bit_lib->type_names, bit=1 ; (i= *array++) ; bit<<=1)
 
5507
    {
 
5508
      j=pos;
 
5509
      while (j != end)
 
5510
      {
 
5511
        if (my_toupper(mysqld_charset,*i++) !=
 
5512
            my_toupper(mysqld_charset,*j++))
 
5513
          goto skip;
 
5514
      }
 
5515
      found_int=bit;
 
5516
      if (! *i)
 
5517
      {
 
5518
        found_count=1;
 
5519
        break;
 
5520
      }
 
5521
      else if (j != pos)                        // Half field found
 
5522
      {
 
5523
        found_count++;                          // Could be one of two values
 
5524
      }
 
5525
skip: ;
 
5526
    }
 
5527
    if (found_count != 1)
 
5528
      DBUG_RETURN(~(ulong) 0);                          // No unique value
 
5529
    found|=found_int;
 
5530
    pos=end+1;
 
5531
  }
 
5532
 
 
5533
  DBUG_PRINT("exit",("bit-field: %ld",(ulong) found));
 
5534
  DBUG_RETURN(found);
 
5535
} /* find_bit_type */
 
5536
 
 
5537
 
 
5538
/**
 
5539
  Check if file system used for databases is case insensitive.
 
5540
 
 
5541
  @param dir_name                       Directory to test
 
5542
 
 
5543
  @retval
 
5544
    -1  Don't know (Test failed)
 
5545
  @retval
 
5546
    0   File system is case sensitive
 
5547
  @retval
 
5548
    1   File system is case insensitive
 
5549
*/
 
5550
 
 
5551
static int test_if_case_insensitive(const char *dir_name)
 
5552
{
 
5553
  int result= 0;
 
5554
  File file;
 
5555
  char buff[FN_REFLEN], buff2[FN_REFLEN];
 
5556
  MY_STAT stat_info;
 
5557
  DBUG_ENTER("test_if_case_insensitive");
 
5558
 
 
5559
  fn_format(buff, glob_hostname, dir_name, ".lower-test",
 
5560
            MY_UNPACK_FILENAME | MY_REPLACE_EXT | MY_REPLACE_DIR);
 
5561
  fn_format(buff2, glob_hostname, dir_name, ".LOWER-TEST",
 
5562
            MY_UNPACK_FILENAME | MY_REPLACE_EXT | MY_REPLACE_DIR);
 
5563
  (void) my_delete(buff2, MYF(0));
 
5564
  if ((file= my_create(buff, 0666, O_RDWR, MYF(0))) < 0)
 
5565
  {
 
5566
    sql_print_warning("Can't create test file %s", buff);
 
5567
    DBUG_RETURN(-1);
 
5568
  }
 
5569
  my_close(file, MYF(0));
 
5570
  if (my_stat(buff2, &stat_info, MYF(0)))
 
5571
    result= 1;                                  // Can access file
 
5572
  (void) my_delete(buff, MYF(MY_WME));
 
5573
  DBUG_PRINT("exit", ("result: %d", result));
 
5574
  DBUG_RETURN(result);
 
5575
}
 
5576
 
 
5577
 
 
5578
/**
 
5579
  Create file to store pid number.
 
5580
*/
 
5581
static void create_pid_file()
 
5582
{
 
5583
  File file;
 
5584
  if ((file = my_create(pidfile_name,0664,
 
5585
                        O_WRONLY | O_TRUNC, MYF(MY_WME))) >= 0)
 
5586
  {
 
5587
    char buff[21], *end;
 
5588
    end= int10_to_str((long) getpid(), buff, 10);
 
5589
    *end++= '\n';
 
5590
    if (!my_write(file, (uchar*) buff, (uint) (end-buff), MYF(MY_WME | MY_NABP)))
 
5591
    {
 
5592
      (void) my_close(file, MYF(0));
 
5593
      return;
 
5594
    }
 
5595
    (void) my_close(file, MYF(0));
 
5596
  }
 
5597
  sql_perror("Can't start server: can't create PID file");
 
5598
  exit(1);
 
5599
}
 
5600
 
 
5601
/** Clear most status variables. */
 
5602
void refresh_status(THD *thd)
 
5603
{
 
5604
  pthread_mutex_lock(&LOCK_status);
 
5605
 
 
5606
  /* Add thread's status variabes to global status */
 
5607
  add_to_status(&global_status_var, &thd->status_var);
 
5608
 
 
5609
  /* Reset thread's status variables */
 
5610
  bzero((uchar*) &thd->status_var, sizeof(thd->status_var));
 
5611
 
 
5612
  /* Reset some global variables */
 
5613
  reset_status_vars();
 
5614
 
 
5615
  /* Reset the counters of all key caches (default and named). */
 
5616
  process_key_caches(reset_key_cache_counters);
 
5617
  flush_status_time= time((time_t*) 0);
 
5618
  pthread_mutex_unlock(&LOCK_status);
 
5619
 
 
5620
  /*
 
5621
    Set max_used_connections to the number of currently open
 
5622
    connections.  Lock LOCK_thread_count out of LOCK_status to avoid
 
5623
    deadlocks.  Status reset becomes not atomic, but status data is
 
5624
    not exact anyway.
 
5625
  */
 
5626
  pthread_mutex_lock(&LOCK_thread_count);
 
5627
  max_used_connections= thread_count;
 
5628
  pthread_mutex_unlock(&LOCK_thread_count);
 
5629
}
 
5630
 
 
5631
 
 
5632
/*****************************************************************************
 
5633
  Instantiate templates
 
5634
*****************************************************************************/
 
5635
 
 
5636
#ifdef HAVE_EXPLICIT_TEMPLATE_INSTANTIATION
 
5637
/* Used templates */
 
5638
template class I_List<THD>;
 
5639
template class I_List_iterator<THD>;
 
5640
template class I_List<i_string>;
 
5641
template class I_List<i_string_pair>;
 
5642
template class I_List<NAMED_LIST>;
 
5643
template class I_List<Statement>;
 
5644
template class I_List_iterator<Statement>;
 
5645
#endif