1 /* -*- mode: C++; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2 // vim: ft=cpp:expandtab:ts=8:sw=4:softtabstop=4:
3 /* -*- mode: C; c-basic-offset: 4 -*- */
4 #ident "$Id$"
5 /*======
6 This file is part of TokuDB
7 
8 
9 Copyright (c) 2006, 2015, Percona and/or its affiliates. All rights reserved.
10 
11     TokuDBis is free software: you can redistribute it and/or modify
12     it under the terms of the GNU General Public License, version 2,
13     as published by the Free Software Foundation.
14 
15     TokuDB is distributed in the hope that it will be useful,
16     but WITHOUT ANY WARRANTY; without even the implied warranty of
17     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18     GNU General Public License for more details.
19 
20     You should have received a copy of the GNU General Public License
21     along with TokuDB.  If not, see <http://www.gnu.org/licenses/>.
22 
23 ======= */
24 
25 #ident "Copyright (c) 2006, 2015, Percona and/or its affiliates. All rights reserved."
26 
27 #include "hatoku_hton.h"
28 #include "sql_acl.h"
29 #include "tokudb_dir_cmd.h"
30 #include "sql_parse.h"
31 #include "sql_plugin.h"
32 
33 namespace tokudb {
34 namespace sysvars {
35 
36 //******************************************************************************
37 // global variables
38 //******************************************************************************
39 #ifdef TOKUDB_VERSION
40 #define tokudb_stringify_2(x) #x
41 #define tokudb_stringify(x) tokudb_stringify_2(x)
42 #define TOKUDB_VERSION_STR tokudb_stringify(TOKUDB_VERSION)
43 #else
44 #define TOKUDB_VERSION_STR NULL
45 #endif
46 
47 const size_t error_buffer_max_size = 1024;
48 
49 ulonglong   cache_size = 0;
50 uint        cachetable_pool_threads = 0;
51 int         cardinality_scale_percent = 0;
52 my_bool     checkpoint_on_flush_logs = FALSE;
53 uint        checkpoint_pool_threads = 0;
54 uint        checkpointing_period = 0;
55 ulong       cleaner_iterations = 0;
56 ulong       cleaner_period = 0;
57 uint        client_pool_threads = 0;
58 my_bool     compress_buffers_before_eviction = TRUE;
59 char*       data_dir = NULL;
60 ulong       debug = 0;
61 #if defined(TOKUDB_DEBUG) && TOKUDB_DEBUG
62 // used to control background job manager
63 my_bool     debug_pause_background_job_manager = FALSE;
64 #endif  // defined(TOKUDB_DEBUG) && TOKUDB_DEBUG
65 my_bool     directio = FALSE;
66 my_bool     enable_native_partition = FALSE;
67 my_bool     enable_partial_eviction = TRUE;
68 // file system reserve as a percentage of total disk space
69 int         fs_reserve_percent = 0;
70 uint        fsync_log_period = 0;
71 char*       log_dir = NULL;
72 ulonglong   max_lock_memory = 0;
73 uint        read_status_frequency = 0;
74 my_bool     strip_frm_data = FALSE;
75 char*       tmp_dir = NULL;
76 uint        write_status_frequency = 0;
77 my_bool     dir_per_db = TRUE;
78 char*       version = (char*) TOKUDB_VERSION_STR;
79 
80 my_bool        check_jemalloc = TRUE;
81 
82 static MYSQL_SYSVAR_ULONGLONG(
83     cache_size,
84     cache_size,
85     PLUGIN_VAR_READONLY,
86     "cache table size",
87     NULL,
88     NULL,
89     0,
90     0,
91     ~0ULL,
92     0);
93 
94 static MYSQL_SYSVAR_UINT(
95     force_recovery,
96     force_recovery,
97     PLUGIN_VAR_READONLY,
98     "force recovery. Set to 6 to skip reading the logs",
99     NULL,
100     NULL,
101     0,
102     0,
103     0,
104     0);
105 
106 static MYSQL_SYSVAR_UINT(
107     cachetable_pool_threads,
108     cachetable_pool_threads,
109     PLUGIN_VAR_READONLY,
110     "cachetable ops thread pool size",
111     NULL,
112     NULL,
113     0,
114     0,
115     1024,
116     0);
117 
118 static MYSQL_SYSVAR_INT(
119     cardinality_scale_percent,
120     cardinality_scale_percent,
121     0,
122     "index cardinality scale percentage",
123     NULL,
124     NULL,
125     100,
126     0,
127     100,
128     0);
129 
130 static MYSQL_SYSVAR_BOOL(
131     checkpoint_on_flush_logs,
132     checkpoint_on_flush_logs,
133     0,
134     "checkpoint on flush logs",
135     NULL,
136     NULL,
137     FALSE);
138 
139 static MYSQL_SYSVAR_UINT(
140     checkpoint_pool_threads,
141     checkpoint_pool_threads,
142     PLUGIN_VAR_READONLY,
143     "checkpoint ops thread pool size",
144     NULL,
145     NULL,
146     0,
147     0,
148     1024,
149     0);
150 
checkpointing_period_update(TOKUDB_UNUSED (THD * thd),TOKUDB_UNUSED (st_mysql_sys_var * sys_var),void * var,const void * save)151 static void checkpointing_period_update(
152     TOKUDB_UNUSED(THD* thd),
153     TOKUDB_UNUSED(st_mysql_sys_var* sys_var),
154     void* var,
155     const void* save) {
156     uint* cp = (uint*)var;
157     *cp = *(const uint*)save;
158     int r = db_env->checkpointing_set_period(db_env, *cp);
159     assert(r == 0);
160 }
161 
162 static MYSQL_SYSVAR_UINT(
163     checkpointing_period,
164     checkpointing_period,
165     0,
166     "checkpointing period",
167     NULL,
168     checkpointing_period_update,
169     60,
170     0,
171     ~0U,
172     0);
173 
cleaner_iterations_update(TOKUDB_UNUSED (THD * thd),TOKUDB_UNUSED (st_mysql_sys_var * sys_var),void * var,const void * save)174 static void cleaner_iterations_update(TOKUDB_UNUSED(THD* thd),
175                                       TOKUDB_UNUSED(st_mysql_sys_var* sys_var),
176                                       void* var,
177                                       const void* save) {
178     ulong* ci = (ulong*)var;
179     *ci = *(const ulong*)save;
180     int r = db_env->cleaner_set_iterations(db_env, *ci);
181     assert(r == 0);
182 }
183 
184 static MYSQL_SYSVAR_ULONG(
185     cleaner_iterations,
186     cleaner_iterations,
187     0,
188     "cleaner_iterations",
189     NULL,
190     cleaner_iterations_update,
191     DEFAULT_TOKUDB_CLEANER_ITERATIONS,
192     0,
193     ~0UL,
194     0);
195 
cleaner_period_update(TOKUDB_UNUSED (THD * thd),TOKUDB_UNUSED (st_mysql_sys_var * sys_var),void * var,const void * save)196 static void cleaner_period_update(TOKUDB_UNUSED(THD* thd),
197                                   TOKUDB_UNUSED(st_mysql_sys_var* sys_var),
198                                   void* var,
199                                   const void* save) {
200     ulong* cp = (ulong*)var;
201     *cp = *(const ulong*)save;
202     int r = db_env->cleaner_set_period(db_env, *cp);
203     assert(r == 0);
204 }
205 
206 static MYSQL_SYSVAR_ULONG(
207     cleaner_period,
208     cleaner_period,
209     0,
210     "cleaner_period",
211     NULL,
212     cleaner_period_update,
213     DEFAULT_TOKUDB_CLEANER_PERIOD,
214     0,
215     ~0UL,
216     0);
217 
218 static MYSQL_SYSVAR_UINT(
219     client_pool_threads,
220     client_pool_threads,
221     PLUGIN_VAR_READONLY,
222     "client ops thread pool size",
223     NULL,
224     NULL,
225     0,
226     0,
227     1024,
228     0);
229 
230 static MYSQL_SYSVAR_BOOL(
231     compress_buffers_before_eviction,
232     compress_buffers_before_eviction,
233     PLUGIN_VAR_READONLY,
234     "enable in-memory buffer compression before partial eviction",
235     NULL,
236     NULL,
237     TRUE);
238 
239 static MYSQL_SYSVAR_STR(
240     data_dir,
241     data_dir,
242     PLUGIN_VAR_READONLY,
243     "data directory",
244     NULL,
245     NULL,
246     NULL);
247 
248 static MYSQL_SYSVAR_ULONG(
249     debug,
250     debug,
251     0,
252     "plugin debug mask",
253     NULL,
254     NULL,
255     0,
256     0,
257     ~0UL,
258     0);
259 
260 #if defined(TOKUDB_DEBUG) && TOKUDB_DEBUG
261 static MYSQL_SYSVAR_BOOL(
262     debug_pause_background_job_manager,
263     debug_pause_background_job_manager,
264     0,
265     "debug : pause the background job manager",
266     NULL,
267     NULL,
268     FALSE);
269 #endif  // defined(TOKUDB_DEBUG) && TOKUDB_DEBUG
270 
271 static MYSQL_SYSVAR_BOOL(
272     directio,
273     directio,
274     PLUGIN_VAR_READONLY, "enable direct i/o ",
275     NULL,
276     NULL,
277     FALSE);
278 
279 static MYSQL_SYSVAR_BOOL(
280     enable_native_partition,
281     enable_native_partition,
282     PLUGIN_VAR_READONLY,
283     "enable native partitioning",
284     NULL,
285     NULL,
286     FALSE);
287 
enable_partial_eviction_update(TOKUDB_UNUSED (THD * thd),TOKUDB_UNUSED (st_mysql_sys_var * sys_var),void * var,const void * save)288 static void enable_partial_eviction_update(
289     TOKUDB_UNUSED(THD* thd),
290     TOKUDB_UNUSED(st_mysql_sys_var* sys_var),
291     void* var,
292     const void* save) {
293     my_bool* epe = (my_bool*)var;
294     *epe = *(const my_bool*)save;
295     int r = db_env->evictor_set_enable_partial_eviction(db_env, *epe);
296     assert(r == 0);
297 }
298 
299 static MYSQL_SYSVAR_BOOL(
300     enable_partial_eviction,
301     enable_partial_eviction,
302     0,
303     "enable partial node eviction",
304     NULL,
305     enable_partial_eviction_update,
306     TRUE);
307 
308 static MYSQL_SYSVAR_INT(
309     fs_reserve_percent,
310     fs_reserve_percent,
311     PLUGIN_VAR_READONLY,
312     "file system space reserve (percent free required)",
313     NULL,
314     NULL,
315     5,
316     0,
317     100,
318     0);
319 
fsync_log_period_update(TOKUDB_UNUSED (THD * thd),TOKUDB_UNUSED (st_mysql_sys_var * sys_var),void * var,const void * save)320 static void fsync_log_period_update(TOKUDB_UNUSED(THD* thd),
321                                     TOKUDB_UNUSED(st_mysql_sys_var* sys_var),
322                                     void* var,
323                                     const void* save) {
324     uint* flp = (uint*)var;
325     *flp = *(const uint*)save;
326     db_env->change_fsync_log_period(db_env, *flp);
327 }
328 
329 static MYSQL_SYSVAR_UINT(
330     fsync_log_period,
331     fsync_log_period,
332     0,
333     "fsync log period",
334     NULL,
335     fsync_log_period_update,
336     0,
337     0,
338     ~0U,
339     0);
340 
341 static MYSQL_SYSVAR_STR(
342     log_dir,
343     log_dir,
344     PLUGIN_VAR_READONLY,
345     "log directory",
346     NULL,
347     NULL,
348     NULL);
349 
350 static MYSQL_SYSVAR_ULONGLONG(
351     max_lock_memory,
352     max_lock_memory,
353     PLUGIN_VAR_READONLY,
354     "max memory for locks",
355     NULL,
356     NULL,
357     0,
358     0,
359     ~0ULL,
360     0);
361 
362 static MYSQL_SYSVAR_UINT(
363     read_status_frequency,
364     read_status_frequency,
365     0,
366     "frequency that show processlist updates status of reads",
367     NULL,
368     NULL,
369     10000,
370     0,
371     ~0U,
372     0);
373 
374 static MYSQL_SYSVAR_BOOL(
375     strip_frm_data,
376     strip_frm_data,
377     PLUGIN_VAR_READONLY,
378     "strip .frm data from metadata file(s)",
379     NULL,
380     NULL,
381     FALSE);
382 
383 static MYSQL_SYSVAR_STR(
384     tmp_dir,
385     tmp_dir,
386     PLUGIN_VAR_READONLY,
387     "directory to use for temporary files",
388     NULL,
389     NULL,
390     NULL);
391 
392 static MYSQL_SYSVAR_STR(
393     version,
394     version,
395     PLUGIN_VAR_READONLY,
396     "plugin version",
397     NULL,
398     NULL,
399     NULL);
400 
401 static MYSQL_SYSVAR_UINT(
402     write_status_frequency,
403     write_status_frequency,
404     0,
405     "frequency that show processlist updates status of writes",
406     NULL,
407     NULL,
408     1000,
409     0,
410     ~0U,
411     0);
412 
tokudb_dir_per_db_update(TOKUDB_UNUSED (THD * thd),TOKUDB_UNUSED (struct st_mysql_sys_var * sys_var),void * var,const void * save)413 static void tokudb_dir_per_db_update(
414     TOKUDB_UNUSED(THD* thd),
415     TOKUDB_UNUSED(struct st_mysql_sys_var* sys_var),
416     void* var,
417     const void* save) {
418     my_bool *value = (my_bool *) var;
419     *value = *(const my_bool *) save;
420     db_env->set_dir_per_db(db_env, *value);
421 }
422 
423 static MYSQL_SYSVAR_BOOL(dir_per_db, dir_per_db,
424     0, "TokuDB store ft files in db directories",
425     NULL, tokudb_dir_per_db_update, TRUE);
426 
427 static MYSQL_SYSVAR_BOOL(
428     check_jemalloc,
429     check_jemalloc,
430     PLUGIN_VAR_READONLY|PLUGIN_VAR_RQCMDARG,
431     "check if jemalloc is linked and transparent huge pages are disabled",
432     NULL,
433     NULL,
434     TRUE);
435 
436 
437 //******************************************************************************
438 // session variables
439 //******************************************************************************
440 static MYSQL_THDVAR_BOOL(
441     alter_print_error,
442     0,
443     "print errors for alter table operations",
444     NULL,
445     NULL,
446     false);
447 
448 static MYSQL_THDVAR_DOUBLE(
449     analyze_delete_fraction,
450     0,
451     "fraction of rows allowed to be deleted",
452     NULL,
453     NULL,
454     1.0,
455     0,
456     1.0,
457     1);
458 
459 static MYSQL_THDVAR_BOOL(
460     analyze_in_background,
461     0,
462     "dispatch ANALYZE TABLE to background job.",
463     NULL,
464     NULL,
465     true);
466 
467 const char* srv_analyze_mode_names[] = {
468     "TOKUDB_ANALYZE_STANDARD",
469     "TOKUDB_ANALYZE_RECOUNT_ROWS",
470     "TOKUDB_ANALYZE_CANCEL",
471     NullS
472 };
473 
474 static TYPELIB tokudb_analyze_mode_typelib = {
475     array_elements(srv_analyze_mode_names) - 1,
476     "tokudb_analyze_mode_typelib",
477     srv_analyze_mode_names,
478     NULL
479 };
480 
481 static MYSQL_THDVAR_ENUM(analyze_mode,
482     PLUGIN_VAR_RQCMDARG,
483     "Controls the function of ANALYZE TABLE. Possible values are: "
484     "TOKUDB_ANALYZE_STANDARD perform standard table analysis (default); "
485     "TOKUDB_ANALYZE_RECOUNT_ROWS perform logical recount of table rows;"
486     "TOKUDB_ANALYZE_CANCEL terminate and cancel all scheduled background jobs "
487     "for a table",
488     NULL,
489     NULL,
490     TOKUDB_ANALYZE_STANDARD,
491     &tokudb_analyze_mode_typelib);
492 
493 static MYSQL_THDVAR_ULONGLONG(
494     analyze_throttle,
495     0,
496     "analyze throttle (keys)",
497     NULL,
498     NULL,
499     0,
500     0,
501     ~0U,
502     1);
503 
504 static MYSQL_THDVAR_UINT(
505     analyze_time,
506     0,
507     "analyze time (seconds)",
508     NULL,
509     NULL,
510     5,
511     0,
512     ~0U,
513     1);
514 
515 static MYSQL_THDVAR_ULONGLONG(
516     auto_analyze,
517     0,
518     "auto analyze threshold (percent)",
519     NULL,
520     NULL,
521     30,
522     0,
523     ~0U,
524     1);
525 
526 static MYSQL_THDVAR_UINT(
527     block_size,
528     0,
529     "fractal tree block size",
530     NULL,
531     NULL,
532     4<<20,
533     4096,
534     ~0U,
535     1);
536 
537 static MYSQL_THDVAR_BOOL(
538     bulk_fetch,
539     PLUGIN_VAR_THDLOCAL,
540     "enable bulk fetch",
541     NULL,
542     NULL,
543     true);
544 
checkpoint_lock_update(TOKUDB_UNUSED (THD * thd),TOKUDB_UNUSED (st_mysql_sys_var * var),void * var_ptr,const void * save)545 static void checkpoint_lock_update(TOKUDB_UNUSED(THD* thd),
546                                    TOKUDB_UNUSED(st_mysql_sys_var* var),
547                                    void* var_ptr,
548                                    const void* save) {
549     my_bool* val = (my_bool*)var_ptr;
550     *val= *(my_bool*)save ? true : false;
551     if (*val) {
552         tokudb_checkpoint_lock(thd);
553     } else {
554         tokudb_checkpoint_unlock(thd);
555     }
556 }
557 
558 static MYSQL_THDVAR_BOOL(
559     checkpoint_lock,
560     0,
561     "checkpoint lock",
562     NULL,
563     checkpoint_lock_update,
564     false);
565 
566 static MYSQL_THDVAR_BOOL(
567     commit_sync,
568     PLUGIN_VAR_THDLOCAL,
569     "sync on txn commit",
570     NULL,
571     NULL,
572     true);
573 
574 static MYSQL_THDVAR_BOOL(
575     create_index_online,
576     0,
577     "if on, create index done online",
578     NULL,
579     NULL,
580     true);
581 
582 static MYSQL_THDVAR_BOOL(
583     disable_hot_alter,
584     0,
585     "if on, hot alter table is disabled",
586     NULL,
587     NULL,
588     false);
589 
590 static MYSQL_THDVAR_BOOL(
591     disable_prefetching,
592     0,
593     "if on, prefetching disabled",
594     NULL,
595     NULL,
596     false);
597 
598 static MYSQL_THDVAR_BOOL(
599     disable_slow_alter,
600     0,
601     "if on, alter tables that require copy are disabled",
602     NULL,
603     NULL,
604     false);
605 
606 static const char *tokudb_empty_scan_names[] = {
607     "disabled",
608     "lr",
609     "rl",
610     NullS
611 };
612 
613 static TYPELIB tokudb_empty_scan_typelib = {
614     array_elements(tokudb_empty_scan_names) - 1,
615     "tokudb_empty_scan_typelib",
616     tokudb_empty_scan_names,
617     NULL
618 };
619 
620 static MYSQL_THDVAR_ENUM(
621     empty_scan,
622     PLUGIN_VAR_OPCMDARG,
623     "algorithm to check if the table is empty when opened",
624     NULL,
625     NULL,
626     TOKUDB_EMPTY_SCAN_RL,
627     &tokudb_empty_scan_typelib);
628 
629 static MYSQL_THDVAR_UINT(
630     fanout,
631     0,
632     "fractal tree fanout",
633     NULL,
634     NULL,
635     16,
636     2,
637     16*1024,
638     1);
639 
640 static MYSQL_THDVAR_BOOL(
641     hide_default_row_format,
642     0,
643     "hide the default row format",
644     NULL,
645     NULL,
646     true);
647 
648 static MYSQL_THDVAR_ULONGLONG(
649     killed_time,
650     0,
651     "killed time",
652     NULL,
653     NULL,
654     DEFAULT_TOKUDB_KILLED_TIME,
655     0,
656     ~0ULL,
657     1);
658 
659 static MYSQL_THDVAR_STR(last_lock_timeout,
660                         PLUGIN_VAR_MEMALLOC | PLUGIN_VAR_NOCMDOPT |
661                             PLUGIN_VAR_READONLY,
662                         "last lock timeout",
663                         NULL,
664                         NULL,
665                         NULL);
666 
667 static MYSQL_THDVAR_BOOL(
668     load_save_space,
669     0,
670     "compress intermediate bulk loader files to save space",
671     NULL,
672     NULL,
673     true);
674 
675 static MYSQL_THDVAR_ULONGLONG(
676     loader_memory_size,
677     0,
678     "loader memory size",
679     NULL,
680     NULL,
681     100*1000*1000,
682     0,
683     ~0ULL,
684     1);
685 
686 static MYSQL_THDVAR_ULONGLONG(
687     lock_timeout,
688     0,
689     "lock timeout",
690     NULL,
691     NULL,
692     DEFAULT_TOKUDB_LOCK_TIMEOUT,
693     0,
694     ~0ULL,
695     1);
696 
697 static MYSQL_THDVAR_UINT(
698     lock_timeout_debug,
699     0,
700     "lock timeout debug",
701     NULL,
702     NULL,
703     1,
704     0,
705     ~0U,
706     1);
707 
708 static MYSQL_THDVAR_DOUBLE(
709     optimize_index_fraction,
710     0,
711     "optimize index fraction (default 1.0 all)",
712     NULL,
713     NULL,
714     1.0,
715     0,
716     1.0,
717     1);
718 
719 static MYSQL_THDVAR_STR(
720     optimize_index_name,
721     PLUGIN_VAR_THDLOCAL + PLUGIN_VAR_MEMALLOC,
722     "optimize index name (default all indexes)",
723     NULL,
724     NULL,
725     NULL);
726 
727 static MYSQL_THDVAR_ULONGLONG(
728     optimize_throttle,
729     0,
730     "optimize throttle (default no throttle)",
731     NULL,
732     NULL,
733     0,
734     0,
735     ~0ULL,
736     1);
737 
738 static MYSQL_THDVAR_BOOL(
739     prelock_empty,
740     0,
741     "prelock empty table",
742     NULL,
743     NULL,
744     true);
745 
746 static MYSQL_THDVAR_UINT(
747     read_block_size,
748     0,
749     "fractal tree read block size",
750     NULL,
751     NULL,
752     64*1024,
753     4096,
754     ~0U,
755     1);
756 
757 static MYSQL_THDVAR_UINT(
758     read_buf_size,
759     0,
760     "range query read buffer size",
761     NULL,
762     NULL,
763     128*1024,
764     0,
765     1*1024*1024,
766     1);
767 
768 static const char *tokudb_row_format_names[] = {
769     "tokudb_uncompressed",
770     "tokudb_zlib",
771     "tokudb_snappy",
772     "tokudb_quicklz",
773     "tokudb_lzma",
774     "tokudb_fast",
775     "tokudb_small",
776     "tokudb_default",
777     NullS
778 };
779 
780 static TYPELIB tokudb_row_format_typelib = {
781     array_elements(tokudb_row_format_names) - 1,
782     "tokudb_row_format_typelib",
783     tokudb_row_format_names,
784     NULL
785 };
786 
787 static MYSQL_THDVAR_ENUM(
788     row_format,
789     PLUGIN_VAR_OPCMDARG,
790     "Specifies the compression method for a table created during this session. "
791     "Possible values are TOKUDB_UNCOMPRESSED, TOKUDB_ZLIB, TOKUDB_SNAPPY, "
792     "TOKUDB_QUICKLZ, TOKUDB_LZMA, TOKUDB_FAST, TOKUDB_SMALL and TOKUDB_DEFAULT",
793     NULL,
794     NULL,
795     SRV_ROW_FORMAT_ZLIB,
796     &tokudb_row_format_typelib);
797 
798 #if defined(TOKU_INCLUDE_RFR) && TOKU_INCLUDE_RFR
799 static MYSQL_THDVAR_BOOL(
800     rpl_check_readonly,
801     PLUGIN_VAR_THDLOCAL,
802     "check if the slave is read only",
803     NULL,
804     NULL,
805     true);
806 
807 static MYSQL_THDVAR_BOOL(
808     rpl_lookup_rows,
809     PLUGIN_VAR_THDLOCAL,
810     "lookup a row on rpl slave",
811     NULL,
812     NULL,
813     true);
814 
815 static MYSQL_THDVAR_ULONGLONG(
816     rpl_lookup_rows_delay,
817     PLUGIN_VAR_THDLOCAL,
818     "time in milliseconds to add to lookups on replication slave",
819     NULL,
820     NULL,
821     0,
822     0,
823     ~0ULL,
824     1);
825 
826 static MYSQL_THDVAR_BOOL(
827     rpl_unique_checks,
828     PLUGIN_VAR_THDLOCAL,
829     "enable unique checks on replication slave",
830     NULL,
831     NULL,
832     true);
833 
834 static MYSQL_THDVAR_ULONGLONG(
835     rpl_unique_checks_delay,
836     PLUGIN_VAR_THDLOCAL,
837     "time in milliseconds to add to unique checks test on replication slave",
838     NULL,
839     NULL,
840     0,
841     0,
842     ~0ULL,
843     1);
844 #endif // defined(TOKU_INCLUDE_RFR) && TOKU_INCLUDE_RFR
845 
846 #if defined(TOKU_INCLUDE_UPSERT) && TOKU_INCLUDE_UPSERT
847 static MYSQL_THDVAR_BOOL(
848     enable_fast_update,
849     PLUGIN_VAR_THDLOCAL,
850     "disable slow update",
851     NULL,
852     NULL,
853     false);
854 
855 static MYSQL_THDVAR_BOOL(
856     enable_fast_upsert,
857     PLUGIN_VAR_THDLOCAL,
858     "disable slow upsert",
859     NULL,
860     NULL,
861     false);
862 #endif  // defined(TOKU_INCLUDE_UPSERT) && TOKU_INCLUDE_UPSERT
863 
864 static const char* deprecated_tokudb_support_xa =
865     "Using tokudb_support_xa is deprecated and the "
866     "parameter may be removed in future releases.";
867 static const char* deprecated_tokudb_support_xa_off =
868     "Using tokudb_support_xa is deprecated and the "
869     "parameter may be removed in future releases. "
870     "Only tokudb_support_xa=ON is allowed.";
871 
support_xa_update(THD * thd,st_mysql_sys_var * var,void * var_ptr,const void * save)872 static void support_xa_update(
873     THD* thd,
874     st_mysql_sys_var* var,
875     void* var_ptr,
876     const void* save) {
877     my_bool tokudb_support_xa = *static_cast<const my_bool*>(save);
878     push_warning(thd,
879                  Sql_condition::SL_WARNING,
880                  HA_ERR_WRONG_COMMAND,
881                  tokudb_support_xa ? deprecated_tokudb_support_xa :
882                  deprecated_tokudb_support_xa_off);
883 }
884 
885 static MYSQL_THDVAR_BOOL(
886     support_xa,
887     PLUGIN_VAR_OPCMDARG,
888     "Enable TokuDB support for the XA two-phase commit",
889     NULL,
890     support_xa_update,
891     true);
892 
893 static int dir_cmd_check(THD* thd, struct st_mysql_sys_var* var,
894                          void* save, struct st_mysql_value* value) ;
895 
896 static MYSQL_THDVAR_INT(dir_cmd_last_error,
897     PLUGIN_VAR_THDLOCAL,
898     "error from the last dir command. 0 is success",
899     NULL, NULL, 0, 0, 0, 1);
900 
901 static MYSQL_THDVAR_STR(dir_cmd_last_error_string,
902     PLUGIN_VAR_THDLOCAL + PLUGIN_VAR_MEMALLOC,
903     "error string from the last dir command",
904     NULL, NULL, NULL);
905 
906 static MYSQL_THDVAR_STR(dir_cmd,
907     PLUGIN_VAR_THDLOCAL + PLUGIN_VAR_MEMALLOC,
908     "name of the directory where the backup is stored",
909     dir_cmd_check, NULL, NULL);
910 
911 static void MY_ATTRIBUTE((format(printf, 3, 4)))
dir_cmd_set_error(THD * thd,int error,const char * error_fmt,...)912     dir_cmd_set_error(THD* thd, int error, const char* error_fmt, ...) {
913     char   buff[error_buffer_max_size];
914     va_list varargs;
915 
916     assert(thd);
917     assert(error_fmt);
918 
919     va_start(varargs, error_fmt);
920     vsnprintf(buff, sizeof(buff), error_fmt, varargs);
921     va_end(varargs);
922 
923     THDVAR_SET(thd, dir_cmd_last_error, &error);
924     THDVAR_SET(thd, dir_cmd_last_error_string, buff);
925 }
926 
dir_cmd_clear_error(THD * thd)927 static void dir_cmd_clear_error(THD* thd) {
928     static constexpr int no_error = 0;
929     static const char* empty_error_str = "";
930     THDVAR_SET(thd, dir_cmd_last_error, &no_error);
931     THDVAR_SET(thd, dir_cmd_last_error_string, empty_error_str);
932 }
933 
dir_cmd_check(THD * thd,TOKUDB_UNUSED (struct st_mysql_sys_var * var),void * save,struct st_mysql_value * value)934 static int dir_cmd_check(THD* thd,
935                          TOKUDB_UNUSED(struct st_mysql_sys_var* var),
936                          void* save,
937                          struct st_mysql_value* value) {
938     int error = 0;
939     dir_cmd_clear_error(thd);
940 
941     if (check_global_access(thd, SUPER_ACL)) {
942         return 1;
943     }
944 
945     char buff[STRING_BUFFER_USUAL_SIZE];
946     int length = sizeof(buff);
947     const char *str = value->val_str(value, buff, &length);
948     if (str) {
949         str = thd->strmake(str, length);
950         *(const char**)save = str;
951     }
952 
953     if (str) {
954         dir_cmd_callbacks callbacks { .set_error = dir_cmd_set_error };
955         process_dir_cmd(thd, str, callbacks);
956 
957         error = THDVAR(thd, dir_cmd_last_error);
958     } else {
959         error = EINVAL;
960     }
961 
962     return error;
963 }
964 
965 //******************************************************************************
966 // all system variables
967 //******************************************************************************
968 st_mysql_sys_var* system_variables[] = {
969     // global vars
970     MYSQL_SYSVAR(cache_size),
971     MYSQL_SYSVAR(force_recovery),
972     MYSQL_SYSVAR(checkpoint_on_flush_logs),
973     MYSQL_SYSVAR(cachetable_pool_threads),
974     MYSQL_SYSVAR(cardinality_scale_percent),
975     MYSQL_SYSVAR(checkpoint_pool_threads),
976     MYSQL_SYSVAR(checkpointing_period),
977     MYSQL_SYSVAR(cleaner_iterations),
978     MYSQL_SYSVAR(cleaner_period),
979     MYSQL_SYSVAR(client_pool_threads),
980     MYSQL_SYSVAR(compress_buffers_before_eviction),
981     MYSQL_SYSVAR(data_dir),
982     MYSQL_SYSVAR(debug),
983     MYSQL_SYSVAR(directio),
984     MYSQL_SYSVAR(enable_native_partition),
985     MYSQL_SYSVAR(enable_partial_eviction),
986     MYSQL_SYSVAR(fs_reserve_percent),
987     MYSQL_SYSVAR(fsync_log_period),
988     MYSQL_SYSVAR(log_dir),
989     MYSQL_SYSVAR(max_lock_memory),
990     MYSQL_SYSVAR(read_status_frequency),
991     MYSQL_SYSVAR(strip_frm_data),
992     MYSQL_SYSVAR(tmp_dir),
993     MYSQL_SYSVAR(version),
994     MYSQL_SYSVAR(write_status_frequency),
995     MYSQL_SYSVAR(dir_per_db),
996     MYSQL_SYSVAR(check_jemalloc),
997 
998     // session vars
999     MYSQL_SYSVAR(alter_print_error),
1000     MYSQL_SYSVAR(analyze_delete_fraction),
1001     MYSQL_SYSVAR(analyze_in_background),
1002     MYSQL_SYSVAR(analyze_mode),
1003     MYSQL_SYSVAR(analyze_throttle),
1004     MYSQL_SYSVAR(analyze_time),
1005     MYSQL_SYSVAR(auto_analyze),
1006     MYSQL_SYSVAR(block_size),
1007     MYSQL_SYSVAR(bulk_fetch),
1008     MYSQL_SYSVAR(checkpoint_lock),
1009     MYSQL_SYSVAR(commit_sync),
1010     MYSQL_SYSVAR(create_index_online),
1011     MYSQL_SYSVAR(disable_hot_alter),
1012     MYSQL_SYSVAR(disable_prefetching),
1013     MYSQL_SYSVAR(disable_slow_alter),
1014     MYSQL_SYSVAR(empty_scan),
1015     MYSQL_SYSVAR(fanout),
1016     MYSQL_SYSVAR(hide_default_row_format),
1017     MYSQL_SYSVAR(killed_time),
1018     MYSQL_SYSVAR(last_lock_timeout),
1019     MYSQL_SYSVAR(load_save_space),
1020     MYSQL_SYSVAR(loader_memory_size),
1021     MYSQL_SYSVAR(lock_timeout),
1022     MYSQL_SYSVAR(lock_timeout_debug),
1023     MYSQL_SYSVAR(optimize_index_fraction),
1024     MYSQL_SYSVAR(optimize_index_name),
1025     MYSQL_SYSVAR(optimize_throttle),
1026     MYSQL_SYSVAR(prelock_empty),
1027     MYSQL_SYSVAR(read_block_size),
1028     MYSQL_SYSVAR(read_buf_size),
1029     MYSQL_SYSVAR(row_format),
1030 #if defined(TOKU_INCLUDE_RFR) && TOKU_INCLUDE_RFR
1031     MYSQL_SYSVAR(rpl_check_readonly),
1032     MYSQL_SYSVAR(rpl_lookup_rows),
1033     MYSQL_SYSVAR(rpl_lookup_rows_delay),
1034     MYSQL_SYSVAR(rpl_unique_checks),
1035     MYSQL_SYSVAR(rpl_unique_checks_delay),
1036 #endif  // defined(TOKU_INCLUDE_RFR) && TOKU_INCLUDE_RFR
1037 #if defined(TOKU_INCLUDE_UPSERT) && TOKU_INCLUDE_UPSERT
1038     MYSQL_SYSVAR(enable_fast_update),
1039     MYSQL_SYSVAR(enable_fast_upsert),
1040 #endif  // defined(TOKU_INCLUDE_UPSERT) && TOKU_INCLUDE_UPSERT
1041     MYSQL_SYSVAR(support_xa),
1042 
1043 #if defined(TOKUDB_DEBUG) && TOKUDB_DEBUG
1044     MYSQL_SYSVAR(debug_pause_background_job_manager),
1045 #endif  // defined(TOKUDB_DEBUG) && TOKUDB_DEBUG
1046     MYSQL_SYSVAR(dir_cmd_last_error),
1047     MYSQL_SYSVAR(dir_cmd_last_error_string),
1048     MYSQL_SYSVAR(dir_cmd),
1049 
1050     NULL
1051 };
1052 
alter_print_error(THD * thd)1053 my_bool alter_print_error(THD* thd) {
1054     return (THDVAR(thd, alter_print_error) != 0);
1055 }
analyze_delete_fraction(THD * thd)1056 double analyze_delete_fraction(THD* thd) {
1057     return THDVAR(thd, analyze_delete_fraction);
1058 }
analyze_in_background(THD * thd)1059 my_bool analyze_in_background(THD* thd) {
1060     return (THDVAR(thd, analyze_in_background) != 0);
1061 }
analyze_mode(THD * thd)1062 analyze_mode_t analyze_mode(THD* thd) {
1063     return (analyze_mode_t ) THDVAR(thd, analyze_mode);
1064 }
analyze_throttle(THD * thd)1065 ulonglong analyze_throttle(THD* thd) {
1066     return THDVAR(thd, analyze_throttle);
1067 }
analyze_time(THD * thd)1068 ulonglong analyze_time(THD* thd) {
1069     return THDVAR(thd, analyze_time);
1070 }
auto_analyze(THD * thd)1071 ulonglong auto_analyze(THD* thd) {
1072     return THDVAR(thd, auto_analyze);
1073 }
bulk_fetch(THD * thd)1074 my_bool bulk_fetch(THD* thd) {
1075     return (THDVAR(thd, bulk_fetch) != 0);
1076 }
block_size(THD * thd)1077 uint block_size(THD* thd) {
1078     return THDVAR(thd, block_size);
1079 }
commit_sync(THD * thd)1080 my_bool commit_sync(THD* thd) {
1081     return (THDVAR(thd, commit_sync) != 0);
1082 }
create_index_online(THD * thd)1083 my_bool create_index_online(THD* thd) {
1084     return (THDVAR(thd, create_index_online) != 0);
1085 }
disable_hot_alter(THD * thd)1086 my_bool disable_hot_alter(THD* thd) {
1087     return (THDVAR(thd, disable_hot_alter) != 0);
1088 }
disable_prefetching(THD * thd)1089 my_bool disable_prefetching(THD* thd) {
1090     return (THDVAR(thd, disable_prefetching) != 0);
1091 }
disable_slow_alter(THD * thd)1092 my_bool disable_slow_alter(THD* thd) {
1093     return (THDVAR(thd, disable_slow_alter) != 0);
1094 }
1095 #if defined(TOKU_INCLUDE_UPSERT) && TOKU_INCLUDE_UPSERT
enable_fast_update(THD * thd)1096 my_bool enable_fast_update(THD* thd) {
1097     return (THDVAR(thd, enable_fast_update) != 0);
1098 }
enable_fast_upsert(THD * thd)1099 my_bool enable_fast_upsert(THD* thd) {
1100     return (THDVAR(thd, enable_fast_upsert) != 0);
1101 }
1102 #endif  // defined(TOKU_INCLUDE_UPSERT) && TOKU_INCLUDE_UPSERT
empty_scan(THD * thd)1103 empty_scan_mode_t empty_scan(THD* thd) {
1104     return (empty_scan_mode_t)THDVAR(thd, empty_scan);
1105 }
fanout(THD * thd)1106 uint fanout(THD* thd) {
1107     return THDVAR(thd, fanout);
1108 }
hide_default_row_format(THD * thd)1109 my_bool hide_default_row_format(THD* thd) {
1110     return (THDVAR(thd, hide_default_row_format) != 0);
1111 }
killed_time(THD * thd)1112 ulonglong killed_time(THD* thd) {
1113     return THDVAR(thd, killed_time);
1114 }
last_lock_timeout(THD * thd)1115 char* last_lock_timeout(THD* thd) {
1116     return THDVAR(thd, last_lock_timeout);
1117 }
set_last_lock_timeout(THD * thd,char * last)1118 void set_last_lock_timeout(THD* thd, char* last) {
1119     THDVAR(thd, last_lock_timeout) = last;
1120 }
load_save_space(THD * thd)1121 my_bool load_save_space(THD* thd) {
1122     return (THDVAR(thd, load_save_space) != 0);
1123 }
loader_memory_size(THD * thd)1124 ulonglong loader_memory_size(THD* thd) {
1125     return THDVAR(thd, loader_memory_size);
1126 }
lock_timeout(THD * thd)1127 ulonglong lock_timeout(THD* thd) {
1128     return THDVAR(thd, lock_timeout);
1129 }
lock_timeout_debug(THD * thd)1130 uint lock_timeout_debug(THD* thd) {
1131     return THDVAR(thd, lock_timeout_debug);
1132 }
optimize_index_fraction(THD * thd)1133 double optimize_index_fraction(THD* thd) {
1134     return THDVAR(thd, optimize_index_fraction);
1135 }
optimize_index_name(THD * thd)1136 const char* optimize_index_name(THD* thd) {
1137     return THDVAR(thd, optimize_index_name);
1138 }
optimize_throttle(THD * thd)1139 ulonglong optimize_throttle(THD* thd) {
1140     return THDVAR(thd, optimize_throttle);
1141 }
prelock_empty(THD * thd)1142 my_bool prelock_empty(THD* thd) {
1143     return (THDVAR(thd, prelock_empty) != 0);
1144 }
read_block_size(THD * thd)1145 uint read_block_size(THD* thd) {
1146     return THDVAR(thd, read_block_size);
1147 }
read_buf_size(THD * thd)1148 uint read_buf_size(THD* thd) {
1149     return THDVAR(thd, read_buf_size);
1150 }
row_format(THD * thd)1151 row_format_t row_format(THD *thd) {
1152     return (row_format_t) THDVAR(thd, row_format);
1153 }
1154 #if defined(TOKU_INCLUDE_RFR) && TOKU_INCLUDE_RFR
rpl_check_readonly(THD * thd)1155 my_bool rpl_check_readonly(THD* thd) {
1156     return (THDVAR(thd, rpl_check_readonly) != 0);
1157 }
rpl_lookup_rows(THD * thd)1158 my_bool rpl_lookup_rows(THD* thd) {
1159     return (THDVAR(thd, rpl_lookup_rows) != 0);
1160 }
rpl_lookup_rows_delay(THD * thd)1161 ulonglong rpl_lookup_rows_delay(THD* thd) {
1162     return THDVAR(thd, rpl_lookup_rows_delay);
1163 }
rpl_unique_checks(THD * thd)1164 my_bool rpl_unique_checks(THD* thd) {
1165     return (THDVAR(thd, rpl_unique_checks) != 0);
1166 }
rpl_unique_checks_delay(THD * thd)1167 ulonglong rpl_unique_checks_delay(THD* thd) {
1168     return THDVAR(thd, rpl_unique_checks_delay);
1169 }
1170 #endif // defined(TOKU_INCLUDE_RFR) && TOKU_INCLUDE_RFR
support_xa(THD * thd)1171 my_bool support_xa(THD* thd) {
1172     return (THDVAR(thd, support_xa) != 0);
1173 }
set_support_xa(THD * thd,my_bool xa)1174 void set_support_xa(THD* thd, my_bool xa) {
1175     THDVAR(thd, support_xa) = xa;
1176 }
1177 } // namespace sysvars
1178 } // namespace tokudb
1179