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 <toku_portability.h>
40 
41 #include <memory.h>
42 #include <db.h>
43 
44 #include <ft/cachetable/checkpoint.h>
45 #include <ft/ft.h>
46 #include <ft/ft-ops.h>
47 #include <ft/ft-flusher.h>
48 #include <ft/logger/recover.h>
49 #include <ft/loader/loader.h>
50 
51 #include "ydb_env_func.h"
52 
53 // For test purposes only.
54 // These callbacks are never used in production code, only as a way to test the system
55 // (for example, by causing crashes at predictable times).
56 void (*checkpoint_callback_f)(void*) = NULL;
57 void * checkpoint_callback_extra     = NULL;
58 void (*checkpoint_callback2_f)(void*) = NULL;
59 void * checkpoint_callback2_extra     = NULL;
60 
61 bool engine_status_enable = true; // if false, suppress engine status output on failed assert, for test programs only
62 
db_env_set_direct_io(bool direct_io_on)63 void db_env_set_direct_io (bool direct_io_on) {
64     toku_ft_set_direct_io(direct_io_on);
65 }
66 
db_env_set_compress_buffers_before_eviction(bool compress_buffers)67 void db_env_set_compress_buffers_before_eviction (bool compress_buffers) {
68     toku_ft_set_compress_buffers_before_eviction(compress_buffers);
69 }
70 
db_env_set_func_fsync(int (* fsync_function)(int))71 void db_env_set_func_fsync (int (*fsync_function)(int)) {
72     toku_set_func_fsync(fsync_function);
73 }
74 
db_env_set_func_pwrite(ssize_t (* pwrite_function)(int,const void *,size_t,toku_off_t))75 void db_env_set_func_pwrite (ssize_t (*pwrite_function)(int, const void *, size_t, toku_off_t)) {
76     toku_set_func_pwrite(pwrite_function);
77 }
78 
db_env_set_func_full_pwrite(ssize_t (* pwrite_function)(int,const void *,size_t,toku_off_t))79 void db_env_set_func_full_pwrite (ssize_t (*pwrite_function)(int, const void *, size_t, toku_off_t)) {
80     toku_set_func_full_pwrite(pwrite_function);
81 }
82 
db_env_set_func_write(ssize_t (* write_function)(int,const void *,size_t))83 void db_env_set_func_write (ssize_t (*write_function)(int, const void *, size_t)) {
84     toku_set_func_write(write_function);
85 }
86 
db_env_set_func_full_write(ssize_t (* write_function)(int,const void *,size_t))87 void db_env_set_func_full_write (ssize_t (*write_function)(int, const void *, size_t)) {
88     toku_set_func_full_write(write_function);
89 }
90 
db_env_set_func_fdopen(FILE * (* fdopen_function)(int,const char *))91 void db_env_set_func_fdopen (FILE * (*fdopen_function)(int, const char *)) {
92     toku_set_func_fdopen(fdopen_function);
93 }
94 
db_env_set_func_fopen(FILE * (* fopen_function)(const char *,const char *))95 void db_env_set_func_fopen (FILE * (*fopen_function)(const char *, const char *)) {
96     toku_set_func_fopen(fopen_function);
97 }
98 
db_env_set_func_open(int (* open_function)(const char *,int,int))99 void db_env_set_func_open (int (*open_function)(const char *, int, int)) {
100     toku_set_func_open(open_function);
101 }
102 
db_env_set_func_fclose(int (* fclose_function)(FILE *))103 void db_env_set_func_fclose (int (*fclose_function)(FILE*)) {
104     toku_set_func_fclose(fclose_function);
105 }
106 
db_env_set_func_pread(ssize_t (* fun)(int,void *,size_t,off_t))107 void db_env_set_func_pread (ssize_t (*fun)(int, void *, size_t, off_t)) {
108     toku_set_func_pread(fun);
109 }
110 
db_env_set_func_loader_fwrite(size_t (* fwrite_fun)(const void *,size_t,size_t,FILE *))111 void db_env_set_func_loader_fwrite (size_t (*fwrite_fun)(const void*,size_t,size_t,FILE*)) {
112     toku_set_func_fwrite(fwrite_fun);
113 }
114 
db_env_set_func_malloc(void * (* f)(size_t))115 void db_env_set_func_malloc (void *(*f)(size_t)) {
116     toku_set_func_malloc(f);
117 }
118 
db_env_set_func_realloc(void * (* f)(void *,size_t))119 void db_env_set_func_realloc (void *(*f)(void*, size_t)) {
120     toku_set_func_realloc(f);
121 }
122 
db_env_set_func_free(void (* f)(void *))123 void db_env_set_func_free (void (*f)(void*)) {
124     toku_set_func_free(f);
125 }
126 
127 // For test purposes only.
128 // With this interface, all checkpoint users get the same callbacks and the same extras.
129 void
db_env_set_checkpoint_callback(void (* callback_f)(void *),void * extra)130 db_env_set_checkpoint_callback (void (*callback_f)(void*), void* extra) {
131     toku_checkpoint_safe_client_lock();
132     checkpoint_callback_f = callback_f;
133     checkpoint_callback_extra = extra;
134     toku_checkpoint_safe_client_unlock();
135 }
136 
137 void
db_env_set_checkpoint_callback2(void (* callback_f)(void *),void * extra)138 db_env_set_checkpoint_callback2 (void (*callback_f)(void*), void* extra) {
139     toku_checkpoint_safe_client_lock();
140     checkpoint_callback2_f = callback_f;
141     checkpoint_callback2_extra = extra;
142     toku_checkpoint_safe_client_unlock();
143 }
144 
145 void
db_env_set_recover_callback(void (* callback_f)(void *),void * extra)146 db_env_set_recover_callback (void (*callback_f)(void*), void* extra) {
147     toku_recover_set_callback(callback_f, extra);
148 }
149 
150 void
db_env_set_recover_callback2(void (* callback_f)(void *),void * extra)151 db_env_set_recover_callback2 (void (*callback_f)(void*), void* extra) {
152     toku_recover_set_callback2(callback_f, extra);
153 }
154 
155 void
db_env_set_flusher_thread_callback(void (* callback_f)(int,void *),void * extra)156 db_env_set_flusher_thread_callback(void (*callback_f)(int, void*), void* extra) {
157     toku_flusher_thread_set_callback(callback_f, extra);
158 }
159 
160 void
db_env_set_loader_size_factor(uint32_t factor)161 db_env_set_loader_size_factor (uint32_t factor) {
162     toku_ft_loader_set_size_factor(factor);
163 }
164 
165 void
db_env_set_mvcc_garbage_collection_verification(uint32_t verification_mode)166 db_env_set_mvcc_garbage_collection_verification(uint32_t verification_mode) {
167     garbage_collection_debug = (verification_mode != 0);
168 }
169 
170 // Purpose: allow test programs that expect to fail to suppress engine status output on failed assert.
171 void
db_env_enable_engine_status(bool enable)172 db_env_enable_engine_status(bool enable) {
173     engine_status_enable = enable;
174 }
175 
176 void
db_env_set_num_bucket_mutexes(uint32_t num_mutexes)177 db_env_set_num_bucket_mutexes(uint32_t num_mutexes) {
178     toku_pair_list_set_lock_size(num_mutexes);
179 }
180 
db_env_try_gdb_stack_trace(const char * gdb_path)181 void db_env_try_gdb_stack_trace(const char *gdb_path) {
182     toku_try_gdb_stack_trace(gdb_path);
183 }
184 
185