/
ha_rocksdb.cc
10219 lines (8727 loc) · 303 KB
/
ha_rocksdb.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) 2012, Monty Program Ab
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
#ifdef USE_PRAGMA_IMPLEMENTATION
#pragma implementation // gcc: Class implementation
#endif
#define MYSQL_SERVER 1
/* The C++ file's header */
#include "./ha_rocksdb.h"
/* C++ standard header files */
#include <set>
#include <string>
#include <vector>
/* MySQL includes */
#include "./debug_sync.h"
#include "./my_bit.h"
#include "./my_stacktrace.h"
#include "./sql_table.h"
#include <mysql/psi/mysql_table.h>
#include <mysql/thread_pool_priv.h>
/* RocksDB includes */
#include "rocksdb/compaction_filter.h"
#include "rocksdb/rate_limiter.h"
#include "rocksdb/slice_transform.h"
#include "rocksdb/utilities/checkpoint.h"
#include "rocksdb/utilities/convenience.h"
#include "rocksdb/utilities/flashcache.h"
#include "rocksdb/utilities/memory_util.h"
/* MyRocks includes */
#include "./event_listener.h"
#include "./ha_rocksdb_proto.h"
#include "./logger.h"
#include "./rdb_cf_manager.h"
#include "./rdb_cf_options.h"
#include "./rdb_comparator.h"
#include "./rdb_datadic.h"
#include "./rdb_i_s.h"
#include "./rdb_mutex_wrapper.h"
#include "./rdb_threads.h"
#ifdef TARGET_OS_LINUX
extern my_bool cachedev_enabled;
#endif /* TARGET_OS_LINUX */
// Internal MySQL APIs not exposed in any header.
extern "C"
{
/**
Mark transaction to rollback and mark error as fatal to a sub-statement.
@param thd Thread handle
@param all TRUE <=> rollback main transaction.
*/
void thd_mark_transaction_to_rollback(MYSQL_THD thd, bool all);
/**
* Get the user thread's binary logging format
* @param thd user thread
* @return Value to be used as index into the binlog_format_names array
*/
int thd_binlog_format(const MYSQL_THD thd);
/**
* Check if binary logging is filtered for thread's current db.
* @param thd Thread handle
* @retval 1 the query is not filtered, 0 otherwise.
*/
bool thd_binlog_filter_ok(const MYSQL_THD thd);
}
namespace myrocks {
static st_global_stats global_stats;
static st_export_stats export_stats;
/**
Updates row counters based on the table type and operation type.
*/
void ha_rocksdb::update_row_stats(operation_type type) {
DBUG_ASSERT(type < ROWS_MAX);
// Find if we are modifying system databases.
if (table->s && m_tbl_def->m_is_mysql_system_table)
global_stats.system_rows[type].inc();
else
global_stats.rows[type].inc();
}
void dbug_dump_database(rocksdb::DB *db);
static handler *rocksdb_create_handler(my_core::handlerton *hton,
my_core::TABLE_SHARE *table_arg,
my_core::MEM_ROOT *mem_root);
bool can_use_bloom_filter(THD *thd,
const std::shared_ptr<const Rdb_key_def>& kd,
const rocksdb::Slice &eq_cond,
const bool use_all_keys,
bool is_ascending);
///////////////////////////////////////////////////////////
// Parameters and settings
///////////////////////////////////////////////////////////
static char * rocksdb_default_cf_options;
static char * rocksdb_override_cf_options;
Rdb_cf_options rocksdb_cf_options_map;
///////////////////////////////////////////////////////////
// Globals
///////////////////////////////////////////////////////////
handlerton *rocksdb_hton;
rocksdb::TransactionDB *rdb= nullptr;
static std::shared_ptr<rocksdb::Statistics> rocksdb_stats;
static std::unique_ptr<rocksdb::Env> flashcache_aware_env;
static std::shared_ptr<Rdb_tbl_prop_coll_factory>
properties_collector_factory;
Rdb_dict_manager dict_manager;
Rdb_cf_manager cf_manager;
Rdb_ddl_manager ddl_manager;
Rdb_binlog_manager binlog_manager;
/**
MyRocks background thread control
N.B. This is besides RocksDB's own background threads
(@see rocksdb::CancelAllBackgroundWork())
*/
static Rdb_background_thread rdb_bg_thread;
// List of table names (using regex) that are exceptions to the strict
// collation check requirement.
Regex_list_handler *rdb_collation_exceptions;
static const char* const ERRSTR_ROLLBACK_ONLY
= "This transaction was rolled back and cannot be "
"committed. Only supported operation is to roll it back, "
"so all pending changes will be discarded. "
"Please restart another transaction.";
static void
rocksdb_flush_all_memtables()
{
Rdb_cf_manager& cf_manager= rdb_get_cf_manager();
for (auto cf_handle : cf_manager.get_all_cf()) {
rdb->Flush(rocksdb::FlushOptions(), cf_handle);
}
}
static void
rocksdb_compact_column_family_stub(THD* thd,
struct st_mysql_sys_var* var,
void* var_ptr,
const void* save)
{
}
static int
rocksdb_compact_column_family(THD* thd,
struct st_mysql_sys_var* var,
void* var_ptr,
struct st_mysql_value* value)
{
char buff[STRING_BUFFER_USUAL_SIZE];
int len = sizeof(buff);
if (const char* cf = value->val_str(value, buff, &len)) {
bool is_automatic;
auto cfh = cf_manager.get_cf(cf, "", nullptr, &is_automatic);
if (cfh != nullptr && rdb != nullptr) {
sql_print_information("RocksDB: Manual compaction of column family: %s\n", cf);
rdb->CompactRange(rocksdb::CompactRangeOptions(), cfh, nullptr, nullptr);
}
}
return 0;
}
///////////////////////////////////////////////////////////
// Hash map: table name => open table handler
///////////////////////////////////////////////////////////
namespace // anonymous namespace = not visible outside this source file
{
struct Rdb_open_tables_map
{
/* Hash table used to track the handlers of open tables */
my_core::HASH m_hash;
/* The mutex used to protect the hash table */
mutable mysql_mutex_t m_mutex;
void init_hash(void)
{
(void) my_hash_init(&m_hash, my_core::system_charset_info, 32, 0, 0,
(my_hash_get_key) Rdb_open_tables_map::get_hash_key,
0, 0);
}
void free_hash(void)
{
my_hash_free(&m_hash);
}
static uchar* get_hash_key(Rdb_table_handler *table_handler,
size_t *length,
my_bool not_used __attribute__((__unused__)));
Rdb_table_handler* get_table_handler(const char *table_name);
void release_table_handler(Rdb_table_handler *table_handler);
std::vector<std::string> get_table_names(void) const;
};
} // anonymous namespace
static Rdb_open_tables_map rdb_open_tables;
static std::string rdb_normalize_dir(std::string dir)
{
while (dir.size() > 0 && dir.back() == '/')
{
dir.resize(dir.size() - 1);
}
return dir;
}
static int rocksdb_create_checkpoint(
THD* thd __attribute__((__unused__)),
struct st_mysql_sys_var* var __attribute__((__unused__)),
void* save __attribute__((__unused__)),
struct st_mysql_value* value)
{
char buf[512];
int len = sizeof(buf);
const char* checkpoint_dir_raw= value->val_str(value, buf, &len);
if (checkpoint_dir_raw) {
if (rdb != nullptr) {
std::string checkpoint_dir= rdb_normalize_dir(checkpoint_dir_raw);
// NO_LINT_DEBUG
sql_print_information("RocksDB: creating checkpoint in directory : %s\n",
checkpoint_dir.c_str());
rocksdb::Checkpoint* checkpoint;
auto status = rocksdb::Checkpoint::Create(rdb, &checkpoint);
if (status.ok()) {
status = checkpoint->CreateCheckpoint(checkpoint_dir.c_str());
if (status.ok()) {
sql_print_information(
"RocksDB: created checkpoint in directory : %s\n",
checkpoint_dir.c_str());
} else {
my_printf_error(
ER_UNKNOWN_ERROR,
"RocksDB: Failed to create checkpoint directory. status %d %s",
MYF(0), status.code(), status.ToString().c_str());
}
delete checkpoint;
} else {
std::string err_text(status.ToString());
my_printf_error(ER_UNKNOWN_ERROR,
"RocksDB: failed to initialize checkpoint. status %d %s\n",
MYF(0), status.code(), err_text.c_str());
}
return status.code();
}
}
return HA_ERR_INTERNAL_ERROR;
}
/* This method is needed to indicate that the
ROCKSDB_CREATE_CHECKPOINT command is not read-only */
static void
rocksdb_create_checkpoint_stub(THD* thd,
struct st_mysql_sys_var* var,
void* var_ptr,
const void* save)
{
}
static void
rocksdb_force_flush_memtable_now_stub(THD* thd,
struct st_mysql_sys_var* var,
void* var_ptr,
const void* save)
{
}
static int
rocksdb_force_flush_memtable_now(THD* thd,
struct st_mysql_sys_var* var,
void* var_ptr,
struct st_mysql_value* value)
{
sql_print_information("RocksDB: Manual memtable flush\n");
rocksdb_flush_all_memtables();
return 0;
}
static void rocksdb_drop_index_wakeup_thread(
my_core::THD* thd __attribute__((__unused__)),
struct st_mysql_sys_var* var __attribute__((__unused__)),
void* var_ptr __attribute__((__unused__)),
const void* save);
static my_bool rocksdb_pause_background_work= 0;
static mysql_mutex_t rdb_sysvars_mutex;
static void rocksdb_set_pause_background_work(
my_core::THD* thd __attribute__((__unused__)),
struct st_mysql_sys_var* var __attribute__((__unused__)),
void* var_ptr __attribute__((__unused__)),
const void* save)
{
mysql_mutex_lock(&rdb_sysvars_mutex);
bool pause_requested= *static_cast<const bool*>(save);
if (rocksdb_pause_background_work != pause_requested) {
if (pause_requested) {
rdb->PauseBackgroundWork();
} else {
rdb->ContinueBackgroundWork();
}
rocksdb_pause_background_work= pause_requested;
}
mysql_mutex_unlock(&rdb_sysvars_mutex);
}
static void
rocksdb_set_compaction_options(THD* thd,
struct st_mysql_sys_var* var,
void* var_ptr,
const void* save);
static void
rocksdb_set_table_stats_sampling_pct(THD* thd,
struct st_mysql_sys_var* var,
void* var_ptr,
const void* save);
static void
rocksdb_set_rate_limiter_bytes_per_sec(THD* thd,
struct st_mysql_sys_var* var,
void* var_ptr,
const void* save);
static void rdb_set_collation_exception_list(const char *exception_list);
static void
rocksdb_set_collation_exception_list(THD* thd,
struct st_mysql_sys_var* var,
void* var_ptr,
const void* save);
static void
rocksdb_set_bulk_load(THD* thd,
struct st_mysql_sys_var* var __attribute__((__unused__)),
void* var_ptr,
const void* save);
//////////////////////////////////////////////////////////////////////////////
// Options definitions
//////////////////////////////////////////////////////////////////////////////
static long long rocksdb_block_cache_size;
/* Use unsigned long long instead of uint64_t because of MySQL compatibility */
static unsigned long long // NOLINT(runtime/int)
rocksdb_rate_limiter_bytes_per_sec;
static uint64_t rocksdb_info_log_level;
static char * rocksdb_wal_dir;
static uint64_t rocksdb_index_type;
static char rocksdb_background_sync;
static uint32_t rocksdb_debug_optimizer_n_rows;
static my_bool rocksdb_debug_optimizer_no_zero_cardinality;
static uint32_t rocksdb_wal_recovery_mode;
static uint32_t rocksdb_access_hint_on_compaction_start;
static char * rocksdb_compact_cf_name;
static char * rocksdb_checkpoint_name;
static my_bool rocksdb_signal_drop_index_thread;
static my_bool rocksdb_strict_collation_check= 1;
static my_bool rocksdb_disable_2pc= 0;
static char * rocksdb_strict_collation_exceptions;
static my_bool rocksdb_collect_sst_properties= 1;
static my_bool rocksdb_force_flush_memtable_now_var= 0;
static uint64_t rocksdb_number_stat_computes= 0;
static uint32_t rocksdb_seconds_between_stat_computes= 3600;
static long long rocksdb_compaction_sequential_deletes= 0l;
static long long rocksdb_compaction_sequential_deletes_window= 0l;
static long long rocksdb_compaction_sequential_deletes_file_size= 0l;
static uint32_t rocksdb_validate_tables = 1;
static char * rocksdb_datadir;
static uint32_t rocksdb_table_stats_sampling_pct;
std::atomic<uint64_t> rocksdb_snapshot_conflict_errors(0);
static rocksdb::DBOptions rdb_init_rocksdb_db_options(void)
{
rocksdb::DBOptions o;
o.create_if_missing= true;
o.listeners.push_back(std::make_shared<Rdb_event_listener>(&ddl_manager));
o.info_log_level= rocksdb::InfoLogLevel::INFO_LEVEL;
o.max_subcompactions= DEFAULT_SUBCOMPACTIONS;
return o;
}
static rocksdb::DBOptions rocksdb_db_options= rdb_init_rocksdb_db_options();
static rocksdb::BlockBasedTableOptions rocksdb_tbl_options;
static std::shared_ptr<rocksdb::RateLimiter> rocksdb_rate_limiter;
/* This enum needs to be kept up to date with rocksdb::InfoLogLevel */
static const char* info_log_level_names[] = {
"debug_level",
"info_level",
"warn_level",
"error_level",
"fatal_level",
NullS
};
static TYPELIB info_log_level_typelib = {
array_elements(info_log_level_names) - 1,
"info_log_level_typelib",
info_log_level_names,
nullptr
};
static void
rocksdb_set_rocksdb_info_log_level(THD* thd,
struct st_mysql_sys_var* var,
void* var_ptr,
const void* save)
{
mysql_mutex_lock(&rdb_sysvars_mutex);
rocksdb_info_log_level = *static_cast<const uint64_t*>(save);
rocksdb_db_options.info_log->SetInfoLogLevel(
static_cast<const rocksdb::InfoLogLevel>(rocksdb_info_log_level));
mysql_mutex_unlock(&rdb_sysvars_mutex);
}
static const char* index_type_names[] = {
"kBinarySearch",
"kHashSearch",
NullS
};
static TYPELIB index_type_typelib = {
array_elements(index_type_names) - 1,
"index_type_typelib",
index_type_names,
nullptr
};
//TODO: 0 means don't wait at all, and we don't support it yet?
static MYSQL_THDVAR_ULONG(lock_wait_timeout, PLUGIN_VAR_RQCMDARG,
"Number of seconds to wait for lock",
nullptr, nullptr, /*default*/ 1, /*min*/ 1, /*max*/ 1024*1024*1024, 0);
static MYSQL_THDVAR_BOOL(bulk_load, PLUGIN_VAR_RQCMDARG,
"Use bulk-load mode for inserts. This enables both "
"rocksdb_skip_unique_check and rocksdb_commit_in_the_middle.",
nullptr, rocksdb_set_bulk_load, FALSE);
static MYSQL_THDVAR_BOOL(skip_unique_check, PLUGIN_VAR_RQCMDARG,
"Skip unique constraint checking", nullptr, nullptr, FALSE);
static MYSQL_THDVAR_BOOL(commit_in_the_middle, PLUGIN_VAR_RQCMDARG,
"Commit rows implicitly every rocksdb_bulk_load_size, on bulk load/insert, "
"update and delete",
nullptr, nullptr, FALSE);
static MYSQL_THDVAR_BOOL(rpl_lookup_rows, PLUGIN_VAR_RQCMDARG,
"Lookup a row on replication slave", nullptr, nullptr, TRUE);
static MYSQL_THDVAR_BOOL(skip_bloom_filter_on_read, PLUGIN_VAR_RQCMDARG,
"Skip using bloom filter for reads", nullptr, nullptr, FALSE);
static MYSQL_THDVAR_ULONG(max_row_locks, PLUGIN_VAR_RQCMDARG,
"Maximum number of locks a transaction can have",
nullptr, nullptr, /*default*/ 1024*1024*1024, /*min*/ 1,
/*max*/ 1024*1024*1024, 0);
static MYSQL_THDVAR_BOOL(lock_scanned_rows, PLUGIN_VAR_RQCMDARG,
"Take and hold locks on rows that are scanned but not updated",
nullptr, nullptr, FALSE);
static MYSQL_THDVAR_ULONG(bulk_load_size, PLUGIN_VAR_RQCMDARG,
"Max #records in a batch for bulk-load mode",
nullptr, nullptr, /*default*/ 1000, /*min*/ 1, /*max*/ 1024*1024*1024, 0);
static MYSQL_SYSVAR_BOOL(create_if_missing,
*reinterpret_cast<my_bool*>(&rocksdb_db_options.create_if_missing),
PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY,
"DBOptions::create_if_missing for RocksDB",
nullptr, nullptr, rocksdb_db_options.create_if_missing);
static MYSQL_SYSVAR_BOOL(create_missing_column_families,
*reinterpret_cast<my_bool*>(
&rocksdb_db_options.create_missing_column_families),
PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY,
"DBOptions::create_missing_column_families for RocksDB",
nullptr, nullptr, rocksdb_db_options.create_missing_column_families);
static MYSQL_SYSVAR_BOOL(error_if_exists,
*reinterpret_cast<my_bool*>(&rocksdb_db_options.error_if_exists),
PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY,
"DBOptions::error_if_exists for RocksDB",
nullptr, nullptr, rocksdb_db_options.error_if_exists);
static MYSQL_SYSVAR_BOOL(paranoid_checks,
*reinterpret_cast<my_bool*>(&rocksdb_db_options.paranoid_checks),
PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY,
"DBOptions::paranoid_checks for RocksDB",
nullptr, nullptr, rocksdb_db_options.paranoid_checks);
static MYSQL_SYSVAR_ULONGLONG(rate_limiter_bytes_per_sec,
rocksdb_rate_limiter_bytes_per_sec,
PLUGIN_VAR_RQCMDARG,
"DBOptions::rate_limiter bytes_per_sec for RocksDB",
nullptr, rocksdb_set_rate_limiter_bytes_per_sec, /* default */ 0L,
/* min */ 0L, /* max */ MAX_RATE_LIMITER_BYTES_PER_SEC, 0);
static MYSQL_SYSVAR_ENUM(info_log_level,
rocksdb_info_log_level,
PLUGIN_VAR_RQCMDARG,
"Filter level for info logs to be written mysqld error log. "
"Valid values include 'debug_level', 'info_level', 'warn_level'"
"'error_level' and 'fatal_level'.",
nullptr, rocksdb_set_rocksdb_info_log_level,
rocksdb::InfoLogLevel::ERROR_LEVEL, &info_log_level_typelib);
static MYSQL_THDVAR_INT(perf_context_level,
PLUGIN_VAR_RQCMDARG,
"Perf Context Level for rocksdb internal timer stat collection",
nullptr, nullptr,
/* default */ rocksdb::PerfLevel::kUninitialized,
/* min */ rocksdb::PerfLevel::kUninitialized,
/* max */ rocksdb::PerfLevel::kOutOfBounds - 1, 0);
static MYSQL_SYSVAR_UINT(wal_recovery_mode,
rocksdb_wal_recovery_mode,
PLUGIN_VAR_RQCMDARG,
"DBOptions::wal_recovery_mode for RocksDB",
nullptr, nullptr, 2,
/* min */ 0L, /* max */ 3, 0);
static MYSQL_SYSVAR_ULONG(compaction_readahead_size,
rocksdb_db_options.compaction_readahead_size,
PLUGIN_VAR_RQCMDARG,
"DBOptions::compaction_readahead_size for RocksDB",
nullptr, nullptr, rocksdb_db_options.compaction_readahead_size,
/* min */ 0L, /* max */ ULONG_MAX, 0);
static MYSQL_SYSVAR_BOOL(new_table_reader_for_compaction_inputs,
*reinterpret_cast<my_bool*>
(&rocksdb_db_options.new_table_reader_for_compaction_inputs),
PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY,
"DBOptions::new_table_reader_for_compaction_inputs for RocksDB",
nullptr, nullptr, rocksdb_db_options.new_table_reader_for_compaction_inputs);
static MYSQL_SYSVAR_UINT(access_hint_on_compaction_start,
rocksdb_access_hint_on_compaction_start,
PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY,
"DBOptions::access_hint_on_compaction_start for RocksDB",
nullptr, nullptr, 1,
/* min */ 0L, /* max */ 3, 0);
static MYSQL_SYSVAR_BOOL(allow_concurrent_memtable_write,
*reinterpret_cast<my_bool*>(
&rocksdb_db_options.allow_concurrent_memtable_write),
PLUGIN_VAR_RQCMDARG,
"DBOptions::allow_concurrent_memtable_write for RocksDB",
nullptr, nullptr, rocksdb_db_options.allow_concurrent_memtable_write);
static MYSQL_SYSVAR_BOOL(enable_write_thread_adaptive_yield,
*reinterpret_cast<my_bool*>(
&rocksdb_db_options.enable_write_thread_adaptive_yield),
PLUGIN_VAR_RQCMDARG,
"DBOptions::enable_write_thread_adaptive_yield for RocksDB",
nullptr, nullptr, rocksdb_db_options.enable_write_thread_adaptive_yield);
static MYSQL_SYSVAR_INT(max_open_files,
rocksdb_db_options.max_open_files,
PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY,
"DBOptions::max_open_files for RocksDB",
nullptr, nullptr, rocksdb_db_options.max_open_files,
/* min */ -1, /* max */ INT_MAX, 0);
static MYSQL_SYSVAR_ULONG(max_total_wal_size,
rocksdb_db_options.max_total_wal_size,
PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY,
"DBOptions::max_total_wal_size for RocksDB",
nullptr, nullptr, rocksdb_db_options.max_total_wal_size,
/* min */ 0L, /* max */ LONG_MAX, 0);
static MYSQL_SYSVAR_BOOL(disabledatasync,
*reinterpret_cast<my_bool*>(&rocksdb_db_options.disableDataSync),
PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY,
"DBOptions::disableDataSync for RocksDB",
nullptr, nullptr, rocksdb_db_options.disableDataSync);
static MYSQL_SYSVAR_BOOL(use_fsync,
*reinterpret_cast<my_bool*>(&rocksdb_db_options.use_fsync),
PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY,
"DBOptions::use_fsync for RocksDB",
nullptr, nullptr, rocksdb_db_options.use_fsync);
static MYSQL_SYSVAR_STR(wal_dir, rocksdb_wal_dir,
PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY,
"DBOptions::wal_dir for RocksDB",
nullptr, nullptr, rocksdb_db_options.wal_dir.c_str());
static MYSQL_SYSVAR_ULONG(delete_obsolete_files_period_micros,
rocksdb_db_options.delete_obsolete_files_period_micros,
PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY,
"DBOptions::delete_obsolete_files_period_micros for RocksDB",
nullptr, nullptr, rocksdb_db_options.delete_obsolete_files_period_micros,
/* min */ 0L, /* max */ LONG_MAX, 0);
static MYSQL_SYSVAR_INT(base_background_compactions,
rocksdb_db_options.base_background_compactions,
PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY,
"DBOptions::base_background_compactions for RocksDB",
nullptr, nullptr, rocksdb_db_options.base_background_compactions,
/* min */ -1, /* max */ MAX_BACKGROUND_COMPACTIONS, 0);
static MYSQL_SYSVAR_INT(max_background_compactions,
rocksdb_db_options.max_background_compactions,
PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY,
"DBOptions::max_background_compactions for RocksDB",
nullptr, nullptr, rocksdb_db_options.max_background_compactions,
/* min */ 1, /* max */ MAX_BACKGROUND_COMPACTIONS, 0);
static MYSQL_SYSVAR_INT(max_background_flushes,
rocksdb_db_options.max_background_flushes,
PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY,
"DBOptions::max_background_flushes for RocksDB",
nullptr, nullptr, rocksdb_db_options.max_background_flushes,
/* min */ 1, /* max */ MAX_BACKGROUND_FLUSHES, 0);
static MYSQL_SYSVAR_UINT(max_subcompactions,
rocksdb_db_options.max_subcompactions,
PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY,
"DBOptions::max_subcompactions for RocksDB",
nullptr, nullptr, rocksdb_db_options.max_subcompactions,
/* min */ 1, /* max */ MAX_SUBCOMPACTIONS, 0);
static MYSQL_SYSVAR_ULONG(max_log_file_size,
rocksdb_db_options.max_log_file_size,
PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY,
"DBOptions::max_log_file_size for RocksDB",
nullptr, nullptr, rocksdb_db_options.max_log_file_size,
/* min */ 0L, /* max */ LONG_MAX, 0);
static MYSQL_SYSVAR_ULONG(log_file_time_to_roll,
rocksdb_db_options.log_file_time_to_roll,
PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY,
"DBOptions::log_file_time_to_roll for RocksDB",
nullptr, nullptr, rocksdb_db_options.log_file_time_to_roll,
/* min */ 0L, /* max */ LONG_MAX, 0);
static MYSQL_SYSVAR_ULONG(keep_log_file_num,
rocksdb_db_options.keep_log_file_num,
PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY,
"DBOptions::keep_log_file_num for RocksDB",
nullptr, nullptr, rocksdb_db_options.keep_log_file_num,
/* min */ 0L, /* max */ LONG_MAX, 0);
static MYSQL_SYSVAR_ULONG(max_manifest_file_size,
rocksdb_db_options.max_manifest_file_size,
PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY,
"DBOptions::max_manifest_file_size for RocksDB",
nullptr, nullptr, rocksdb_db_options.max_manifest_file_size,
/* min */ 0L, /* max */ ULONG_MAX, 0);
static MYSQL_SYSVAR_INT(table_cache_numshardbits,
rocksdb_db_options.table_cache_numshardbits,
PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY,
"DBOptions::table_cache_numshardbits for RocksDB",
nullptr, nullptr, rocksdb_db_options.table_cache_numshardbits,
/* min */ 0, /* max */ INT_MAX, 0);
static MYSQL_SYSVAR_ULONG(wal_ttl_seconds,
rocksdb_db_options.WAL_ttl_seconds,
PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY,
"DBOptions::WAL_ttl_seconds for RocksDB",
nullptr, nullptr, rocksdb_db_options.WAL_ttl_seconds,
/* min */ 0L, /* max */ LONG_MAX, 0);
static MYSQL_SYSVAR_ULONG(wal_size_limit_mb,
rocksdb_db_options.WAL_size_limit_MB,
PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY,
"DBOptions::WAL_size_limit_MB for RocksDB",
nullptr, nullptr, rocksdb_db_options.WAL_size_limit_MB,
/* min */ 0L, /* max */ LONG_MAX, 0);
static MYSQL_SYSVAR_ULONG(manifest_preallocation_size,
rocksdb_db_options.manifest_preallocation_size,
PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY,
"DBOptions::manifest_preallocation_size for RocksDB",
nullptr, nullptr, rocksdb_db_options.manifest_preallocation_size,
/* min */ 0L, /* max */ LONG_MAX, 0);
static MYSQL_SYSVAR_BOOL(allow_os_buffer,
*reinterpret_cast<my_bool*>(&rocksdb_db_options.allow_os_buffer),
PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY,
"DBOptions::allow_os_buffer for RocksDB",
nullptr, nullptr, rocksdb_db_options.allow_os_buffer);
static MYSQL_SYSVAR_BOOL(allow_mmap_reads,
*reinterpret_cast<my_bool*>(&rocksdb_db_options.allow_mmap_reads),
PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY,
"DBOptions::allow_mmap_reads for RocksDB",
nullptr, nullptr, rocksdb_db_options.allow_mmap_reads);
static MYSQL_SYSVAR_BOOL(allow_mmap_writes,
*reinterpret_cast<my_bool*>(&rocksdb_db_options.allow_mmap_writes),
PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY,
"DBOptions::allow_mmap_writes for RocksDB",
nullptr, nullptr, rocksdb_db_options.allow_mmap_writes);
static MYSQL_SYSVAR_BOOL(is_fd_close_on_exec,
*reinterpret_cast<my_bool*>(&rocksdb_db_options.is_fd_close_on_exec),
PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY,
"DBOptions::is_fd_close_on_exec for RocksDB",
nullptr, nullptr, rocksdb_db_options.is_fd_close_on_exec);
static MYSQL_SYSVAR_UINT(stats_dump_period_sec,
rocksdb_db_options.stats_dump_period_sec,
PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY,
"DBOptions::stats_dump_period_sec for RocksDB",
nullptr, nullptr, rocksdb_db_options.stats_dump_period_sec,
/* min */ 0, /* max */ INT_MAX, 0);
static MYSQL_SYSVAR_BOOL(advise_random_on_open,
*reinterpret_cast<my_bool*>(&rocksdb_db_options.advise_random_on_open),
PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY,
"DBOptions::advise_random_on_open for RocksDB",
nullptr, nullptr, rocksdb_db_options.advise_random_on_open);
static MYSQL_SYSVAR_ULONG(db_write_buffer_size,
rocksdb_db_options.db_write_buffer_size,
PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY,
"DBOptions::db_write_buffer_size for RocksDB",
nullptr, nullptr, rocksdb_db_options.db_write_buffer_size,
/* min */ 0L, /* max */ LONG_MAX, 0);
static MYSQL_SYSVAR_BOOL(use_adaptive_mutex,
*reinterpret_cast<my_bool*>(&rocksdb_db_options.use_adaptive_mutex),
PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY,
"DBOptions::use_adaptive_mutex for RocksDB",
nullptr, nullptr, rocksdb_db_options.use_adaptive_mutex);
static MYSQL_SYSVAR_ULONG(bytes_per_sync,
rocksdb_db_options.bytes_per_sync,
PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY,
"DBOptions::bytes_per_sync for RocksDB",
nullptr, nullptr, rocksdb_db_options.bytes_per_sync,
/* min */ 0L, /* max */ LONG_MAX, 0);
static MYSQL_SYSVAR_ULONG(wal_bytes_per_sync,
rocksdb_db_options.wal_bytes_per_sync,
PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY,
"DBOptions::wal_bytes_per_sync for RocksDB",
nullptr, nullptr, rocksdb_db_options.wal_bytes_per_sync,
/* min */ 0L, /* max */ LONG_MAX, 0);
static MYSQL_SYSVAR_BOOL(enable_thread_tracking,
*reinterpret_cast<my_bool*>(&rocksdb_db_options.enable_thread_tracking),
PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY,
"DBOptions::enable_thread_tracking for RocksDB",
nullptr, nullptr, rocksdb_db_options.enable_thread_tracking);
static MYSQL_SYSVAR_LONGLONG(block_cache_size, rocksdb_block_cache_size,
PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY,
"block_cache size for RocksDB",
nullptr, nullptr, /* RocksDB's default is 8 MB: */ 8*1024*1024L,
/* min */ 1024L, /* max */ LONGLONG_MAX, /* Block size */1024L);
static MYSQL_SYSVAR_BOOL(cache_index_and_filter_blocks,
*reinterpret_cast<my_bool*>(
&rocksdb_tbl_options.cache_index_and_filter_blocks),
PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY,
"BlockBasedTableOptions::cache_index_and_filter_blocks for RocksDB",
nullptr, nullptr, true);
// When pin_l0_filter_and_index_blocks_in_cache is true, RocksDB will use the
// LRU cache, but will always keep the filter & idndex block's handle checked
// out (=won't call ShardedLRUCache::Release), plus the parsed out objects
// the LRU cache will never push flush them out, hence they're pinned.
//
// This fixes the mutex contention between :ShardedLRUCache::Lookup and
// ShardedLRUCache::Release which reduced the QPS ratio (QPS using secondary
// index / QPS using PK).
static MYSQL_SYSVAR_BOOL(pin_l0_filter_and_index_blocks_in_cache,
*reinterpret_cast<my_bool*>(
&rocksdb_tbl_options.pin_l0_filter_and_index_blocks_in_cache),
PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY,
"pin_l0_filter_and_index_blocks_in_cache for RocksDB",
nullptr, nullptr, true);
static MYSQL_SYSVAR_ENUM(index_type,
rocksdb_index_type,
PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY,
"BlockBasedTableOptions::index_type for RocksDB",
nullptr, nullptr,
(uint64_t)rocksdb_tbl_options.index_type, &index_type_typelib);
static MYSQL_SYSVAR_BOOL(hash_index_allow_collision,
*reinterpret_cast<my_bool*>(&rocksdb_tbl_options.hash_index_allow_collision),
PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY,
"BlockBasedTableOptions::hash_index_allow_collision for RocksDB",
nullptr, nullptr, rocksdb_tbl_options.hash_index_allow_collision);
static MYSQL_SYSVAR_BOOL(no_block_cache,
*reinterpret_cast<my_bool*>(&rocksdb_tbl_options.no_block_cache),
PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY,
"BlockBasedTableOptions::no_block_cache for RocksDB",
nullptr, nullptr, rocksdb_tbl_options.no_block_cache);
static MYSQL_SYSVAR_ULONG(block_size,
rocksdb_tbl_options.block_size,
PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY,
"BlockBasedTableOptions::block_size for RocksDB",
nullptr, nullptr, rocksdb_tbl_options.block_size,
/* min */ 1L, /* max */ LONG_MAX, 0);
static MYSQL_SYSVAR_INT(block_size_deviation,
rocksdb_tbl_options.block_size_deviation,
PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY,
"BlockBasedTableOptions::block_size_deviation for RocksDB",
nullptr, nullptr, rocksdb_tbl_options.block_size_deviation,
/* min */ 0, /* max */ INT_MAX, 0);
static MYSQL_SYSVAR_INT(block_restart_interval,
rocksdb_tbl_options.block_restart_interval,
PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY,
"BlockBasedTableOptions::block_restart_interval for RocksDB",
nullptr, nullptr, rocksdb_tbl_options.block_restart_interval,
/* min */ 1, /* max */ INT_MAX, 0);
static MYSQL_SYSVAR_BOOL(whole_key_filtering,
*reinterpret_cast<my_bool*>(&rocksdb_tbl_options.whole_key_filtering),
PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY,
"BlockBasedTableOptions::whole_key_filtering for RocksDB",
nullptr, nullptr, rocksdb_tbl_options.whole_key_filtering);
static MYSQL_SYSVAR_STR(default_cf_options, rocksdb_default_cf_options,
PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY,
"default cf options for RocksDB",
nullptr, nullptr, "");
static MYSQL_SYSVAR_STR(override_cf_options, rocksdb_override_cf_options,
PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY,
"option overrides per cf for RocksDB",
nullptr, nullptr, "");
static MYSQL_SYSVAR_BOOL(background_sync,
rocksdb_background_sync,
PLUGIN_VAR_RQCMDARG,
"turns on background syncs for RocksDB",
nullptr, nullptr, FALSE);
static MYSQL_THDVAR_BOOL(write_sync,
PLUGIN_VAR_RQCMDARG,
"WriteOptions::sync for RocksDB",
nullptr, nullptr, rocksdb::WriteOptions().sync);
static MYSQL_THDVAR_BOOL(write_disable_wal,
PLUGIN_VAR_RQCMDARG,
"WriteOptions::disableWAL for RocksDB",
nullptr, nullptr, rocksdb::WriteOptions().disableWAL);
static MYSQL_THDVAR_BOOL(write_ignore_missing_column_families,
PLUGIN_VAR_RQCMDARG,
"WriteOptions::ignore_missing_column_families for RocksDB",
nullptr, nullptr, rocksdb::WriteOptions().ignore_missing_column_families);
static MYSQL_THDVAR_BOOL(skip_fill_cache,
PLUGIN_VAR_RQCMDARG,
"Skip filling block cache on read requests",
nullptr, nullptr, FALSE);
static MYSQL_THDVAR_BOOL(unsafe_for_binlog,
PLUGIN_VAR_RQCMDARG,
"Allowing statement based binary logging which may break consistency",
nullptr, nullptr, FALSE);
static MYSQL_THDVAR_UINT(records_in_range,
PLUGIN_VAR_RQCMDARG,
"Used to override the result of records_in_range(). Set to a positive number to override",
nullptr, nullptr, 0,
/* min */ 0, /* max */ INT_MAX, 0);
static MYSQL_THDVAR_UINT(force_index_records_in_range,
PLUGIN_VAR_RQCMDARG,
"Used to override the result of records_in_range() when FORCE INDEX is used.",
nullptr, nullptr, 0,
/* min */ 0, /* max */ INT_MAX, 0);
static MYSQL_SYSVAR_UINT(debug_optimizer_n_rows,
rocksdb_debug_optimizer_n_rows,
PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY | PLUGIN_VAR_NOSYSVAR,
"Test only to override rocksdb estimates of table size in a memtable",
nullptr, nullptr, 0, /* min */ 0, /* max */ INT_MAX, 0);
static MYSQL_SYSVAR_BOOL(debug_optimizer_no_zero_cardinality,
rocksdb_debug_optimizer_no_zero_cardinality,
PLUGIN_VAR_RQCMDARG,
"In case if cardinality is zero, overrides it with some value",
nullptr, nullptr, TRUE);
static MYSQL_SYSVAR_STR(compact_cf, rocksdb_compact_cf_name,
PLUGIN_VAR_RQCMDARG,
"Compact column family",
rocksdb_compact_column_family, rocksdb_compact_column_family_stub, "");
static MYSQL_SYSVAR_STR(create_checkpoint, rocksdb_checkpoint_name,
PLUGIN_VAR_RQCMDARG,
"Checkpoint directory",
rocksdb_create_checkpoint, rocksdb_create_checkpoint_stub, "");
static MYSQL_SYSVAR_BOOL(signal_drop_index_thread,
rocksdb_signal_drop_index_thread,
PLUGIN_VAR_RQCMDARG,
"Wake up drop index thread",
nullptr, rocksdb_drop_index_wakeup_thread, FALSE);
static MYSQL_SYSVAR_BOOL(pause_background_work,
rocksdb_pause_background_work,
PLUGIN_VAR_RQCMDARG,
"Disable all rocksdb background operations",
nullptr, rocksdb_set_pause_background_work, FALSE);
static MYSQL_SYSVAR_BOOL(disable_2pc,
rocksdb_disable_2pc,
PLUGIN_VAR_RQCMDARG,
"Disable two phase commit for MyRocks",
nullptr, nullptr, TRUE);
static MYSQL_SYSVAR_BOOL(strict_collation_check,
rocksdb_strict_collation_check,
PLUGIN_VAR_RQCMDARG,
"Enforce case sensitive collation for MyRocks indexes",
nullptr, nullptr, TRUE);
static MYSQL_SYSVAR_STR(strict_collation_exceptions,
rocksdb_strict_collation_exceptions,
PLUGIN_VAR_RQCMDARG|PLUGIN_VAR_MEMALLOC,
"List of tables (using regex) that are excluded "
"from the case sensitive collation enforcement",
nullptr, rocksdb_set_collation_exception_list, "");
static MYSQL_SYSVAR_BOOL(collect_sst_properties,
rocksdb_collect_sst_properties,
PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY,
"Enables collecting SST file properties on each flush",
nullptr, nullptr, rocksdb_collect_sst_properties);
static MYSQL_SYSVAR_BOOL(
force_flush_memtable_now,
rocksdb_force_flush_memtable_now_var,
PLUGIN_VAR_RQCMDARG,
"Forces memstore flush which may block all write requests so be careful",
rocksdb_force_flush_memtable_now,
rocksdb_force_flush_memtable_now_stub, FALSE);
static MYSQL_THDVAR_BOOL(
flush_memtable_on_analyze,
PLUGIN_VAR_RQCMDARG,
"Forces memtable flush on ANALZYE table to get accurate cardinality",
nullptr, nullptr, true);
static MYSQL_SYSVAR_UINT(seconds_between_stat_computes,
rocksdb_seconds_between_stat_computes,
PLUGIN_VAR_RQCMDARG,
"Sets a number of seconds to wait between optimizer stats recomputation. "
"Only changed indexes will be refreshed.",
nullptr, nullptr, rocksdb_seconds_between_stat_computes,
/* min */ 0L, /* max */ UINT_MAX, 0);