forked from Meituan-Dianping/SQLAdvisor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmysqld.cc
executable file
·2991 lines (2598 loc) · 99.3 KB
/
mysqld.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights
reserved.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; version 2 of the License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
#include "my_global.h" /* NO_EMBEDDED_ACCESS_CHECKS */
#include <vector>
#include <algorithm>
#include <functional>
#include <list>
#include <set>
#include "sql_priv.h"
#include "unireg.h"
#include <signal.h>
#include "sql_parse.h"
#include "sql_locale.h" // MY_LOCALES, my_locales, my_locale_by_name
#include "sql_show.h" // free_status_vars, add_status_vars,
// reset_status_vars
#include "strfunc.h" // find_set_from_flags
#include "parse_file.h" // File_parser_dummy_hook
#include "sql_db.h" // my_dboptions_cache_free
// my_dboptions_cache_init
#include "sql_table.h" // release_ddl_log, execute_ddl_log_recovery
#include "sql_time.h" // known_date_time_formats,
// get_date_time_format_str,
// date_time_format_make
#include "sql_acl.h" // acl_free, grant_free, acl_init,
// grant_init
#include "sql_base.h" // table_def_free, table_def_init,
// Table_cache,
// cached_table_definitions
#include "sql_test.h" // mysql_print_status
#include "item_create.h" // item_create_cleanup, item_create_init
#include "sql_servers.h" // servers_free, servers_init
#include "init.h" // unireg_init
#include "derror.h" // init_errmessage
#include "derror.h" // init_errmessage
#include <m_ctype.h>
#include <my_dir.h>
#include <my_bit.h>
#include <sql_common.h>
#include <my_stacktrace.h>
#include "mysqld_suffix.h"
#include "mysys_err.h"
#include "probes_mysql.h"
#include "sql_callback.h"
#include "global_threads.h"
#include "mysqld.h"
#include "my_default.h"
#ifdef WITH_PERFSCHEMA_STORAGE_ENGINE
#include "../storage/perfschema/pfs_server.h"
#endif /* WITH_PERFSCHEMA_STORAGE_ENGINE */
#include <mysql/psi/mysql_idle.h>
#include <mysql/psi/mysql_socket.h>
#include <mysql/psi/mysql_statement.h>
#include "mysql_com_server.h"
#include "set_var.h"
#include "sys_vars_shared.h"
#ifdef HAVE_SYS_PRCTL_H
#include <sys/prctl.h>
#endif
#include <thr_alarm.h>
#include <ft_global.h>
#include <errmsg.h>
#include "sql_reload.h" // reload_acl_and_cache
#include "my_timer.h" // my_os_timer_init_ext, my_os_timer_deinit
#ifdef HAVE_POLL_H
#include <poll.h>
#endif
#ifdef HAVE_FESETROUND
#include <fenv.h>
#endif
using std::min;
using std::max;
using std::vector;
#define mysqld_charset &my_charset_latin1
/* We have HAVE_purify below as this speeds up the shutdown of MySQL */
#if defined(HAVE_DEC_3_2_THREADS) || defined(SIGNALS_DONT_BREAK_READ) || defined(HAVE_purify) && defined(__linux__)
#define HAVE_CLOSE_SERVER_SOCK 1
#endif
extern "C" { // Because of SCO 3.2V4.2
#include <errno.h>
#include <sys/stat.h>
#ifndef __GNU_LIBRARY__
#define __GNU_LIBRARY__ // Skip warnings in getopt.h
#endif
#include <my_getopt.h>
#ifdef HAVE_SYSENT_H
#include <sysent.h>
#endif
#ifdef HAVE_PWD_H
#include <pwd.h> // For getpwent
#endif
#ifdef HAVE_GRP_H
#include <grp.h>
#endif
#include <my_net.h>
#if !defined(__WIN__)
#include <sys/resource.h>
#ifdef HAVE_SYS_UN_H
#include <sys/un.h>
#endif
#ifdef HAVE_SELECT_H
#include <select.h>
#endif
#ifdef HAVE_SYS_SELECT_H
#include <sys/select.h>
#endif
#include <sys/utsname.h>
#endif /* __WIN__ */
#include <my_libwrap.h>
#ifdef HAVE_SYS_MMAN_H
#include <sys/mman.h>
#endif
#ifdef __WIN__
#include <crtdbg.h>
#endif
#ifdef HAVE_SOLARIS_LARGE_PAGES
#include <sys/mman.h>
#if defined(__sun__) && defined(__GNUC__) && defined(__cplusplus) \
&& defined(_XOPEN_SOURCE)
extern int getpagesizes(size_t *, int);
extern int getpagesizes2(size_t *, int);
extern int memcntl(caddr_t, size_t, int, caddr_t, int, int);
#endif /* __sun__ ... */
#endif /* HAVE_SOLARIS_LARGE_PAGES */
#ifdef _AIX41
int initgroups(const char *,unsigned int);
#endif
#if defined(__FreeBSD__) && defined(HAVE_IEEEFP_H) && !defined(HAVE_FEDISABLEEXCEPT)
#include <ieeefp.h>
#ifdef HAVE_FP_EXCEPT // Fix type conflict
typedef fp_except fp_except_t;
#endif
#endif /* __FreeBSD__ && HAVE_IEEEFP_H && !HAVE_FEDISABLEEXCEPT */
#ifdef HAVE_SYS_FPU_H
/* for IRIX to use set_fpc_csr() */
#include <sys/fpu.h>
#endif
#ifdef HAVE_FPU_CONTROL_H
#include <fpu_control.h>
#endif
#if defined(__i386__) && !defined(HAVE_FPU_CONTROL_H)
# define fpu_control_t unsigned int
# define _FPU_EXTENDED 0x300
# define _FPU_DOUBLE 0x200
# if defined(__GNUC__) || (defined(__SUNPRO_CC) && __SUNPRO_CC >= 0x590)
# define _FPU_GETCW(cw) asm volatile ("fnstcw %0" : "=m" (*&cw))
# define _FPU_SETCW(cw) asm volatile ("fldcw %0" : : "m" (*&cw))
# else
# define _FPU_GETCW(cw) (cw= 0)
# define _FPU_SETCW(cw)
# endif
#endif
inline void setup_fpu()
{
#if defined(__FreeBSD__) && defined(HAVE_IEEEFP_H) && !defined(HAVE_FEDISABLEEXCEPT)
/* We can't handle floating point exceptions with threads, so disable
this on freebsd
Don't fall for overflow, underflow,divide-by-zero or loss of precision.
fpsetmask() is deprecated in favor of fedisableexcept() in C99.
*/
#if defined(FP_X_DNML)
fpsetmask(~(FP_X_INV | FP_X_DNML | FP_X_OFL | FP_X_UFL | FP_X_DZ |
FP_X_IMP));
#else
fpsetmask(~(FP_X_INV | FP_X_OFL | FP_X_UFL | FP_X_DZ |
FP_X_IMP));
#endif /* FP_X_DNML */
#endif /* __FreeBSD__ && HAVE_IEEEFP_H && !HAVE_FEDISABLEEXCEPT */
#ifdef HAVE_FEDISABLEEXCEPT
fedisableexcept(FE_ALL_EXCEPT);
#endif
#ifdef HAVE_FESETROUND
/* Set FPU rounding mode to "round-to-nearest" */
fesetround(FE_TONEAREST);
#endif /* HAVE_FESETROUND */
/*
x86 (32-bit) requires FPU precision to be explicitly set to 64 bit
(double precision) for portable results of floating point operations.
However, there is no need to do so if compiler is using SSE2 for floating
point, double values will be stored and processed in 64 bits anyway.
*/
#if defined(__i386__) && !defined(__SSE2_MATH__)
#if defined(_WIN32)
#if !defined(_WIN64)
_control87(_PC_53, MCW_PC);
#endif /* !_WIN64 */
#else /* !_WIN32 */
fpu_control_t cw;
_FPU_GETCW(cw);
cw= (cw & ~_FPU_EXTENDED) | _FPU_DOUBLE;
_FPU_SETCW(cw);
#endif /* _WIN32 && */
#endif /* __i386__ */
#if defined(__sgi) && defined(HAVE_SYS_FPU_H)
/* Enable denormalized DOUBLE values support for IRIX */
union fpc_csr n;
n.fc_word = get_fpc_csr();
n.fc_struct.flush = 0;
set_fpc_csr(n.fc_word);
#endif
}
} /* cplusplus */
#define MYSQL_KILL_SIGNAL SIGTERM
#include <my_pthread.h> // For thr_setconcurency()
#ifdef SOLARIS
extern "C" int gethostname(char *name, int namelen);
#endif
extern "C" sig_handler handle_fatal_signal(int sig);
#if defined(__linux__)
#define ENABLE_TEMP_POOL 1
#else
#define ENABLE_TEMP_POOL 0
#endif
/* Constants */
#include <welcome_copyright_notice.h> // ORACLE_WELCOME_COPYRIGHT_NOTICE
const char *show_comp_option_name[]= {"YES", "NO", "DISABLED"};
static const char *tc_heuristic_recover_names[]=
{
"NONE", "COMMIT", "ROLLBACK", NullS
};
static TYPELIB tc_heuristic_recover_typelib=
{
array_elements(tc_heuristic_recover_names)-1,"",
tc_heuristic_recover_names, NULL
};
const char *first_keyword= "first", *binary_keyword= "BINARY";
const char *my_localhost= "localhost", *delayed_user= "DELAYED";
bool opt_large_files= sizeof(my_off_t) > 4;
static my_bool opt_autocommit; ///< for --autocommit command-line option
/*
Used with --help for detailed option
*/
static my_bool opt_help= 0, opt_verbose= 0;
arg_cmp_func Arg_comparator::comparator_matrix[5][2] =
{{&Arg_comparator::compare_string, &Arg_comparator::compare_e_string},
{&Arg_comparator::compare_real, &Arg_comparator::compare_e_real},
{&Arg_comparator::compare_int_signed, &Arg_comparator::compare_e_int},
{&Arg_comparator::compare_row, &Arg_comparator::compare_e_row},
{&Arg_comparator::compare_decimal, &Arg_comparator::compare_e_decimal}};
/* static variables */
#ifdef HAVE_PSI_INTERFACE
#if (defined(_WIN32) || defined(HAVE_SMEM)) && !defined(EMBEDDED_LIBRARY)
static PSI_thread_key key_thread_handle_con_namedpipes;
static PSI_cond_key key_COND_handler_count;
#endif /* _WIN32 || HAVE_SMEM && !EMBEDDED_LIBRARY */
#if defined(HAVE_SMEM) && !defined(EMBEDDED_LIBRARY)
static PSI_thread_key key_thread_handle_con_sharedmem;
#endif /* HAVE_SMEM && !EMBEDDED_LIBRARY */
#if (defined(_WIN32) || defined(HAVE_SMEM)) && !defined(EMBEDDED_LIBRARY)
static PSI_thread_key key_thread_handle_con_sockets;
#endif /* _WIN32 || HAVE_SMEM && !EMBEDDED_LIBRARY */
#ifdef __WIN__
static PSI_thread_key key_thread_handle_shutdown;
#endif /* __WIN__ */
#if defined (HAVE_OPENSSL) && !defined(HAVE_YASSL)
static PSI_rwlock_key key_rwlock_openssl;
#endif
#endif /* HAVE_PSI_INTERFACE */
/**
Statement instrumentation key for replication.
*/
#ifdef HAVE_PSI_STATEMENT_INTERFACE
PSI_statement_info stmt_info_rpl;
#endif
/* the default log output is log tables */
static bool lower_case_table_names_used= 0;
/* See Bug#56666 and Bug#56760 */;
volatile bool ready_to_exit;
static my_bool opt_debugging= 0, opt_external_locking= 0, opt_console= 0;
static my_bool opt_short_log_format= 0;
static uint kill_blocked_pthreads_flag, wake_pthread;
static char *mysqld_user, *mysqld_chroot;
static char *default_character_set_name;
static char *character_set_filesystem_name;
static char *lc_messages;
static char *lc_time_names_name;
char *my_bind_addr_str;
static char *default_collation_name;
char *default_storage_engine;
char *default_tmp_storage_engine;
static char compiled_default_collation_name[]= MYSQL_DEFAULT_COLLATION_NAME;
LEX_STRING opt_init_connect, opt_init_slave;
static mysql_cond_t COND_thread_cache, COND_flush_thread_cache;
/* Global variables */
bool opt_bin_log, opt_ignore_builtin_innodb= 0;
my_bool opt_log, opt_log_raw;
ulonglong log_output_options;
my_bool opt_log_queries_not_using_indexes= 0;
ulong opt_log_throttle_queries_not_using_indexes= 0;
bool opt_error_log= IF_WIN(1,0);
bool opt_disable_networking=0, opt_skip_show_db=0;
bool opt_skip_name_resolve=0;
my_bool opt_character_set_client_handshake= 1;
bool server_id_supplied = 0;
bool opt_endinfo, using_udf_functions;
bool opt_using_transactions;
bool volatile abort_loop;
bool volatile shutdown_in_progress;
ulong log_warnings;
uint host_cache_size;
#if defined(_WIN32) && !defined(EMBEDDED_LIBRARY)
ulong slow_start_timeout;
#endif
/*
True if the bootstrap thread is running. Protected by LOCK_thread_count.
Used in bootstrap() function to determine if the bootstrap thread
has completed. Note, that we can't use 'thread_count' instead,
since in 5.1, in presence of the Event Scheduler, there may be
event threads running in parallel, so it's impossible to know
what value of 'thread_count' is a sign of completion of the
bootstrap thread.
At the same time, we can't start the event scheduler after
bootstrap either, since we want to be able to process event-related
SQL commands in the init file and in --bootstrap mode.
*/
bool in_bootstrap= FALSE;
my_bool opt_bootstrap= 0;
/**
@brief 'grant_option' is used to indicate if privileges needs
to be checked, in which case the lock, LOCK_grant, is used
to protect access to the grant table.
@note This flag is dropped in 5.1
@see grant_init()
*/
bool volatile grant_option;
my_bool opt_skip_slave_start = 0; ///< If set, slave is not autostarted
my_bool opt_reckless_slave = 0;
my_bool opt_enable_named_pipe= 0;
my_bool opt_local_infile, opt_slave_compressed_protocol;
my_bool opt_safe_user_create = 0;
my_bool opt_show_slave_auth_info;
my_bool opt_log_slave_updates= 0;
char *opt_slave_skip_errors;
my_bool opt_slave_allow_batching= 0;
/**
compatibility option:
- index usage hints (USE INDEX without a FOR clause) behave as in 5.0
*/
my_bool old_mode;
/*
Legacy global handlerton. These will be removed (please do not add more).
*/
handlerton *heap_hton;
handlerton *myisam_hton;
handlerton *partition_hton;
uint opt_server_id_bits= 0;
ulong opt_server_id_mask= 0;
my_bool read_only= 0, opt_readonly= 0;
my_bool super_read_only= 0, opt_super_readonly= 0;
my_bool use_temp_pool, relay_log_purge;
my_bool relay_log_recovery;
my_bool opt_sync_frm, opt_allow_suspicious_udfs;
my_bool opt_secure_auth= 0;
char* opt_secure_file_priv= NULL;
my_bool opt_secure_file_priv_noarg= FALSE;
my_bool lower_case_file_system= 1;
my_bool opt_myisam_use_mmap= 0;
uint opt_large_page_size= 0;
#if defined(ENABLED_DEBUG_SYNC)
MYSQL_PLUGIN_IMPORT uint opt_debug_sync_timeout= 0;
#endif /* defined(ENABLED_DEBUG_SYNC) */
my_bool opt_userstat= 0, opt_thread_statistics= 0;
/*
True if there is at least one per-hour limit for some user, so we should
check them before each query (and possibly reset counters when hour is
changed). False otherwise.
*/
volatile bool mqh_used = 0;
my_bool opt_noacl= 0;
#ifdef HAVE_INITGROUPS
volatile sig_atomic_t calling_initgroups= 0; /**< Used in SIGSEGV handler. */
#endif
uint mysqld_port, test_flags, select_errors, ha_open_options;
uint mysqld_extra_port;
uint mysqld_port_timeout;
ulong delay_key_write_options;
uint lower_case_table_names;
ulong tc_heuristic_recover= 0;
int32 num_thread_running;
ulong what_to_log;
ulong slow_launch_time;
ulong open_files_limit;
ulonglong opt_mts_pending_jobs_size_max;
ulong refresh_version; /* Increments on each reload */
ulong specialflag=0;
ulonglong denied_connections= 0;
Error_log_throttle err_log_throttle(Log_throttle::LOG_THROTTLE_WINDOW_SIZE,
sql_print_error,
"Error log throttle: %10lu 'Can't create"
" thread to handle new connection'"
" error(s) suppressed");
/**
Limit of the total number of prepared statements in the server.
Is necessary to protect the server against out-of-memory attacks.
*/
ulong max_prepared_stmt_count;
/**
Current total number of prepared statements in the server. This number
is exact, and therefore may not be equal to the difference between
`com_stmt_prepare' and `com_stmt_close' (global status variables), as
the latter ones account for all registered attempts to prepare
a statement (including unsuccessful ones). Prepared statements are
currently connection-local: if the same SQL query text is prepared in
two different connections, this counts as two distinct prepared
statements.
*/
ulong prepared_stmt_count=0;
ulong thread_id=1L,current_pid;
ulong slow_launch_threads = 0;
uint opt_mts_checkpoint_period, opt_mts_checkpoint_group;
ulong expire_logs_days = 0;
/**
Soft upper limit for number of sp_head objects that can be stored
in the sp_cache for one connection.
*/
ulong stored_program_cache_size= 0;
const double log_10[] = {
1e000, 1e001, 1e002, 1e003, 1e004, 1e005, 1e006, 1e007, 1e008, 1e009,
1e010, 1e011, 1e012, 1e013, 1e014, 1e015, 1e016, 1e017, 1e018, 1e019,
1e020, 1e021, 1e022, 1e023, 1e024, 1e025, 1e026, 1e027, 1e028, 1e029,
1e030, 1e031, 1e032, 1e033, 1e034, 1e035, 1e036, 1e037, 1e038, 1e039,
1e040, 1e041, 1e042, 1e043, 1e044, 1e045, 1e046, 1e047, 1e048, 1e049,
1e050, 1e051, 1e052, 1e053, 1e054, 1e055, 1e056, 1e057, 1e058, 1e059,
1e060, 1e061, 1e062, 1e063, 1e064, 1e065, 1e066, 1e067, 1e068, 1e069,
1e070, 1e071, 1e072, 1e073, 1e074, 1e075, 1e076, 1e077, 1e078, 1e079,
1e080, 1e081, 1e082, 1e083, 1e084, 1e085, 1e086, 1e087, 1e088, 1e089,
1e090, 1e091, 1e092, 1e093, 1e094, 1e095, 1e096, 1e097, 1e098, 1e099,
1e100, 1e101, 1e102, 1e103, 1e104, 1e105, 1e106, 1e107, 1e108, 1e109,
1e110, 1e111, 1e112, 1e113, 1e114, 1e115, 1e116, 1e117, 1e118, 1e119,
1e120, 1e121, 1e122, 1e123, 1e124, 1e125, 1e126, 1e127, 1e128, 1e129,
1e130, 1e131, 1e132, 1e133, 1e134, 1e135, 1e136, 1e137, 1e138, 1e139,
1e140, 1e141, 1e142, 1e143, 1e144, 1e145, 1e146, 1e147, 1e148, 1e149,
1e150, 1e151, 1e152, 1e153, 1e154, 1e155, 1e156, 1e157, 1e158, 1e159,
1e160, 1e161, 1e162, 1e163, 1e164, 1e165, 1e166, 1e167, 1e168, 1e169,
1e170, 1e171, 1e172, 1e173, 1e174, 1e175, 1e176, 1e177, 1e178, 1e179,
1e180, 1e181, 1e182, 1e183, 1e184, 1e185, 1e186, 1e187, 1e188, 1e189,
1e190, 1e191, 1e192, 1e193, 1e194, 1e195, 1e196, 1e197, 1e198, 1e199,
1e200, 1e201, 1e202, 1e203, 1e204, 1e205, 1e206, 1e207, 1e208, 1e209,
1e210, 1e211, 1e212, 1e213, 1e214, 1e215, 1e216, 1e217, 1e218, 1e219,
1e220, 1e221, 1e222, 1e223, 1e224, 1e225, 1e226, 1e227, 1e228, 1e229,
1e230, 1e231, 1e232, 1e233, 1e234, 1e235, 1e236, 1e237, 1e238, 1e239,
1e240, 1e241, 1e242, 1e243, 1e244, 1e245, 1e246, 1e247, 1e248, 1e249,
1e250, 1e251, 1e252, 1e253, 1e254, 1e255, 1e256, 1e257, 1e258, 1e259,
1e260, 1e261, 1e262, 1e263, 1e264, 1e265, 1e266, 1e267, 1e268, 1e269,
1e270, 1e271, 1e272, 1e273, 1e274, 1e275, 1e276, 1e277, 1e278, 1e279,
1e280, 1e281, 1e282, 1e283, 1e284, 1e285, 1e286, 1e287, 1e288, 1e289,
1e290, 1e291, 1e292, 1e293, 1e294, 1e295, 1e296, 1e297, 1e298, 1e299,
1e300, 1e301, 1e302, 1e303, 1e304, 1e305, 1e306, 1e307, 1e308
};
time_t server_start_time, flush_status_time;
char mysql_home[FN_REFLEN], pidfile_name[FN_REFLEN], system_time_zone[30];
char default_logfile_name[FN_REFLEN];
char *default_tz_name;
char log_error_file[FN_REFLEN], glob_hostname[FN_REFLEN];
char mysql_real_data_home[FN_REFLEN],
lc_messages_dir[FN_REFLEN], reg_ext[FN_EXTLEN],
mysql_charsets_dir[FN_REFLEN],
*opt_init_file, *opt_tc_log_file;
char *lc_messages_dir_ptr;
char mysql_unpacked_real_data_home[FN_REFLEN];
int mysql_unpacked_real_data_home_len;
uint mysql_real_data_home_len, mysql_data_home_len= 1;
uint reg_ext_length;
char logname_path[FN_REFLEN];
char secure_file_real_path[FN_REFLEN];
DATE_TIME_FORMAT global_date_format, global_datetime_format, global_time_format;
Time_zone *default_tz;
char *mysql_data_home= const_cast<char*>(".");
const char *mysql_real_data_home_ptr= mysql_real_data_home;
char server_version[SERVER_VERSION_LENGTH];
char *mysqld_unix_port, *opt_mysql_tmpdir;
ulong thread_handling;
/** name of reference on left expression in rewritten IN subquery */
const char *in_left_expr_name= "<left expr>";
/** name of additional condition */
const char *in_additional_cond= "<IN COND>";
const char *in_having_cond= "<IN HAVING>";
my_decimal decimal_zero;
/** Number of connection errors when selecting on the listening port */
ulong connection_errors_select= 0;
/** Number of connection errors when accepting sockets in the listening port. */
ulong connection_errors_accept= 0;
/** Number of connection errors from TCP wrappers. */
ulong connection_errors_tcpwrap= 0;
/** Number of connection errors from internal server errors. */
ulong connection_errors_internal= 0;
/** Number of connection errors from the server max_connection limit. */
ulong connection_errors_max_connection= 0;
/** Number of errors when reading the peer address. */
ulong connection_errors_peer_addr= 0;
/* classes for comparation parsing/processing */
Eq_creator eq_creator;
Ne_creator ne_creator;
Gt_creator gt_creator;
Lt_creator lt_creator;
Ge_creator ge_creator;
Le_creator le_creator;
MYSQL_FILE *bootstrap_file;
int bootstrap_error;
struct system_variables global_system_variables;
struct system_variables max_system_variables;
MY_TMPDIR mysql_tmpdir_list;
MY_BITMAP temp_pool;
CHARSET_INFO *system_charset_info, *files_charset_info ;
CHARSET_INFO *national_charset_info, *table_alias_charset;
CHARSET_INFO *character_set_filesystem;
CHARSET_INFO *error_message_charset_info;
MY_LOCALE *my_default_lc_messages;
MY_LOCALE *my_default_lc_time_names;
SHOW_COMP_OPTION have_ssl, have_symlink, have_dlopen, have_query_cache;
SHOW_COMP_OPTION have_geometry, have_rtree_keys;
SHOW_COMP_OPTION have_crypt, have_compress;
SHOW_COMP_OPTION have_profiling;
SHOW_COMP_OPTION have_backup_locks;
SHOW_COMP_OPTION have_snapshot_cloning;
ulonglong opt_log_warnings_suppress= 0;
char* enforce_storage_engine= NULL;
char* utility_user= NULL;
char* utility_user_password= NULL;
char* utility_user_schema_access= NULL;
/* Plucking this from sql/sql_acl.cc for an array of privilege names */
extern TYPELIB utility_user_privileges_typelib;
ulonglong utility_user_privileges= 0;
SHOW_COMP_OPTION have_statement_timeout= SHOW_OPTION_DISABLED;
/* Thread specific variables */
pthread_key(MEM_ROOT**,THR_MALLOC);
pthread_key(THD*, THR_THD);
mysql_mutex_t LOCK_thread_created;
mysql_mutex_t LOCK_thread_count, LOCK_thd_remove;
mysql_mutex_t
LOCK_status, LOCK_error_log, LOCK_uuid_generator,
LOCK_delayed_insert, LOCK_delayed_status, LOCK_delayed_create,
LOCK_crypt,
LOCK_global_system_variables,
LOCK_user_conn, LOCK_slave_list, LOCK_active_mi,
LOCK_connection_count, LOCK_error_messages;
mysql_mutex_t LOCK_sql_rand;
mysql_mutex_t
LOCK_stats, LOCK_global_user_client_stats,
LOCK_global_table_stats, LOCK_global_index_stats;
/**
The below lock protects access to two global server variables:
max_prepared_stmt_count and prepared_stmt_count. These variables
set the limit and hold the current total number of prepared statements
in the server, respectively. As PREPARE/DEALLOCATE rate in a loaded
server may be fairly high, we need a dedicated lock.
*/
mysql_mutex_t LOCK_prepared_stmt_count;
/*
The below two locks are introudced as guards (second mutex) for
the global variables sql_slave_skip_counter and slave_net_timeout
respectively. See fix_slave_skip_counter/fix_slave_net_timeout
for more details
*/
mysql_mutex_t LOCK_sql_slave_skip_counter;
mysql_mutex_t LOCK_slave_net_timeout;
mysql_mutex_t LOCK_log_throttle_qni;
#ifdef HAVE_OPENSSL
mysql_mutex_t LOCK_des_key_file;
#endif
mysql_rwlock_t LOCK_grant, LOCK_sys_init_connect, LOCK_sys_init_slave;
mysql_rwlock_t LOCK_system_variables_hash;
mysql_cond_t COND_thread_count;
pthread_t signal_thread;
pthread_attr_t connection_attrib;
mysql_mutex_t LOCK_server_started;
mysql_rwlock_t LOCK_consistent_snapshot;
int mysqld_server_started= 0;
File_parser_dummy_hook file_parser_dummy_hook;
/* replication parameters, if master_host is not NULL, we are a slave */
uint report_port= 0;
ulong master_retry_count=0;
char *master_info_file;
char *relay_log_info_file, *report_user, *report_password, *report_host;
char *opt_relay_logname = 0, *opt_relaylog_index_name=0;
char *opt_logname, *opt_slow_logname, *opt_bin_logname;
/* Static variables */
static volatile sig_atomic_t kill_in_progress;
static my_bool opt_myisam_log;
static int cleanup_done;
static ulong opt_specialflag;
static char *opt_update_logname;
char *opt_binlog_index_name;
char *mysql_home_ptr, *pidfile_name_ptr;
/**
Initial command line arguments (arguments), after load_defaults().
This memory is allocated by @c load_defaults() and should be freed
using @c free_defaults().
Do not modify defaults_argc / defaults_argv,
use remaining_argc / remaining_argv instead to parse the command
line arguments in multiple steps.
*/
static char **defaults_argv;
/** Remaining command line arguments (count), filtered by handle_options().*/
static int remaining_argc;
/** Remaining command line arguments (arguments), filtered by handle_options().*/
static char **remaining_argv;
int orig_argc;
char **orig_argv;
THD *thd;
#if defined(HAVE_OPENSSL) && !defined(HAVE_YASSL)
bool init_rsa_keys(void);
void deinit_rsa_keys(void);
int show_rsa_public_key(THD *thd, SHOW_VAR *var, char *buff);
#endif
static volatile sig_atomic_t global_thread_count= 0;
static std::set<THD*> *global_thread_list= NULL;
static ulong blocked_pthread_count= 0;
static std::list<THD*> *waiting_thd_list= NULL;
/*
global_thread_list and waiting_thd_list are both pointers to objects
on the heap, to avoid potential problems with running destructors atexit().
*/
static void delete_global_thread_list()
{
delete global_thread_list;
delete waiting_thd_list;
global_thread_list= NULL;
waiting_thd_list= NULL;
}
Thread_iterator global_thread_list_begin()
{
mysql_mutex_assert_owner(&LOCK_thread_count);
return global_thread_list->begin();
}
Thread_iterator global_thread_list_end()
{
mysql_mutex_assert_owner(&LOCK_thread_count);
return global_thread_list->end();
}
void copy_global_thread_list(std::set<THD*> *new_copy)
{
mysql_mutex_assert_owner(&LOCK_thd_remove);
mysql_mutex_lock(&LOCK_thread_count);
*new_copy= *global_thread_list;
mysql_mutex_unlock(&LOCK_thread_count);
}
void add_global_thread(THD *thd)
{
DBUG_PRINT("info", ("add_global_thread %p", thd));
mysql_mutex_assert_owner(&LOCK_thread_count);
const bool have_thread=
global_thread_list->find(thd) != global_thread_list->end();
if (!have_thread)
{
++global_thread_count;
global_thread_list->insert(thd);
}
// Adding the same THD twice is an error.
DBUG_ASSERT(!have_thread);
}
void remove_global_thread(THD *thd)
{
DBUG_PRINT("info", ("remove_global_thread %p",
thd));
mysql_mutex_lock(&LOCK_thd_remove);
mysql_mutex_lock(&LOCK_thread_count);
DBUG_ASSERT(thd->release_resources_done());
/*
Used by binlog_reset_master. It would be cleaner to use
DEBUG_SYNC here, but that's not possible because the THD's debug
sync feature has been shut down at this point.
*/
DBUG_EXECUTE_IF("sleep_after_lock_thread_count_before_delete_thd",
sleep(5););
const size_t num_erased= global_thread_list->erase(thd);
if (num_erased == 1)
--global_thread_count;
// Removing a THD that was never added is an error.
DBUG_ASSERT(1 == num_erased);
mysql_mutex_unlock(&LOCK_thd_remove);
mysql_cond_broadcast(&COND_thread_count);
mysql_mutex_unlock(&LOCK_thread_count);
}
uint get_thread_count()
{
return (uint) global_thread_count;
}
/*
Multiple threads of execution use the random state maintained in global
sql_rand to generate random numbers. sql_rnd_with_mutex use mutex
LOCK_sql_rand to protect sql_rand across multiple instantiations that use
sql_rand to generate random numbers.
*/
ulong sql_rnd_with_mutex()
{
mysql_mutex_lock(&LOCK_sql_rand);
ulong tmp=(ulong) (my_rnd(&sql_rand) * 0xffffffff); /* make all bits random */
mysql_mutex_unlock(&LOCK_sql_rand);
return tmp;
}
#ifdef HAVE_PSI_STATEMENT_INTERFACE
PSI_statement_info stmt_info_new_packet;
#endif
/**
A log message for the error log, buffered in memory.
Log messages are temporarily buffered when generated before the error log
is initialized, and then printed once the error log is ready.
*/
class Buffered_log : public Sql_alloc
{
public:
Buffered_log(enum loglevel level, const char *message);
~Buffered_log()
{}
void print(void);
private:
/** Log message level. */
enum loglevel m_level;
/** Log message text. */
String m_message;
};
/**
Constructor.
@param level the message log level
@param message the message text
*/
Buffered_log::Buffered_log(enum loglevel level, const char *message)
: m_level(level), m_message()
{
m_message.copy(message, strlen(message), &my_charset_latin1);
}
/**
Print a buffered log to the real log file.
*/
void Buffered_log::print()
{
/*
Since messages are buffered, they can be printed out
of order with other entries in the log.
Add "Buffered xxx" to the message text to prevent confusion.
*/
switch(m_level)
{
case ERROR_LEVEL:
sql_print_error("Buffered error: %s\n", m_message.c_ptr_safe());
break;
case WARNING_LEVEL:
sql_print_warning("Buffered warning: %s\n", m_message.c_ptr_safe());
break;
case INFORMATION_LEVEL:
/*
Messages printed as "information" still end up in the mysqld *error* log,
but with a [Note] tag instead of an [ERROR] tag.
While this is probably fine for a human reading the log,
it is upsetting existing automated scripts used to parse logs,
because such scripts are likely to not already handle [Note] properly.
INFORMATION_LEVEL messages are simply silenced, on purpose,
to avoid un needed verbosity.
*/
break;
}
}
/**
Collection of all the buffered log messages.
*/
class Buffered_logs
{
public:
Buffered_logs()
{}
~Buffered_logs()
{}
void init();
void cleanup();
void buffer(enum loglevel m_level, const char *msg);
void print();
private:
/**
Memory root to use to store buffered logs.
This memory root lifespan is between init and cleanup.
Once the buffered logs are printed, they are not needed anymore,
and all the memory used is reclaimed.
*/
MEM_ROOT m_root;
/** List of buffered log messages. */
List<Buffered_log> m_list;
};
void Buffered_logs::init()
{
init_alloc_root(&m_root, 1024, 0);
}
void Buffered_logs::cleanup()
{
m_list.delete_elements();
free_root(&m_root, MYF(0));
}
/**
Add a log message to the buffer.
*/
void Buffered_logs::buffer(enum loglevel level, const char *msg)
{
/*
Do not let Sql_alloc::operator new(size_t) allocate memory,
there is no memory root associated with the main() thread.
Give explicitly the proper memory root to use to
Sql_alloc::operator new(size_t, MEM_ROOT *) instead.
*/
Buffered_log *log= new (&m_root) Buffered_log(level, msg);
if (log)
m_list.push_back(log, &m_root);
}
/**
Print buffered log messages.
*/
void Buffered_logs::print()
{
Buffered_log *log;
List_iterator_fast<Buffered_log> it(m_list);
while ((log= it++))
log->print();
}
/** Logs reported before a logger is available. */
static Buffered_logs buffered_logs;
/**
Error reporter that buffer log messages.
@param level log message level
@param format log message format string
*/
C_MODE_START
static void buffered_option_error_reporter(enum loglevel level,
const char *format, ...)
{
va_list args;
char buffer[1024];
va_start(args, format);
my_vsnprintf(buffer, sizeof(buffer), format, args);
va_end(args);
buffered_logs.buffer(level, buffer);
}
/**
Character set and collation error reporter that prints to sql error log.
@param level log message level
@param format log message format string
This routine is used to print character set and collation
warnings and errors inside an already running mysqld server,
e.g. when a character set or collation is requested for the very first time
and its initialization does not go well for some reasons.
Note: At early mysqld initialization stage,
when error log is not yet available,
we use buffered_option_error_reporter() instead,
to print general character set subsystem initialization errors,
such as Index.xml syntax problems, bad XML tag hierarchy, etc.
*/
static void charset_error_reporter(enum loglevel level,
const char *format, ...)
{
va_list args;
va_start(args, format);
vprint_msg_to_log(level, format, args);
va_end(args);
}
C_MODE_END