1 /* -*- mode: C++; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2 // vim: ft=cpp:expandtab:ts=8:sw=4:softtabstop=4:
3 #ident "$Id$"
4 /*======
5 This file is part of PerconaFT.
6
7
8 Copyright (c) 2006, 2015, Percona and/or its affiliates. All rights reserved.
9
10 PerconaFT is free software: you can redistribute it and/or modify
11 it under the terms of the GNU General Public License, version 2,
12 as published by the Free Software Foundation.
13
14 PerconaFT is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with PerconaFT. If not, see <http://www.gnu.org/licenses/>.
21
22 ----------------------------------------
23
24 PerconaFT is free software: you can redistribute it and/or modify
25 it under the terms of the GNU Affero General Public License, version 3,
26 as published by the Free Software Foundation.
27
28 PerconaFT is distributed in the hope that it will be useful,
29 but WITHOUT ANY WARRANTY; without even the implied warranty of
30 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31 GNU Affero General Public License for more details.
32
33 You should have received a copy of the GNU Affero General Public License
34 along with PerconaFT. If not, see <http://www.gnu.org/licenses/>.
35 ======= */
36
37 #ident "Copyright (c) 2006, 2015, Percona and/or its affiliates. All rights reserved."
38
39 #include <my_global.h>
40 #include <toku_portability.h>
41
42 #include <memory.h>
43 #include <db.h>
44
45 #include <ft/cachetable/checkpoint.h>
46 #include <ft/ft.h>
47 #include <ft/ft-ops.h>
48 #include <ft/ft-flusher.h>
49 #include <ft/logger/recover.h>
50 #include <ft/loader/loader.h>
51
52 #include "ydb_env_func.h"
53
54 // For test purposes only.
55 // These callbacks are never used in production code, only as a way to test the system
56 // (for example, by causing crashes at predictable times).
57 void (*checkpoint_callback_f)(void*) = NULL;
58 void * checkpoint_callback_extra = NULL;
59 void (*checkpoint_callback2_f)(void*) = NULL;
60 void * checkpoint_callback2_extra = NULL;
61
62 bool engine_status_enable = true; // if false, suppress engine status output on failed assert, for test programs only
63
db_env_set_direct_io(bool direct_io_on)64 void db_env_set_direct_io (bool direct_io_on) {
65 toku_ft_set_direct_io(direct_io_on);
66 }
67
db_env_set_compress_buffers_before_eviction(bool compress_buffers)68 void db_env_set_compress_buffers_before_eviction (bool compress_buffers) {
69 toku_ft_set_compress_buffers_before_eviction(compress_buffers);
70 }
71
db_env_set_func_fsync(int (* fsync_function)(int))72 void db_env_set_func_fsync (int (*fsync_function)(int)) {
73 toku_set_func_fsync(fsync_function);
74 }
75
db_env_set_func_pwrite(ssize_t (* pwrite_function)(int,const void *,size_t,toku_off_t))76 void db_env_set_func_pwrite (ssize_t (*pwrite_function)(int, const void *, size_t, toku_off_t)) {
77 toku_set_func_pwrite(pwrite_function);
78 }
79
db_env_set_func_full_pwrite(ssize_t (* pwrite_function)(int,const void *,size_t,toku_off_t))80 void db_env_set_func_full_pwrite (ssize_t (*pwrite_function)(int, const void *, size_t, toku_off_t)) {
81 toku_set_func_full_pwrite(pwrite_function);
82 }
83
db_env_set_func_write(ssize_t (* write_function)(int,const void *,size_t))84 void db_env_set_func_write (ssize_t (*write_function)(int, const void *, size_t)) {
85 toku_set_func_write(write_function);
86 }
87
db_env_set_func_full_write(ssize_t (* write_function)(int,const void *,size_t))88 void db_env_set_func_full_write (ssize_t (*write_function)(int, const void *, size_t)) {
89 toku_set_func_full_write(write_function);
90 }
91
db_env_set_func_fdopen(FILE * (* fdopen_function)(int,const char *))92 void db_env_set_func_fdopen (FILE * (*fdopen_function)(int, const char *)) {
93 toku_set_func_fdopen(fdopen_function);
94 }
95
db_env_set_func_fopen(FILE * (* fopen_function)(const char *,const char *))96 void db_env_set_func_fopen (FILE * (*fopen_function)(const char *, const char *)) {
97 toku_set_func_fopen(fopen_function);
98 }
99
db_env_set_func_open(int (* open_function)(const char *,int,int))100 void db_env_set_func_open (int (*open_function)(const char *, int, int)) {
101 toku_set_func_open(open_function);
102 }
103
db_env_set_func_fclose(int (* fclose_function)(FILE *))104 void db_env_set_func_fclose (int (*fclose_function)(FILE*)) {
105 toku_set_func_fclose(fclose_function);
106 }
107
db_env_set_func_pread(ssize_t (* fun)(int,void *,size_t,off_t))108 void db_env_set_func_pread (ssize_t (*fun)(int, void *, size_t, off_t)) {
109 toku_set_func_pread(fun);
110 }
111
db_env_set_func_loader_fwrite(size_t (* fwrite_fun)(const void *,size_t,size_t,FILE *))112 void db_env_set_func_loader_fwrite (size_t (*fwrite_fun)(const void*,size_t,size_t,FILE*)) {
113 toku_set_func_fwrite(fwrite_fun);
114 }
115
db_env_set_func_malloc(void * (* f)(size_t))116 void db_env_set_func_malloc (void *(*f)(size_t)) {
117 toku_set_func_malloc(f);
118 }
119
db_env_set_func_realloc(void * (* f)(void *,size_t))120 void db_env_set_func_realloc (void *(*f)(void*, size_t)) {
121 toku_set_func_realloc(f);
122 }
123
db_env_set_func_free(void (* f)(void *))124 void db_env_set_func_free (void (*f)(void*)) {
125 toku_set_func_free(f);
126 }
127
128 // For test purposes only.
129 // With this interface, all checkpoint users get the same callbacks and the same extras.
130 void
db_env_set_checkpoint_callback(void (* callback_f)(void *),void * extra)131 db_env_set_checkpoint_callback (void (*callback_f)(void*), void* extra) {
132 toku_checkpoint_safe_client_lock();
133 checkpoint_callback_f = callback_f;
134 checkpoint_callback_extra = extra;
135 toku_checkpoint_safe_client_unlock();
136 }
137
138 void
db_env_set_checkpoint_callback2(void (* callback_f)(void *),void * extra)139 db_env_set_checkpoint_callback2 (void (*callback_f)(void*), void* extra) {
140 toku_checkpoint_safe_client_lock();
141 checkpoint_callback2_f = callback_f;
142 checkpoint_callback2_extra = extra;
143 toku_checkpoint_safe_client_unlock();
144 }
145
146 void
db_env_set_recover_callback(void (* callback_f)(void *),void * extra)147 db_env_set_recover_callback (void (*callback_f)(void*), void* extra) {
148 toku_recover_set_callback(callback_f, extra);
149 }
150
151 void
db_env_set_recover_callback2(void (* callback_f)(void *),void * extra)152 db_env_set_recover_callback2 (void (*callback_f)(void*), void* extra) {
153 toku_recover_set_callback2(callback_f, extra);
154 }
155
156 void
db_env_set_flusher_thread_callback(void (* callback_f)(int,void *),void * extra)157 db_env_set_flusher_thread_callback(void (*callback_f)(int, void*), void* extra) {
158 toku_flusher_thread_set_callback(callback_f, extra);
159 }
160
161 void
db_env_set_loader_size_factor(uint32_t factor)162 db_env_set_loader_size_factor (uint32_t factor) {
163 toku_ft_loader_set_size_factor(factor);
164 }
165
166 void
db_env_set_mvcc_garbage_collection_verification(uint32_t verification_mode)167 db_env_set_mvcc_garbage_collection_verification(uint32_t verification_mode) {
168 garbage_collection_debug = (verification_mode != 0);
169 }
170
171 // Purpose: allow test programs that expect to fail to suppress engine status output on failed assert.
172 void
db_env_enable_engine_status(bool enable)173 db_env_enable_engine_status(bool enable) {
174 engine_status_enable = enable;
175 }
176
177 void
db_env_set_num_bucket_mutexes(uint32_t num_mutexes)178 db_env_set_num_bucket_mutexes(uint32_t num_mutexes) {
179 toku_pair_list_set_lock_size(num_mutexes);
180 }
181
db_env_try_gdb_stack_trace(const char * gdb_path)182 void db_env_try_gdb_stack_trace(const char *gdb_path) {
183 toku_try_gdb_stack_trace(gdb_path);
184 }
185
186