You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

831 lines
45 KiB

implement db->get_key_after_bytes closes #18 squashed commits: create db->get_key_after_bytes() api down to the ft layer, and start a unit test refs #18 setup/teardown for get_key_after_bytes test refs #18 rename test because it really is going to be a small unit test refs #18 implement a few initial checks refs #18 adding actually_skipped parameter because we will want it in splitVector refs #18 NULL -> nullptr, I'm rusty from mongo work refs #18 fix some old apis to fit what get_key_after_bytes needs: make keyrange_compare_s hold an FT instead of FT_HANDLE to prepare for reuse refs #18 make keyrange_compare_s hold a const dbt refs #18 fix const-correctness of fill_bfe functions refs #18 add unit test for an empty dictionary refs #18 implement get_key_after_bytes for a single basement node, passes simple tests refs #18 add test for multiple basement nodes refs #18 fix usage of ft_search_t, we do need a full one after all refs #18 check actually_skipped for correctness (even though it's an estimate) refs #18 restructure test to be faster, and test keys before the beginning of the table refs #18 don't try to read in the right basement node, just check the bns you have refs #18 implement get_key_after_bytes for height > 0 trees refs #18 return the amount skipped even if we hit the end of the table refs #18 add inexact test for height > 0 trees, adjust constants so it's faster refs #18 don't do I/O to bring in basement nodes just for get_key_after_bytes refs #18 don't blindly check the first basement node, it's not guaranteed to be there anymore refs #18 fix leak in get_key_after_bytes_unit.tdb refs #18 add get_key_after_bytes to test_stress5 refs #18 switch to a callback API to save mallocs and memcpys refs #18
13 years ago
  1. /* -*- mode: C++; c-basic-offset: 4; indent-tabs-mode: nil -*- */
  2. // vim: ft=cpp:expandtab:ts=8:sw=4:softtabstop=4:
  3. /*
  4. COPYING CONDITIONS NOTICE:
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of version 2 of the GNU General Public License as
  7. published by the Free Software Foundation, and provided that the
  8. following conditions are met:
  9. * Redistributions of source code must retain this COPYING
  10. CONDITIONS NOTICE, the COPYRIGHT NOTICE (below), the
  11. DISCLAIMER (below), the UNIVERSITY PATENT NOTICE (below), the
  12. PATENT MARKING NOTICE (below), and the PATENT RIGHTS
  13. GRANT (below).
  14. * Redistributions in binary form must reproduce this COPYING
  15. CONDITIONS NOTICE, the COPYRIGHT NOTICE (below), the
  16. DISCLAIMER (below), the UNIVERSITY PATENT NOTICE (below), the
  17. PATENT MARKING NOTICE (below), and the PATENT RIGHTS
  18. GRANT (below) in the documentation and/or other materials
  19. provided with the distribution.
  20. You should have received a copy of the GNU General Public License
  21. along with this program; if not, write to the Free Software
  22. Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  23. 02110-1301, USA.
  24. COPYRIGHT NOTICE:
  25. TokuDB, Tokutek Fractal Tree Indexing Library.
  26. Copyright (C) 2007-2013 Tokutek, Inc.
  27. DISCLAIMER:
  28. This program is distributed in the hope that it will be useful, but
  29. WITHOUT ANY WARRANTY; without even the implied warranty of
  30. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  31. General Public License for more details.
  32. UNIVERSITY PATENT NOTICE:
  33. The technology is licensed by the Massachusetts Institute of
  34. Technology, Rutgers State University of New Jersey, and the Research
  35. Foundation of State University of New York at Stony Brook under
  36. United States of America Serial No. 11/760379 and to the patents
  37. and/or patent applications resulting from it.
  38. PATENT MARKING NOTICE:
  39. This software is covered by US Patent No. 8,185,551.
  40. PATENT RIGHTS GRANT:
  41. "THIS IMPLEMENTATION" means the copyrightable works distributed by
  42. Tokutek as part of the Fractal Tree project.
  43. "PATENT CLAIMS" means the claims of patents that are owned or
  44. licensable by Tokutek, both currently or in the future; and that in
  45. the absence of this license would be infringed by THIS
  46. IMPLEMENTATION or by using or running THIS IMPLEMENTATION.
  47. "PATENT CHALLENGE" shall mean a challenge to the validity,
  48. patentability, enforceability and/or non-infringement of any of the
  49. PATENT CLAIMS or otherwise opposing any of the PATENT CLAIMS.
  50. Tokutek hereby grants to you, for the term and geographical scope of
  51. the PATENT CLAIMS, a non-exclusive, no-charge, royalty-free,
  52. irrevocable (except as stated in this section) patent license to
  53. make, have made, use, offer to sell, sell, import, transfer, and
  54. otherwise run, modify, and propagate the contents of THIS
  55. IMPLEMENTATION, where such license applies only to the PATENT
  56. CLAIMS. This grant does not include claims that would be infringed
  57. only as a consequence of further modifications of THIS
  58. IMPLEMENTATION. If you or your agent or licensee institute or order
  59. or agree to the institution of patent litigation against any entity
  60. (including a cross-claim or counterclaim in a lawsuit) alleging that
  61. THIS IMPLEMENTATION constitutes direct or contributory patent
  62. infringement, or inducement of patent infringement, then any rights
  63. granted to you under this License shall terminate as of the date
  64. such litigation is filed. If you or your agent or exclusive
  65. licensee institute or order or agree to the institution of a PATENT
  66. CHALLENGE, then Tokutek may terminate any rights granted to you
  67. under this License.
  68. */
  69. #ident "Copyright (c) 2007-2013 Tokutek Inc. All rights reserved."
  70. #ident "$Id$"
  71. /* LICENSE: This file is licensed under the GPL or from Tokutek. */
  72. /* Make a db.h that will be link-time compatible with Sleepycat's Berkeley DB. */
  73. #include <stdio.h>
  74. #include <stdlib.h>
  75. // Don't include toku_assert.h. Just use assert.h
  76. #include <assert.h>
  77. #include <string.h>
  78. #include <sys/types.h>
  79. #define VISIBLE "__attribute__((__visibility__(\"default\")))"
  80. #define FIELD_LIMIT 100
  81. struct fieldinfo {
  82. const char *decl_format_string;
  83. const char *name;
  84. size_t offset;
  85. } fields[FIELD_LIMIT];
  86. static int field_counter=0;
  87. static int compare_fields (const void *av, const void *bv) {
  88. const struct fieldinfo *a = (const struct fieldinfo *) av;
  89. const struct fieldinfo *b = (const struct fieldinfo *) bv;
  90. if (a->offset< b->offset) return -1;
  91. if (a->offset==b->offset) return 0;
  92. return +1;
  93. }
  94. #define STRUCT_SETUP(typ, fname, fstring) ({ \
  95. assert(field_counter<FIELD_LIMIT); \
  96. fields[field_counter].decl_format_string = fstring; \
  97. fields[field_counter].name = #fname; \
  98. fields[field_counter].offset = __builtin_offsetof(typ, fname); \
  99. field_counter++; })
  100. static void sort_and_dump_fields (const char *structname, bool has_internal, const char *extra_decls[]) {
  101. int i;
  102. qsort(fields, field_counter, sizeof(fields[0]), compare_fields);
  103. printf("struct __toku_%s {\n", structname);
  104. if (has_internal) {
  105. printf(" struct __toku_%s_internal *i;\n", structname);
  106. printf("#define %s_struct_i(x) ((x)->i)\n", structname);
  107. }
  108. if (extra_decls) {
  109. while (*extra_decls) {
  110. printf(" %s;\n", *extra_decls);
  111. extra_decls++;
  112. }
  113. }
  114. for (i=0; i<field_counter; i++) {
  115. printf(" ");
  116. printf(fields[i].decl_format_string, fields[i].name);
  117. printf(";\n");
  118. }
  119. printf("};\n");
  120. }
  121. #include "db-4.6.19.h"
  122. static void print_dbtype(void) {
  123. /* DBTYPE is mentioned by db_open.html */
  124. printf("typedef enum {\n");
  125. printf(" DB_BTREE=%d,\n", DB_BTREE);
  126. printf(" DB_UNKNOWN=%d\n", DB_UNKNOWN);
  127. printf("} DBTYPE;\n");
  128. }
  129. #define dodefine(name) printf("#define %s %d\n", #name, name)
  130. #define dodefine_track(flags, name) ({ assert((flags & name) != name); \
  131. flags |= (name); \
  132. printf("#define %s %d\n", #name, name); })
  133. #define dodefine_from_track(flags, name) ({\
  134. uint32_t which; \
  135. uint32_t bit; \
  136. for (which = 0; which < 32; which++) { \
  137. bit = 1U << which; \
  138. if (!(flags & bit)) break; \
  139. } \
  140. assert(which < 32); \
  141. printf("#define %s %u\n", #name, bit); \
  142. flags |= bit; \
  143. })
  144. #define dodefine_track_enum(flags, name) ({ assert(name>=0 && name<256); \
  145. assert(!(flags[name])); \
  146. flags[name] = 1; \
  147. printf("#define %s %d\n", #name, (int)(name)); })
  148. #define dodefine_from_track_enum(flags, name) ({\
  149. uint32_t which; \
  150. /* don't use 0 */ \
  151. for (which = 1; which < 256; which++) { \
  152. if (!(flags[which])) break; \
  153. } \
  154. assert(which < 256); \
  155. flags[which] = 1; \
  156. printf("#define %s %u\n", #name, which); \
  157. })
  158. enum {
  159. TOKUDB_OUT_OF_LOCKS = -100000,
  160. TOKUDB_SUCCEEDED_EARLY = -100001,
  161. TOKUDB_FOUND_BUT_REJECTED = -100002,
  162. TOKUDB_USER_CALLBACK_ERROR = -100003,
  163. TOKUDB_DICTIONARY_TOO_OLD = -100004,
  164. TOKUDB_DICTIONARY_TOO_NEW = -100005,
  165. TOKUDB_DICTIONARY_NO_HEADER = -100006,
  166. TOKUDB_CANCELED = -100007,
  167. TOKUDB_NO_DATA = -100008,
  168. TOKUDB_ACCEPT = -100009,
  169. TOKUDB_MVCC_DICTIONARY_TOO_NEW = -100010,
  170. TOKUDB_UPGRADE_FAILURE = -100011,
  171. TOKUDB_TRY_AGAIN = -100012,
  172. TOKUDB_NEEDS_REPAIR = -100013,
  173. TOKUDB_CURSOR_CONTINUE = -100014,
  174. TOKUDB_BAD_CHECKSUM = -100015,
  175. TOKUDB_HUGE_PAGES_ENABLED = -100016,
  176. TOKUDB_OUT_OF_RANGE = -100017,
  177. DONTUSE_I_JUST_PUT_THIS_HERE_SO_I_COULD_HAVE_A_COMMA_AFTER_EACH_ITEM
  178. };
  179. static void print_defines (void) {
  180. dodefine(DB_VERB_DEADLOCK);
  181. dodefine(DB_VERB_RECOVERY);
  182. dodefine(DB_VERB_REPLICATION);
  183. dodefine(DB_VERB_WAITSFOR);
  184. dodefine(DB_ARCH_ABS);
  185. dodefine(DB_ARCH_LOG);
  186. dodefine(DB_CREATE);
  187. dodefine(DB_CXX_NO_EXCEPTIONS);
  188. dodefine(DB_EXCL);
  189. dodefine(DB_PRIVATE);
  190. dodefine(DB_RDONLY);
  191. dodefine(DB_RECOVER);
  192. dodefine(DB_RUNRECOVERY);
  193. dodefine(DB_THREAD);
  194. dodefine(DB_TXN_NOSYNC);
  195. /* according to BDB 4.6.19, this is the next unused flag in the set of
  196. * common flags plus private flags for DB->open */
  197. #define DB_BLACKHOLE 0x0080000
  198. dodefine(DB_BLACKHOLE);
  199. #undef DB_BLACKHOLE
  200. dodefine(DB_LOCK_DEFAULT);
  201. dodefine(DB_LOCK_OLDEST);
  202. dodefine(DB_LOCK_RANDOM);
  203. //dodefine(DB_DUP); No longer supported #2862
  204. //dodefine(DB_DUPSORT); No longer supported #2862
  205. dodefine(DB_KEYFIRST);
  206. dodefine(DB_KEYLAST);
  207. {
  208. static uint8_t insert_flags[256];
  209. dodefine_track_enum(insert_flags, DB_NOOVERWRITE);
  210. dodefine_track_enum(insert_flags, DB_NODUPDATA);
  211. dodefine_from_track_enum(insert_flags, DB_NOOVERWRITE_NO_ERROR);
  212. }
  213. dodefine(DB_OPFLAGS_MASK);
  214. dodefine(DB_AUTO_COMMIT);
  215. dodefine(DB_INIT_LOCK);
  216. dodefine(DB_INIT_LOG);
  217. dodefine(DB_INIT_MPOOL);
  218. dodefine(DB_INIT_TXN);
  219. //dodefine(DB_KEYEMPTY); /// KEYEMPTY is no longer used. We just use DB_NOTFOUND
  220. dodefine(DB_KEYEXIST);
  221. dodefine(DB_LOCK_DEADLOCK);
  222. dodefine(DB_LOCK_NOTGRANTED);
  223. dodefine(DB_NOTFOUND);
  224. dodefine(DB_SECONDARY_BAD);
  225. dodefine(DB_DONOTINDEX);
  226. #ifdef DB_BUFFER_SMALL
  227. dodefine(DB_BUFFER_SMALL);
  228. #endif
  229. printf("#define DB_BADFORMAT -30500\n"); // private tokudb
  230. printf("#define DB_DELETE_ANY %d\n", 1<<16); // private tokudb
  231. dodefine(DB_FIRST);
  232. dodefine(DB_LAST);
  233. dodefine(DB_CURRENT);
  234. dodefine(DB_NEXT);
  235. dodefine(DB_PREV);
  236. dodefine(DB_SET);
  237. dodefine(DB_SET_RANGE);
  238. printf("#define DB_CURRENT_BINDING 253\n"); // private tokudb
  239. printf("#define DB_SET_RANGE_REVERSE 252\n"); // private tokudb
  240. //printf("#define DB_GET_BOTH_RANGE_REVERSE 251\n"); // private tokudb. No longer supported #2862.
  241. dodefine(DB_RMW);
  242. printf("#define DB_IS_RESETTING_OP 0x01000000\n"); // private tokudb
  243. printf("#define DB_PRELOCKED 0x00800000\n"); // private tokudb
  244. printf("#define DB_PRELOCKED_WRITE 0x00400000\n"); // private tokudb
  245. //printf("#define DB_PRELOCKED_FILE_READ 0x00200000\n"); // private tokudb. No longer supported in #4472
  246. printf("#define DB_IS_HOT_INDEX 0x00100000\n"); // private tokudb
  247. printf("#define DBC_DISABLE_PREFETCHING 0x20000000\n"); // private tokudb
  248. printf("#define DB_UPDATE_CMP_DESCRIPTOR 0x40000000\n"); // private tokudb
  249. {
  250. //dbt flags
  251. uint32_t dbt_flags = 0;
  252. dodefine_track(dbt_flags, DB_DBT_APPMALLOC);
  253. dodefine_track(dbt_flags, DB_DBT_DUPOK);
  254. dodefine_track(dbt_flags, DB_DBT_MALLOC);
  255. #ifdef DB_DBT_MULTIPLE
  256. dodefine_track(dbt_flags, DB_DBT_MULTIPLE);
  257. #endif
  258. dodefine_track(dbt_flags, DB_DBT_REALLOC);
  259. dodefine_track(dbt_flags, DB_DBT_USERMEM);
  260. }
  261. // flags for the env->set_flags function
  262. #if DB_VERSION_MAJOR == 4 && DB_VERSION_MINOR >= 3
  263. dodefine(DB_LOG_AUTOREMOVE);
  264. #endif
  265. {
  266. //Txn begin/commit flags
  267. uint32_t txn_flags = 0;
  268. dodefine_track(txn_flags, DB_TXN_WRITE_NOSYNC);
  269. dodefine_track(txn_flags, DB_TXN_NOWAIT);
  270. dodefine_track(txn_flags, DB_TXN_SYNC);
  271. #ifdef DB_TXN_SNAPSHOT
  272. dodefine_track(txn_flags, DB_TXN_SNAPSHOT);
  273. #endif
  274. #ifdef DB_READ_UNCOMMITTED
  275. dodefine_track(txn_flags, DB_READ_UNCOMMITTED);
  276. #endif
  277. #ifdef DB_READ_COMMITTED
  278. dodefine_track(txn_flags, DB_READ_COMMITTED);
  279. #endif
  280. //Add them if they didn't exist
  281. #ifndef DB_TXN_SNAPSHOT
  282. dodefine_from_track(txn_flags, DB_TXN_SNAPSHOT);
  283. #endif
  284. #ifndef DB_READ_UNCOMMITTED
  285. dodefine_from_track(txn_flags, DB_READ_UNCOMMITTED);
  286. #endif
  287. #ifndef DB_READ_COMMITTED
  288. dodefine_from_track(txn_flags, DB_READ_COMMITTED);
  289. #endif
  290. dodefine_from_track(txn_flags, DB_INHERIT_ISOLATION);
  291. dodefine_from_track(txn_flags, DB_SERIALIZABLE);
  292. dodefine_from_track(txn_flags, DB_TXN_READ_ONLY);
  293. }
  294. /* TOKUDB specific error codes*/
  295. printf("/* TOKUDB specific error codes */\n");
  296. dodefine(TOKUDB_OUT_OF_LOCKS);
  297. dodefine(TOKUDB_SUCCEEDED_EARLY);
  298. dodefine(TOKUDB_FOUND_BUT_REJECTED);
  299. dodefine(TOKUDB_USER_CALLBACK_ERROR);
  300. dodefine(TOKUDB_DICTIONARY_TOO_OLD);
  301. dodefine(TOKUDB_DICTIONARY_TOO_NEW);
  302. dodefine(TOKUDB_DICTIONARY_NO_HEADER);
  303. dodefine(TOKUDB_CANCELED);
  304. dodefine(TOKUDB_NO_DATA);
  305. dodefine(TOKUDB_ACCEPT);
  306. dodefine(TOKUDB_MVCC_DICTIONARY_TOO_NEW);
  307. dodefine(TOKUDB_UPGRADE_FAILURE);
  308. dodefine(TOKUDB_TRY_AGAIN);
  309. dodefine(TOKUDB_NEEDS_REPAIR);
  310. dodefine(TOKUDB_CURSOR_CONTINUE);
  311. dodefine(TOKUDB_BAD_CHECKSUM);
  312. dodefine(TOKUDB_HUGE_PAGES_ENABLED);
  313. dodefine(TOKUDB_OUT_OF_RANGE);
  314. /* LOADER flags */
  315. printf("/* LOADER flags */\n");
  316. {
  317. uint32_t loader_flags = 0;
  318. dodefine_from_track(loader_flags, LOADER_DISALLOW_PUTS); // Loader is only used for side effects.
  319. dodefine_from_track(loader_flags, LOADER_COMPRESS_INTERMEDIATES);
  320. }
  321. }
  322. static void print_db_env_struct (void) {
  323. field_counter=0;
  324. STRUCT_SETUP(DB_ENV, api1_internal, "void *%s"); /* Used for C++ hacking. */
  325. STRUCT_SETUP(DB_ENV, app_private, "void *%s");
  326. STRUCT_SETUP(DB_ENV, close, "int (*%s) (DB_ENV *, uint32_t)");
  327. STRUCT_SETUP(DB_ENV, err, "void (*%s) (const DB_ENV *, int, const char *, ...) __attribute__ (( format (printf, 3, 4) ))");
  328. #if DB_VERSION_MAJOR == 4 && DB_VERSION_MINOR >= 3
  329. STRUCT_SETUP(DB_ENV, get_cachesize, "int (*%s) (DB_ENV *, uint32_t *, uint32_t *, int *)");
  330. STRUCT_SETUP(DB_ENV, get_flags, "int (*%s) (DB_ENV *, uint32_t *)");
  331. STRUCT_SETUP(DB_ENV, get_lg_max, "int (*%s) (DB_ENV *, uint32_t*)");
  332. #endif
  333. STRUCT_SETUP(DB_ENV, log_archive, "int (*%s) (DB_ENV *, char **[], uint32_t)");
  334. STRUCT_SETUP(DB_ENV, log_flush, "int (*%s) (DB_ENV *, const DB_LSN *)");
  335. STRUCT_SETUP(DB_ENV, open, "int (*%s) (DB_ENV *, const char *, uint32_t, int)");
  336. STRUCT_SETUP(DB_ENV, set_cachesize, "int (*%s) (DB_ENV *, uint32_t, uint32_t, int)");
  337. STRUCT_SETUP(DB_ENV, set_data_dir, "int (*%s) (DB_ENV *, const char *)");
  338. #if DB_VERSION_MAJOR == 4 && DB_VERSION_MINOR == 1
  339. STRUCT_SETUP(DB_ENV, set_errcall, "void (*%s) (DB_ENV *, void (*)(const char *, char *))");
  340. #endif
  341. #if DB_VERSION_MAJOR == 4 && DB_VERSION_MINOR >= 3
  342. STRUCT_SETUP(DB_ENV, set_errcall, "void (*%s) (DB_ENV *, void (*)(const DB_ENV *, const char *, const char *))");
  343. #endif
  344. STRUCT_SETUP(DB_ENV, set_errfile, "void (*%s) (DB_ENV *, FILE*)");
  345. STRUCT_SETUP(DB_ENV, set_errpfx, "void (*%s) (DB_ENV *, const char *)");
  346. STRUCT_SETUP(DB_ENV, set_flags, "int (*%s) (DB_ENV *, uint32_t, int)");
  347. STRUCT_SETUP(DB_ENV, set_lg_bsize, "int (*%s) (DB_ENV *, uint32_t)");
  348. STRUCT_SETUP(DB_ENV, set_lg_dir, "int (*%s) (DB_ENV *, const char *)");
  349. STRUCT_SETUP(DB_ENV, set_lg_max, "int (*%s) (DB_ENV *, uint32_t)");
  350. STRUCT_SETUP(DB_ENV, set_lk_detect, "int (*%s) (DB_ENV *, uint32_t)");
  351. #if DB_VERSION_MAJOR == 4 && DB_VERSION_MINOR <= 4
  352. STRUCT_SETUP(DB_ENV, set_lk_max, "int (*%s) (DB_ENV *, uint32_t)");
  353. #endif
  354. //STRUCT_SETUP(DB_ENV, set_noticecall, "void (*%s) (DB_ENV *, void (*)(DB_ENV *, db_notices))");
  355. STRUCT_SETUP(DB_ENV, set_tmp_dir, "int (*%s) (DB_ENV *, const char *)");
  356. STRUCT_SETUP(DB_ENV, set_verbose, "int (*%s) (DB_ENV *, uint32_t, int)");
  357. STRUCT_SETUP(DB_ENV, txn_checkpoint, "int (*%s) (DB_ENV *, uint32_t, uint32_t, uint32_t)");
  358. STRUCT_SETUP(DB_ENV, txn_stat, "int (*%s) (DB_ENV *, DB_TXN_STAT **, uint32_t)");
  359. STRUCT_SETUP(DB_ENV, txn_begin, "int (*%s) (DB_ENV *, DB_TXN *, DB_TXN **, uint32_t)");
  360. STRUCT_SETUP(DB_ENV, txn_recover, "int (*%s) (DB_ENV *, DB_PREPLIST preplist[/*count*/], long count, /*out*/ long *retp, uint32_t flags)");
  361. STRUCT_SETUP(DB_ENV, dbremove, "int (*%s) (DB_ENV *, DB_TXN *, const char *, const char *, uint32_t)");
  362. STRUCT_SETUP(DB_ENV, dbrename, "int (*%s) (DB_ENV *, DB_TXN *, const char *, const char *, const char *, uint32_t)");
  363. const char *extra[]={
  364. "int (*checkpointing_set_period) (DB_ENV*, uint32_t) /* Change the delay between automatic checkpoints. 0 means disabled. */",
  365. "int (*checkpointing_get_period) (DB_ENV*, uint32_t*) /* Retrieve the delay between automatic checkpoints. 0 means disabled. */",
  366. "int (*cleaner_set_period) (DB_ENV*, uint32_t) /* Change the delay between automatic cleaner attempts. 0 means disabled. */",
  367. "int (*cleaner_get_period) (DB_ENV*, uint32_t*) /* Retrieve the delay between automatic cleaner attempts. 0 means disabled. */",
  368. "int (*cleaner_set_iterations) (DB_ENV*, uint32_t) /* Change the number of attempts on each cleaner invokation. 0 means disabled. */",
  369. "int (*cleaner_get_iterations) (DB_ENV*, uint32_t*) /* Retrieve the number of attempts on each cleaner invokation. 0 means disabled. */",
  370. "int (*checkpointing_postpone) (DB_ENV*) /* Use for 'rename table' or any other operation that must be disjoint from a checkpoint */",
  371. "int (*checkpointing_resume) (DB_ENV*) /* Alert tokudb 'postpone' is no longer necessary */",
  372. "int (*checkpointing_begin_atomic_operation) (DB_ENV*) /* Begin a set of operations (that must be atomic as far as checkpoints are concerned). i.e. inserting into every index in one table */",
  373. "int (*checkpointing_end_atomic_operation) (DB_ENV*) /* End a set of operations (that must be atomic as far as checkpoints are concerned). */",
  374. "int (*set_default_bt_compare) (DB_ENV*,int (*bt_compare) (DB *, const DBT *, const DBT *)) /* Set default (key) comparison function for all DBs in this environment. Required for RECOVERY since you cannot open the DBs manually. */",
  375. "int (*get_engine_status_num_rows) (DB_ENV*, uint64_t*) /* return number of rows in engine status */",
  376. "int (*get_engine_status) (DB_ENV*, TOKU_ENGINE_STATUS_ROW, uint64_t, uint64_t*, fs_redzone_state*, uint64_t*, char*, int, toku_engine_status_include_type) /* Fill in status struct and redzone state, possibly env panic string */",
  377. "int (*get_engine_status_text) (DB_ENV*, char*, int) /* Fill in status text */",
  378. "int (*crash) (DB_ENV*, const char*/*expr_as_string*/,const char */*fun*/,const char*/*file*/,int/*line*/, int/*errno*/)",
  379. "int (*get_iname) (DB_ENV* env, DBT* dname_dbt, DBT* iname_dbt) /* FOR TEST ONLY: lookup existing iname */",
  380. "int (*create_loader) (DB_ENV *env, DB_TXN *txn, DB_LOADER **blp, DB *src_db, int N, DB *dbs[/*N*/], uint32_t db_flags[/*N*/], uint32_t dbt_flags[/*N*/], uint32_t loader_flags)",
  381. "int (*create_indexer) (DB_ENV *env, DB_TXN *txn, DB_INDEXER **idxrp, DB *src_db, int N, DB *dbs[/*N*/], uint32_t db_flags[/*N*/], uint32_t indexer_flags)",
  382. "int (*put_multiple) (DB_ENV *env, DB *src_db, DB_TXN *txn,\n"
  383. " const DBT *src_key, const DBT *src_val,\n"
  384. " uint32_t num_dbs, DB **db_array, DBT *keys, DBT *vals, uint32_t *flags_array) /* insert into multiple DBs */",
  385. "int (*set_generate_row_callback_for_put) (DB_ENV *env, generate_row_for_put_func generate_row_for_put)",
  386. "int (*del_multiple) (DB_ENV *env, DB *src_db, DB_TXN *txn,\n"
  387. " const DBT *src_key, const DBT *src_val,\n"
  388. " uint32_t num_dbs, DB **db_array, DBT *keys, uint32_t *flags_array) /* delete from multiple DBs */",
  389. "int (*set_generate_row_callback_for_del) (DB_ENV *env, generate_row_for_del_func generate_row_for_del)",
  390. "int (*update_multiple) (DB_ENV *env, DB *src_db, DB_TXN *txn,\n"
  391. " DBT *old_src_key, DBT *old_src_data,\n"
  392. " DBT *new_src_key, DBT *new_src_data,\n"
  393. " uint32_t num_dbs, DB **db_array, uint32_t *flags_array,\n"
  394. " uint32_t num_keys, DBT *keys,\n"
  395. " uint32_t num_vals, DBT *vals) /* update multiple DBs */",
  396. "int (*get_redzone) (DB_ENV *env, int *redzone) /* get the redzone limit */",
  397. "int (*set_redzone) (DB_ENV *env, int redzone) /* set the redzone limit in percent of total space */",
  398. "int (*set_lk_max_memory) (DB_ENV *env, uint64_t max)",
  399. "int (*get_lk_max_memory) (DB_ENV *env, uint64_t *max)",
  400. "void (*set_update) (DB_ENV *env, int (*update_function)(DB *, const DBT *key, const DBT *old_val, const DBT *extra, void (*set_val)(const DBT *new_val, void *set_extra), void *set_extra))",
  401. "int (*set_lock_timeout) (DB_ENV *env, uint64_t lock_wait_time_msec)",
  402. "int (*get_lock_timeout) (DB_ENV *env, uint64_t *lock_wait_time_msec)",
  403. "int (*txn_xa_recover) (DB_ENV*, TOKU_XA_XID list[/*count*/], long count, /*out*/ long *retp, uint32_t flags)",
  404. "int (*get_txn_from_xid) (DB_ENV*, /*in*/ TOKU_XA_XID *, /*out*/ DB_TXN **)",
  405. "int (*get_cursor_for_directory) (DB_ENV*, /*in*/ DB_TXN *, /*out*/ DBC **)",
  406. "int (*get_cursor_for_persistent_environment) (DB_ENV*, /*in*/ DB_TXN *, /*out*/ DBC **)",
  407. "void (*change_fsync_log_period)(DB_ENV*, uint32_t)",
  408. NULL};
  409. sort_and_dump_fields("db_env", true, extra);
  410. }
  411. static void print_db_key_range_struct (void) {
  412. field_counter=0;
  413. STRUCT_SETUP(DB_KEY_RANGE, less, "double %s");
  414. STRUCT_SETUP(DB_KEY_RANGE, equal, "double %s");
  415. STRUCT_SETUP(DB_KEY_RANGE, greater, "double %s");
  416. sort_and_dump_fields("db_key_range", false, NULL);
  417. }
  418. static void print_db_lsn_struct (void) {
  419. field_counter=0;
  420. sort_and_dump_fields("db_lsn", false, NULL);
  421. }
  422. static void print_dbt_struct (void) {
  423. field_counter=0;
  424. #if 0 && DB_VERSION_MAJOR==4 && DB_VERSION_MINOR==1
  425. STRUCT_SETUP(DBT, app_private, "void*%s");
  426. #endif
  427. STRUCT_SETUP(DBT, data, "void*%s");
  428. STRUCT_SETUP(DBT, flags, "uint32_t %s");
  429. STRUCT_SETUP(DBT, size, "uint32_t %s");
  430. STRUCT_SETUP(DBT, ulen, "uint32_t %s");
  431. sort_and_dump_fields("dbt", false, NULL);
  432. }
  433. static void print_db_struct (void) {
  434. /* Do these in alphabetical order. */
  435. field_counter=0;
  436. STRUCT_SETUP(DB, api_internal, "void *%s"); /* Used for C++ hacking. */
  437. STRUCT_SETUP(DB, app_private, "void *%s");
  438. STRUCT_SETUP(DB, close, "int (*%s) (DB*, uint32_t)");
  439. STRUCT_SETUP(DB, cursor, "int (*%s) (DB *, DB_TXN *, DBC **, uint32_t)");
  440. STRUCT_SETUP(DB, dbenv, "DB_ENV *%s");
  441. STRUCT_SETUP(DB, del, "int (*%s) (DB *, DB_TXN *, DBT *, uint32_t)");
  442. STRUCT_SETUP(DB, fd, "int (*%s) (DB *, int *)");
  443. STRUCT_SETUP(DB, get, "int (*%s) (DB *, DB_TXN *, DBT *, DBT *, uint32_t)");
  444. #if DB_VERSION_MAJOR == 4 && DB_VERSION_MINOR >= 3
  445. STRUCT_SETUP(DB, get_flags, "int (*%s) (DB *, uint32_t *)");
  446. STRUCT_SETUP(DB, get_pagesize, "int (*%s) (DB *, uint32_t *)");
  447. #endif
  448. STRUCT_SETUP(DB, key_range, "int (*%s) (DB *, DB_TXN *, DBT *, DB_KEY_RANGE *, uint32_t)");
  449. STRUCT_SETUP(DB, open, "int (*%s) (DB *, DB_TXN *, const char *, const char *, DBTYPE, uint32_t, int)");
  450. STRUCT_SETUP(DB, put, "int (*%s) (DB *, DB_TXN *, DBT *, DBT *, uint32_t)");
  451. STRUCT_SETUP(DB, set_errfile, "void (*%s) (DB *, FILE*)");
  452. STRUCT_SETUP(DB, set_flags, "int (*%s) (DB *, uint32_t)");
  453. STRUCT_SETUP(DB, set_pagesize, "int (*%s) (DB *, uint32_t)");
  454. STRUCT_SETUP(DB, stat, "int (*%s) (DB *, void *, uint32_t)");
  455. STRUCT_SETUP(DB, verify, "int (*%s) (DB *, const char *, const char *, FILE *, uint32_t)");
  456. const char *extra[]={
  457. "int (*key_range64)(DB*, DB_TXN *, DBT *, uint64_t *less, uint64_t *equal, uint64_t *greater, int *is_exact)",
  458. "int (*get_key_after_bytes)(DB *, DB_TXN *, const DBT *, uint64_t, void (*callback)(const DBT *, uint64_t, void *), void *, uint32_t); /* given start_key and skip_len, find largest end_key such that the elements in [start_key,end_key) sum to <= skip_len bytes */",
  459. "int (*keys_range64)(DB*, DB_TXN *, DBT *keyleft, DBT *keyright, uint64_t *less, uint64_t *left, uint64_t *between, uint64_t *right, uint64_t *greater, bool *middle_3_exact)",
  460. "int (*stat64)(DB *, DB_TXN *, DB_BTREE_STAT64 *)",
  461. "int (*pre_acquire_table_lock)(DB*, DB_TXN*)",
  462. "int (*pre_acquire_fileops_lock)(DB*, DB_TXN*)",
  463. "const DBT* (*dbt_pos_infty)(void) /* Return the special DBT that refers to positive infinity in the lock table.*/",
  464. "const DBT* (*dbt_neg_infty)(void)/* Return the special DBT that refers to negative infinity in the lock table.*/",
  465. "void (*get_max_row_size) (DB*, uint32_t *max_key_size, uint32_t *max_row_size)",
  466. "DESCRIPTOR descriptor /* saved row/dictionary descriptor for aiding in comparisons */",
  467. "DESCRIPTOR cmp_descriptor /* saved row/dictionary descriptor for aiding in comparisons */",
  468. "int (*change_descriptor) (DB*, DB_TXN*, const DBT* descriptor, uint32_t) /* change row/dictionary descriptor for a db. Available only while db is open */",
  469. "int (*getf_set)(DB*, DB_TXN*, uint32_t, DBT*, YDB_CALLBACK_FUNCTION, void*) /* same as DBC->c_getf_set without a persistent cursor) */",
  470. "int (*optimize)(DB*) /* Run garbage collecion and promote all transactions older than oldest. Amortized (happens during flattening) */",
  471. "int (*hot_optimize)(DB*, int (*progress_callback)(void *progress_extra, float progress), void *progress_extra)",
  472. "int (*get_fragmentation)(DB*,TOKU_DB_FRAGMENTATION)",
  473. "int (*change_pagesize)(DB*,uint32_t)",
  474. "int (*change_readpagesize)(DB*,uint32_t)",
  475. "int (*get_readpagesize)(DB*,uint32_t*)",
  476. "int (*set_readpagesize)(DB*,uint32_t)",
  477. "int (*change_compression_method)(DB*,TOKU_COMPRESSION_METHOD)",
  478. "int (*get_compression_method)(DB*,TOKU_COMPRESSION_METHOD*)",
  479. "int (*set_compression_method)(DB*,TOKU_COMPRESSION_METHOD)",
  480. "int (*set_indexer)(DB*, DB_INDEXER*)",
  481. "void (*get_indexer)(DB*, DB_INDEXER**)",
  482. "int (*verify_with_progress)(DB *, int (*progress_callback)(void *progress_extra, float progress), void *progress_extra, int verbose, int keep_going)",
  483. "int (*update)(DB *, DB_TXN*, const DBT *key, const DBT *extra, uint32_t flags)",
  484. "int (*update_broadcast)(DB *, DB_TXN*, const DBT *extra, uint32_t flags)",
  485. "int (*get_fractal_tree_info64)(DB*,uint64_t*,uint64_t*,uint64_t*,uint64_t*)",
  486. "int (*iterate_fractal_tree_block_map)(DB*,int(*)(uint64_t,int64_t,int64_t,int64_t,int64_t,void*),void*)",
  487. NULL};
  488. sort_and_dump_fields("db", true, extra);
  489. }
  490. static void print_db_txn_active_struct (void) {
  491. field_counter=0;
  492. STRUCT_SETUP(DB_TXN_ACTIVE, lsn, "DB_LSN %s");
  493. STRUCT_SETUP(DB_TXN_ACTIVE, txnid, "uint32_t %s");
  494. sort_and_dump_fields("db_txn_active", false, NULL);
  495. }
  496. static void print_db_txn_struct (void) {
  497. field_counter=0;
  498. STRUCT_SETUP(DB_TXN, abort, "int (*%s) (DB_TXN *)");
  499. STRUCT_SETUP(DB_TXN, api_internal,"void *%s");
  500. STRUCT_SETUP(DB_TXN, commit, "int (*%s) (DB_TXN*, uint32_t)");
  501. STRUCT_SETUP(DB_TXN, prepare, "int (*%s) (DB_TXN*, uint8_t gid[DB_GID_SIZE])");
  502. STRUCT_SETUP(DB_TXN, id, "uint32_t (*%s) (DB_TXN *)");
  503. STRUCT_SETUP(DB_TXN, mgrp, "DB_ENV *%s /*In TokuDB, mgrp is a DB_ENV not a DB_TXNMGR*/");
  504. STRUCT_SETUP(DB_TXN, parent, "DB_TXN *%s");
  505. const char *extra[] = {
  506. "int (*txn_stat)(DB_TXN *, struct txn_stat **)",
  507. "struct toku_list open_txns",
  508. "int (*commit_with_progress)(DB_TXN*, uint32_t, TXN_PROGRESS_POLL_FUNCTION, void*)",
  509. "int (*abort_with_progress)(DB_TXN*, TXN_PROGRESS_POLL_FUNCTION, void*)",
  510. "int (*xa_prepare) (DB_TXN*, TOKU_XA_XID *)",
  511. "uint64_t (*id64) (DB_TXN*)",
  512. NULL};
  513. sort_and_dump_fields("db_txn", false, extra);
  514. }
  515. static void print_db_txn_stat_struct (void) {
  516. field_counter=0;
  517. STRUCT_SETUP(DB_TXN_STAT, st_nactive, "uint32_t %s");
  518. STRUCT_SETUP(DB_TXN_STAT, st_txnarray, "DB_TXN_ACTIVE *%s");
  519. sort_and_dump_fields("db_txn_stat", false, NULL);
  520. }
  521. static void print_dbc_struct (void) {
  522. field_counter=0;
  523. STRUCT_SETUP(DBC, c_close, "int (*%s) (DBC *)");
  524. //STRUCT_SETUP(DBC, c_del, "int (*%s) (DBC *, uint32_t)"); // c_del was removed. See #4576.
  525. STRUCT_SETUP(DBC, c_get, "int (*%s) (DBC *, DBT *, DBT *, uint32_t)");
  526. STRUCT_SETUP(DBC, dbp, "DB *%s");
  527. const char *extra[]={
  528. "int (*c_getf_first)(DBC *, uint32_t, YDB_CALLBACK_FUNCTION, void *)",
  529. "int (*c_getf_last)(DBC *, uint32_t, YDB_CALLBACK_FUNCTION, void *)",
  530. "int (*c_getf_next)(DBC *, uint32_t, YDB_CALLBACK_FUNCTION, void *)",
  531. "int (*c_getf_prev)(DBC *, uint32_t, YDB_CALLBACK_FUNCTION, void *)",
  532. "int (*c_getf_current)(DBC *, uint32_t, YDB_CALLBACK_FUNCTION, void *)",
  533. "int (*c_getf_set)(DBC *, uint32_t, DBT *, YDB_CALLBACK_FUNCTION, void *)",
  534. "int (*c_getf_set_range)(DBC *, uint32_t, DBT *, YDB_CALLBACK_FUNCTION, void *)",
  535. "int (*c_getf_set_range_reverse)(DBC *, uint32_t, DBT *, YDB_CALLBACK_FUNCTION, void *)",
  536. "int (*c_set_bounds)(DBC*, const DBT*, const DBT*, bool pre_acquire, int out_of_range_error)",
  537. "void (*c_remove_restriction)(DBC*)",
  538. NULL};
  539. sort_and_dump_fields("dbc", false, extra);
  540. }
  541. int main (int argc, char *const argv[] __attribute__((__unused__))) {
  542. assert(argc==1);
  543. printf("#ifndef _DB_H\n");
  544. printf("#define _DB_H\n");
  545. printf("/* This code generated by make_db_h. Copyright (c) 2007-2013 Tokutek */\n");
  546. printf("#ident \"Copyright (c) 2007-2013 Tokutek Inc. All rights reserved.\"\n");
  547. printf("#include <sys/types.h>\n");
  548. printf("/*stdio is needed for the FILE* in db->verify*/\n");
  549. printf("#include <stdio.h>\n");
  550. printf("/*stdbool is needed for the bool in db_env_enable_engine_status*/\n");
  551. printf("#include <stdbool.h>\n");
  552. printf("#include <stdint.h>\n");
  553. //printf("#include <inttypes.h>\n");
  554. printf("#if defined(__cplusplus) || defined(__cilkplusplus)\nextern \"C\" {\n#endif\n");
  555. printf("#define TOKUDB 1\n");
  556. printf("#define DB_VERSION_MAJOR %d\n", DB_VERSION_MAJOR);
  557. printf("#define DB_VERSION_MINOR %d\n", DB_VERSION_MINOR);
  558. printf("/* As of r40364 (post TokuDB 5.2.7), the patch version number is 100+ the BDB header patch version number.*/\n");
  559. printf("#define DB_VERSION_PATCH %d\n", 100+DB_VERSION_PATCH);
  560. printf("#define DB_VERSION_STRING \"Tokutek: TokuDB %d.%d.%d\"\n", DB_VERSION_MAJOR, DB_VERSION_MINOR, 100+DB_VERSION_PATCH);
  561. #ifndef DB_GID_SIZE
  562. #define DB_GID_SIZE DB_XIDDATASIZE
  563. #endif
  564. dodefine(DB_GID_SIZE);
  565. printf("typedef struct toku_xa_xid_s { /* This struct is intended to be binary compatible with the XID in the XA architecture. See source:/import/opengroup.org/C193.pdf */\n"
  566. " long formatID; /* format identifier */\n"
  567. " long gtrid_length; /* value from 1 through 64 */\n"
  568. " long bqual_length; /* value from 1 through 64 */\n"
  569. " char data[DB_GID_SIZE];\n"
  570. "} TOKU_XA_XID;\n");
  571. //Typedef toku_off_t
  572. printf("#ifndef TOKU_OFF_T_DEFINED\n"
  573. "#define TOKU_OFF_T_DEFINED\n"
  574. "typedef int64_t toku_off_t;\n"
  575. "#endif\n");
  576. printf("typedef struct __toku_db_env DB_ENV;\n");
  577. printf("typedef struct __toku_db_key_range DB_KEY_RANGE;\n");
  578. printf("typedef struct __toku_db_lsn DB_LSN;\n");
  579. printf("typedef struct __toku_db DB;\n");
  580. printf("typedef struct __toku_db_txn DB_TXN;\n");
  581. printf("typedef struct __toku_db_txn_active DB_TXN_ACTIVE;\n");
  582. printf("typedef struct __toku_db_txn_stat DB_TXN_STAT;\n");
  583. printf("typedef struct __toku_dbc DBC;\n");
  584. printf("typedef struct __toku_dbt DBT;\n");
  585. printf("typedef struct __toku_db_preplist { DB_TXN *txn; uint8_t gid[DB_GID_SIZE]; } DB_PREPLIST;\n");
  586. printf("typedef uint32_t db_recno_t;\n");
  587. printf("typedef int(*YDB_CALLBACK_FUNCTION)(DBT const*, DBT const*, void*);\n");
  588. printf("#include <tdb-internal.h>\n");
  589. //stat64
  590. printf("typedef struct __toku_db_btree_stat64 {\n");
  591. printf(" uint64_t bt_nkeys; /* how many unique keys (guaranteed only to be an estimate, even when flattened) */\n");
  592. printf(" uint64_t bt_ndata; /* how many key-value pairs (an estimate, but exact when flattened) */\n");
  593. printf(" uint64_t bt_dsize; /* how big are the keys+values (not counting the lengths) (an estimate, unless flattened) */\n");
  594. printf(" uint64_t bt_fsize; /* how big is the underlying file */\n");
  595. // 4018
  596. printf(" uint64_t bt_create_time_sec; /* Creation time, in seconds */\n");
  597. printf(" uint64_t bt_modify_time_sec; /* Time of last serialization, in seconds */\n");
  598. printf(" uint64_t bt_verify_time_sec; /* Time of last verification, in seconds */\n");
  599. printf("} DB_BTREE_STAT64;\n");
  600. // compression methods
  601. printf("typedef enum toku_compression_method {\n");
  602. printf(" TOKU_NO_COMPRESSION = 0,\n"); // "identity" compression
  603. printf(" TOKU_ZLIB_METHOD = 8,\n"); // RFC 1950 says use 8 for zlib. It reserves 15 to allow more bytes.
  604. printf(" TOKU_QUICKLZ_METHOD = 9,\n"); // We use 9 for QUICKLZ (the QLZ compression level is stored int he high-order nibble). I couldn't find any standard for any other numbers, so I just use 9. -Bradley
  605. printf(" TOKU_LZMA_METHOD = 10,\n"); // We use 10 for LZMA. (Note the compression level is stored in the high-order nibble).
  606. printf(" TOKU_ZLIB_WITHOUT_CHECKSUM_METHOD = 11,\n"); // We wrap a zlib without checksumming compression technique in our own checksummed metadata.
  607. printf(" TOKU_DEFAULT_COMPRESSION_METHOD = 1,\n"); // default is actually quicklz
  608. printf(" TOKU_FAST_COMPRESSION_METHOD = 2,\n"); // friendlier names
  609. printf(" TOKU_SMALL_COMPRESSION_METHOD = 3,\n");
  610. printf("} TOKU_COMPRESSION_METHOD;\n");
  611. //bulk loader
  612. printf("typedef struct __toku_loader DB_LOADER;\n");
  613. printf("struct __toku_loader_internal;\n");
  614. printf("struct __toku_loader {\n");
  615. printf(" struct __toku_loader_internal *i;\n");
  616. printf(" int (*set_error_callback)(DB_LOADER *loader, void (*error_cb)(DB *db, int i, int err, DBT *key, DBT *val, void *error_extra), void *error_extra); /* set the error callback */\n");
  617. printf(" int (*set_poll_function)(DB_LOADER *loader, int (*poll_func)(void *extra, float progress), void *poll_extra); /* set the polling function */\n");
  618. printf(" int (*put)(DB_LOADER *loader, DBT *key, DBT* val); /* give a row to the loader */\n");
  619. printf(" int (*close)(DB_LOADER *loader); /* finish loading, free memory */\n");
  620. printf(" int (*abort)(DB_LOADER *loader); /* abort loading, free memory */\n");
  621. printf("};\n");
  622. //indexer
  623. printf("typedef struct __toku_indexer DB_INDEXER;\n");
  624. printf("struct __toku_indexer_internal;\n");
  625. printf("struct __toku_indexer {\n");
  626. printf(" struct __toku_indexer_internal *i;\n");
  627. printf(" int (*set_error_callback)(DB_INDEXER *indexer, void (*error_cb)(DB *db, int i, int err, DBT *key, DBT *val, void *error_extra), void *error_extra); /* set the error callback */\n");
  628. printf(" int (*set_poll_function)(DB_INDEXER *indexer, int (*poll_func)(void *extra, float progress), void *poll_extra); /* set the polling function */\n");
  629. printf(" int (*build)(DB_INDEXER *indexer); /* build the indexes */\n");
  630. printf(" int (*close)(DB_INDEXER *indexer); /* finish indexing, free memory */\n");
  631. printf(" int (*abort)(DB_INDEXER *indexer); /* abort indexing, free memory */\n");
  632. printf("};\n");
  633. // Filesystem redzone state
  634. printf("typedef enum { \n");
  635. printf(" FS_GREEN = 0, // green zone (we have lots of space) \n");
  636. printf(" FS_YELLOW = 1, // yellow zone (issue warning but allow operations) \n");
  637. printf(" FS_RED = 2, // red zone (prevent insert operations) \n");
  638. printf(" FS_BLOCKED = 3 // For reporting engine status, completely blocked \n");
  639. printf("} fs_redzone_state;\n");
  640. printf("// engine status info\n");
  641. printf("// engine status is passed to handlerton as an array of TOKU_ENGINE_STATUS_ROW_S[]\n");
  642. printf("typedef enum {\n");
  643. printf(" FS_STATE = 0, // interpret as file system state (redzone) enum \n");
  644. printf(" UINT64, // interpret as uint64_t \n");
  645. printf(" CHARSTR, // interpret as char * \n");
  646. printf(" UNIXTIME, // interpret as time_t \n");
  647. printf(" TOKUTIME, // interpret as tokutime_t \n");
  648. printf(" PARCOUNT // interpret as PARTITIONED_COUNTER\n");
  649. printf("} toku_engine_status_display_type; \n");
  650. printf("typedef enum {\n");
  651. printf(" TOKU_ENGINE_STATUS = (1ULL<<0), // Include when asking for engine status\n");
  652. printf(" TOKU_GLOBAL_STATUS = (1ULL<<1), // Include when asking for information_schema.global_status\n");
  653. printf("} toku_engine_status_include_type; \n");
  654. printf("typedef struct __toku_engine_status_row {\n");
  655. printf(" const char * keyname; // info schema key, should not change across revisions without good reason \n");
  656. printf(" const char * columnname; // column for mysql, e.g. information_schema.global_status. TOKUDB_ will automatically be prefixed.\n");
  657. printf(" const char * legend; // the text that will appear at user interface \n");
  658. printf(" toku_engine_status_display_type type; // how to interpret the value \n");
  659. printf(" toku_engine_status_include_type include; // which kinds of callers should get read this row?\n");
  660. printf(" union { \n");
  661. printf(" double dnum; \n");
  662. printf(" uint64_t num; \n");
  663. printf(" const char * str; \n");
  664. printf(" char datebuf[26]; \n");
  665. printf(" struct partitioned_counter *parcount;\n");
  666. printf(" } value; \n");
  667. printf("} * TOKU_ENGINE_STATUS_ROW, TOKU_ENGINE_STATUS_ROW_S; \n");
  668. print_dbtype();
  669. print_defines();
  670. printf("typedef int (*generate_row_for_put_func)(DB *dest_db, DB *src_db, DBT *dest_key, DBT *dest_val, const DBT *src_key, const DBT *src_val);\n");
  671. printf("typedef int (*generate_row_for_del_func)(DB *dest_db, DB *src_db, DBT *dest_key, const DBT *src_key, const DBT *src_val);\n");
  672. print_db_env_struct();
  673. print_db_key_range_struct();
  674. print_db_lsn_struct();
  675. print_dbt_struct();
  676. printf("typedef struct __toku_descriptor {\n");
  677. printf(" DBT dbt;\n");
  678. printf("} *DESCRIPTOR, DESCRIPTOR_S;\n");
  679. //file fragmentation info
  680. //a block is just a contiguous region in a file.
  681. printf("//One header is included in 'data'\n");
  682. printf("//One header is included in 'additional for checkpoint'\n");
  683. printf("typedef struct __toku_db_fragmentation {\n");
  684. printf(" uint64_t file_size_bytes; //Total file size in bytes\n");
  685. printf(" uint64_t data_bytes; //Compressed User Data in bytes\n");
  686. printf(" uint64_t data_blocks; //Number of blocks of compressed User Data\n");
  687. printf(" uint64_t checkpoint_bytes_additional; //Additional bytes used for checkpoint system\n");
  688. printf(" uint64_t checkpoint_blocks_additional; //Additional blocks used for checkpoint system \n");
  689. printf(" uint64_t unused_bytes; //Unused space in file\n");
  690. printf(" uint64_t unused_blocks; //Number of contiguous regions of unused space\n");
  691. printf(" uint64_t largest_unused_block; //Size of largest contiguous unused space\n");
  692. printf("} *TOKU_DB_FRAGMENTATION, TOKU_DB_FRAGMENTATION_S;\n");
  693. print_db_struct();
  694. print_db_txn_active_struct();
  695. printf("typedef struct __toku_txn_progress {\n");
  696. printf(" uint64_t entries_total;\n");
  697. printf(" uint64_t entries_processed;\n");
  698. printf(" uint8_t is_commit;\n");
  699. printf(" uint8_t stalled_on_checkpoint;\n");
  700. printf("} *TOKU_TXN_PROGRESS, TOKU_TXN_PROGRESS_S;\n");
  701. printf("typedef void(*TXN_PROGRESS_POLL_FUNCTION)(TOKU_TXN_PROGRESS, void*);\n");
  702. printf("struct txn_stat {\n uint64_t rollback_raw_count;\n uint64_t rollback_num_entries;\n};\n");
  703. print_db_txn_struct();
  704. print_db_txn_stat_struct();
  705. print_dbc_struct();
  706. printf("int db_env_create(DB_ENV **, uint32_t) %s;\n", VISIBLE);
  707. printf("int db_create(DB **, DB_ENV *, uint32_t) %s;\n", VISIBLE);
  708. printf("const char *db_strerror(int) %s;\n", VISIBLE);
  709. printf("const char *db_version(int*,int *,int *) %s;\n", VISIBLE);
  710. printf("int log_compare (const DB_LSN*, const DB_LSN *) %s;\n", VISIBLE);
  711. printf("int toku_set_trace_file (const char *fname) %s;\n", VISIBLE);
  712. printf("int toku_close_trace_file (void) %s;\n", VISIBLE);
  713. printf("void db_env_set_direct_io (bool direct_io_on) %s;\n", VISIBLE);
  714. printf("void db_env_set_func_fsync (int (*)(int)) %s;\n", VISIBLE);
  715. printf("void db_env_set_func_free (void (*)(void*)) %s;\n", VISIBLE);
  716. printf("void db_env_set_func_malloc (void *(*)(size_t)) %s;\n", VISIBLE);
  717. printf("void db_env_set_func_realloc (void *(*)(void*, size_t)) %s;\n", VISIBLE);
  718. printf("void db_env_set_func_pwrite (ssize_t (*)(int, const void *, size_t, toku_off_t)) %s;\n", VISIBLE);
  719. printf("void db_env_set_func_full_pwrite (ssize_t (*)(int, const void *, size_t, toku_off_t)) %s;\n", VISIBLE);
  720. printf("void db_env_set_func_write (ssize_t (*)(int, const void *, size_t)) %s;\n", VISIBLE);
  721. printf("void db_env_set_func_full_write (ssize_t (*)(int, const void *, size_t)) %s;\n", VISIBLE);
  722. printf("void db_env_set_func_fdopen (FILE* (*)(int, const char *)) %s;\n", VISIBLE);
  723. printf("void db_env_set_func_fopen (FILE* (*)(const char *, const char *)) %s;\n", VISIBLE);
  724. printf("void db_env_set_func_open (int (*)(const char *, int, int)) %s;\n", VISIBLE);
  725. printf("void db_env_set_func_fclose (int (*)(FILE*)) %s;\n", VISIBLE);
  726. printf("void db_env_set_func_pread (ssize_t (*)(int, void *, size_t, off_t)) %s;\n", VISIBLE);
  727. printf("void db_env_set_func_loader_fwrite (size_t (*fwrite_fun)(const void*,size_t,size_t,FILE*)) %s;\n", VISIBLE);
  728. printf("void db_env_set_checkpoint_callback (void (*)(void*), void*) %s;\n", VISIBLE);
  729. printf("void db_env_set_checkpoint_callback2 (void (*)(void*), void*) %s;\n", VISIBLE);
  730. printf("void db_env_set_recover_callback (void (*)(void*), void*) %s;\n", VISIBLE);
  731. printf("void db_env_set_recover_callback2 (void (*)(void*), void*) %s;\n", VISIBLE);
  732. printf("void db_env_set_loader_size_factor (uint32_t) %s;\n", VISIBLE);
  733. printf("void db_env_set_mvcc_garbage_collection_verification(uint32_t) %s;\n", VISIBLE);
  734. printf("void db_env_enable_engine_status(bool) %s;\n", VISIBLE);
  735. printf("void db_env_set_flusher_thread_callback (void (*)(int, void*), void*) %s;\n", VISIBLE);
  736. printf("void db_env_set_num_bucket_mutexes(uint32_t) %s;\n", VISIBLE);
  737. printf("int db_env_set_toku_product_name(const char*) %s;\n", VISIBLE);
  738. printf("#if defined(__cplusplus) || defined(__cilkplusplus)\n}\n#endif\n");
  739. printf("#endif\n");
  740. return 0;
  741. }