forked from mysql/mysql-server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathha_innodb.cc
21452 lines (17714 loc) · 600 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, 2023, Oracle and/or its affiliates.
Copyright (c) 2008, 2009 Google Inc.
Copyright (c) 2009, Percona Inc.
Copyright (c) 2012, Facebook Inc.
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, version 2.0,
as published by the Free Software Foundation.
This program is also distributed with certain software (including
but not limited to OpenSSL) that is licensed under separate terms,
as designated in a particular file or component or in included license
documentation. The authors of MySQL hereby grant you an additional
permission to link the program and your derivative works with the
separately licensed software that they have included with MySQL.
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, version 2.0, 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, Suite 500, 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 <strfunc.h>
#include <sql_acl.h>
#include <sql_class.h>
#include <sql_show.h>
#include <sql_table.h>
#include <sql_tablespace.h>
#include <sql_thd_internal_api.h>
#include <my_check_opt.h>
#include <my_bitmap.h>
#include <mysql/service_thd_alloc.h>
#include <mysql/service_thd_wait.h>
/* Include necessary InnoDB headers */
#include "api0api.h"
#include "api0misc.h"
#include "btr0btr.h"
#include "btr0cur.h"
#include "btr0bulk.h"
#include "btr0sea.h"
#include "buf0dblwr.h"
#include "buf0dump.h"
#include "buf0flu.h"
#include "buf0lru.h"
#include "dict0boot.h"
#include "dict0crea.h"
#include "dict0dict.h"
#include "dict0stats.h"
#include "dict0stats_bg.h"
#include "fil0fil.h"
#include "fsp0fsp.h"
#include "fsp0space.h"
#include "fsp0sysspace.h"
#include "fts0fts.h"
#include "fts0plugin.h"
#include "fts0priv.h"
#include "fts0types.h"
#include "ibuf0ibuf.h"
#include "lock0lock.h"
#include "log0log.h"
#include "mem0mem.h"
#include "mtr0mtr.h"
#include "os0file.h"
#include "os0thread.h"
#include "page0zip.h"
#include "pars0pars.h"
#include "rem0types.h"
#include "row0import.h"
#include "row0ins.h"
#include "row0merge.h"
#include "row0mysql.h"
#include "row0quiesce.h"
#include "row0sel.h"
#include "row0trunc.h"
#include "row0upd.h"
#include "srv0mon.h"
#include "srv0srv.h"
#include "srv0start.h"
#ifdef UNIV_DEBUG
#include "trx0purge.h"
#endif /* UNIV_DEBUG */
#include "trx0roll.h"
#include "trx0sys.h"
#include "trx0trx.h"
#include "trx0xa.h"
#include "ut0mem.h"
#include "row0ext.h"
enum_tx_isolation thd_get_trx_isolation(const THD* thd);
#include "ha_innodb.h"
#include "i_s.h"
#include "sync0sync.h"
/* for ha_innopart, Native InnoDB Partitioning. */
#include "ha_innopart.h"
/** to protect innobase_open_files */
static mysql_mutex_t innobase_share_mutex;
/** to force correct commit order in binlog */
static ulong commit_threads = 0;
static mysql_cond_t commit_cond;
static mysql_mutex_t commit_cond_m;
static bool innodb_inited = 0;
#define INSIDE_HA_INNOBASE_CC
#define EQ_CURRENT_THD(thd) ((thd) == current_thd)
static 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 long innobase_log_buffer_size;
static long innobase_open_files;
static long innobase_autoinc_lock_mode;
static ulong innobase_commit_concurrency = 0;
static ulong innobase_read_io_threads;
static ulong innobase_write_io_threads;
static long long innobase_buffer_pool_size, innobase_log_file_size;
/** Percentage of the buffer pool to reserve for 'old' blocks.
Connected to buf_LRU_old_ratio. */
static uint innobase_old_blocks_pct;
/* The default values for the following char* start-up parameters
are determined in innobase_init below: */
static char* innobase_data_home_dir = NULL;
static char* innobase_data_file_path = NULL;
static char* innobase_temp_data_file_path = NULL;
static char* innobase_file_format_name = NULL;
static char* innobase_change_buffering = NULL;
static char* innobase_enable_monitor_counter = NULL;
static char* innobase_disable_monitor_counter = NULL;
static char* innobase_reset_monitor_counter = NULL;
static char* innobase_reset_all_monitor_counter = NULL;
/* The highest file format being used in the database. The value can be
set by user, however, it will be adjusted to the newer file format if
a table of such format is created/opened. */
char* innobase_file_format_max = NULL;
/** Default value of innodb_file_format */
static const char* innodb_file_format_default = "Barracuda";
/** Default value of innodb_file_format_max */
static const char* innodb_file_format_max_default = "Antelope";
static char* innobase_file_flush_method = NULL;
/* This variable can be set in the server configure file, specifying
stopword table to be used */
static char* innobase_server_stopword_table = NULL;
/* Below we have boolean-valued start-up parameters, and their default
values */
static ulong innobase_fast_shutdown = 1;
static my_bool innobase_file_format_check = TRUE;
static my_bool innobase_use_doublewrite = TRUE;
static my_bool innobase_use_checksums = TRUE;
static my_bool innobase_locks_unsafe_for_binlog = FALSE;
static my_bool innobase_rollback_on_timeout = FALSE;
static my_bool innobase_create_status_file = FALSE;
my_bool innobase_stats_on_metadata = TRUE;
static my_bool innobase_large_prefix = FALSE;
static my_bool innodb_optimize_fulltext_only = FALSE;
static char* innodb_version_str = (char*) INNODB_VERSION_STR;
/** 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,
};
/** 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;
#ifdef UNIV_DEBUG
/** Values for --innodb-debug-compress names. */
static const char* innodb_debug_compress_names[] = {
"none",
"zlib",
"lz4",
"lz4hc",
NullS
};
/** Enumeration of --innodb-debug-compress */
static TYPELIB innodb_debug_compress_typelib = {
array_elements(innodb_debug_compress_names) - 1,
"innodb_debug_compress_typelib",
innodb_debug_compress_names,
NULL
};
#endif /* UNIV_DEBUG */
/** 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 */
static const char* innodb_checksum_algorithm_names[] = {
"crc32",
"strict_crc32",
"innodb",
"strict_innodb",
"none",
"strict_none",
NullS
};
/** Used to define an enumerate type of the system variable
innodb_checksum_algorithm. */
static 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
};
/* The following counter is used to convey information to InnoDB
about server activity: in case of normal DML ops it is not
sensible to call srv_active_wake_master_thread after each
operation, we only do it every INNOBASE_WAKE_INTERVAL'th step. */
#define INNOBASE_WAKE_INTERVAL 32
static ulong innobase_active_counter = 0;
static hash_table_t* innobase_open_tables;
/** Allowed values of innodb_change_buffering */
static const char* innobase_change_buffering_values[IBUF_USE_COUNT] = {
"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 */
};
/* Deprecation warning text */
const char PARTITION_IN_SHARED_TABLESPACE_WARNING[] =
"InnoDB : A table partition in a shared tablespace";
/* This tablespace name is reserved by InnoDB in order to explicitly
create a file_per_table tablespace for the table. */
const char reserved_file_per_table_space_name[] = "innodb_file_per_table";
/* This tablespace name is reserved by InnoDB for the system tablespace
which uses space_id 0 and stores extra types of system pages like UNDO
and doublewrite. */
const char reserved_system_space_name[] = "innodb_system";
/* This tablespace name is reserved by InnoDB for the predefined temporary
tablespace. */
const char reserved_temporary_space_name[] = "innodb_temporary";
/* 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};
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.m_value, #n, 0}
/* All RWLOCK used in Innodb are SX-locks */
# define PSI_RWLOCK_KEY(n) {&n##_key.m_value, #n, PSI_RWLOCK_FLAG_SX}
/* Keys to register pthread mutexes/cond in the current file with
performance schema */
static mysql_pfs_key_t innobase_share_mutex_key;
static mysql_pfs_key_t commit_cond_mutex_key;
static mysql_pfs_key_t commit_cond_key;
static PSI_mutex_info all_pthread_mutexes[] = {
PSI_KEY(commit_cond_mutex),
PSI_KEY(innobase_share_mutex)
};
static PSI_cond_info all_innodb_conds[] = {
PSI_KEY(commit_cond)
};
# ifdef UNIV_PFS_MUTEX
/* 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(autoinc_mutex),
# ifndef PFS_SKIP_BUFFER_MUTEX_RWLOCK
PSI_KEY(buffer_block_mutex),
# endif /* !PFS_SKIP_BUFFER_MUTEX_RWLOCK */
PSI_KEY(buf_pool_mutex),
PSI_KEY(buf_pool_zip_mutex),
PSI_KEY(cache_last_read_mutex),
PSI_KEY(dict_foreign_err_mutex),
PSI_KEY(dict_sys_mutex),
PSI_KEY(recalc_pool_mutex),
PSI_KEY(file_format_max_mutex),
PSI_KEY(fil_system_mutex),
PSI_KEY(flush_list_mutex),
PSI_KEY(fts_bg_threads_mutex),
PSI_KEY(fts_delete_mutex),
PSI_KEY(fts_optimize_mutex),
PSI_KEY(fts_doc_id_mutex),
PSI_KEY(fts_pll_tokenize_mutex),
PSI_KEY(log_flush_order_mutex),
PSI_KEY(hash_table_mutex),
PSI_KEY(ibuf_bitmap_mutex),
PSI_KEY(ibuf_mutex),
PSI_KEY(ibuf_pessimistic_insert_mutex),
PSI_KEY(log_sys_mutex),
PSI_KEY(log_sys_write_mutex),
PSI_KEY(log_cmdq_mutex),
PSI_KEY(mutex_list_mutex),
PSI_KEY(page_cleaner_mutex),
PSI_KEY(page_zip_stat_per_index_mutex),
PSI_KEY(purge_sys_pq_mutex),
PSI_KEY(recv_sys_mutex),
PSI_KEY(recv_writer_mutex),
PSI_KEY(redo_rseg_mutex),
PSI_KEY(noredo_rseg_mutex),
# ifdef UNIV_DEBUG
PSI_KEY(rw_lock_debug_mutex),
# endif /* UNIV_DEBUG */
PSI_KEY(rw_lock_list_mutex),
PSI_KEY(rw_lock_mutex),
PSI_KEY(srv_dict_tmpfile_mutex),
PSI_KEY(srv_innodb_monitor_mutex),
PSI_KEY(srv_misc_tmpfile_mutex),
PSI_KEY(srv_monitor_file_mutex),
# ifdef UNIV_DEBUG
PSI_KEY(sync_thread_mutex),
# endif /* UNIV_DEBUG */
PSI_KEY(buf_dblwr_mutex),
PSI_KEY(trx_undo_mutex),
PSI_KEY(trx_pool_mutex),
PSI_KEY(trx_pool_manager_mutex),
PSI_KEY(srv_sys_mutex),
PSI_KEY(lock_mutex),
PSI_KEY(lock_wait_mutex),
PSI_KEY(trx_mutex),
PSI_KEY(srv_threads_mutex),
# ifndef PFS_SKIP_EVENT_MUTEX
PSI_KEY(event_mutex),
PSI_KEY(event_manager_mutex),
# endif /* PFS_SKIP_EVENT_MUTEX */
PSI_KEY(rtr_active_mutex),
PSI_KEY(rtr_match_mutex),
PSI_KEY(rtr_path_mutex),
PSI_KEY(rtr_ssn_mutex),
PSI_KEY(trx_sys_mutex),
PSI_KEY(thread_mutex),
PSI_KEY(sync_array_mutex),
PSI_KEY(zip_pad_mutex),
PSI_KEY(row_drop_list_mutex),
PSI_KEY(master_key_id_mutex),
PSI_KEY(analyze_index_mutex),
};
# endif /* UNIV_PFS_MUTEX */
# ifdef UNIV_PFS_RWLOCK
/* all_innodb_rwlocks array contains rwlocks that are
performance schema instrumented if "UNIV_PFS_RWLOCK"
is defined */
static PSI_rwlock_info all_innodb_rwlocks[] = {
PSI_RWLOCK_KEY(btr_search_latch),
# ifndef PFS_SKIP_BUFFER_MUTEX_RWLOCK
PSI_RWLOCK_KEY(buf_block_lock),
# endif /* !PFS_SKIP_BUFFER_MUTEX_RWLOCK */
# ifdef UNIV_DEBUG
PSI_RWLOCK_KEY(buf_block_debug_latch),
# endif /* UNIV_DEBUG */
PSI_RWLOCK_KEY(dict_operation_lock),
PSI_RWLOCK_KEY(fil_space_latch),
PSI_RWLOCK_KEY(checkpoint_lock),
PSI_RWLOCK_KEY(fts_cache_rw_lock),
PSI_RWLOCK_KEY(fts_cache_init_rw_lock),
PSI_RWLOCK_KEY(trx_i_s_cache_lock),
PSI_RWLOCK_KEY(trx_purge_latch),
PSI_RWLOCK_KEY(index_tree_rw_lock),
PSI_RWLOCK_KEY(index_online_log),
PSI_RWLOCK_KEY(dict_table_stats),
PSI_RWLOCK_KEY(hash_table_locks),
};
# 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(buf_dump_thread),
PSI_KEY(dict_stats_thread),
PSI_KEY(io_handler_thread),
PSI_KEY(io_ibuf_thread),
PSI_KEY(io_log_thread),
PSI_KEY(io_read_thread),
PSI_KEY(io_write_thread),
PSI_KEY(page_cleaner_thread),
PSI_KEY(recv_writer_thread),
PSI_KEY(srv_error_monitor_thread),
PSI_KEY(srv_lock_timeout_thread),
PSI_KEY(srv_master_thread),
PSI_KEY(srv_monitor_thread),
PSI_KEY(srv_purge_thread),
PSI_KEY(srv_worker_thread),
PSI_KEY(trx_rollback_clean_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_log_file),
PSI_KEY(innodb_temp_file)
};
# endif /* UNIV_PFS_IO */
#endif /* HAVE_PSI_INTERFACE */
/** Set up InnoDB API callback function array */
ib_cb_t innodb_api_cb[] = {
(ib_cb_t) ib_cursor_open_table,
(ib_cb_t) ib_cursor_read_row,
(ib_cb_t) ib_cursor_insert_row,
(ib_cb_t) ib_cursor_delete_row,
(ib_cb_t) ib_cursor_update_row,
(ib_cb_t) ib_cursor_moveto,
(ib_cb_t) ib_cursor_first,
(ib_cb_t) ib_cursor_next,
(ib_cb_t) ib_cursor_set_match_mode,
(ib_cb_t) ib_sec_search_tuple_create,
(ib_cb_t) ib_clust_read_tuple_create,
(ib_cb_t) ib_tuple_delete,
(ib_cb_t) ib_tuple_read_u8,
(ib_cb_t) ib_tuple_read_u16,
(ib_cb_t) ib_tuple_read_u32,
(ib_cb_t) ib_tuple_read_u64,
(ib_cb_t) ib_tuple_read_i8,
(ib_cb_t) ib_tuple_read_i16,
(ib_cb_t) ib_tuple_read_i32,
(ib_cb_t) ib_tuple_read_i64,
(ib_cb_t) ib_tuple_get_n_cols,
(ib_cb_t) ib_col_set_value,
(ib_cb_t) ib_col_get_value,
(ib_cb_t) ib_col_get_meta,
(ib_cb_t) ib_trx_begin,
(ib_cb_t) ib_trx_commit,
(ib_cb_t) ib_trx_rollback,
(ib_cb_t) ib_trx_start,
(ib_cb_t) ib_trx_release,
(ib_cb_t) ib_cursor_lock,
(ib_cb_t) ib_cursor_close,
(ib_cb_t) ib_cursor_new_trx,
(ib_cb_t) ib_cursor_reset,
(ib_cb_t) ib_col_get_name,
(ib_cb_t) ib_table_truncate,
(ib_cb_t) ib_cursor_open_index_using_name,
(ib_cb_t) ib_cfg_get_cfg,
(ib_cb_t) ib_cursor_set_memcached_sync,
(ib_cb_t) ib_cursor_set_cluster_access,
(ib_cb_t) ib_cursor_commit_trx,
(ib_cb_t) ib_cfg_trx_level,
(ib_cb_t) ib_tuple_get_n_user_cols,
(ib_cb_t) ib_cursor_set_lock_mode,
(ib_cb_t) ib_get_idx_field_name,
(ib_cb_t) ib_trx_get_start_time,
(ib_cb_t) ib_cfg_bk_commit_interval,
(ib_cb_t) ib_ut_strerr,
(ib_cb_t) ib_cursor_stmt_begin,
(ib_cb_t) ib_trx_read_only,
(ib_cb_t) ib_is_virtual_table
};
/******************************************************************//**
Function used to loop a thread (for debugging/instrumentation
purpose). */
void
srv_debug_loop(void)
/*================*/
{
ibool set = TRUE;
while (set) {
os_thread_yield();
}
}
/******************************************************************//**
Debug function used to read a MBR data */
#ifdef UNIV_DEBUG
void
srv_mbr_debug(const byte* data)
{
double a, b, c , d;
a = mach_double_read(data);
data += sizeof(double);
b = mach_double_read(data);
data += sizeof(double);
c = mach_double_read(data);
data += sizeof(double);
d = mach_double_read(data);
ut_ad(a && b && c &&d);
}
#endif
/**Check whether valid argument given to innobase_*_stopword_table.
This function is registered as a callback with MySQL.
@param[in] thd thread handle
@param[in] var pointer to system variable
@param[out] save immediate result for update function
@param[in] value incoming string
@return 0 for valid stopword table */
static
int
innodb_stopword_table_validate(
/*===========================*/
THD* thd,
struct st_mysql_sys_var* var,
void* save,
struct st_mysql_value* value);
/** 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* 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::SL_WARNING,
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::SL_WARNING,
ER_WRONG_ARGUMENTS,
"Path length should not exceed %d bytes", FN_REFLEN);
*static_cast<const char**>(save) = NULL;
return(1);
}
os_normalize_path(alter_tmp_dir);
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::SL_WARNING,
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::SL_WARNING,
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::SL_WARNING,
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::SL_WARNING,
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
ulint
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
@return offset */
static inline
uint
get_field_offset(
const TABLE* table,
const Field* field);
static const char innobase_hton_name[]= "InnoDB";
static const char* deprecated_innodb_support_xa
= "Using innodb_support_xa is deprecated and the"
" parameter may be removed in future releases.";
static const char* deprecated_innodb_support_xa_off
= "Using innodb_support_xa is deprecated and the"
" parameter may be removed in future releases."
" Only innodb_support_xa=ON is allowed.";
/** Update the session variable innodb_support_xa.
@param[in] thd current session
@param[in] var the system variable innodb_support_xa
@param[in,out] var_ptr the contents of the variable
@param[in] save the to-be-updated value */
static
void
innodb_support_xa_update(
THD* thd,
struct st_mysql_sys_var* var,
void* var_ptr,
const void* save)
{
my_bool innodb_support_xa = *static_cast<const my_bool*>(save);
push_warning(thd, Sql_condition::SL_WARNING,
HA_ERR_WRONG_COMMAND,
innodb_support_xa
? deprecated_innodb_support_xa
: deprecated_innodb_support_xa_off);
}
static MYSQL_THDVAR_BOOL(support_xa, PLUGIN_VAR_OPCMDARG,
"Enable InnoDB support for the XA two-phase commit",
/* check_func */ NULL, innodb_support_xa_update,
/* default */ TRUE);
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_ULONG(lock_wait_timeout, PLUGIN_VAR_RQCMDARG,
"Timeout in seconds an InnoDB transaction may wait for a lock before being rolled back. Values above 100000000 disable the timeout.",
NULL, NULL, 50, 1, 1024 * 1024 * 1024, 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 SHOW_VAR innodb_status_variables[]= {
{"buffer_pool_dump_status",
(char*) &export_vars.innodb_buffer_pool_dump_status, SHOW_CHAR, SHOW_SCOPE_GLOBAL},
{"buffer_pool_load_status",
(char*) &export_vars.innodb_buffer_pool_load_status, SHOW_CHAR, SHOW_SCOPE_GLOBAL},
{"buffer_pool_resize_status",
(char*) &export_vars.innodb_buffer_pool_resize_status, SHOW_CHAR, SHOW_SCOPE_GLOBAL},
{"buffer_pool_pages_data",
(char*) &export_vars.innodb_buffer_pool_pages_data, SHOW_LONG, SHOW_SCOPE_GLOBAL},
{"buffer_pool_bytes_data",
(char*) &export_vars.innodb_buffer_pool_bytes_data, SHOW_LONG, SHOW_SCOPE_GLOBAL},
{"buffer_pool_pages_dirty",
(char*) &export_vars.innodb_buffer_pool_pages_dirty, SHOW_LONG, SHOW_SCOPE_GLOBAL},
{"buffer_pool_bytes_dirty",
(char*) &export_vars.innodb_buffer_pool_bytes_dirty, SHOW_LONG, SHOW_SCOPE_GLOBAL},
{"buffer_pool_pages_flushed",
(char*) &export_vars.innodb_buffer_pool_pages_flushed, SHOW_LONG, SHOW_SCOPE_GLOBAL},
{"buffer_pool_pages_free",
(char*) &export_vars.innodb_buffer_pool_pages_free, SHOW_LONG, SHOW_SCOPE_GLOBAL},
#ifdef UNIV_DEBUG
{"buffer_pool_pages_latched",
(char*) &export_vars.innodb_buffer_pool_pages_latched, SHOW_LONG, SHOW_SCOPE_GLOBAL},
#endif /* UNIV_DEBUG */
{"buffer_pool_pages_misc",
(char*) &export_vars.innodb_buffer_pool_pages_misc, SHOW_LONG, SHOW_SCOPE_GLOBAL},
{"buffer_pool_pages_total",
(char*) &export_vars.innodb_buffer_pool_pages_total, SHOW_LONG, SHOW_SCOPE_GLOBAL},
{"buffer_pool_read_ahead_rnd",
(char*) &export_vars.innodb_buffer_pool_read_ahead_rnd, SHOW_LONG, SHOW_SCOPE_GLOBAL},
{"buffer_pool_read_ahead",
(char*) &export_vars.innodb_buffer_pool_read_ahead, SHOW_LONG, SHOW_SCOPE_GLOBAL},
{"buffer_pool_read_ahead_evicted",
(char*) &export_vars.innodb_buffer_pool_read_ahead_evicted, SHOW_LONG, SHOW_SCOPE_GLOBAL},
{"buffer_pool_read_requests",
(char*) &export_vars.innodb_buffer_pool_read_requests, SHOW_LONG, SHOW_SCOPE_GLOBAL},
{"buffer_pool_reads",
(char*) &export_vars.innodb_buffer_pool_reads, SHOW_LONG, SHOW_SCOPE_GLOBAL},
{"buffer_pool_wait_free",
(char*) &export_vars.innodb_buffer_pool_wait_free, SHOW_LONG, SHOW_SCOPE_GLOBAL},
{"buffer_pool_write_requests",
(char*) &export_vars.innodb_buffer_pool_write_requests, SHOW_LONG, SHOW_SCOPE_GLOBAL},
{"data_fsyncs",
(char*) &export_vars.innodb_data_fsyncs, SHOW_LONG, SHOW_SCOPE_GLOBAL},
{"data_pending_fsyncs",
(char*) &export_vars.innodb_data_pending_fsyncs, SHOW_LONG, SHOW_SCOPE_GLOBAL},
{"data_pending_reads",
(char*) &export_vars.innodb_data_pending_reads, SHOW_LONG, SHOW_SCOPE_GLOBAL},
{"data_pending_writes",
(char*) &export_vars.innodb_data_pending_writes, SHOW_LONG, SHOW_SCOPE_GLOBAL},
{"data_read",
(char*) &export_vars.innodb_data_read, SHOW_LONG, SHOW_SCOPE_GLOBAL},
{"data_reads",
(char*) &export_vars.innodb_data_reads, SHOW_LONG, SHOW_SCOPE_GLOBAL},
{"data_writes",
(char*) &export_vars.innodb_data_writes, SHOW_LONG, SHOW_SCOPE_GLOBAL},
{"data_written",
(char*) &export_vars.innodb_data_written, SHOW_LONG, SHOW_SCOPE_GLOBAL},
{"dblwr_pages_written",
(char*) &export_vars.innodb_dblwr_pages_written, SHOW_LONG, SHOW_SCOPE_GLOBAL},
{"dblwr_writes",
(char*) &export_vars.innodb_dblwr_writes, SHOW_LONG, SHOW_SCOPE_GLOBAL},
{"log_waits",
(char*) &export_vars.innodb_log_waits, SHOW_LONG, SHOW_SCOPE_GLOBAL},
{"log_write_requests",
(char*) &export_vars.innodb_log_write_requests, SHOW_LONG, SHOW_SCOPE_GLOBAL},
{"log_writes",
(char*) &export_vars.innodb_log_writes, SHOW_LONG, SHOW_SCOPE_GLOBAL},
{"os_log_fsyncs",
(char*) &export_vars.innodb_os_log_fsyncs, SHOW_LONG, SHOW_SCOPE_GLOBAL},
{"os_log_pending_fsyncs",
(char*) &export_vars.innodb_os_log_pending_fsyncs, SHOW_LONG, SHOW_SCOPE_GLOBAL},
{"os_log_pending_writes",
(char*) &export_vars.innodb_os_log_pending_writes, SHOW_LONG, SHOW_SCOPE_GLOBAL},
{"os_log_written",
(char*) &export_vars.innodb_os_log_written, SHOW_LONGLONG, SHOW_SCOPE_GLOBAL},
{"page_size",
(char*) &export_vars.innodb_page_size, SHOW_LONG, SHOW_SCOPE_GLOBAL},
{"pages_created",
(char*) &export_vars.innodb_pages_created, SHOW_LONG, SHOW_SCOPE_GLOBAL},
{"pages_read",
(char*) &export_vars.innodb_pages_read, SHOW_LONG, SHOW_SCOPE_GLOBAL},
{"pages_written",
(char*) &export_vars.innodb_pages_written, SHOW_LONG, SHOW_SCOPE_GLOBAL},
{"row_lock_current_waits",
(char*) &export_vars.innodb_row_lock_current_waits, SHOW_LONG, SHOW_SCOPE_GLOBAL},
{"row_lock_time",
(char*) &export_vars.innodb_row_lock_time, SHOW_LONGLONG, SHOW_SCOPE_GLOBAL},
{"row_lock_time_avg",
(char*) &export_vars.innodb_row_lock_time_avg, SHOW_LONG, SHOW_SCOPE_GLOBAL},
{"row_lock_time_max",
(char*) &export_vars.innodb_row_lock_time_max, SHOW_LONG, SHOW_SCOPE_GLOBAL},
{"row_lock_waits",
(char*) &export_vars.innodb_row_lock_waits, SHOW_LONG, SHOW_SCOPE_GLOBAL},
{"rows_deleted",
(char*) &export_vars.innodb_rows_deleted, SHOW_LONG, SHOW_SCOPE_GLOBAL},
{"rows_inserted",
(char*) &export_vars.innodb_rows_inserted, SHOW_LONG, SHOW_SCOPE_GLOBAL},
{"rows_read",
(char*) &export_vars.innodb_rows_read, SHOW_LONG, SHOW_SCOPE_GLOBAL},
{"rows_updated",
(char*) &export_vars.innodb_rows_updated, SHOW_LONG, SHOW_SCOPE_GLOBAL},
{"num_open_files",
(char*) &export_vars.innodb_num_open_files, SHOW_LONG, SHOW_SCOPE_GLOBAL},
{"truncated_status_writes",
(char*) &export_vars.innodb_truncated_status_writes, SHOW_LONG, SHOW_SCOPE_GLOBAL},
{"available_undo_logs",
(char*) &export_vars.innodb_available_undo_logs, SHOW_LONG, SHOW_SCOPE_GLOBAL},
#ifdef UNIV_DEBUG
{"purge_trx_id_age",
(char*) &export_vars.innodb_purge_trx_id_age, SHOW_LONG, SHOW_SCOPE_GLOBAL},
{"purge_view_trx_id_age",
(char*) &export_vars.innodb_purge_view_trx_id_age, SHOW_LONG, SHOW_SCOPE_GLOBAL},
{"ahi_drop_lookups",
(char*) &export_vars.innodb_ahi_drop_lookups, SHOW_LONG, SHOW_SCOPE_GLOBAL},
#endif /* UNIV_DEBUG */
{NullS, NullS, SHOW_LONG, SHOW_SCOPE_GLOBAL}
};
/************************************************************************//**
Handling the shared INNOBASE_SHARE structure that is needed to provide table
locking. Register the table name if it doesn't exist in the hash table. */
static
INNOBASE_SHARE*
get_share(
/*======*/
const char* table_name); /*!< in: table to lookup */
/************************************************************************//**
Free the shared object that was registered with get_share(). */
static
void
free_share(
/*=======*/
INNOBASE_SHARE* share); /*!< in/own: share to free */
/*****************************************************************//**
Frees a possible InnoDB trx object associated with the current THD.
@return 0 or error number */
static
int
innobase_close_connection(
/*======================*/
handlerton* hton, /*!< in/out: InnoDB handlerton */
THD* thd); /*!< in: MySQL thread handle for
which to close the connection */
/*****************************************************************//**
Cancel any pending lock request associated with the current THD. */
static
void
innobase_kill_connection(
/*=====================*/
handlerton* hton, /*!< in/out: InnoDB handlerton */
THD* thd); /*!< in: MySQL thread handle for
which to close the connection */
/*****************************************************************//**
Commits a transaction in an InnoDB database or marks an SQL statement
ended.
@return 0 */
static
int
innobase_commit(
/*============*/
handlerton* hton, /*!< in/out: InnoDB handlerton */
THD* thd, /*!< in: MySQL thread handle of the
user for whom the transaction should
be committed */
bool commit_trx); /*!< in: true - commit transaction
false - the current SQL statement
ended */
/*****************************************************************//**
Rolls back a transaction to a savepoint.
@return 0 if success, HA_ERR_NO_SAVEPOINT if no savepoint with the
given name */
static
int
innobase_rollback(
/*==============*/
handlerton* hton, /*!< in/out: InnoDB handlerton */
THD* thd, /*!< in: handle to the MySQL thread
of the user whose transaction should
be rolled back */
bool rollback_trx); /*!< in: TRUE - rollback entire
transaction FALSE - rollback the current
statement only */
/*****************************************************************//**
Rolls back a transaction to a savepoint.
@return 0 if success, HA_ERR_NO_SAVEPOINT if no savepoint with the
given name */