/
ha_innodb.cc
21249 lines (18022 loc) · 610 KB
/
ha_innodb.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, 2020, Oracle and/or its affiliates. All Rights Reserved.
Copyright (c) 2008, 2009 Google Inc.
Copyright (c) 2009, Percona Inc.
Copyright (c) 2012, Facebook Inc.
Copyright (c) 2013, 2023, MariaDB Corporation.
Portions of this file contain modifications contributed and copyrighted by
Google, Inc. Those modifications are gratefully acknowledged and are described
briefly in the InnoDB documentation. The contributions by Google are
incorporated with their permission, and subject to the conditions contained in
the file COPYING.Google.
Portions of this file contain modifications contributed and copyrighted
by Percona Inc.. Those modifications are
gratefully acknowledged and are described briefly in the InnoDB
documentation. The contributions by Percona Inc. are incorporated with
their permission, and subject to the conditions contained in the file
COPYING.Percona.
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 Street, Fifth Floor, Boston, MA 02110-1335 USA
*****************************************************************************/
/** @file ha_innodb.cc */
#include "univ.i"
/* Include necessary SQL headers */
#include "ha_prototypes.h"
#include <debug_sync.h>
#include <gstream.h>
#include <log.h>
#include <mysys_err.h>
#include <innodb_priv.h>
#include <strfunc.h>
#include <sql_acl.h>
#include <sql_class.h>
#include <sql_show.h>
#include <sql_table.h>
#include <table_cache.h>
#include <my_check_opt.h>
#include <my_bitmap.h>
#include <mysql/service_thd_alloc.h>
#include <mysql/service_thd_wait.h>
#include "sql_type_geom.h"
#include "scope.h"
#include "srv0srv.h"
// MYSQL_PLUGIN_IMPORT extern my_bool lower_case_file_system;
// MYSQL_PLUGIN_IMPORT extern char mysql_unpacked_real_data_home[];
#include <my_service_manager.h>
#include <key.h>
#include <sql_manager.h>
/* Include necessary InnoDB headers */
#include "btr0btr.h"
#include "btr0cur.h"
#include "btr0bulk.h"
#include "btr0sea.h"
#include "buf0dblwr.h"
#include "buf0dump.h"
#include "buf0buf.h"
#include "buf0flu.h"
#include "buf0lru.h"
#include "dict0boot.h"
#include "dict0load.h"
#include "btr0defragment.h"
#include "dict0crea.h"
#include "dict0stats.h"
#include "dict0stats_bg.h"
#include "fil0fil.h"
#include "fsp0fsp.h"
#include "fts0fts.h"
#include "fts0plugin.h"
#include "fts0priv.h"
#include "fts0types.h"
#include "ibuf0ibuf.h"
#include "lock0lock.h"
#include "log0crypt.h"
#include "mtr0mtr.h"
#include "os0file.h"
#include "page0zip.h"
#include "row0import.h"
#include "row0ins.h"
#include "row0log.h"
#include "row0merge.h"
#include "row0mysql.h"
#include "row0quiesce.h"
#include "row0sel.h"
#include "row0upd.h"
#include "fil0crypt.h"
#include "srv0mon.h"
#include "srv0start.h"
#include "rem0rec.h"
#include "trx0purge.h"
#include "trx0roll.h"
#include "trx0rseg.h"
#include "trx0trx.h"
#include "fil0pagecompress.h"
#include "ut0mem.h"
#include "row0ext.h"
#include "lz4.h"
#include "lzo/lzo1x.h"
#include "lzma.h"
#include "bzlib.h"
#include "snappy-c.h"
#include <limits>
#define thd_get_trx_isolation(X) ((enum_tx_isolation)thd_tx_isolation(X))
extern "C" void thd_mark_transaction_to_rollback(MYSQL_THD thd, bool all);
unsigned long long thd_get_query_id(const MYSQL_THD thd);
void thd_clear_error(MYSQL_THD thd);
TABLE *find_fk_open_table(THD *thd, const char *db, size_t db_len,
const char *table, size_t table_len);
MYSQL_THD create_background_thd();
void reset_thd(MYSQL_THD thd);
TABLE *get_purge_table(THD *thd);
TABLE *open_purge_table(THD *thd, const char *db, size_t dblen,
const char *tb, size_t tblen);
void close_thread_tables(THD* thd);
#ifdef MYSQL_DYNAMIC_PLUGIN
#define tc_size 400
#endif
#include <mysql/plugin.h>
#include <mysql/service_wsrep.h>
#include "ha_innodb.h"
#include "i_s.h"
#include <string>
#include <sstream>
#ifdef WITH_WSREP
#include <mysql/service_md5.h>
#include "wsrep_sst.h"
#endif /* WITH_WSREP */
#ifdef HAVE_URING
/** The Linux kernel version if io_uring() is considered unsafe */
const char *io_uring_may_be_unsafe;
#endif
#define INSIDE_HA_INNOBASE_CC
#define EQ_CURRENT_THD(thd) ((thd) == current_thd)
struct handlerton* innodb_hton_ptr;
static const long AUTOINC_OLD_STYLE_LOCKING = 0;
static const long AUTOINC_NEW_STYLE_LOCKING = 1;
static const long AUTOINC_NO_LOCKING = 2;
static constexpr size_t buf_pool_chunk_min_size= 1U << 20;
static ulong innobase_open_files;
static long innobase_autoinc_lock_mode;
ulonglong innobase_buffer_pool_size;
/** Percentage of the buffer pool to reserve for 'old' blocks.
Connected to buf_LRU_old_ratio. */
static uint innobase_old_blocks_pct;
static char* innobase_data_file_path;
static char* innobase_temp_data_file_path;
/* The default values for the following char* start-up parameters
are determined in innodb_init_params(). */
static char* innobase_data_home_dir;
static char* innobase_enable_monitor_counter;
static char* innobase_disable_monitor_counter;
static char* innobase_reset_monitor_counter;
static char* innobase_reset_all_monitor_counter;
/* This variable can be set in the server configure file, specifying
stopword table to be used */
static char* innobase_server_stopword_table;
my_bool innobase_rollback_on_timeout;
static my_bool innobase_create_status_file;
my_bool innobase_stats_on_metadata;
static my_bool innodb_optimize_fulltext_only;
extern uint srv_fil_crypt_rotate_key_age;
extern uint srv_n_fil_crypt_iops;
#ifdef UNIV_DEBUG
my_bool innodb_evict_tables_on_commit_debug;
#endif
/** File format constraint for ALTER TABLE */
ulong innodb_instant_alter_column_allowed;
/** Note we cannot use rec_format_enum because we do not allow
COMPRESSED row format for innodb_default_row_format option. */
enum default_row_format_enum {
DEFAULT_ROW_FORMAT_REDUNDANT = 0,
DEFAULT_ROW_FORMAT_COMPACT = 1,
DEFAULT_ROW_FORMAT_DYNAMIC = 2,
};
/** Whether ROW_FORMAT=COMPRESSED tables are read-only */
static my_bool innodb_read_only_compressed;
/** A dummy variable */
static uint innodb_max_purge_lag_wait;
/** Wait for trx_sys.history_size() to be below a limit. */
static void innodb_max_purge_lag_wait_update(THD *thd, st_mysql_sys_var *,
void *, const void *limit)
{
const uint l= *static_cast<const uint*>(limit);
if (!trx_sys.history_exceeds(l))
return;
mysql_mutex_unlock(&LOCK_global_system_variables);
while (trx_sys.history_exceeds(l))
{
if (thd_kill_level(thd))
break;
/* Adjust for purge_coordinator_state::refresh() */
log_sys.latch.rd_lock(SRW_LOCK_CALL);
const lsn_t last= log_sys.last_checkpoint_lsn,
max_age= log_sys.max_checkpoint_age;
log_sys.latch.rd_unlock();
const lsn_t lsn= log_sys.get_lsn();
if ((lsn - last) / 4 >= max_age / 5)
buf_flush_ahead(last + max_age / 5, false);
srv_wake_purge_thread_if_not_active();
std::this_thread::sleep_for(std::chrono::milliseconds(100));
}
mysql_mutex_lock(&LOCK_global_system_variables);
}
static
void set_my_errno(int err)
{
errno = err;
}
/** Checks whether the file name belongs to a partition of a table.
@param[in] file_name file name
@return pointer to the end of the table name part of the file name, or NULL */
static
char*
is_partition(
/*=========*/
char* file_name)
{
/* We look for pattern #P# to see if the table is partitioned
MariaDB table. */
return strstr(file_name, table_name_t::part_suffix);
}
/** Return the InnoDB ROW_FORMAT enum value
@param[in] row_format row_format from "innodb_default_row_format"
@return InnoDB ROW_FORMAT value from rec_format_t enum. */
static
rec_format_t
get_row_format(
ulong row_format)
{
switch(row_format) {
case DEFAULT_ROW_FORMAT_REDUNDANT:
return(REC_FORMAT_REDUNDANT);
case DEFAULT_ROW_FORMAT_COMPACT:
return(REC_FORMAT_COMPACT);
case DEFAULT_ROW_FORMAT_DYNAMIC:
return(REC_FORMAT_DYNAMIC);
default:
ut_ad(0);
return(REC_FORMAT_DYNAMIC);
}
}
static ulong innodb_default_row_format = DEFAULT_ROW_FORMAT_DYNAMIC;
/** Possible values for system variable "innodb_stats_method". The values
are defined the same as its corresponding MyISAM system variable
"myisam_stats_method"(see "myisam_stats_method_names"), for better usability */
static const char* innodb_stats_method_names[] = {
"nulls_equal",
"nulls_unequal",
"nulls_ignored",
NullS
};
/** Used to define an enumerate type of the system variable innodb_stats_method.
This is the same as "myisam_stats_method_typelib" */
static TYPELIB innodb_stats_method_typelib = {
array_elements(innodb_stats_method_names) - 1,
"innodb_stats_method_typelib",
innodb_stats_method_names,
NULL
};
/** Possible values of the parameter innodb_checksum_algorithm */
const char* innodb_checksum_algorithm_names[] = {
"crc32",
"strict_crc32",
"full_crc32",
"strict_full_crc32",
NullS
};
/** Used to define an enumerate type of the system variable
innodb_checksum_algorithm. */
TYPELIB innodb_checksum_algorithm_typelib = {
array_elements(innodb_checksum_algorithm_names) - 1,
"innodb_checksum_algorithm_typelib",
innodb_checksum_algorithm_names,
NULL
};
/** Possible values for system variable "innodb_default_row_format". */
static const char* innodb_default_row_format_names[] = {
"redundant",
"compact",
"dynamic",
NullS
};
/** Used to define an enumerate type of the system variable
innodb_default_row_format. */
static TYPELIB innodb_default_row_format_typelib = {
array_elements(innodb_default_row_format_names) - 1,
"innodb_default_row_format_typelib",
innodb_default_row_format_names,
NULL
};
/** Names of allowed values of innodb_flush_method */
const char* innodb_flush_method_names[] = {
"fsync",
"O_DSYNC",
"littlesync",
"nosync",
"O_DIRECT",
"O_DIRECT_NO_FSYNC",
#ifdef _WIN32
"unbuffered",
"async_unbuffered" /* alias for "unbuffered" */,
"normal" /* alias for "fsync" */,
#endif
NullS
};
/** Enumeration of innodb_flush_method */
TYPELIB innodb_flush_method_typelib = {
array_elements(innodb_flush_method_names) - 1,
"innodb_flush_method_typelib",
innodb_flush_method_names,
NULL
};
/** Names of allowed values of innodb_deadlock_report */
static const char *innodb_deadlock_report_names[]= {
"off", /* Do not report any details of deadlocks */
"basic", /* Report waiting transactions and lock requests */
"full", /* Also report blocking locks */
NullS
};
static_assert(Deadlock::REPORT_OFF == 0, "compatibility");
static_assert(Deadlock::REPORT_BASIC == 1, "compatibility");
static_assert(Deadlock::REPORT_FULL == 2, "compatibility");
/** Enumeration of innodb_deadlock_report */
static TYPELIB innodb_deadlock_report_typelib = {
array_elements(innodb_deadlock_report_names) - 1,
"innodb_deadlock_report_typelib",
innodb_deadlock_report_names,
NULL
};
/** Allowed values of innodb_change_buffering */
static const char* innodb_change_buffering_names[] = {
"none", /* IBUF_USE_NONE */
"inserts", /* IBUF_USE_INSERT */
"deletes", /* IBUF_USE_DELETE_MARK */
"changes", /* IBUF_USE_INSERT_DELETE_MARK */
"purges", /* IBUF_USE_DELETE */
"all", /* IBUF_USE_ALL */
NullS
};
/** Enumeration of innodb_change_buffering */
static TYPELIB innodb_change_buffering_typelib = {
array_elements(innodb_change_buffering_names) - 1,
"innodb_change_buffering_typelib",
innodb_change_buffering_names,
NULL
};
/** Allowed values of innodb_instant_alter_column_allowed */
const char* innodb_instant_alter_column_allowed_names[] = {
"never", /* compatible with MariaDB 5.5 to 10.2 */
"add_last",/* allow instant ADD COLUMN ... LAST */
"add_drop_reorder", /* allow instant ADD anywhere & DROP & reorder */
NullS
};
/** Enumeration of innodb_instant_alter_column_allowed */
static TYPELIB innodb_instant_alter_column_allowed_typelib = {
array_elements(innodb_instant_alter_column_allowed_names) - 1,
"innodb_instant_alter_column_allowed_typelib",
innodb_instant_alter_column_allowed_names,
NULL
};
/** Retrieve the FTS Relevance Ranking result for doc with doc_id
of m_prebuilt->fts_doc_id
@param[in,out] fts_hdl FTS handler
@return the relevance ranking value */
static
float
innobase_fts_retrieve_ranking(
FT_INFO* fts_hdl);
/** Free the memory for the FTS handler
@param[in,out] fts_hdl FTS handler */
static
void
innobase_fts_close_ranking(
FT_INFO* fts_hdl);
/** Find and Retrieve the FTS Relevance Ranking result for doc with doc_id
of m_prebuilt->fts_doc_id
@param[in,out] fts_hdl FTS handler
@return the relevance ranking value */
static
float
innobase_fts_find_ranking(
FT_INFO* fts_hdl,
uchar*,
uint);
/* Call back function array defined by MySQL and used to
retrieve FTS results. */
const struct _ft_vft ft_vft_result = {NULL,
innobase_fts_find_ranking,
innobase_fts_close_ranking,
innobase_fts_retrieve_ranking,
NULL};
/** @return version of the extended FTS API */
static
uint
innobase_fts_get_version()
{
/* Currently this doesn't make much sense as returning
HA_CAN_FULLTEXT_EXT automatically mean this version is supported.
This supposed to ease future extensions. */
return(2);
}
/** @return Which part of the extended FTS API is supported */
static
ulonglong
innobase_fts_flags()
{
return(FTS_ORDERED_RESULT | FTS_DOCID_IN_RESULT);
}
/** Find and Retrieve the FTS doc_id for the current result row
@param[in,out] fts_hdl FTS handler
@return the document ID */
static
ulonglong
innobase_fts_retrieve_docid(
FT_INFO_EXT* fts_hdl);
/** Find and retrieve the size of the current result
@param[in,out] fts_hdl FTS handler
@return number of matching rows */
static
ulonglong
innobase_fts_count_matches(
FT_INFO_EXT* fts_hdl) /*!< in: FTS handler */
{
NEW_FT_INFO* handle = reinterpret_cast<NEW_FT_INFO*>(fts_hdl);
if (handle->ft_result->rankings_by_id != NULL) {
return(rbt_size(handle->ft_result->rankings_by_id));
} else {
return(0);
}
}
const struct _ft_vft_ext ft_vft_ext_result = {innobase_fts_get_version,
innobase_fts_flags,
innobase_fts_retrieve_docid,
innobase_fts_count_matches};
#ifdef HAVE_PSI_INTERFACE
# define PSI_KEY(n) {&n##_key, #n, 0}
/* Keys to register pthread mutexes in the current file with
performance schema */
static mysql_pfs_key_t pending_checkpoint_mutex_key;
# ifdef UNIV_PFS_MUTEX
mysql_pfs_key_t buf_pool_mutex_key;
mysql_pfs_key_t dict_foreign_err_mutex_key;
mysql_pfs_key_t fil_system_mutex_key;
mysql_pfs_key_t flush_list_mutex_key;
mysql_pfs_key_t fts_cache_mutex_key;
mysql_pfs_key_t fts_cache_init_mutex_key;
mysql_pfs_key_t fts_delete_mutex_key;
mysql_pfs_key_t fts_doc_id_mutex_key;
mysql_pfs_key_t ibuf_bitmap_mutex_key;
mysql_pfs_key_t ibuf_mutex_key;
mysql_pfs_key_t ibuf_pessimistic_insert_mutex_key;
mysql_pfs_key_t recalc_pool_mutex_key;
mysql_pfs_key_t purge_sys_pq_mutex_key;
mysql_pfs_key_t recv_sys_mutex_key;
mysql_pfs_key_t page_zip_stat_per_index_mutex_key;
mysql_pfs_key_t rtr_active_mutex_key;
mysql_pfs_key_t rtr_match_mutex_key;
mysql_pfs_key_t rtr_path_mutex_key;
mysql_pfs_key_t srv_innodb_monitor_mutex_key;
mysql_pfs_key_t srv_misc_tmpfile_mutex_key;
mysql_pfs_key_t srv_monitor_file_mutex_key;
mysql_pfs_key_t buf_dblwr_mutex_key;
mysql_pfs_key_t trx_pool_mutex_key;
mysql_pfs_key_t trx_pool_manager_mutex_key;
mysql_pfs_key_t lock_wait_mutex_key;
mysql_pfs_key_t trx_sys_mutex_key;
mysql_pfs_key_t srv_threads_mutex_key;
/* all_innodb_mutexes array contains mutexes that are
performance schema instrumented if "UNIV_PFS_MUTEX"
is defined */
static PSI_mutex_info all_innodb_mutexes[] = {
PSI_KEY(pending_checkpoint_mutex),
PSI_KEY(buf_pool_mutex),
PSI_KEY(dict_foreign_err_mutex),
PSI_KEY(recalc_pool_mutex),
PSI_KEY(fil_system_mutex),
PSI_KEY(flush_list_mutex),
PSI_KEY(fts_cache_mutex),
PSI_KEY(fts_cache_init_mutex),
PSI_KEY(fts_delete_mutex),
PSI_KEY(fts_doc_id_mutex),
PSI_KEY(ibuf_mutex),
PSI_KEY(ibuf_pessimistic_insert_mutex),
PSI_KEY(index_online_log),
PSI_KEY(page_zip_stat_per_index_mutex),
PSI_KEY(purge_sys_pq_mutex),
PSI_KEY(recv_sys_mutex),
PSI_KEY(srv_innodb_monitor_mutex),
PSI_KEY(srv_misc_tmpfile_mutex),
PSI_KEY(srv_monitor_file_mutex),
PSI_KEY(buf_dblwr_mutex),
PSI_KEY(trx_pool_mutex),
PSI_KEY(trx_pool_manager_mutex),
PSI_KEY(lock_wait_mutex),
PSI_KEY(srv_threads_mutex),
PSI_KEY(rtr_active_mutex),
PSI_KEY(rtr_match_mutex),
PSI_KEY(rtr_path_mutex),
PSI_KEY(trx_sys_mutex),
};
# endif /* UNIV_PFS_MUTEX */
# ifdef UNIV_PFS_RWLOCK
mysql_pfs_key_t dict_operation_lock_key;
mysql_pfs_key_t index_tree_rw_lock_key;
mysql_pfs_key_t index_online_log_key;
mysql_pfs_key_t fil_space_latch_key;
mysql_pfs_key_t trx_i_s_cache_lock_key;
mysql_pfs_key_t trx_purge_latch_key;
mysql_pfs_key_t trx_rseg_latch_key;
mysql_pfs_key_t lock_latch_key;
mysql_pfs_key_t log_latch_key;
/* all_innodb_rwlocks array contains rwlocks that are
performance schema instrumented if "UNIV_PFS_RWLOCK"
is defined */
static PSI_rwlock_info all_innodb_rwlocks[] =
{
# ifdef BTR_CUR_HASH_ADAPT
{ &btr_search_latch_key, "btr_search_latch", 0 },
# endif
{ &dict_operation_lock_key, "dict_operation_lock", 0 },
{ &fil_space_latch_key, "fil_space_latch", 0 },
{ &trx_i_s_cache_lock_key, "trx_i_s_cache_lock", 0 },
{ &trx_purge_latch_key, "trx_purge_latch", 0 },
{ &trx_rseg_latch_key, "trx_rseg_latch", 0 },
{ &lock_latch_key, "lock_latch", 0 },
{ &log_latch_key, "log_latch", 0 },
{ &index_tree_rw_lock_key, "index_tree_rw_lock", PSI_RWLOCK_FLAG_SX }
};
# endif /* UNIV_PFS_RWLOCK */
# ifdef UNIV_PFS_THREAD
/* all_innodb_threads array contains threads that are
performance schema instrumented if "UNIV_PFS_THREAD"
is defined */
static PSI_thread_info all_innodb_threads[] = {
PSI_KEY(page_cleaner_thread),
PSI_KEY(trx_rollback_clean_thread),
PSI_KEY(thread_pool_thread)
};
# endif /* UNIV_PFS_THREAD */
# ifdef UNIV_PFS_IO
/* all_innodb_files array contains the type of files that are
performance schema instrumented if "UNIV_PFS_IO" is defined */
static PSI_file_info all_innodb_files[] = {
PSI_KEY(innodb_data_file),
PSI_KEY(innodb_temp_file)
};
# endif /* UNIV_PFS_IO */
#endif /* HAVE_PSI_INTERFACE */
static void innodb_remember_check_sysvar_funcs();
mysql_var_check_func check_sysvar_enum;
mysql_var_check_func check_sysvar_int;
// should page compression be used by default for new tables
static MYSQL_THDVAR_BOOL(compression_default, PLUGIN_VAR_OPCMDARG,
"Is compression the default for new tables",
NULL, NULL, FALSE);
/** Update callback for SET [SESSION] innodb_default_encryption_key_id */
static void
innodb_default_encryption_key_id_update(THD* thd, st_mysql_sys_var* var,
void* var_ptr, const void *save)
{
uint key_id = *static_cast<const uint*>(save);
if (key_id != FIL_DEFAULT_ENCRYPTION_KEY
&& !encryption_key_id_exists(key_id)) {
push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN,
ER_WRONG_ARGUMENTS,
"innodb_default_encryption_key=%u"
" is not available", key_id);
}
*static_cast<uint*>(var_ptr) = key_id;
}
static MYSQL_THDVAR_UINT(default_encryption_key_id, PLUGIN_VAR_RQCMDARG,
"Default encryption key id used for table encryption.",
NULL, innodb_default_encryption_key_id_update,
FIL_DEFAULT_ENCRYPTION_KEY, 1, UINT_MAX32, 0);
/**
Structure for CREATE TABLE options (table options).
It needs to be called ha_table_option_struct.
The option values can be specified in the CREATE TABLE at the end:
CREATE TABLE ( ... ) *here*
*/
ha_create_table_option innodb_table_option_list[]=
{
/* With this option user can enable page compression feature for the
table */
HA_TOPTION_SYSVAR("PAGE_COMPRESSED", page_compressed, compression_default),
/* With this option user can set zip compression level for page
compression for this table*/
HA_TOPTION_NUMBER("PAGE_COMPRESSION_LEVEL", page_compression_level, 0, 1, 9, 1),
/* With this option the user can enable encryption for the table */
HA_TOPTION_ENUM("ENCRYPTED", encryption, "DEFAULT,YES,NO", 0),
/* With this option the user defines the key identifier using for the encryption */
HA_TOPTION_SYSVAR("ENCRYPTION_KEY_ID", encryption_key_id, default_encryption_key_id),
HA_TOPTION_END
};
/*************************************************************//**
Check whether valid argument given to innodb_ft_*_stopword_table.
This function is registered as a callback with MySQL.
@return 0 for valid stopword table */
static
int
innodb_stopword_table_validate(
/*===========================*/
THD* thd, /*!< in: thread handle */
struct st_mysql_sys_var* var, /*!< in: pointer to system
variable */
void* save, /*!< out: immediate result
for update function */
struct st_mysql_value* value); /*!< in: incoming string */
static
void innodb_ft_cache_size_update(THD*, st_mysql_sys_var*, void*, const void* save)
{
fts_max_cache_size= *static_cast<const size_t*>(save);
}
static
void innodb_ft_total_cache_size_update(THD*, st_mysql_sys_var*, void*, const void* save)
{
fts_max_total_cache_size= *static_cast<const size_t*>(save);
}
static bool is_mysql_datadir_path(const char *path);
/** Validate passed-in "value" is a valid directory name.
This function is registered as a callback with MySQL.
@param[in,out] thd thread handle
@param[in] var pointer to system variable
@param[out] save immediate result for update
@param[in] value incoming string
@return 0 for valid name */
static
int
innodb_tmpdir_validate(
THD* thd,
struct st_mysql_sys_var*,
void* save,
struct st_mysql_value* value)
{
char* alter_tmp_dir;
char* innodb_tmp_dir;
char buff[OS_FILE_MAX_PATH];
int len = sizeof(buff);
char tmp_abs_path[FN_REFLEN + 2];
ut_ad(save != NULL);
ut_ad(value != NULL);
if (check_global_access(thd, FILE_ACL)) {
push_warning_printf(
thd, Sql_condition::WARN_LEVEL_WARN,
ER_WRONG_ARGUMENTS,
"InnoDB: FILE Permissions required");
*static_cast<const char**>(save) = NULL;
return(1);
}
alter_tmp_dir = (char*) value->val_str(value, buff, &len);
if (!alter_tmp_dir) {
*static_cast<const char**>(save) = alter_tmp_dir;
return(0);
}
if (strlen(alter_tmp_dir) > FN_REFLEN) {
push_warning_printf(
thd, Sql_condition::WARN_LEVEL_WARN,
ER_WRONG_ARGUMENTS,
"Path length should not exceed %d bytes", FN_REFLEN);
*static_cast<const char**>(save) = NULL;
return(1);
}
my_realpath(tmp_abs_path, alter_tmp_dir, 0);
size_t tmp_abs_len = strlen(tmp_abs_path);
if (my_access(tmp_abs_path, F_OK)) {
push_warning_printf(
thd, Sql_condition::WARN_LEVEL_WARN,
ER_WRONG_ARGUMENTS,
"InnoDB: Path doesn't exist.");
*static_cast<const char**>(save) = NULL;
return(1);
} else if (my_access(tmp_abs_path, R_OK | W_OK)) {
push_warning_printf(
thd, Sql_condition::WARN_LEVEL_WARN,
ER_WRONG_ARGUMENTS,
"InnoDB: Server doesn't have permission in "
"the given location.");
*static_cast<const char**>(save) = NULL;
return(1);
}
MY_STAT stat_info_dir;
if (my_stat(tmp_abs_path, &stat_info_dir, MYF(0))) {
if ((stat_info_dir.st_mode & S_IFDIR) != S_IFDIR) {
push_warning_printf(
thd, Sql_condition::WARN_LEVEL_WARN,
ER_WRONG_ARGUMENTS,
"Given path is not a directory. ");
*static_cast<const char**>(save) = NULL;
return(1);
}
}
if (!is_mysql_datadir_path(tmp_abs_path)) {
push_warning_printf(
thd, Sql_condition::WARN_LEVEL_WARN,
ER_WRONG_ARGUMENTS,
"InnoDB: Path Location should not be same as "
"mysql data directory location.");
*static_cast<const char**>(save) = NULL;
return(1);
}
innodb_tmp_dir = static_cast<char*>(
thd_memdup(thd, tmp_abs_path, tmp_abs_len + 1));
*static_cast<const char**>(save) = innodb_tmp_dir;
return(0);
}
/******************************************************************//**
Maps a MySQL trx isolation level code to the InnoDB isolation level code
@return InnoDB isolation level */
static inline
uint
innobase_map_isolation_level(
/*=========================*/
enum_tx_isolation iso); /*!< in: MySQL isolation level code */
/** Gets field offset for a field in a table.
@param[in] table MySQL table object
@param[in] field MySQL field object (from table->field array)
@return offset */
static inline
uint
get_field_offset(
const TABLE* table,
const Field* field)
{
return field->offset(table->record[0]);
}
/*************************************************************//**
Check for a valid value of innobase_compression_algorithm.
@return 0 for valid innodb_compression_algorithm. */
static
int
innodb_compression_algorithm_validate(
/*==================================*/
THD* thd, /*!< in: thread handle */
struct st_mysql_sys_var* var, /*!< in: pointer to system
variable */
void* save, /*!< out: immediate result
for update function */
struct st_mysql_value* value); /*!< in: incoming string */
static ibool innodb_have_punch_hole=IF_PUNCH_HOLE(1, 0);
static
int
innodb_encrypt_tables_validate(
/*==================================*/
THD* thd, /*!< in: thread handle */
struct st_mysql_sys_var* var, /*!< in: pointer to system
variable */
void* save, /*!< out: immediate result
for update function */
struct st_mysql_value* value); /*!< in: incoming string */
static const char innobase_hton_name[]= "InnoDB";
static MYSQL_THDVAR_BOOL(table_locks, PLUGIN_VAR_OPCMDARG,
"Enable InnoDB locking in LOCK TABLES",
/* check_func */ NULL, /* update_func */ NULL,
/* default */ TRUE);
static MYSQL_THDVAR_BOOL(strict_mode, PLUGIN_VAR_OPCMDARG,
"Use strict mode when evaluating create options.",
NULL, NULL, TRUE);
static MYSQL_THDVAR_BOOL(ft_enable_stopword, PLUGIN_VAR_OPCMDARG,
"Create FTS index with stopword.",
NULL, NULL,
/* default */ TRUE);
static MYSQL_THDVAR_UINT(lock_wait_timeout, PLUGIN_VAR_RQCMDARG,
"Timeout in seconds an InnoDB transaction may wait for a lock before being rolled back. The value 100000000 is infinite timeout.",
NULL, NULL, 50, 0, 100000000, 0);
static MYSQL_THDVAR_STR(ft_user_stopword_table,
PLUGIN_VAR_OPCMDARG|PLUGIN_VAR_MEMALLOC,
"User supplied stopword table name, effective in the session level.",
innodb_stopword_table_validate, NULL, NULL);
static MYSQL_THDVAR_STR(tmpdir,
PLUGIN_VAR_OPCMDARG|PLUGIN_VAR_MEMALLOC,
"Directory for temporary non-tablespace files.",
innodb_tmpdir_validate, NULL, NULL);
static size_t truncated_status_writes;
static SHOW_VAR innodb_status_variables[]= {
#ifdef BTR_CUR_HASH_ADAPT
{"adaptive_hash_hash_searches", &export_vars.innodb_ahi_hit, SHOW_SIZE_T},
{"adaptive_hash_non_hash_searches",
&export_vars.innodb_ahi_miss, SHOW_SIZE_T},
#endif
{"background_log_sync", &srv_log_writes_and_flush, SHOW_SIZE_T},
{"buffer_pool_dump_status",
(char*) &export_vars.innodb_buffer_pool_dump_status, SHOW_CHAR},
{"buffer_pool_load_status",
(char*) &export_vars.innodb_buffer_pool_load_status, SHOW_CHAR},
{"buffer_pool_resize_status",
(char*) &export_vars.innodb_buffer_pool_resize_status, SHOW_CHAR},
{"buffer_pool_load_incomplete",
&export_vars.innodb_buffer_pool_load_incomplete, SHOW_BOOL},
{"buffer_pool_pages_data", &UT_LIST_GET_LEN(buf_pool.LRU), SHOW_SIZE_T},
{"buffer_pool_bytes_data",
&export_vars.innodb_buffer_pool_bytes_data, SHOW_SIZE_T},
{"buffer_pool_pages_dirty",
&UT_LIST_GET_LEN(buf_pool.flush_list), SHOW_SIZE_T},
{"buffer_pool_bytes_dirty", &buf_pool.flush_list_bytes, SHOW_SIZE_T},
{"buffer_pool_pages_flushed", &buf_pool.stat.n_pages_written, SHOW_SIZE_T},
{"buffer_pool_pages_free", &UT_LIST_GET_LEN(buf_pool.free), SHOW_SIZE_T},
#ifdef UNIV_DEBUG
{"buffer_pool_pages_latched",
&export_vars.innodb_buffer_pool_pages_latched, SHOW_SIZE_T},
#endif /* UNIV_DEBUG */
{"buffer_pool_pages_made_not_young",
&buf_pool.stat.n_pages_not_made_young, SHOW_SIZE_T},
{"buffer_pool_pages_made_young",
&buf_pool.stat.n_pages_made_young, SHOW_SIZE_T},
{"buffer_pool_pages_misc",
&export_vars.innodb_buffer_pool_pages_misc, SHOW_SIZE_T},
{"buffer_pool_pages_old", &buf_pool.LRU_old_len, SHOW_SIZE_T},
{"buffer_pool_pages_total",
&export_vars.innodb_buffer_pool_pages_total, SHOW_SIZE_T},
{"buffer_pool_pages_LRU_flushed", &buf_lru_flush_page_count, SHOW_SIZE_T},
{"buffer_pool_pages_LRU_freed", &buf_lru_freed_page_count, SHOW_SIZE_T},
{"buffer_pool_pages_split", &buf_pool.pages_split, SHOW_SIZE_T},
{"buffer_pool_read_ahead_rnd",
&buf_pool.stat.n_ra_pages_read_rnd, SHOW_SIZE_T},
{"buffer_pool_read_ahead", &buf_pool.stat.n_ra_pages_read, SHOW_SIZE_T},
{"buffer_pool_read_ahead_evicted",
&buf_pool.stat.n_ra_pages_evicted, SHOW_SIZE_T},
{"buffer_pool_read_requests", &buf_pool.stat.n_page_gets, SHOW_SIZE_T},
{"buffer_pool_reads", &buf_pool.stat.n_pages_read, SHOW_SIZE_T},
{"buffer_pool_wait_free", &buf_pool.stat.LRU_waits, SHOW_SIZE_T},
{"buffer_pool_write_requests", &buf_pool.flush_list_requests, SHOW_SIZE_T},
{"checkpoint_age", &export_vars.innodb_checkpoint_age, SHOW_SIZE_T},
{"checkpoint_max_age", &export_vars.innodb_checkpoint_max_age, SHOW_SIZE_T},
{"data_fsyncs", (size_t*) &os_n_fsyncs, SHOW_SIZE_T},
{"data_pending_fsyncs",
(size_t*) &fil_n_pending_tablespace_flushes, SHOW_SIZE_T},
{"data_pending_reads", &export_vars.innodb_data_pending_reads, SHOW_SIZE_T},
{"data_pending_writes", &export_vars.innodb_data_pending_writes,SHOW_SIZE_T},
{"data_read", &export_vars.innodb_data_read, SHOW_SIZE_T},
{"data_reads", &export_vars.innodb_data_reads, SHOW_SIZE_T},
{"data_writes", &export_vars.innodb_data_writes, SHOW_SIZE_T},
{"data_written", &export_vars.innodb_data_written, SHOW_SIZE_T},
{"dblwr_pages_written", &export_vars.innodb_dblwr_pages_written,SHOW_SIZE_T},
{"dblwr_writes", &export_vars.innodb_dblwr_writes, SHOW_SIZE_T},
{"deadlocks", &lock_sys.deadlocks, SHOW_SIZE_T},
{"history_list_length", &export_vars.innodb_history_list_length,SHOW_SIZE_T},
{"ibuf_discarded_delete_marks", &ibuf.n_discarded_ops[IBUF_OP_DELETE_MARK],
SHOW_SIZE_T},
{"ibuf_discarded_deletes", &ibuf.n_discarded_ops[IBUF_OP_DELETE],
SHOW_SIZE_T},
{"ibuf_discarded_inserts", &ibuf.n_discarded_ops[IBUF_OP_INSERT],
SHOW_SIZE_T},
{"ibuf_free_list", &ibuf.free_list_len, SHOW_SIZE_T},
{"ibuf_merged_delete_marks", &ibuf.n_merged_ops[IBUF_OP_DELETE_MARK],
SHOW_SIZE_T},
{"ibuf_merged_deletes", &ibuf.n_merged_ops[IBUF_OP_DELETE], SHOW_SIZE_T},
{"ibuf_merged_inserts", &ibuf.n_merged_ops[IBUF_OP_INSERT], SHOW_SIZE_T},
{"ibuf_merges", &ibuf.n_merges, SHOW_SIZE_T},
{"ibuf_segment_size", &ibuf.seg_size, SHOW_SIZE_T},
{"ibuf_size", &ibuf.size, SHOW_SIZE_T},
{"log_waits", &log_sys.waits, SHOW_SIZE_T},
{"log_write_requests", &log_sys.write_to_buf, SHOW_SIZE_T},
{"log_writes", &log_sys.write_to_log, SHOW_SIZE_T},
{"lsn_current", &export_vars.innodb_lsn_current, SHOW_ULONGLONG},
{"lsn_flushed", &export_vars.innodb_lsn_flushed, SHOW_ULONGLONG},
{"lsn_last_checkpoint", &export_vars.innodb_lsn_last_checkpoint,
SHOW_ULONGLONG},
{"master_thread_active_loops", &srv_main_active_loops, SHOW_SIZE_T},
{"master_thread_idle_loops", &srv_main_idle_loops, SHOW_SIZE_T},
{"max_trx_id", &export_vars.innodb_max_trx_id, SHOW_ULONGLONG},
#ifdef BTR_CUR_HASH_ADAPT
{"mem_adaptive_hash", &export_vars.innodb_mem_adaptive_hash, SHOW_SIZE_T},
#endif
{"mem_dictionary", &export_vars.innodb_mem_dictionary, SHOW_SIZE_T},
{"os_log_written", &export_vars.innodb_os_log_written, SHOW_SIZE_T},
{"page_size", &srv_page_size, SHOW_ULONG},
{"pages_created", &buf_pool.stat.n_pages_created, SHOW_SIZE_T},
{"pages_read", &buf_pool.stat.n_pages_read, SHOW_SIZE_T},
{"pages_written", &buf_pool.stat.n_pages_written, SHOW_SIZE_T},
{"row_lock_current_waits", &export_vars.innodb_row_lock_current_waits,
SHOW_SIZE_T},
{"row_lock_time", &export_vars.innodb_row_lock_time, SHOW_LONGLONG},