summaryrefslogtreecommitdiff
path: root/storage/tokudb/tokudb_information_schema.cc
blob: 0b9882060cd3ff0d99d164b34ceec5039a40955d (plain)
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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
/* -*- mode: C++; c-basic-offset: 4; indent-tabs-mode: nil -*- */
// vim: ft=cpp:expandtab:ts=8:sw=4:softtabstop=4:
/* -*- mode: C; c-basic-offset: 4 -*- */
#ident "$Id$"
/*======
This file is part of TokuDB


Copyright (c) 2006, 2015, Percona and/or its affiliates. All rights reserved.

    TokuDBis is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License, version 2,
    as published by the Free Software Foundation.

    TokuDB 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 TokuDB.  If not, see <http://www.gnu.org/licenses/>.

======= */

#ident "Copyright (c) 2006, 2015, Percona and/or its affiliates. All rights reserved."

#include "hatoku_hton.h"
#include "tokudb_information_schema.h"
#include "sql_time.h"
#include "tokudb_background.h"


namespace tokudb {
namespace information_schema {

static void field_store_time_t(Field* field, time_t time) {
    MYSQL_TIME  my_time;
    struct tm tm_time;

    if (time) {
        localtime_r(&time, &tm_time);
        localtime_to_TIME(&my_time, &tm_time);
        my_time.time_type = MYSQL_TIMESTAMP_DATETIME;
#ifdef MARIA_PLUGIN_INTERFACE_VERSION
        field->store_time(&my_time);
#else
        field->store_time(&my_time, MYSQL_TIMESTAMP_DATETIME);
#endif
        field->set_notnull();
    } else {
        field->set_null();
    }
}

st_mysql_information_schema trx_information_schema = {
    MYSQL_INFORMATION_SCHEMA_INTERFACE_VERSION
};

ST_FIELD_INFO trx_field_info[] = {
    {"trx_id", 0, MYSQL_TYPE_LONGLONG, 0, 0, NULL, SKIP_OPEN_TABLE },
    {"trx_mysql_thread_id", 0, MYSQL_TYPE_LONGLONG, 0, 0, NULL, SKIP_OPEN_TABLE },
    {"trx_time", 0, MYSQL_TYPE_LONGLONG, 0, 0, NULL, SKIP_OPEN_TABLE },
    {NULL, 0, MYSQL_TYPE_NULL, 0, 0, NULL, SKIP_OPEN_TABLE}
};

struct trx_extra_t {
    THD *thd;
    TABLE *table;
};

int trx_callback(DB_TXN* txn,
                 TOKUDB_UNUSED(iterate_row_locks_callback iterate_locks),
                 TOKUDB_UNUSED(void* locks_extra),
                 void* extra) {
    uint64_t txn_id = txn->id64(txn);
    uint64_t client_id;
    txn->get_client_id(txn, &client_id, NULL);
    uint64_t start_time = txn->get_start_time(txn);
    trx_extra_t* e = reinterpret_cast<struct trx_extra_t*>(extra);
    THD* thd = e->thd;
    TABLE* table = e->table;
    table->field[0]->store(txn_id, false);
    table->field[1]->store(client_id, false);
    uint64_t tnow = (uint64_t) ::time(NULL);
    table->field[2]->store(tnow >= start_time ? tnow - start_time : 0, false);
    int error = schema_table_store_record(thd, table);
    if (!error && thd_kill_level(thd))
        error = ER_QUERY_INTERRUPTED;
    return error;
}

#if MYSQL_VERSION_ID >= 50600
int trx_fill_table(THD* thd, TABLE_LIST* tables, TOKUDB_UNUSED(Item* cond)) {
#else
int trx_fill_table(THD* thd, TABLE_LIST* tables, TOKUDB_UNUSED(COND* cond)) {
#endif
    TOKUDB_DBUG_ENTER("");
    int error;

    rwlock_t_lock_read(tokudb_hton_initialized_lock);

    if (!tokudb_hton_initialized) {
        error = ER_PLUGIN_IS_NOT_LOADED;
        my_error(error, MYF(0), tokudb_hton_name);
    } else {
        trx_extra_t e = { thd, tables->table };
        error = db_env->iterate_live_transactions(db_env, trx_callback, &e);
        if (error)
            my_error(ER_GET_ERRNO, MYF(0), error, tokudb_hton_name);
    }

    tokudb_hton_initialized_lock.unlock();
    TOKUDB_DBUG_RETURN(error);
}

int trx_init(void* p) {
    ST_SCHEMA_TABLE *schema = (ST_SCHEMA_TABLE*) p;
    schema->fields_info = trx_field_info;
    schema->fill_table = trx_fill_table;
    return 0;
}

int trx_done(TOKUDB_UNUSED(void* p)) {
    return 0;
}

st_mysql_plugin trx = {
    MYSQL_INFORMATION_SCHEMA_PLUGIN,
    &trx_information_schema,
    "TokuDB_trx",
    "Percona",
    "Percona TokuDB Storage Engine with Fractal Tree(tm) Technology",
    PLUGIN_LICENSE_GPL,
    trx_init,                   /* plugin init */
    trx_done,                   /* plugin deinit */
    TOKUDB_PLUGIN_VERSION,
    NULL,                      /* status variables */
    NULL,                      /* system variables */
#ifdef MARIA_PLUGIN_INTERFACE_VERSION
    tokudb::sysvars::version,
    MariaDB_PLUGIN_MATURITY_STABLE /* maturity */
#else
    NULL,                      /* config options */
    0,                         /* flags */
#endif
};



st_mysql_information_schema lock_waits_information_schema = {
    MYSQL_INFORMATION_SCHEMA_INTERFACE_VERSION
};

ST_FIELD_INFO lock_waits_field_info[] = {
    {"requesting_trx_id", 0, MYSQL_TYPE_LONGLONG, 0, 0, NULL, SKIP_OPEN_TABLE },
    {"blocking_trx_id", 0, MYSQL_TYPE_LONGLONG, 0, 0, NULL, SKIP_OPEN_TABLE },
    {"lock_waits_dname", 256, MYSQL_TYPE_STRING, 0, 0, NULL, SKIP_OPEN_TABLE },
    {"lock_waits_key_left", 256, MYSQL_TYPE_STRING, 0, 0, NULL, SKIP_OPEN_TABLE },
    {"lock_waits_key_right", 256, MYSQL_TYPE_STRING, 0, 0, NULL, SKIP_OPEN_TABLE },
    {"lock_waits_start_time", 0, MYSQL_TYPE_LONGLONG, 0, 0, NULL, SKIP_OPEN_TABLE },
    {"lock_waits_table_schema", 256, MYSQL_TYPE_STRING, 0, 0, NULL, SKIP_OPEN_TABLE },
    {"lock_waits_table_name", 256, MYSQL_TYPE_STRING, 0, 0, NULL, SKIP_OPEN_TABLE },
    {"lock_waits_table_dictionary_name", 256, MYSQL_TYPE_STRING, 0, 0, NULL, SKIP_OPEN_TABLE },
    {NULL, 0, MYSQL_TYPE_NULL, 0, 0, NULL, SKIP_OPEN_TABLE}
};

struct lock_waits_extra_t {
    THD* thd;
    TABLE* table;
};

int lock_waits_callback(
    DB* db,
    uint64_t requesting_txnid,
    const DBT* left_key,
    const DBT* right_key,
    uint64_t blocking_txnid,
    uint64_t start_time,
    void *extra) {

    lock_waits_extra_t* e =
        reinterpret_cast<struct lock_waits_extra_t*>(extra);
    THD* thd = e->thd;
    TABLE* table = e->table;
    table->field[0]->store(requesting_txnid, false);
    table->field[1]->store(blocking_txnid, false);
    const char* dname = tokudb_get_index_name(db);
    size_t dname_length = strlen(dname);
    table->field[2]->store(dname, dname_length, system_charset_info);
    String left_str;
    tokudb_pretty_left_key(left_key, &left_str);
    table->field[3]->store(
        left_str.ptr(),
        left_str.length(),
        system_charset_info);
    String right_str;
    tokudb_pretty_right_key(right_key, &right_str);
    table->field[4]->store(
        right_str.ptr(),
        right_str.length(),
        system_charset_info);
    table->field[5]->store(start_time, false);

    String database_name, table_name, dictionary_name;
    tokudb_split_dname(dname, database_name, table_name, dictionary_name);
    table->field[6]->store(
        database_name.c_ptr(),
        database_name.length(),
        system_charset_info);
    table->field[7]->store(
        table_name.c_ptr(),
        table_name.length(),
        system_charset_info);
    table->field[8]->store(
        dictionary_name.c_ptr(),
        dictionary_name.length(),
        system_charset_info);

    int error = schema_table_store_record(thd, table);

    if (!error && thd_kill_level(thd))
        error = ER_QUERY_INTERRUPTED;

    return error;
}

#if MYSQL_VERSION_ID >= 50600
int lock_waits_fill_table(THD* thd,
                          TABLE_LIST* tables,
                          TOKUDB_UNUSED(Item* cond)) {
#else
int lock_waits_fill_table(THD* thd,
                          TABLE_LIST* tables,
                          TOKUDB_UNUSED(COND* cond)) {
#endif
    TOKUDB_DBUG_ENTER("");
    int error;

    rwlock_t_lock_read(tokudb_hton_initialized_lock);

    if (!tokudb_hton_initialized) {
        error = ER_PLUGIN_IS_NOT_LOADED;
        my_error(error, MYF(0), tokudb_hton_name);
    } else {
        lock_waits_extra_t e = { thd, tables->table };
        error = db_env->iterate_pending_lock_requests(
            db_env,
            lock_waits_callback,
            &e);
        if (error)
            my_error(ER_GET_ERRNO, MYF(0), error, tokudb_hton_name);
    }

    tokudb_hton_initialized_lock.unlock();
    TOKUDB_DBUG_RETURN(error);
}

int lock_waits_init(void* p) {
    ST_SCHEMA_TABLE* schema = (ST_SCHEMA_TABLE*)p;
    schema->fields_info = lock_waits_field_info;
    schema->fill_table = lock_waits_fill_table;
    return 0;
}

int lock_waits_done(TOKUDB_UNUSED(void *p)) {
    return 0;
}

st_mysql_plugin lock_waits = {
    MYSQL_INFORMATION_SCHEMA_PLUGIN,
    &lock_waits_information_schema,
    "TokuDB_lock_waits",
    "Percona",
    "Percona TokuDB Storage Engine with Fractal Tree(tm) Technology",
    PLUGIN_LICENSE_GPL,
    lock_waits_init,            /* plugin init */
    lock_waits_done,            /* plugin deinit */
    TOKUDB_PLUGIN_VERSION,
    NULL,                       /* status variables */
    NULL,                       /* system variables */
#ifdef MARIA_PLUGIN_INTERFACE_VERSION
    tokudb::sysvars::version,
    MariaDB_PLUGIN_MATURITY_STABLE /* maturity */
#else
    NULL,                       /* config options */
    0,                          /* flags */
#endif
};



st_mysql_information_schema locks_information_schema = {
    MYSQL_INFORMATION_SCHEMA_INTERFACE_VERSION
};

 ST_FIELD_INFO locks_field_info[] = {
    {"locks_trx_id", 0, MYSQL_TYPE_LONGLONG, 0, 0, NULL, SKIP_OPEN_TABLE },
    {"locks_mysql_thread_id", 0, MYSQL_TYPE_LONGLONG, 0, 0, NULL, SKIP_OPEN_TABLE },
    {"locks_dname", 256, MYSQL_TYPE_STRING, 0, 0, NULL, SKIP_OPEN_TABLE },
    {"locks_key_left", 256, MYSQL_TYPE_STRING, 0, 0, NULL, SKIP_OPEN_TABLE },
    {"locks_key_right", 256, MYSQL_TYPE_STRING, 0, 0, NULL, SKIP_OPEN_TABLE },
    {"locks_table_schema", 256, MYSQL_TYPE_STRING, 0, 0, NULL, SKIP_OPEN_TABLE },
    {"locks_table_name", 256, MYSQL_TYPE_STRING, 0, 0, NULL, SKIP_OPEN_TABLE },
    {"locks_table_dictionary_name", 256, MYSQL_TYPE_STRING, 0, 0, NULL, SKIP_OPEN_TABLE },
    {NULL, 0, MYSQL_TYPE_NULL, 0, 0, NULL, SKIP_OPEN_TABLE}
};

struct locks_extra_t {
    THD* thd;
    TABLE* table;
};

int locks_callback(
    DB_TXN* txn,
    iterate_row_locks_callback iterate_locks,
    void* locks_extra,
    void* extra) {

    uint64_t txn_id = txn->id64(txn);
    uint64_t client_id;
    txn->get_client_id(txn, &client_id, NULL);
    locks_extra_t* e = reinterpret_cast<struct locks_extra_t*>(extra);
    THD* thd = e->thd;
    TABLE* table = e->table;
    int error = 0;
    DB* db;
    DBT left_key, right_key;
    while (error == 0 &&
           iterate_locks(&db, &left_key, &right_key, locks_extra) == 0) {
        table->field[0]->store(txn_id, false);
        table->field[1]->store(client_id, false);

        const char* dname = tokudb_get_index_name(db);
        size_t dname_length = strlen(dname);
        table->field[2]->store(dname, dname_length, system_charset_info);

        String left_str;
        tokudb_pretty_left_key(&left_key, &left_str);
        table->field[3]->store(
            left_str.ptr(),
            left_str.length(),
            system_charset_info);

        String right_str;
        tokudb_pretty_right_key(&right_key, &right_str);
        table->field[4]->store(
            right_str.ptr(),
            right_str.length(),
            system_charset_info);

        String database_name, table_name, dictionary_name;
        tokudb_split_dname(dname, database_name, table_name, dictionary_name);
        table->field[5]->store(
            database_name.c_ptr(),
            database_name.length(),
            system_charset_info);
        table->field[6]->store(
            table_name.c_ptr(),
            table_name.length(),
            system_charset_info);
        table->field[7]->store(
            dictionary_name.c_ptr(),
            dictionary_name.length(),
            system_charset_info);

        error = schema_table_store_record(thd, table);

        if (!error && thd_kill_level(thd))
            error = ER_QUERY_INTERRUPTED;
    }
    return error;
}

#if MYSQL_VERSION_ID >= 50600
int locks_fill_table(THD* thd, TABLE_LIST* tables, TOKUDB_UNUSED(Item* cond)) {
#else
int locks_fill_table(THD* thd, TABLE_LIST* tables, TOKUDB_UNUSED(COND* cond)) {
#endif
    TOKUDB_DBUG_ENTER("");
    int error;

    rwlock_t_lock_read(tokudb_hton_initialized_lock);

    if (!tokudb_hton_initialized) {
        error = ER_PLUGIN_IS_NOT_LOADED;
        my_error(error, MYF(0), tokudb_hton_name);
    } else {
        locks_extra_t e = { thd, tables->table };
        error = db_env->iterate_live_transactions(db_env, locks_callback, &e);
        if (error)
            my_error(ER_GET_ERRNO, MYF(0), error, tokudb_hton_name);
    }

    tokudb_hton_initialized_lock.unlock();
    TOKUDB_DBUG_RETURN(error);
}

int locks_init(void* p) {
    ST_SCHEMA_TABLE* schema = (ST_SCHEMA_TABLE*)p;
    schema->fields_info = locks_field_info;
    schema->fill_table = locks_fill_table;
    return 0;
}

int locks_done(TOKUDB_UNUSED(void* p)) {
    return 0;
}

st_mysql_plugin locks = {
    MYSQL_INFORMATION_SCHEMA_PLUGIN,
    &locks_information_schema,
    "TokuDB_locks",
    "Percona",
    "Percona TokuDB Storage Engine with Fractal Tree(tm) Technology",
    PLUGIN_LICENSE_GPL,
    locks_init,                 /* plugin init */
    locks_done,                 /* plugin deinit */
    TOKUDB_PLUGIN_VERSION,
    NULL,                       /* status variables */
    NULL,                       /* system variables */
#ifdef MARIA_PLUGIN_INTERFACE_VERSION
    tokudb::sysvars::version,
    MariaDB_PLUGIN_MATURITY_STABLE /* maturity */
#else
    NULL,                       /* config options */
    0,                         /* flags */
#endif
};



st_mysql_information_schema file_map_information_schema = {
    MYSQL_INFORMATION_SCHEMA_INTERFACE_VERSION
};

ST_FIELD_INFO file_map_field_info[] = {
    {"dictionary_name", 256, MYSQL_TYPE_STRING, 0, 0, NULL, SKIP_OPEN_TABLE },
    {"internal_file_name", 256, MYSQL_TYPE_STRING, 0, 0, NULL, SKIP_OPEN_TABLE },
    {"table_schema", 256, MYSQL_TYPE_STRING, 0, 0, NULL, SKIP_OPEN_TABLE },
    {"table_name", 256, MYSQL_TYPE_STRING, 0, 0, NULL, SKIP_OPEN_TABLE },
    {"table_dictionary_name", 256, MYSQL_TYPE_STRING, 0, 0, NULL, SKIP_OPEN_TABLE },
    {NULL, 0, MYSQL_TYPE_NULL, 0, 0, NULL, SKIP_OPEN_TABLE}
};

int report_file_map(TABLE* table, THD* thd) {
    int error;
    DB_TXN* txn = NULL;
    DBC* tmp_cursor = NULL;
    DBT curr_key;
    DBT curr_val;
    memset(&curr_key, 0, sizeof curr_key);
    memset(&curr_val, 0, sizeof curr_val);
    error = txn_begin(db_env, 0, &txn, DB_READ_UNCOMMITTED, thd);
    if (error) {
        goto cleanup;
    }
    error = db_env->get_cursor_for_directory(db_env, txn, &tmp_cursor);
    if (error) {
        goto cleanup;
    }
    while (error == 0) {
        error = tmp_cursor->c_get(tmp_cursor, &curr_key, &curr_val, DB_NEXT);
        if (!error) {
            // We store the NULL terminator in the directory so it's included
            // in the size.
            // See #5789
            // Recalculate and check just to be safe.
            const char *dname = (const char *) curr_key.data;
            size_t dname_len = strlen(dname);
            assert(dname_len == curr_key.size - 1);
            table->field[0]->store(dname, dname_len, system_charset_info);

            const char *iname = (const char *) curr_val.data;
            size_t iname_len = strlen(iname);
            assert(iname_len == curr_val.size - 1);
            table->field[1]->store(iname, iname_len, system_charset_info);

            // split the dname
            String database_name, table_name, dictionary_name;
            tokudb_split_dname(
                dname,
                database_name,
                table_name,
                dictionary_name);
            table->field[2]->store(
                database_name.c_ptr(),
                database_name.length(),
                system_charset_info);
            table->field[3]->store(
                table_name.c_ptr(),
                table_name.length(),
                system_charset_info);
            table->field[4]->store(
                dictionary_name.c_ptr(),
                dictionary_name.length(),
                system_charset_info);

            error = schema_table_store_record(thd, table);
        }
        if (!error && thd_kill_level(thd))
            error = ER_QUERY_INTERRUPTED;
    }
    if (error == DB_NOTFOUND) {
        error = 0;
    }
cleanup:
    if (tmp_cursor) {
        int r = tmp_cursor->c_close(tmp_cursor);
        assert(r == 0);
    }
    if (txn) {
        commit_txn(txn, 0);
    }
    return error;
}

#if MYSQL_VERSION_ID >= 50600
int file_map_fill_table(THD* thd,
                        TABLE_LIST* tables,
                        TOKUDB_UNUSED(Item* cond)) {
#else
int file_map_fill_table(THD* thd,
                        TABLE_LIST* tables,
                        TOKUDB_UNUSED(COND* cond)) {
#endif
    TOKUDB_DBUG_ENTER("");
    int error;
    TABLE* table = tables->table;

    rwlock_t_lock_read(tokudb_hton_initialized_lock);

    if (!tokudb_hton_initialized) {
        error = ER_PLUGIN_IS_NOT_LOADED;
        my_error(error, MYF(0), tokudb_hton_name);
    } else {
        error = report_file_map(table, thd);
        if (error)
            my_error(ER_GET_ERRNO, MYF(0), error, tokudb_hton_name);
    }

    tokudb_hton_initialized_lock.unlock();
    TOKUDB_DBUG_RETURN(error);
}

int file_map_init(void* p) {
    ST_SCHEMA_TABLE* schema = (ST_SCHEMA_TABLE*)p;
    schema->fields_info = file_map_field_info;
    schema->fill_table = file_map_fill_table;
    return 0;
}

int file_map_done(TOKUDB_UNUSED(void* p)) {
    return 0;
}

st_mysql_plugin file_map = {
    MYSQL_INFORMATION_SCHEMA_PLUGIN,
    &file_map_information_schema,
    "TokuDB_file_map",
    "Percona",
    "Percona TokuDB Storage Engine with Fractal Tree(tm) Technology",
    PLUGIN_LICENSE_GPL,
    file_map_init,              /* plugin init */
    file_map_done,              /* plugin deinit */
    TOKUDB_PLUGIN_VERSION,
    NULL,                       /* status variables */
    NULL,                       /* system variables */
#ifdef MARIA_PLUGIN_INTERFACE_VERSION
    tokudb::sysvars::version,
    MariaDB_PLUGIN_MATURITY_STABLE /* maturity */
#else
    NULL,                       /* config options */
    0,                          /* flags */
#endif
};



st_mysql_information_schema fractal_tree_info_information_schema = {
    MYSQL_INFORMATION_SCHEMA_INTERFACE_VERSION
};

ST_FIELD_INFO fractal_tree_info_field_info[] = {
    {"dictionary_name", 256, MYSQL_TYPE_STRING, 0, 0, NULL, SKIP_OPEN_TABLE },
    {"internal_file_name", 256, MYSQL_TYPE_STRING, 0, 0, NULL, SKIP_OPEN_TABLE },
    {"bt_num_blocks_allocated", 0, MYSQL_TYPE_LONGLONG, 0, 0, NULL, SKIP_OPEN_TABLE },
    {"bt_num_blocks_in_use", 0, MYSQL_TYPE_LONGLONG, 0, 0, NULL, SKIP_OPEN_TABLE },
    {"bt_size_allocated", 0, MYSQL_TYPE_LONGLONG, 0, 0, NULL, SKIP_OPEN_TABLE },
    {"bt_size_in_use", 0, MYSQL_TYPE_LONGLONG, 0, 0, NULL, SKIP_OPEN_TABLE },
    {"table_schema", 256, MYSQL_TYPE_STRING, 0, 0, NULL, SKIP_OPEN_TABLE },
    {"table_name", 256, MYSQL_TYPE_STRING, 0, 0, NULL, SKIP_OPEN_TABLE },
    {"table_dictionary_name", 256, MYSQL_TYPE_STRING, 0, 0, NULL, SKIP_OPEN_TABLE },
    {NULL, 0, MYSQL_TYPE_NULL, 0, 0, NULL, SKIP_OPEN_TABLE}
};

int report_fractal_tree_info_for_db(
    const DBT* dname,
    const DBT* iname,
    TABLE* table,
    THD* thd) {

    int error;
    uint64_t bt_num_blocks_allocated;
    uint64_t bt_num_blocks_in_use;
    uint64_t bt_size_allocated;
    uint64_t bt_size_in_use;

    DB *db = NULL;
    error = db_create(&db, db_env, 0);
    if (error) {
        goto exit;
    }
    error = db->open(db, NULL, (char *)dname->data, NULL, DB_BTREE, 0, 0666);
    if (error) {
        goto exit;
    }
    error = db->get_fractal_tree_info64(
        db,
        &bt_num_blocks_allocated,
        &bt_num_blocks_in_use,
        &bt_size_allocated,
        &bt_size_in_use);
    if (error) {
        goto exit;
    }

    // We store the NULL terminator in the directory so it's included in the
    // size.
    // See #5789
    // Recalculate and check just to be safe.
    {
        size_t dname_len = strlen((const char*)dname->data);
        assert(dname_len == dname->size - 1);
        table->field[0]->store(
            (char*)dname->data,
            dname_len,
            system_charset_info);
        size_t iname_len = strlen((const char*)iname->data);
        assert(iname_len == iname->size - 1);
        table->field[1]->store(
            (char*)iname->data,
            iname_len,
            system_charset_info);
    }
    table->field[2]->store(bt_num_blocks_allocated, false);
    table->field[3]->store(bt_num_blocks_in_use, false);
    table->field[4]->store(bt_size_allocated, false);
    table->field[5]->store(bt_size_in_use, false);

    // split the dname
    {
        String database_name, table_name, dictionary_name;
        tokudb_split_dname(
            (const char*)dname->data,
            database_name,
            table_name,
            dictionary_name);
        table->field[6]->store(
            database_name.c_ptr(),
            database_name.length(),
            system_charset_info);
        table->field[7]->store(
            table_name.c_ptr(),
            table_name.length(),
            system_charset_info);
        table->field[8]->store(
            dictionary_name.c_ptr(),
            dictionary_name.length(),
            system_charset_info);
    }
    error = schema_table_store_record(thd, table);

exit:
    if (db) {
        int close_error = db->close(db, 0);
        if (error == 0)
            error = close_error;
    }
    return error;
}

int report_fractal_tree_info(TABLE* table, THD* thd) {
    int error;
    DB_TXN* txn = NULL;
    DBC* tmp_cursor = NULL;
    DBT curr_key;
    DBT curr_val;
    memset(&curr_key, 0, sizeof curr_key);
    memset(&curr_val, 0, sizeof curr_val);
    error = txn_begin(db_env, 0, &txn, DB_READ_UNCOMMITTED, thd);
    if (error) {
        goto cleanup;
    }
    error = db_env->get_cursor_for_directory(db_env, txn, &tmp_cursor);
    if (error) {
        goto cleanup;
    }
    while (error == 0) {
        error = tmp_cursor->c_get(tmp_cursor, &curr_key, &curr_val, DB_NEXT);
        if (!error) {
            error = report_fractal_tree_info_for_db(
                &curr_key,
                &curr_val,
                table,
                thd);
            if (error)
                error = 0; // ignore read uncommitted errors
        }
        if (!error && thd_kill_level(thd))
            error = ER_QUERY_INTERRUPTED;
    }
    if (error == DB_NOTFOUND) {
        error = 0;
    }
cleanup:
    if (tmp_cursor) {
        int r = tmp_cursor->c_close(tmp_cursor);
        assert(r == 0);
    }
    if (txn) {
        commit_txn(txn, 0);
    }
    return error;
}

#if MYSQL_VERSION_ID >= 50600
int fractal_tree_info_fill_table(THD* thd,
                                 TABLE_LIST* tables,
                                 TOKUDB_UNUSED(Item* cond)) {
#else
int fractal_tree_info_fill_table(THD* thd,
                                 TABLE_LIST* tables,
                                 TOKUDB_UNUSED(COND* cond)) {
#endif
    TOKUDB_DBUG_ENTER("");
    int error;
    TABLE* table = tables->table;

    // 3938: Get a read lock on the status flag, since we must
    // read it before safely proceeding
    rwlock_t_lock_read(tokudb_hton_initialized_lock);

    if (!tokudb_hton_initialized) {
        error = ER_PLUGIN_IS_NOT_LOADED;
        my_error(error, MYF(0), tokudb_hton_name);
    } else {
        error = report_fractal_tree_info(table, thd);
        if (error)
            my_error(ER_GET_ERRNO, MYF(0), error, tokudb_hton_name);
    }

    //3938: unlock the status flag lock
    tokudb_hton_initialized_lock.unlock();
    TOKUDB_DBUG_RETURN(error);
}

int fractal_tree_info_init(void* p) {
    ST_SCHEMA_TABLE* schema = (ST_SCHEMA_TABLE*)p;
    schema->fields_info = fractal_tree_info_field_info;
    schema->fill_table = fractal_tree_info_fill_table;
    return 0;
}

int fractal_tree_info_done(TOKUDB_UNUSED(void* p)) {
    return 0;
}

st_mysql_plugin fractal_tree_info = {
    MYSQL_INFORMATION_SCHEMA_PLUGIN,
    &fractal_tree_info_information_schema,
    "TokuDB_fractal_tree_info",
    "Percona",
    "Percona TokuDB Storage Engine with Fractal Tree(tm) Technology",
    PLUGIN_LICENSE_GPL,
    fractal_tree_info_init,         /* plugin init */
    fractal_tree_info_done,         /* plugin deinit */
    TOKUDB_PLUGIN_VERSION,
    NULL,                           /* status variables */
    NULL,                           /* system variables */
#ifdef MARIA_PLUGIN_INTERFACE_VERSION
    tokudb::sysvars::version,
    MariaDB_PLUGIN_MATURITY_STABLE /* maturity */
#else
    NULL,                           /* config options */
    0,                              /* flags */
#endif
};



st_mysql_information_schema fractal_tree_block_map_information_schema = {
    MYSQL_INFORMATION_SCHEMA_INTERFACE_VERSION
};

ST_FIELD_INFO fractal_tree_block_map_field_info[] = {
    {"dictionary_name", 256, MYSQL_TYPE_STRING, 0, 0, NULL, SKIP_OPEN_TABLE },
    {"internal_file_name", 256, MYSQL_TYPE_STRING, 0, 0, NULL, SKIP_OPEN_TABLE },
    {"checkpoint_count", 0, MYSQL_TYPE_LONGLONG, 0, 0, NULL, SKIP_OPEN_TABLE },
    {"blocknum", 0, MYSQL_TYPE_LONGLONG, 0, 0, NULL, SKIP_OPEN_TABLE },
    {"offset", 0, MYSQL_TYPE_LONGLONG, 0, MY_I_S_MAYBE_NULL, NULL, SKIP_OPEN_TABLE },
    {"size", 0, MYSQL_TYPE_LONGLONG, 0, MY_I_S_MAYBE_NULL, NULL, SKIP_OPEN_TABLE },
    {"table_schema", 256, MYSQL_TYPE_STRING, 0, 0, NULL, SKIP_OPEN_TABLE },
    {"table_name", 256, MYSQL_TYPE_STRING, 0, 0, NULL, SKIP_OPEN_TABLE },
    {"table_dictionary_name", 256, MYSQL_TYPE_STRING, 0, 0, NULL, SKIP_OPEN_TABLE },
    {NULL, 0, MYSQL_TYPE_NULL, 0, 0, NULL, SKIP_OPEN_TABLE}
};

struct report_fractal_tree_block_map_iterator_extra_t {
    int64_t num_rows;
    int64_t i;
    uint64_t* checkpoint_counts;
    int64_t* blocknums;
    int64_t* diskoffs;
    int64_t* sizes;
};

// This iterator is called while holding the blocktable lock.
// We should be as quick as possible.
// We don't want to do one call to get the number of rows, release the
// blocktable lock, and then do another call to get all the rows because
// the number of rows may change if we don't hold the lock.
// As a compromise, we'll do some mallocs inside the lock on the first call,
// but everything else should be fast.
int report_fractal_tree_block_map_iterator(
    uint64_t checkpoint_count,
    int64_t num_rows,
    int64_t blocknum,
    int64_t diskoff,
    int64_t size,
    void* iter_extra) {

    struct report_fractal_tree_block_map_iterator_extra_t* e =
        static_cast<struct report_fractal_tree_block_map_iterator_extra_t*>(iter_extra);

    assert(num_rows > 0);
    if (e->num_rows == 0) {
        e->checkpoint_counts =
            (uint64_t*)tokudb::memory::malloc(
                num_rows * (sizeof *e->checkpoint_counts),
                MYF(MY_WME|MY_ZEROFILL|MY_FAE));
        e->blocknums =
            (int64_t*)tokudb::memory::malloc(
                num_rows * (sizeof *e->blocknums),
                MYF(MY_WME|MY_ZEROFILL|MY_FAE));
        e->diskoffs =
            (int64_t*)tokudb::memory::malloc(
                num_rows * (sizeof *e->diskoffs),
                MYF(MY_WME|MY_ZEROFILL|MY_FAE));
        e->sizes =
            (int64_t*)tokudb::memory::malloc(
                num_rows * (sizeof *e->sizes),
                MYF(MY_WME|MY_ZEROFILL|MY_FAE));
        e->num_rows = num_rows;
    }

    e->checkpoint_counts[e->i] = checkpoint_count;
    e->blocknums[e->i] = blocknum;
    e->diskoffs[e->i] = diskoff;
    e->sizes[e->i] = size;
    ++(e->i);

    return 0;
}

int report_fractal_tree_block_map_for_db(
    const DBT* dname,
    const DBT* iname,
    TABLE* table,
    THD* thd) {

    int error;
    DB* db;
    // avoid struct initializers so that we can compile with older gcc versions
    report_fractal_tree_block_map_iterator_extra_t e = {};

    error = db_create(&db, db_env, 0);
    if (error) {
        goto exit;
    }
    error = db->open(db, NULL, (char *)dname->data, NULL, DB_BTREE, 0, 0666);
    if (error) {
        goto exit;
    }
    error = db->iterate_fractal_tree_block_map(
        db,
        report_fractal_tree_block_map_iterator,
        &e);
    {
        int close_error = db->close(db, 0);
        if (!error) {
            error = close_error;
        }
    }
    if (error) {
        goto exit;
    }

    // If not, we should have gotten an error and skipped this section of code
    assert(e.i == e.num_rows);
    for (int64_t i = 0; error == 0 && i < e.num_rows; ++i) {
        // We store the NULL terminator in the directory so it's included in the size.
        // See #5789
        // Recalculate and check just to be safe.
        size_t dname_len = strlen((const char*)dname->data);
        assert(dname_len == dname->size - 1);
        table->field[0]->store(
            (char*)dname->data,
            dname_len,
            system_charset_info);

        size_t iname_len = strlen((const char*)iname->data);
        assert(iname_len == iname->size - 1);
        table->field[1]->store(
            (char*)iname->data,
            iname_len,
            system_charset_info);

        table->field[2]->store(e.checkpoint_counts[i], false);
        table->field[3]->store(e.blocknums[i], false);
        static const int64_t freelist_null = -1;
        static const int64_t diskoff_unused = -2;
        if (e.diskoffs[i] == diskoff_unused || e.diskoffs[i] == freelist_null) {
            table->field[4]->set_null();
        } else {
            table->field[4]->set_notnull();
            table->field[4]->store(e.diskoffs[i], false);
        }
        static const int64_t size_is_free = -1;
        if (e.sizes[i] == size_is_free) {
            table->field[5]->set_null();
        } else {
            table->field[5]->set_notnull();
            table->field[5]->store(e.sizes[i], false);
        }

        // split the dname
        String database_name, table_name, dictionary_name;
        tokudb_split_dname(
            (const char*)dname->data,
            database_name,
            table_name,
            dictionary_name);
        table->field[6]->store(
            database_name.c_ptr(),
            database_name.length(),
            system_charset_info);
        table->field[7]->store(
            table_name.c_ptr(),
            table_name.length(),
            system_charset_info);
        table->field[8]->store(
            dictionary_name.c_ptr(),
            dictionary_name.length(),
            system_charset_info);

        error = schema_table_store_record(thd, table);
    }

exit:
    if (e.checkpoint_counts != NULL) {
        tokudb::memory::free(e.checkpoint_counts);
        e.checkpoint_counts = NULL;
    }
    if (e.blocknums != NULL) {
        tokudb::memory::free(e.blocknums);
        e.blocknums = NULL;
    }
    if (e.diskoffs != NULL) {
        tokudb::memory::free(e.diskoffs);
        e.diskoffs = NULL;
    }
    if (e.sizes != NULL) {
        tokudb::memory::free(e.sizes);
        e.sizes = NULL;
    }
    return error;
}

int report_fractal_tree_block_map(TABLE* table, THD* thd) {
    int error;
    DB_TXN* txn = NULL;
    DBC* tmp_cursor = NULL;
    DBT curr_key;
    DBT curr_val;
    memset(&curr_key, 0, sizeof curr_key);
    memset(&curr_val, 0, sizeof curr_val);
    error = txn_begin(db_env, 0, &txn, DB_READ_UNCOMMITTED, thd);
    if (error) {
        goto cleanup;
    }
    error = db_env->get_cursor_for_directory(db_env, txn, &tmp_cursor);
    if (error) {
        goto cleanup;
    }
    while (error == 0) {
        error = tmp_cursor->c_get(tmp_cursor, &curr_key, &curr_val, DB_NEXT);
        if (!error) {
            error = report_fractal_tree_block_map_for_db(
                &curr_key,
                &curr_val,
                table,
                thd);
        }
        if (!error && thd_kill_level(thd))
            error = ER_QUERY_INTERRUPTED;
    }
    if (error == DB_NOTFOUND) {
        error = 0;
    }
cleanup:
    if (tmp_cursor) {
        int r = tmp_cursor->c_close(tmp_cursor);
        assert(r == 0);
    }
    if (txn) {
        commit_txn(txn, 0);
    }
    return error;
}

#if MYSQL_VERSION_ID >= 50600
int fractal_tree_block_map_fill_table(
    THD* thd,
    TABLE_LIST* tables,
    TOKUDB_UNUSED(Item* cond)) {
#else
int fractal_tree_block_map_fill_table(
    THD* thd,
    TABLE_LIST* tables,
    TOKUDB_UNUSED(COND* cond)) {
#endif
    TOKUDB_DBUG_ENTER("");
    int error;
    TABLE* table = tables->table;

    // 3938: Get a read lock on the status flag, since we must
    // read it before safely proceeding
    rwlock_t_lock_read(tokudb_hton_initialized_lock);

    if (!tokudb_hton_initialized) {
        error = ER_PLUGIN_IS_NOT_LOADED;
        my_error(error, MYF(0), tokudb_hton_name);
    } else {
        error = report_fractal_tree_block_map(table, thd);
        if (error)
            my_error(ER_GET_ERRNO, MYF(0), error, tokudb_hton_name);
    }

    //3938: unlock the status flag lock
    tokudb_hton_initialized_lock.unlock();
    TOKUDB_DBUG_RETURN(error);
}

int fractal_tree_block_map_init(void* p) {
    ST_SCHEMA_TABLE* schema = (ST_SCHEMA_TABLE*)p;
    schema->fields_info = fractal_tree_block_map_field_info;
    schema->fill_table = fractal_tree_block_map_fill_table;
    return 0;
}

int fractal_tree_block_map_done(TOKUDB_UNUSED(void *p)) {
    return 0;
}

st_mysql_plugin fractal_tree_block_map = {
    MYSQL_INFORMATION_SCHEMA_PLUGIN,
    &fractal_tree_block_map_information_schema,
    "TokuDB_fractal_tree_block_map",
    "Percona",
    "Percona TokuDB Storage Engine with Fractal Tree(tm) Technology",
    PLUGIN_LICENSE_GPL,
    fractal_tree_block_map_init,     /* plugin init */
    fractal_tree_block_map_done,     /* plugin deinit */
    TOKUDB_PLUGIN_VERSION,
    NULL,                      /* status variables */
    NULL,                      /* system variables */
#ifdef MARIA_PLUGIN_INTERFACE_VERSION
    tokudb::sysvars::version,
    MariaDB_PLUGIN_MATURITY_STABLE /* maturity */
#else
    NULL,                      /* config options */
    0,                         /* flags */
#endif
};


st_mysql_information_schema background_job_status_information_schema = {
    MYSQL_INFORMATION_SCHEMA_INTERFACE_VERSION
};

ST_FIELD_INFO background_job_status_field_info[] = {
    {"id", 0, MYSQL_TYPE_LONGLONG, 0, 0, NULL, SKIP_OPEN_TABLE },
    {"database_name", 256, MYSQL_TYPE_STRING, 0, 0, NULL, SKIP_OPEN_TABLE },
    {"table_name", 256, MYSQL_TYPE_STRING, 0, 0, NULL, SKIP_OPEN_TABLE },
    {"job_type", 256, MYSQL_TYPE_STRING, 0, 0, NULL, SKIP_OPEN_TABLE },
    {"job_params", 256, MYSQL_TYPE_STRING, 0, 0, NULL, SKIP_OPEN_TABLE },
    {"scheduler", 32, MYSQL_TYPE_STRING, 0, 0, NULL, SKIP_OPEN_TABLE },
    {"scheduled_time", 0, MYSQL_TYPE_DATETIME, 0, 0, NULL, SKIP_OPEN_TABLE },
    {"started_time", 0, MYSQL_TYPE_DATETIME, 0, MY_I_S_MAYBE_NULL, NULL, SKIP_OPEN_TABLE },
    {"status", 1024, MYSQL_TYPE_STRING, 0, MY_I_S_MAYBE_NULL, NULL, SKIP_OPEN_TABLE },
    {NULL, 0, MYSQL_TYPE_NULL, 0, 0, NULL, SKIP_OPEN_TABLE}
};

struct background_job_status_extra {
    THD* thd;
    TABLE* table;
};

void background_job_status_callback(
    tokudb::background::job_manager_t::job_t* job,
    void* extra) {

    background_job_status_extra* e =
        reinterpret_cast<background_job_status_extra*>(extra);

    THD* thd = e->thd;
    TABLE* table = e->table;
    const char* tmp = NULL;

    table->field[0]->store(job->id(), false);

    tmp = job->database();
    table->field[1]->store(tmp, strlen(tmp),  system_charset_info);

    tmp = job->table();
    table->field[2]->store(tmp, strlen(tmp),  system_charset_info);

    tmp = job->type();
    table->field[3]->store(tmp, strlen(tmp),  system_charset_info);

    tmp = job->parameters();
    table->field[4]->store(tmp, strlen(tmp),  system_charset_info);

    if (job->user_scheduled())
        table->field[5]->store("USER", strlen("USER"), system_charset_info);
    else
        table->field[5]->store("AUTO", strlen("AUTO"), system_charset_info);

    field_store_time_t(table->field[6], job->scheduled_time());
    field_store_time_t(table->field[7], job->started_time());

    tmp = job->status();
    if (tmp && tmp[0] != '\0') {
        table->field[8]->store(tmp, strlen(tmp), system_charset_info);
        table->field[8]->set_notnull();
    } else {
        table->field[8]->store(NULL, 0, system_charset_info);
        table->field[8]->set_null();
    }

    schema_table_store_record(thd, table);
}

int report_background_job_status(TABLE *table, THD *thd) {
    int error = 0;
    background_job_status_extra extra = {
        thd,
        table
    };
    tokudb::background::_job_manager->iterate_jobs(
        background_job_status_callback,
        &extra);
    return error;
}

#if MYSQL_VERSION_ID >= 50600
int background_job_status_fill_table(THD *thd, TABLE_LIST *tables, TOKUDB_UNUSED(Item *cond)) {
#else
int background_job_status_fill_table(THD *thd, TABLE_LIST *tables, TOKUDB_UNUSED(COND *cond)) {
#endif
    TOKUDB_DBUG_ENTER("");
    int error;
    TABLE* table = tables->table;

    rwlock_t_lock_read(tokudb_hton_initialized_lock);

    if (!tokudb_hton_initialized) {
        error = ER_PLUGIN_IS_NOT_LOADED;
        my_error(error, MYF(0), tokudb_hton_name);
    } else {
        error = report_background_job_status(table, thd);
        if (error)
            my_error(ER_GET_ERRNO, MYF(0), error, tokudb_hton_name);
    }

    tokudb_hton_initialized_lock.unlock();
    TOKUDB_DBUG_RETURN(error);
}

int background_job_status_init(void* p) {
    ST_SCHEMA_TABLE* schema = (ST_SCHEMA_TABLE*)p;
    schema->fields_info = background_job_status_field_info;
    schema->fill_table = background_job_status_fill_table;
    return 0;
}

int background_job_status_done(TOKUDB_UNUSED(void* p)) {
    return 0;
}

st_mysql_plugin background_job_status = {
    MYSQL_INFORMATION_SCHEMA_PLUGIN,
    &background_job_status_information_schema,
    "TokuDB_background_job_status",
    "Percona",
    "Percona TokuDB Storage Engine with Fractal Tree(tm) Technology",
    PLUGIN_LICENSE_GPL,
    background_job_status_init,     /* plugin init */
    background_job_status_done,     /* plugin deinit */
    TOKUDB_PLUGIN_VERSION,
    NULL,                      /* status variables */
    NULL,                      /* system variables */
#ifdef MARIA_PLUGIN_INTERFACE_VERSION
    tokudb::sysvars::version,
    MariaDB_PLUGIN_MATURITY_STABLE /* maturity */
#else
    NULL,                      /* config options */
    0,                         /* flags */
#endif
};

} // namespace information_schema
} // namespace tokudb