]> git.proxmox.com Git - ceph.git/blob - ceph/src/rocksdb/db/c_test.c
import quincy beta 17.1.0
[ceph.git] / ceph / src / rocksdb / db / c_test.c
1 /* Copyright (c) 2011 The LevelDB Authors. All rights reserved.
2 Use of this source code is governed by a BSD-style license that can be
3 found in the LICENSE file. See the AUTHORS file for names of contributors. */
4 // Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
5
6 #include <stdio.h>
7
8 #ifndef ROCKSDB_LITE // Lite does not support C API
9
10 #include "rocksdb/c.h"
11
12 #include <stddef.h>
13 #include <stdlib.h>
14 #include <string.h>
15 #include <sys/types.h>
16 #ifndef OS_WIN
17 #include <unistd.h>
18 #endif
19 #include <inttypes.h>
20
21 // Can not use port/port.h macros as this is a c file
22 #ifdef OS_WIN
23 #include <windows.h>
24
25 // Ok for uniqueness
26 int geteuid() {
27 int result = 0;
28
29 result = ((int)GetCurrentProcessId() << 16);
30 result |= (int)GetCurrentThreadId();
31
32 return result;
33 }
34
35 // VS < 2015
36 #if defined(_MSC_VER) && (_MSC_VER < 1900)
37 #define snprintf _snprintf
38 #endif
39
40 #endif
41
42 const char* phase = "";
43 static char dbname[200];
44 static char sstfilename[200];
45 static char dbbackupname[200];
46 static char dbcheckpointname[200];
47 static char dbpathname[200];
48 static char secondary_path[200];
49
50 static void StartPhase(const char* name) {
51 fprintf(stderr, "=== Test %s\n", name);
52 phase = name;
53 }
54 #ifdef _MSC_VER
55 #pragma warning(push)
56 #pragma warning (disable: 4996) // getenv security warning
57 #endif
58 static const char* GetTempDir(void) {
59 const char* ret = getenv("TEST_TMPDIR");
60 if (ret == NULL || ret[0] == '\0')
61 #ifdef OS_WIN
62 ret = getenv("TEMP");
63 #else
64 ret = "/tmp";
65 #endif
66 return ret;
67 }
68 #ifdef _MSC_VER
69 #pragma warning(pop)
70 #endif
71
72 #define CheckNoError(err) \
73 if ((err) != NULL) { \
74 fprintf(stderr, "%s:%d: %s: %s\n", __FILE__, __LINE__, phase, (err)); \
75 abort(); \
76 }
77
78 #define CheckCondition(cond) \
79 if (!(cond)) { \
80 fprintf(stderr, "%s:%d: %s: %s\n", __FILE__, __LINE__, phase, #cond); \
81 abort(); \
82 }
83
84 static void CheckEqual(const char* expected, const char* v, size_t n) {
85 if (expected == NULL && v == NULL) {
86 // ok
87 } else if (expected != NULL && v != NULL && n == strlen(expected) &&
88 memcmp(expected, v, n) == 0) {
89 // ok
90 return;
91 } else {
92 fprintf(stderr, "%s: expected '%s', got '%s'\n",
93 phase,
94 (expected ? expected : "(null)"),
95 (v ? v : "(null"));
96 abort();
97 }
98 }
99
100 static void Free(char** ptr) {
101 if (*ptr) {
102 free(*ptr);
103 *ptr = NULL;
104 }
105 }
106
107 static void CheckValue(
108 char* err,
109 const char* expected,
110 char** actual,
111 size_t actual_length) {
112 CheckNoError(err);
113 CheckEqual(expected, *actual, actual_length);
114 Free(actual);
115 }
116
117 static void CheckGet(
118 rocksdb_t* db,
119 const rocksdb_readoptions_t* options,
120 const char* key,
121 const char* expected) {
122 char* err = NULL;
123 size_t val_len;
124 char* val;
125 val = rocksdb_get(db, options, key, strlen(key), &val_len, &err);
126 CheckNoError(err);
127 CheckEqual(expected, val, val_len);
128 Free(&val);
129 }
130
131 static void CheckGetCF(
132 rocksdb_t* db,
133 const rocksdb_readoptions_t* options,
134 rocksdb_column_family_handle_t* handle,
135 const char* key,
136 const char* expected) {
137 char* err = NULL;
138 size_t val_len;
139 char* val;
140 val = rocksdb_get_cf(db, options, handle, key, strlen(key), &val_len, &err);
141 CheckNoError(err);
142 CheckEqual(expected, val, val_len);
143 Free(&val);
144 }
145
146 static void CheckPinGet(rocksdb_t* db, const rocksdb_readoptions_t* options,
147 const char* key, const char* expected) {
148 char* err = NULL;
149 size_t val_len;
150 const char* val;
151 rocksdb_pinnableslice_t* p;
152 p = rocksdb_get_pinned(db, options, key, strlen(key), &err);
153 CheckNoError(err);
154 val = rocksdb_pinnableslice_value(p, &val_len);
155 CheckEqual(expected, val, val_len);
156 rocksdb_pinnableslice_destroy(p);
157 }
158
159 static void CheckPinGetCF(rocksdb_t* db, const rocksdb_readoptions_t* options,
160 rocksdb_column_family_handle_t* handle,
161 const char* key, const char* expected) {
162 char* err = NULL;
163 size_t val_len;
164 const char* val;
165 rocksdb_pinnableslice_t* p;
166 p = rocksdb_get_pinned_cf(db, options, handle, key, strlen(key), &err);
167 CheckNoError(err);
168 val = rocksdb_pinnableslice_value(p, &val_len);
169 CheckEqual(expected, val, val_len);
170 rocksdb_pinnableslice_destroy(p);
171 }
172
173 static void CheckIter(rocksdb_iterator_t* iter,
174 const char* key, const char* val) {
175 size_t len;
176 const char* str;
177 str = rocksdb_iter_key(iter, &len);
178 CheckEqual(key, str, len);
179 str = rocksdb_iter_value(iter, &len);
180 CheckEqual(val, str, len);
181 }
182
183 // Callback from rocksdb_writebatch_iterate()
184 static void CheckPut(void* ptr,
185 const char* k, size_t klen,
186 const char* v, size_t vlen) {
187 int* state = (int*) ptr;
188 CheckCondition(*state < 2);
189 switch (*state) {
190 case 0:
191 CheckEqual("bar", k, klen);
192 CheckEqual("b", v, vlen);
193 break;
194 case 1:
195 CheckEqual("box", k, klen);
196 CheckEqual("c", v, vlen);
197 break;
198 }
199 (*state)++;
200 }
201
202 // Callback from rocksdb_writebatch_iterate()
203 static void CheckDel(void* ptr, const char* k, size_t klen) {
204 int* state = (int*) ptr;
205 CheckCondition(*state == 2);
206 CheckEqual("bar", k, klen);
207 (*state)++;
208 }
209
210 static void CmpDestroy(void* arg) { (void)arg; }
211
212 static int CmpCompare(void* arg, const char* a, size_t alen,
213 const char* b, size_t blen) {
214 (void)arg;
215 size_t n = (alen < blen) ? alen : blen;
216 int r = memcmp(a, b, n);
217 if (r == 0) {
218 if (alen < blen) r = -1;
219 else if (alen > blen) r = +1;
220 }
221 return r;
222 }
223
224 static const char* CmpName(void* arg) {
225 (void)arg;
226 return "foo";
227 }
228
229 // Custom filter policy
230 static unsigned char fake_filter_result = 1;
231 static void FilterDestroy(void* arg) { (void)arg; }
232 static const char* FilterName(void* arg) {
233 (void)arg;
234 return "TestFilter";
235 }
236 static char* FilterCreate(
237 void* arg,
238 const char* const* key_array, const size_t* key_length_array,
239 int num_keys,
240 size_t* filter_length) {
241 (void)arg;
242 (void)key_array;
243 (void)key_length_array;
244 (void)num_keys;
245 *filter_length = 4;
246 char* result = malloc(4);
247 memcpy(result, "fake", 4);
248 return result;
249 }
250 static unsigned char FilterKeyMatch(
251 void* arg,
252 const char* key, size_t length,
253 const char* filter, size_t filter_length) {
254 (void)arg;
255 (void)key;
256 (void)length;
257 CheckCondition(filter_length == 4);
258 CheckCondition(memcmp(filter, "fake", 4) == 0);
259 return fake_filter_result;
260 }
261
262 // Custom compaction filter
263 static void CFilterDestroy(void* arg) { (void)arg; }
264 static const char* CFilterName(void* arg) {
265 (void)arg;
266 return "foo";
267 }
268 static unsigned char CFilterFilter(void* arg, int level, const char* key,
269 size_t key_length,
270 const char* existing_value,
271 size_t value_length, char** new_value,
272 size_t* new_value_length,
273 unsigned char* value_changed) {
274 (void)arg;
275 (void)level;
276 (void)existing_value;
277 (void)value_length;
278 if (key_length == 3) {
279 if (memcmp(key, "bar", key_length) == 0) {
280 return 1;
281 } else if (memcmp(key, "baz", key_length) == 0) {
282 *value_changed = 1;
283 *new_value = "newbazvalue";
284 *new_value_length = 11;
285 return 0;
286 }
287 }
288 return 0;
289 }
290
291 static void CFilterFactoryDestroy(void* arg) { (void)arg; }
292 static const char* CFilterFactoryName(void* arg) {
293 (void)arg;
294 return "foo";
295 }
296 static rocksdb_compactionfilter_t* CFilterCreate(
297 void* arg, rocksdb_compactionfiltercontext_t* context) {
298 (void)arg;
299 (void)context;
300 return rocksdb_compactionfilter_create(NULL, CFilterDestroy, CFilterFilter,
301 CFilterName);
302 }
303
304 static rocksdb_t* CheckCompaction(rocksdb_t* db, rocksdb_options_t* options,
305 rocksdb_readoptions_t* roptions,
306 rocksdb_writeoptions_t* woptions) {
307 char* err = NULL;
308 db = rocksdb_open(options, dbname, &err);
309 CheckNoError(err);
310 rocksdb_put(db, woptions, "foo", 3, "foovalue", 8, &err);
311 CheckNoError(err);
312 CheckGet(db, roptions, "foo", "foovalue");
313 rocksdb_put(db, woptions, "bar", 3, "barvalue", 8, &err);
314 CheckNoError(err);
315 CheckGet(db, roptions, "bar", "barvalue");
316 rocksdb_put(db, woptions, "baz", 3, "bazvalue", 8, &err);
317 CheckNoError(err);
318 CheckGet(db, roptions, "baz", "bazvalue");
319
320 // Force compaction
321 rocksdb_compact_range(db, NULL, 0, NULL, 0);
322 // should have filtered bar, but not foo
323 CheckGet(db, roptions, "foo", "foovalue");
324 CheckGet(db, roptions, "bar", NULL);
325 CheckGet(db, roptions, "baz", "newbazvalue");
326 return db;
327 }
328
329 // Custom merge operator
330 static void MergeOperatorDestroy(void* arg) { (void)arg; }
331 static const char* MergeOperatorName(void* arg) {
332 (void)arg;
333 return "TestMergeOperator";
334 }
335 static char* MergeOperatorFullMerge(
336 void* arg,
337 const char* key, size_t key_length,
338 const char* existing_value, size_t existing_value_length,
339 const char* const* operands_list, const size_t* operands_list_length,
340 int num_operands,
341 unsigned char* success, size_t* new_value_length) {
342 (void)arg;
343 (void)key;
344 (void)key_length;
345 (void)existing_value;
346 (void)existing_value_length;
347 (void)operands_list;
348 (void)operands_list_length;
349 (void)num_operands;
350 *new_value_length = 4;
351 *success = 1;
352 char* result = malloc(4);
353 memcpy(result, "fake", 4);
354 return result;
355 }
356 static char* MergeOperatorPartialMerge(
357 void* arg,
358 const char* key, size_t key_length,
359 const char* const* operands_list, const size_t* operands_list_length,
360 int num_operands,
361 unsigned char* success, size_t* new_value_length) {
362 (void)arg;
363 (void)key;
364 (void)key_length;
365 (void)operands_list;
366 (void)operands_list_length;
367 (void)num_operands;
368 *new_value_length = 4;
369 *success = 1;
370 char* result = malloc(4);
371 memcpy(result, "fake", 4);
372 return result;
373 }
374
375 static void CheckTxnGet(
376 rocksdb_transaction_t* txn,
377 const rocksdb_readoptions_t* options,
378 const char* key,
379 const char* expected) {
380 char* err = NULL;
381 size_t val_len;
382 char* val;
383 val = rocksdb_transaction_get(txn, options, key, strlen(key), &val_len, &err);
384 CheckNoError(err);
385 CheckEqual(expected, val, val_len);
386 Free(&val);
387 }
388
389 static void CheckTxnGetCF(rocksdb_transaction_t* txn,
390 const rocksdb_readoptions_t* options,
391 rocksdb_column_family_handle_t* column_family,
392 const char* key, const char* expected) {
393 char* err = NULL;
394 size_t val_len;
395 char* val;
396 val = rocksdb_transaction_get_cf(txn, options, column_family, key,
397 strlen(key), &val_len, &err);
398 CheckNoError(err);
399 CheckEqual(expected, val, val_len);
400 Free(&val);
401 }
402
403 static void CheckTxnDBGet(
404 rocksdb_transactiondb_t* txn_db,
405 const rocksdb_readoptions_t* options,
406 const char* key,
407 const char* expected) {
408 char* err = NULL;
409 size_t val_len;
410 char* val;
411 val = rocksdb_transactiondb_get(txn_db, options, key, strlen(key), &val_len, &err);
412 CheckNoError(err);
413 CheckEqual(expected, val, val_len);
414 Free(&val);
415 }
416
417 static void CheckTxnDBGetCF(rocksdb_transactiondb_t* txn_db,
418 const rocksdb_readoptions_t* options,
419 rocksdb_column_family_handle_t* column_family,
420 const char* key, const char* expected) {
421 char* err = NULL;
422 size_t val_len;
423 char* val;
424 val = rocksdb_transactiondb_get_cf(txn_db, options, column_family, key,
425 strlen(key), &val_len, &err);
426 CheckNoError(err);
427 CheckEqual(expected, val, val_len);
428 Free(&val);
429 }
430
431 int main(int argc, char** argv) {
432 (void)argc;
433 (void)argv;
434 rocksdb_t* db;
435 rocksdb_comparator_t* cmp;
436 rocksdb_cache_t* cache;
437 rocksdb_dbpath_t *dbpath;
438 rocksdb_env_t* env;
439 rocksdb_options_t* options;
440 rocksdb_compactoptions_t* coptions;
441 rocksdb_block_based_table_options_t* table_options;
442 rocksdb_readoptions_t* roptions;
443 rocksdb_writeoptions_t* woptions;
444 rocksdb_ratelimiter_t* rate_limiter;
445 rocksdb_transactiondb_t* txn_db;
446 rocksdb_transactiondb_options_t* txn_db_options;
447 rocksdb_transaction_t* txn;
448 rocksdb_transaction_options_t* txn_options;
449 rocksdb_optimistictransactiondb_t* otxn_db;
450 rocksdb_optimistictransaction_options_t* otxn_options;
451 char* err = NULL;
452 int run = -1;
453
454 snprintf(dbname, sizeof(dbname),
455 "%s/rocksdb_c_test-%d",
456 GetTempDir(),
457 ((int) geteuid()));
458
459 snprintf(dbbackupname, sizeof(dbbackupname),
460 "%s/rocksdb_c_test-%d-backup",
461 GetTempDir(),
462 ((int) geteuid()));
463
464 snprintf(dbcheckpointname, sizeof(dbcheckpointname),
465 "%s/rocksdb_c_test-%d-checkpoint",
466 GetTempDir(),
467 ((int) geteuid()));
468
469 snprintf(sstfilename, sizeof(sstfilename),
470 "%s/rocksdb_c_test-%d-sst",
471 GetTempDir(),
472 ((int)geteuid()));
473
474 snprintf(dbpathname, sizeof(dbpathname),
475 "%s/rocksdb_c_test-%d-dbpath",
476 GetTempDir(),
477 ((int) geteuid()));
478
479 StartPhase("create_objects");
480 cmp = rocksdb_comparator_create(NULL, CmpDestroy, CmpCompare, CmpName);
481 dbpath = rocksdb_dbpath_create(dbpathname, 1024 * 1024);
482 env = rocksdb_create_default_env();
483 cache = rocksdb_cache_create_lru(100000);
484
485 options = rocksdb_options_create();
486 rocksdb_options_set_comparator(options, cmp);
487 rocksdb_options_set_error_if_exists(options, 1);
488 rocksdb_options_set_env(options, env);
489 rocksdb_options_set_info_log(options, NULL);
490 rocksdb_options_set_write_buffer_size(options, 100000);
491 rocksdb_options_set_paranoid_checks(options, 1);
492 rocksdb_options_set_max_open_files(options, 10);
493 rocksdb_options_set_base_background_compactions(options, 1);
494
495 table_options = rocksdb_block_based_options_create();
496 rocksdb_block_based_options_set_block_cache(table_options, cache);
497 rocksdb_block_based_options_set_data_block_index_type(table_options, 1);
498 rocksdb_block_based_options_set_data_block_hash_ratio(table_options, 0.75);
499 rocksdb_options_set_block_based_table_factory(options, table_options);
500
501 rocksdb_options_set_compression(options, rocksdb_no_compression);
502 rocksdb_options_set_compression_options(options, -14, -1, 0, 0);
503 int compression_levels[] = {rocksdb_no_compression, rocksdb_no_compression,
504 rocksdb_no_compression, rocksdb_no_compression};
505 rocksdb_options_set_compression_per_level(options, compression_levels, 4);
506 rate_limiter = rocksdb_ratelimiter_create(1000 * 1024 * 1024, 100 * 1000, 10);
507 rocksdb_options_set_ratelimiter(options, rate_limiter);
508 rocksdb_ratelimiter_destroy(rate_limiter);
509
510 roptions = rocksdb_readoptions_create();
511 rocksdb_readoptions_set_verify_checksums(roptions, 1);
512 rocksdb_readoptions_set_fill_cache(roptions, 1);
513
514 woptions = rocksdb_writeoptions_create();
515 rocksdb_writeoptions_set_sync(woptions, 1);
516
517 coptions = rocksdb_compactoptions_create();
518 rocksdb_compactoptions_set_exclusive_manual_compaction(coptions, 1);
519
520 StartPhase("destroy");
521 rocksdb_destroy_db(options, dbname, &err);
522 Free(&err);
523
524 StartPhase("open_error");
525 rocksdb_open(options, dbname, &err);
526 CheckCondition(err != NULL);
527 Free(&err);
528
529 StartPhase("open");
530 rocksdb_options_set_create_if_missing(options, 1);
531 db = rocksdb_open(options, dbname, &err);
532 CheckNoError(err);
533 CheckGet(db, roptions, "foo", NULL);
534
535 StartPhase("put");
536 rocksdb_put(db, woptions, "foo", 3, "hello", 5, &err);
537 CheckNoError(err);
538 CheckGet(db, roptions, "foo", "hello");
539
540 StartPhase("backup_and_restore");
541 {
542 rocksdb_destroy_db(options, dbbackupname, &err);
543 CheckNoError(err);
544
545 rocksdb_backup_engine_t *be = rocksdb_backup_engine_open(options, dbbackupname, &err);
546 CheckNoError(err);
547
548 rocksdb_backup_engine_create_new_backup(be, db, &err);
549 CheckNoError(err);
550
551 // need a change to trigger a new backup
552 rocksdb_delete(db, woptions, "does-not-exist", 14, &err);
553 CheckNoError(err);
554
555 rocksdb_backup_engine_create_new_backup(be, db, &err);
556 CheckNoError(err);
557
558 const rocksdb_backup_engine_info_t* bei = rocksdb_backup_engine_get_backup_info(be);
559 CheckCondition(rocksdb_backup_engine_info_count(bei) > 1);
560 rocksdb_backup_engine_info_destroy(bei);
561
562 rocksdb_backup_engine_purge_old_backups(be, 1, &err);
563 CheckNoError(err);
564
565 bei = rocksdb_backup_engine_get_backup_info(be);
566 CheckCondition(rocksdb_backup_engine_info_count(bei) == 1);
567 rocksdb_backup_engine_info_destroy(bei);
568
569 rocksdb_delete(db, woptions, "foo", 3, &err);
570 CheckNoError(err);
571
572 rocksdb_close(db);
573
574 rocksdb_destroy_db(options, dbname, &err);
575 CheckNoError(err);
576
577 rocksdb_restore_options_t *restore_options = rocksdb_restore_options_create();
578 rocksdb_restore_options_set_keep_log_files(restore_options, 0);
579 rocksdb_backup_engine_restore_db_from_latest_backup(be, dbname, dbname, restore_options, &err);
580 CheckNoError(err);
581 rocksdb_restore_options_destroy(restore_options);
582
583 rocksdb_options_set_error_if_exists(options, 0);
584 db = rocksdb_open(options, dbname, &err);
585 CheckNoError(err);
586 rocksdb_options_set_error_if_exists(options, 1);
587
588 CheckGet(db, roptions, "foo", "hello");
589
590 rocksdb_backup_engine_close(be);
591 }
592
593 StartPhase("checkpoint");
594 {
595 rocksdb_destroy_db(options, dbcheckpointname, &err);
596 CheckNoError(err);
597
598 rocksdb_checkpoint_t* checkpoint = rocksdb_checkpoint_object_create(db, &err);
599 CheckNoError(err);
600
601 rocksdb_checkpoint_create(checkpoint, dbcheckpointname, 0, &err);
602 CheckNoError(err);
603
604 // start a new database from the checkpoint
605 rocksdb_close(db);
606 rocksdb_options_set_error_if_exists(options, 0);
607 db = rocksdb_open(options, dbcheckpointname, &err);
608 CheckNoError(err);
609
610 CheckGet(db, roptions, "foo", "hello");
611
612 rocksdb_checkpoint_object_destroy(checkpoint);
613
614 rocksdb_close(db);
615 rocksdb_destroy_db(options, dbcheckpointname, &err);
616 CheckNoError(err);
617
618 db = rocksdb_open(options, dbname, &err);
619 CheckNoError(err);
620 rocksdb_options_set_error_if_exists(options, 1);
621 }
622
623 StartPhase("compactall");
624 rocksdb_compact_range(db, NULL, 0, NULL, 0);
625 CheckGet(db, roptions, "foo", "hello");
626
627 StartPhase("compactrange");
628 rocksdb_compact_range(db, "a", 1, "z", 1);
629 CheckGet(db, roptions, "foo", "hello");
630
631 StartPhase("compactallopt");
632 rocksdb_compact_range_opt(db, coptions, NULL, 0, NULL, 0);
633 CheckGet(db, roptions, "foo", "hello");
634
635 StartPhase("compactrangeopt");
636 rocksdb_compact_range_opt(db, coptions, "a", 1, "z", 1);
637 CheckGet(db, roptions, "foo", "hello");
638
639 // Simple check cache usage
640 StartPhase("cache_usage");
641 {
642 rocksdb_readoptions_set_pin_data(roptions, 1);
643 rocksdb_iterator_t* iter = rocksdb_create_iterator(db, roptions);
644 rocksdb_iter_seek(iter, "foo", 3);
645
646 size_t usage = rocksdb_cache_get_usage(cache);
647 CheckCondition(usage > 0);
648
649 size_t pin_usage = rocksdb_cache_get_pinned_usage(cache);
650 CheckCondition(pin_usage > 0);
651
652 rocksdb_iter_next(iter);
653 rocksdb_iter_destroy(iter);
654 rocksdb_readoptions_set_pin_data(roptions, 0);
655 }
656
657 StartPhase("addfile");
658 {
659 rocksdb_envoptions_t* env_opt = rocksdb_envoptions_create();
660 rocksdb_options_t* io_options = rocksdb_options_create();
661 rocksdb_sstfilewriter_t* writer =
662 rocksdb_sstfilewriter_create(env_opt, io_options);
663
664 remove(sstfilename);
665 rocksdb_sstfilewriter_open(writer, sstfilename, &err);
666 CheckNoError(err);
667 rocksdb_sstfilewriter_put(writer, "sstk1", 5, "v1", 2, &err);
668 CheckNoError(err);
669 rocksdb_sstfilewriter_put(writer, "sstk2", 5, "v2", 2, &err);
670 CheckNoError(err);
671 rocksdb_sstfilewriter_put(writer, "sstk3", 5, "v3", 2, &err);
672 CheckNoError(err);
673 rocksdb_sstfilewriter_finish(writer, &err);
674 CheckNoError(err);
675
676 rocksdb_ingestexternalfileoptions_t* ing_opt =
677 rocksdb_ingestexternalfileoptions_create();
678 const char* file_list[1] = {sstfilename};
679 rocksdb_ingest_external_file(db, file_list, 1, ing_opt, &err);
680 CheckNoError(err);
681 CheckGet(db, roptions, "sstk1", "v1");
682 CheckGet(db, roptions, "sstk2", "v2");
683 CheckGet(db, roptions, "sstk3", "v3");
684
685 remove(sstfilename);
686 rocksdb_sstfilewriter_open(writer, sstfilename, &err);
687 CheckNoError(err);
688 rocksdb_sstfilewriter_put(writer, "sstk2", 5, "v4", 2, &err);
689 CheckNoError(err);
690 rocksdb_sstfilewriter_put(writer, "sstk22", 6, "v5", 2, &err);
691 CheckNoError(err);
692 rocksdb_sstfilewriter_put(writer, "sstk3", 5, "v6", 2, &err);
693 CheckNoError(err);
694 rocksdb_sstfilewriter_finish(writer, &err);
695 CheckNoError(err);
696
697 rocksdb_ingest_external_file(db, file_list, 1, ing_opt, &err);
698 CheckNoError(err);
699 CheckGet(db, roptions, "sstk1", "v1");
700 CheckGet(db, roptions, "sstk2", "v4");
701 CheckGet(db, roptions, "sstk22", "v5");
702 CheckGet(db, roptions, "sstk3", "v6");
703
704 rocksdb_ingestexternalfileoptions_destroy(ing_opt);
705 rocksdb_sstfilewriter_destroy(writer);
706 rocksdb_options_destroy(io_options);
707 rocksdb_envoptions_destroy(env_opt);
708
709 // Delete all keys we just ingested
710 rocksdb_delete(db, woptions, "sstk1", 5, &err);
711 CheckNoError(err);
712 rocksdb_delete(db, woptions, "sstk2", 5, &err);
713 CheckNoError(err);
714 rocksdb_delete(db, woptions, "sstk22", 6, &err);
715 CheckNoError(err);
716 rocksdb_delete(db, woptions, "sstk3", 5, &err);
717 CheckNoError(err);
718 }
719
720 StartPhase("writebatch");
721 {
722 rocksdb_writebatch_t* wb = rocksdb_writebatch_create();
723 rocksdb_writebatch_put(wb, "foo", 3, "a", 1);
724 rocksdb_writebatch_clear(wb);
725 rocksdb_writebatch_put(wb, "bar", 3, "b", 1);
726 rocksdb_writebatch_put(wb, "box", 3, "c", 1);
727 rocksdb_writebatch_delete(wb, "bar", 3);
728 rocksdb_write(db, woptions, wb, &err);
729 CheckNoError(err);
730 CheckGet(db, roptions, "foo", "hello");
731 CheckGet(db, roptions, "bar", NULL);
732 CheckGet(db, roptions, "box", "c");
733 int pos = 0;
734 rocksdb_writebatch_iterate(wb, &pos, CheckPut, CheckDel);
735 CheckCondition(pos == 3);
736 rocksdb_writebatch_clear(wb);
737 rocksdb_writebatch_put(wb, "bar", 3, "b", 1);
738 rocksdb_writebatch_put(wb, "bay", 3, "d", 1);
739 rocksdb_writebatch_delete_range(wb, "bar", 3, "bay", 3);
740 rocksdb_write(db, woptions, wb, &err);
741 CheckNoError(err);
742 CheckGet(db, roptions, "bar", NULL);
743 CheckGet(db, roptions, "bay", "d");
744 rocksdb_writebatch_clear(wb);
745 const char* start_list[1] = {"bay"};
746 const size_t start_sizes[1] = {3};
747 const char* end_list[1] = {"baz"};
748 const size_t end_sizes[1] = {3};
749 rocksdb_writebatch_delete_rangev(wb, 1, start_list, start_sizes, end_list,
750 end_sizes);
751 rocksdb_write(db, woptions, wb, &err);
752 CheckNoError(err);
753 CheckGet(db, roptions, "bay", NULL);
754 rocksdb_writebatch_destroy(wb);
755 }
756
757 StartPhase("writebatch_vectors");
758 {
759 rocksdb_writebatch_t* wb = rocksdb_writebatch_create();
760 const char* k_list[2] = { "z", "ap" };
761 const size_t k_sizes[2] = { 1, 2 };
762 const char* v_list[3] = { "x", "y", "z" };
763 const size_t v_sizes[3] = { 1, 1, 1 };
764 rocksdb_writebatch_putv(wb, 2, k_list, k_sizes, 3, v_list, v_sizes);
765 rocksdb_write(db, woptions, wb, &err);
766 CheckNoError(err);
767 CheckGet(db, roptions, "zap", "xyz");
768 rocksdb_writebatch_delete(wb, "zap", 3);
769 rocksdb_write(db, woptions, wb, &err);
770 CheckNoError(err);
771 CheckGet(db, roptions, "zap", NULL);
772 rocksdb_writebatch_destroy(wb);
773 }
774
775 StartPhase("writebatch_savepoint");
776 {
777 rocksdb_writebatch_t* wb = rocksdb_writebatch_create();
778 rocksdb_writebatch_set_save_point(wb);
779 rocksdb_writebatch_set_save_point(wb);
780 const char* k_list[2] = {"z", "ap"};
781 const size_t k_sizes[2] = {1, 2};
782 const char* v_list[3] = {"x", "y", "z"};
783 const size_t v_sizes[3] = {1, 1, 1};
784 rocksdb_writebatch_pop_save_point(wb, &err);
785 CheckNoError(err);
786 rocksdb_writebatch_putv(wb, 2, k_list, k_sizes, 3, v_list, v_sizes);
787 rocksdb_writebatch_rollback_to_save_point(wb, &err);
788 CheckNoError(err);
789 rocksdb_write(db, woptions, wb, &err);
790 CheckNoError(err);
791 CheckGet(db, roptions, "zap", NULL);
792 rocksdb_writebatch_destroy(wb);
793 }
794
795 StartPhase("writebatch_rep");
796 {
797 rocksdb_writebatch_t* wb1 = rocksdb_writebatch_create();
798 rocksdb_writebatch_put(wb1, "baz", 3, "d", 1);
799 rocksdb_writebatch_put(wb1, "quux", 4, "e", 1);
800 rocksdb_writebatch_delete(wb1, "quux", 4);
801 size_t repsize1 = 0;
802 const char* rep = rocksdb_writebatch_data(wb1, &repsize1);
803 rocksdb_writebatch_t* wb2 = rocksdb_writebatch_create_from(rep, repsize1);
804 CheckCondition(rocksdb_writebatch_count(wb1) ==
805 rocksdb_writebatch_count(wb2));
806 size_t repsize2 = 0;
807 CheckCondition(
808 memcmp(rep, rocksdb_writebatch_data(wb2, &repsize2), repsize1) == 0);
809 rocksdb_writebatch_destroy(wb1);
810 rocksdb_writebatch_destroy(wb2);
811 }
812
813 StartPhase("writebatch_wi");
814 {
815 rocksdb_writebatch_wi_t* wbi = rocksdb_writebatch_wi_create(0, 1);
816 rocksdb_writebatch_wi_put(wbi, "foo", 3, "a", 1);
817 rocksdb_writebatch_wi_clear(wbi);
818 rocksdb_writebatch_wi_put(wbi, "bar", 3, "b", 1);
819 rocksdb_writebatch_wi_put(wbi, "box", 3, "c", 1);
820 rocksdb_writebatch_wi_delete(wbi, "bar", 3);
821 int count = rocksdb_writebatch_wi_count(wbi);
822 CheckCondition(count == 3);
823 size_t size;
824 char* value;
825 value = rocksdb_writebatch_wi_get_from_batch(wbi, options, "box", 3, &size, &err);
826 CheckValue(err, "c", &value, size);
827 value = rocksdb_writebatch_wi_get_from_batch(wbi, options, "bar", 3, &size, &err);
828 CheckValue(err, NULL, &value, size);
829 value = rocksdb_writebatch_wi_get_from_batch_and_db(wbi, db, roptions, "foo", 3, &size, &err);
830 CheckValue(err, "hello", &value, size);
831 value = rocksdb_writebatch_wi_get_from_batch_and_db(wbi, db, roptions, "box", 3, &size, &err);
832 CheckValue(err, "c", &value, size);
833 rocksdb_write_writebatch_wi(db, woptions, wbi, &err);
834 CheckNoError(err);
835 CheckGet(db, roptions, "foo", "hello");
836 CheckGet(db, roptions, "bar", NULL);
837 CheckGet(db, roptions, "box", "c");
838 int pos = 0;
839 rocksdb_writebatch_wi_iterate(wbi, &pos, CheckPut, CheckDel);
840 CheckCondition(pos == 3);
841 rocksdb_writebatch_wi_clear(wbi);
842 rocksdb_writebatch_wi_destroy(wbi);
843 }
844
845 StartPhase("writebatch_wi_vectors");
846 {
847 rocksdb_writebatch_wi_t* wb = rocksdb_writebatch_wi_create(0, 1);
848 const char* k_list[2] = { "z", "ap" };
849 const size_t k_sizes[2] = { 1, 2 };
850 const char* v_list[3] = { "x", "y", "z" };
851 const size_t v_sizes[3] = { 1, 1, 1 };
852 rocksdb_writebatch_wi_putv(wb, 2, k_list, k_sizes, 3, v_list, v_sizes);
853 rocksdb_write_writebatch_wi(db, woptions, wb, &err);
854 CheckNoError(err);
855 CheckGet(db, roptions, "zap", "xyz");
856 rocksdb_writebatch_wi_delete(wb, "zap", 3);
857 rocksdb_write_writebatch_wi(db, woptions, wb, &err);
858 CheckNoError(err);
859 CheckGet(db, roptions, "zap", NULL);
860 rocksdb_writebatch_wi_destroy(wb);
861 }
862
863 StartPhase("writebatch_wi_savepoint");
864 {
865 rocksdb_writebatch_wi_t* wb = rocksdb_writebatch_wi_create(0, 1);
866 rocksdb_writebatch_wi_set_save_point(wb);
867 const char* k_list[2] = {"z", "ap"};
868 const size_t k_sizes[2] = {1, 2};
869 const char* v_list[3] = {"x", "y", "z"};
870 const size_t v_sizes[3] = {1, 1, 1};
871 rocksdb_writebatch_wi_putv(wb, 2, k_list, k_sizes, 3, v_list, v_sizes);
872 rocksdb_writebatch_wi_rollback_to_save_point(wb, &err);
873 CheckNoError(err);
874 rocksdb_write_writebatch_wi(db, woptions, wb, &err);
875 CheckNoError(err);
876 CheckGet(db, roptions, "zap", NULL);
877 rocksdb_writebatch_wi_destroy(wb);
878 }
879
880 StartPhase("iter");
881 {
882 rocksdb_iterator_t* iter = rocksdb_create_iterator(db, roptions);
883 CheckCondition(!rocksdb_iter_valid(iter));
884 rocksdb_iter_seek_to_first(iter);
885 CheckCondition(rocksdb_iter_valid(iter));
886 CheckIter(iter, "box", "c");
887 rocksdb_iter_next(iter);
888 CheckIter(iter, "foo", "hello");
889 rocksdb_iter_prev(iter);
890 CheckIter(iter, "box", "c");
891 rocksdb_iter_prev(iter);
892 CheckCondition(!rocksdb_iter_valid(iter));
893 rocksdb_iter_seek_to_last(iter);
894 CheckIter(iter, "foo", "hello");
895 rocksdb_iter_seek(iter, "b", 1);
896 CheckIter(iter, "box", "c");
897 rocksdb_iter_seek_for_prev(iter, "g", 1);
898 CheckIter(iter, "foo", "hello");
899 rocksdb_iter_seek_for_prev(iter, "box", 3);
900 CheckIter(iter, "box", "c");
901 rocksdb_iter_get_error(iter, &err);
902 CheckNoError(err);
903 rocksdb_iter_destroy(iter);
904 }
905
906 StartPhase("wbwi_iter");
907 {
908 rocksdb_iterator_t* base_iter = rocksdb_create_iterator(db, roptions);
909 rocksdb_writebatch_wi_t* wbi = rocksdb_writebatch_wi_create(0, 1);
910 rocksdb_writebatch_wi_put(wbi, "bar", 3, "b", 1);
911 rocksdb_writebatch_wi_delete(wbi, "foo", 3);
912 rocksdb_iterator_t* iter =
913 rocksdb_writebatch_wi_create_iterator_with_base(wbi, base_iter);
914 CheckCondition(!rocksdb_iter_valid(iter));
915 rocksdb_iter_seek_to_first(iter);
916 CheckCondition(rocksdb_iter_valid(iter));
917 CheckIter(iter, "bar", "b");
918 rocksdb_iter_next(iter);
919 CheckIter(iter, "box", "c");
920 rocksdb_iter_prev(iter);
921 CheckIter(iter, "bar", "b");
922 rocksdb_iter_prev(iter);
923 CheckCondition(!rocksdb_iter_valid(iter));
924 rocksdb_iter_seek_to_last(iter);
925 CheckIter(iter, "box", "c");
926 rocksdb_iter_seek(iter, "b", 1);
927 CheckIter(iter, "bar", "b");
928 rocksdb_iter_seek_for_prev(iter, "c", 1);
929 CheckIter(iter, "box", "c");
930 rocksdb_iter_seek_for_prev(iter, "box", 3);
931 CheckIter(iter, "box", "c");
932 rocksdb_iter_get_error(iter, &err);
933 CheckNoError(err);
934 rocksdb_iter_destroy(iter);
935 rocksdb_writebatch_wi_destroy(wbi);
936 }
937
938 StartPhase("multiget");
939 {
940 const char* keys[3] = { "box", "foo", "notfound" };
941 const size_t keys_sizes[3] = { 3, 3, 8 };
942 char* vals[3];
943 size_t vals_sizes[3];
944 char* errs[3];
945 rocksdb_multi_get(db, roptions, 3, keys, keys_sizes, vals, vals_sizes, errs);
946
947 int i;
948 for (i = 0; i < 3; i++) {
949 CheckEqual(NULL, errs[i], 0);
950 switch (i) {
951 case 0:
952 CheckEqual("c", vals[i], vals_sizes[i]);
953 break;
954 case 1:
955 CheckEqual("hello", vals[i], vals_sizes[i]);
956 break;
957 case 2:
958 CheckEqual(NULL, vals[i], vals_sizes[i]);
959 break;
960 }
961 Free(&vals[i]);
962 }
963 }
964
965 StartPhase("pin_get");
966 {
967 CheckPinGet(db, roptions, "box", "c");
968 CheckPinGet(db, roptions, "foo", "hello");
969 CheckPinGet(db, roptions, "notfound", NULL);
970 }
971
972 StartPhase("approximate_sizes");
973 {
974 int i;
975 int n = 20000;
976 char keybuf[100];
977 char valbuf[100];
978 uint64_t sizes[2];
979 const char* start[2] = { "a", "k00000000000000010000" };
980 size_t start_len[2] = { 1, 21 };
981 const char* limit[2] = { "k00000000000000010000", "z" };
982 size_t limit_len[2] = { 21, 1 };
983 rocksdb_writeoptions_set_sync(woptions, 0);
984 for (i = 0; i < n; i++) {
985 snprintf(keybuf, sizeof(keybuf), "k%020d", i);
986 snprintf(valbuf, sizeof(valbuf), "v%020d", i);
987 rocksdb_put(db, woptions, keybuf, strlen(keybuf), valbuf, strlen(valbuf),
988 &err);
989 CheckNoError(err);
990 }
991 rocksdb_approximate_sizes(db, 2, start, start_len, limit, limit_len, sizes);
992 CheckCondition(sizes[0] > 0);
993 CheckCondition(sizes[1] > 0);
994 }
995
996 StartPhase("property");
997 {
998 char* prop = rocksdb_property_value(db, "nosuchprop");
999 CheckCondition(prop == NULL);
1000 prop = rocksdb_property_value(db, "rocksdb.stats");
1001 CheckCondition(prop != NULL);
1002 Free(&prop);
1003 }
1004
1005 StartPhase("snapshot");
1006 {
1007 const rocksdb_snapshot_t* snap;
1008 snap = rocksdb_create_snapshot(db);
1009 rocksdb_delete(db, woptions, "foo", 3, &err);
1010 CheckNoError(err);
1011 rocksdb_readoptions_set_snapshot(roptions, snap);
1012 CheckGet(db, roptions, "foo", "hello");
1013 rocksdb_readoptions_set_snapshot(roptions, NULL);
1014 CheckGet(db, roptions, "foo", NULL);
1015 rocksdb_release_snapshot(db, snap);
1016 }
1017
1018 StartPhase("repair");
1019 {
1020 // If we do not compact here, then the lazy deletion of
1021 // files (https://reviews.facebook.net/D6123) would leave
1022 // around deleted files and the repair process will find
1023 // those files and put them back into the database.
1024 rocksdb_compact_range(db, NULL, 0, NULL, 0);
1025 rocksdb_close(db);
1026 rocksdb_options_set_create_if_missing(options, 0);
1027 rocksdb_options_set_error_if_exists(options, 0);
1028 rocksdb_options_set_wal_recovery_mode(options, 2);
1029 rocksdb_repair_db(options, dbname, &err);
1030 CheckNoError(err);
1031 db = rocksdb_open(options, dbname, &err);
1032 CheckNoError(err);
1033 CheckGet(db, roptions, "foo", NULL);
1034 CheckGet(db, roptions, "bar", NULL);
1035 CheckGet(db, roptions, "box", "c");
1036 rocksdb_options_set_create_if_missing(options, 1);
1037 rocksdb_options_set_error_if_exists(options, 1);
1038 }
1039
1040 StartPhase("filter");
1041 for (run = 0; run <= 2; run++) {
1042 // First run uses custom filter
1043 // Second run uses old block-based bloom filter
1044 // Third run uses full bloom filter
1045 CheckNoError(err);
1046 rocksdb_filterpolicy_t* policy;
1047 if (run == 0) {
1048 policy = rocksdb_filterpolicy_create(NULL, FilterDestroy, FilterCreate,
1049 FilterKeyMatch, NULL, FilterName);
1050 } else if (run == 1) {
1051 policy = rocksdb_filterpolicy_create_bloom(8);
1052 } else {
1053 policy = rocksdb_filterpolicy_create_bloom_full(8);
1054 }
1055 rocksdb_block_based_options_set_filter_policy(table_options, policy);
1056
1057 // Create new database
1058 rocksdb_close(db);
1059 rocksdb_destroy_db(options, dbname, &err);
1060 rocksdb_options_set_block_based_table_factory(options, table_options);
1061 db = rocksdb_open(options, dbname, &err);
1062 CheckNoError(err);
1063 rocksdb_put(db, woptions, "foo", 3, "foovalue", 8, &err);
1064 CheckNoError(err);
1065 rocksdb_put(db, woptions, "bar", 3, "barvalue", 8, &err);
1066 CheckNoError(err);
1067
1068 {
1069 // Add enough keys to get just one reasonably populated Bloom filter
1070 const int keys_to_add = 1500;
1071 int i;
1072 char keybuf[100];
1073 for (i = 0; i < keys_to_add; i++) {
1074 snprintf(keybuf, sizeof(keybuf), "yes%020d", i);
1075 rocksdb_put(db, woptions, keybuf, strlen(keybuf), "val", 3, &err);
1076 CheckNoError(err);
1077 }
1078 }
1079 rocksdb_compact_range(db, NULL, 0, NULL, 0);
1080
1081 fake_filter_result = 1;
1082 CheckGet(db, roptions, "foo", "foovalue");
1083 CheckGet(db, roptions, "bar", "barvalue");
1084 if (run == 0) {
1085 // Must not find value when custom filter returns false
1086 fake_filter_result = 0;
1087 CheckGet(db, roptions, "foo", NULL);
1088 CheckGet(db, roptions, "bar", NULL);
1089 fake_filter_result = 1;
1090
1091 CheckGet(db, roptions, "foo", "foovalue");
1092 CheckGet(db, roptions, "bar", "barvalue");
1093 }
1094
1095 {
1096 // Query some keys not added to identify Bloom filter implementation
1097 // from false positive queries, using perfcontext to detect Bloom
1098 // filter behavior
1099 rocksdb_perfcontext_t* perf = rocksdb_perfcontext_create();
1100 rocksdb_perfcontext_reset(perf);
1101
1102 const int keys_to_query = 10000;
1103 int i;
1104 char keybuf[100];
1105 for (i = 0; i < keys_to_query; i++) {
1106 fake_filter_result = i % 2;
1107 snprintf(keybuf, sizeof(keybuf), "no%020d", i);
1108 CheckGet(db, roptions, keybuf, NULL);
1109 }
1110
1111 const int hits =
1112 (int)rocksdb_perfcontext_metric(perf, rocksdb_bloom_sst_hit_count);
1113 if (run == 0) {
1114 // Due to half true, half false with fake filter result
1115 CheckCondition(hits == keys_to_query / 2);
1116 } else if (run == 1) {
1117 // Essentially a fingerprint of the block-based Bloom schema
1118 CheckCondition(hits == 241);
1119 } else {
1120 // Essentially a fingerprint of the full Bloom schema(s),
1121 // format_version < 5, which vary for three different CACHE_LINE_SIZEs
1122 CheckCondition(hits == 224 || hits == 180 || hits == 125);
1123 }
1124 CheckCondition(
1125 (keys_to_query - hits) ==
1126 (int)rocksdb_perfcontext_metric(perf, rocksdb_bloom_sst_miss_count));
1127
1128 rocksdb_perfcontext_destroy(perf);
1129 }
1130
1131 // Reset the policy
1132 rocksdb_block_based_options_set_filter_policy(table_options, NULL);
1133 rocksdb_options_set_block_based_table_factory(options, table_options);
1134 }
1135
1136 StartPhase("compaction_filter");
1137 {
1138 rocksdb_options_t* options_with_filter = rocksdb_options_create();
1139 rocksdb_options_set_create_if_missing(options_with_filter, 1);
1140 rocksdb_compactionfilter_t* cfilter;
1141 cfilter = rocksdb_compactionfilter_create(NULL, CFilterDestroy,
1142 CFilterFilter, CFilterName);
1143 // Create new database
1144 rocksdb_close(db);
1145 rocksdb_destroy_db(options_with_filter, dbname, &err);
1146 rocksdb_options_set_compaction_filter(options_with_filter, cfilter);
1147 db = CheckCompaction(db, options_with_filter, roptions, woptions);
1148
1149 rocksdb_options_set_compaction_filter(options_with_filter, NULL);
1150 rocksdb_compactionfilter_destroy(cfilter);
1151 rocksdb_options_destroy(options_with_filter);
1152 }
1153
1154 StartPhase("compaction_filter_factory");
1155 {
1156 rocksdb_options_t* options_with_filter_factory = rocksdb_options_create();
1157 rocksdb_options_set_create_if_missing(options_with_filter_factory, 1);
1158 rocksdb_compactionfilterfactory_t* factory;
1159 factory = rocksdb_compactionfilterfactory_create(
1160 NULL, CFilterFactoryDestroy, CFilterCreate, CFilterFactoryName);
1161 // Create new database
1162 rocksdb_close(db);
1163 rocksdb_destroy_db(options_with_filter_factory, dbname, &err);
1164 rocksdb_options_set_compaction_filter_factory(options_with_filter_factory,
1165 factory);
1166 db = CheckCompaction(db, options_with_filter_factory, roptions, woptions);
1167
1168 rocksdb_options_set_compaction_filter_factory(
1169 options_with_filter_factory, NULL);
1170 rocksdb_options_destroy(options_with_filter_factory);
1171 }
1172
1173 StartPhase("merge_operator");
1174 {
1175 rocksdb_mergeoperator_t* merge_operator;
1176 merge_operator = rocksdb_mergeoperator_create(
1177 NULL, MergeOperatorDestroy, MergeOperatorFullMerge,
1178 MergeOperatorPartialMerge, NULL, MergeOperatorName);
1179 // Create new database
1180 rocksdb_close(db);
1181 rocksdb_destroy_db(options, dbname, &err);
1182 rocksdb_options_set_merge_operator(options, merge_operator);
1183 db = rocksdb_open(options, dbname, &err);
1184 CheckNoError(err);
1185 rocksdb_put(db, woptions, "foo", 3, "foovalue", 8, &err);
1186 CheckNoError(err);
1187 CheckGet(db, roptions, "foo", "foovalue");
1188 rocksdb_merge(db, woptions, "foo", 3, "barvalue", 8, &err);
1189 CheckNoError(err);
1190 CheckGet(db, roptions, "foo", "fake");
1191
1192 // Merge of a non-existing value
1193 rocksdb_merge(db, woptions, "bar", 3, "barvalue", 8, &err);
1194 CheckNoError(err);
1195 CheckGet(db, roptions, "bar", "fake");
1196
1197 }
1198
1199 StartPhase("columnfamilies");
1200 {
1201 rocksdb_close(db);
1202 rocksdb_destroy_db(options, dbname, &err);
1203 CheckNoError(err);
1204
1205 rocksdb_options_t* db_options = rocksdb_options_create();
1206 rocksdb_options_set_create_if_missing(db_options, 1);
1207 db = rocksdb_open(db_options, dbname, &err);
1208 CheckNoError(err)
1209 rocksdb_column_family_handle_t* cfh;
1210 cfh = rocksdb_create_column_family(db, db_options, "cf1", &err);
1211 rocksdb_column_family_handle_destroy(cfh);
1212 CheckNoError(err);
1213 rocksdb_close(db);
1214
1215 size_t cflen;
1216 char** column_fams = rocksdb_list_column_families(db_options, dbname, &cflen, &err);
1217 CheckNoError(err);
1218 CheckEqual("default", column_fams[0], 7);
1219 CheckEqual("cf1", column_fams[1], 3);
1220 CheckCondition(cflen == 2);
1221 rocksdb_list_column_families_destroy(column_fams, cflen);
1222
1223 rocksdb_options_t* cf_options = rocksdb_options_create();
1224
1225 const char* cf_names[2] = {"default", "cf1"};
1226 const rocksdb_options_t* cf_opts[2] = {cf_options, cf_options};
1227 rocksdb_column_family_handle_t* handles[2];
1228 db = rocksdb_open_column_families(db_options, dbname, 2, cf_names, cf_opts, handles, &err);
1229 CheckNoError(err);
1230
1231 rocksdb_put_cf(db, woptions, handles[1], "foo", 3, "hello", 5, &err);
1232 CheckNoError(err);
1233
1234 rocksdb_put_cf(db, woptions, handles[1], "foobar1", 7, "hello1", 6, &err);
1235 CheckNoError(err);
1236 rocksdb_put_cf(db, woptions, handles[1], "foobar2", 7, "hello2", 6, &err);
1237 CheckNoError(err);
1238 rocksdb_put_cf(db, woptions, handles[1], "foobar3", 7, "hello3", 6, &err);
1239 CheckNoError(err);
1240 rocksdb_put_cf(db, woptions, handles[1], "foobar4", 7, "hello4", 6, &err);
1241 CheckNoError(err);
1242
1243 rocksdb_flushoptions_t *flush_options = rocksdb_flushoptions_create();
1244 rocksdb_flushoptions_set_wait(flush_options, 1);
1245 rocksdb_flush_cf(db, flush_options, handles[1], &err);
1246 CheckNoError(err)
1247 rocksdb_flushoptions_destroy(flush_options);
1248
1249 CheckGetCF(db, roptions, handles[1], "foo", "hello");
1250 CheckPinGetCF(db, roptions, handles[1], "foo", "hello");
1251
1252 rocksdb_delete_cf(db, woptions, handles[1], "foo", 3, &err);
1253 CheckNoError(err);
1254
1255 rocksdb_delete_range_cf(db, woptions, handles[1], "foobar2", 7, "foobar4",
1256 7, &err);
1257 CheckNoError(err);
1258
1259 CheckGetCF(db, roptions, handles[1], "foo", NULL);
1260 CheckPinGetCF(db, roptions, handles[1], "foo", NULL);
1261
1262 rocksdb_writebatch_t* wb = rocksdb_writebatch_create();
1263 rocksdb_writebatch_put_cf(wb, handles[1], "baz", 3, "a", 1);
1264 rocksdb_writebatch_clear(wb);
1265 rocksdb_writebatch_put_cf(wb, handles[1], "bar", 3, "b", 1);
1266 rocksdb_writebatch_put_cf(wb, handles[1], "box", 3, "c", 1);
1267 rocksdb_writebatch_delete_cf(wb, handles[1], "bar", 3);
1268 rocksdb_write(db, woptions, wb, &err);
1269 CheckNoError(err);
1270 CheckGetCF(db, roptions, handles[1], "baz", NULL);
1271 CheckGetCF(db, roptions, handles[1], "bar", NULL);
1272 CheckGetCF(db, roptions, handles[1], "box", "c");
1273 CheckPinGetCF(db, roptions, handles[1], "baz", NULL);
1274 CheckPinGetCF(db, roptions, handles[1], "bar", NULL);
1275 CheckPinGetCF(db, roptions, handles[1], "box", "c");
1276 rocksdb_writebatch_destroy(wb);
1277
1278 const char* keys[3] = { "box", "box", "barfooxx" };
1279 const rocksdb_column_family_handle_t* get_handles[3] = { handles[0], handles[1], handles[1] };
1280 const size_t keys_sizes[3] = { 3, 3, 8 };
1281 char* vals[3];
1282 size_t vals_sizes[3];
1283 char* errs[3];
1284 rocksdb_multi_get_cf(db, roptions, get_handles, 3, keys, keys_sizes, vals, vals_sizes, errs);
1285
1286 int i;
1287 for (i = 0; i < 3; i++) {
1288 CheckEqual(NULL, errs[i], 0);
1289 switch (i) {
1290 case 0:
1291 CheckEqual(NULL, vals[i], vals_sizes[i]); // wrong cf
1292 break;
1293 case 1:
1294 CheckEqual("c", vals[i], vals_sizes[i]); // bingo
1295 break;
1296 case 2:
1297 CheckEqual(NULL, vals[i], vals_sizes[i]); // normal not found
1298 break;
1299 }
1300 Free(&vals[i]);
1301 }
1302
1303 {
1304 unsigned char value_found = 0;
1305
1306 CheckCondition(!rocksdb_key_may_exist(db, roptions, "invalid_key", 11,
1307 NULL, NULL, NULL, 0, NULL));
1308 CheckCondition(!rocksdb_key_may_exist(db, roptions, "invalid_key", 11,
1309 &vals[0], &vals_sizes[0], NULL, 0,
1310 &value_found));
1311 if (value_found) {
1312 Free(&vals[0]);
1313 }
1314
1315 CheckCondition(!rocksdb_key_may_exist_cf(db, roptions, handles[1],
1316 "invalid_key", 11, NULL, NULL,
1317 NULL, 0, NULL));
1318 CheckCondition(!rocksdb_key_may_exist_cf(db, roptions, handles[1],
1319 "invalid_key", 11, &vals[0],
1320 &vals_sizes[0], NULL, 0, NULL));
1321 if (value_found) {
1322 Free(&vals[0]);
1323 }
1324 }
1325
1326 rocksdb_iterator_t* iter = rocksdb_create_iterator_cf(db, roptions, handles[1]);
1327 CheckCondition(!rocksdb_iter_valid(iter));
1328 rocksdb_iter_seek_to_first(iter);
1329 CheckCondition(rocksdb_iter_valid(iter));
1330
1331 for (i = 0; rocksdb_iter_valid(iter) != 0; rocksdb_iter_next(iter)) {
1332 i++;
1333 }
1334 CheckCondition(i == 3);
1335 rocksdb_iter_get_error(iter, &err);
1336 CheckNoError(err);
1337 rocksdb_iter_destroy(iter);
1338
1339 rocksdb_column_family_handle_t* iters_cf_handles[2] = { handles[0], handles[1] };
1340 rocksdb_iterator_t* iters_handles[2];
1341 rocksdb_create_iterators(db, roptions, iters_cf_handles, iters_handles, 2, &err);
1342 CheckNoError(err);
1343
1344 iter = iters_handles[0];
1345 CheckCondition(!rocksdb_iter_valid(iter));
1346 rocksdb_iter_seek_to_first(iter);
1347 CheckCondition(!rocksdb_iter_valid(iter));
1348 rocksdb_iter_destroy(iter);
1349
1350 iter = iters_handles[1];
1351 CheckCondition(!rocksdb_iter_valid(iter));
1352 rocksdb_iter_seek_to_first(iter);
1353 CheckCondition(rocksdb_iter_valid(iter));
1354
1355 for (i = 0; rocksdb_iter_valid(iter) != 0; rocksdb_iter_next(iter)) {
1356 i++;
1357 }
1358 CheckCondition(i == 3);
1359 rocksdb_iter_get_error(iter, &err);
1360 CheckNoError(err);
1361 rocksdb_iter_destroy(iter);
1362
1363 rocksdb_drop_column_family(db, handles[1], &err);
1364 CheckNoError(err);
1365 for (i = 0; i < 2; i++) {
1366 rocksdb_column_family_handle_destroy(handles[i]);
1367 }
1368 rocksdb_close(db);
1369 rocksdb_destroy_db(options, dbname, &err);
1370 rocksdb_options_destroy(db_options);
1371 rocksdb_options_destroy(cf_options);
1372 }
1373
1374 StartPhase("prefix");
1375 {
1376 // Create new database
1377 rocksdb_options_set_allow_mmap_reads(options, 1);
1378 rocksdb_options_set_prefix_extractor(options, rocksdb_slicetransform_create_fixed_prefix(3));
1379 rocksdb_options_set_hash_skip_list_rep(options, 5000, 4, 4);
1380 rocksdb_options_set_plain_table_factory(options, 4, 10, 0.75, 16);
1381 rocksdb_options_set_allow_concurrent_memtable_write(options, 0);
1382
1383 db = rocksdb_open(options, dbname, &err);
1384 CheckNoError(err);
1385
1386 rocksdb_put(db, woptions, "foo1", 4, "foo", 3, &err);
1387 CheckNoError(err);
1388 rocksdb_put(db, woptions, "foo2", 4, "foo", 3, &err);
1389 CheckNoError(err);
1390 rocksdb_put(db, woptions, "foo3", 4, "foo", 3, &err);
1391 CheckNoError(err);
1392 rocksdb_put(db, woptions, "bar1", 4, "bar", 3, &err);
1393 CheckNoError(err);
1394 rocksdb_put(db, woptions, "bar2", 4, "bar", 3, &err);
1395 CheckNoError(err);
1396 rocksdb_put(db, woptions, "bar3", 4, "bar", 3, &err);
1397 CheckNoError(err);
1398
1399 rocksdb_iterator_t* iter = rocksdb_create_iterator(db, roptions);
1400 CheckCondition(!rocksdb_iter_valid(iter));
1401
1402 rocksdb_iter_seek(iter, "bar", 3);
1403 rocksdb_iter_get_error(iter, &err);
1404 CheckNoError(err);
1405 CheckCondition(rocksdb_iter_valid(iter));
1406
1407 CheckIter(iter, "bar1", "bar");
1408 rocksdb_iter_next(iter);
1409 CheckIter(iter, "bar2", "bar");
1410 rocksdb_iter_next(iter);
1411 CheckIter(iter, "bar3", "bar");
1412 rocksdb_iter_get_error(iter, &err);
1413 CheckNoError(err);
1414 rocksdb_iter_destroy(iter);
1415
1416 rocksdb_readoptions_set_total_order_seek(roptions, 1);
1417 iter = rocksdb_create_iterator(db, roptions);
1418 CheckCondition(!rocksdb_iter_valid(iter));
1419
1420 rocksdb_iter_seek(iter, "ba", 2);
1421 rocksdb_iter_get_error(iter, &err);
1422 CheckNoError(err);
1423 CheckCondition(rocksdb_iter_valid(iter));
1424 CheckIter(iter, "bar1", "bar");
1425
1426 rocksdb_iter_destroy(iter);
1427 rocksdb_readoptions_set_total_order_seek(roptions, 0);
1428
1429 rocksdb_close(db);
1430 rocksdb_destroy_db(options, dbname, &err);
1431 }
1432
1433 // Check memory usage stats
1434 StartPhase("approximate_memory_usage");
1435 {
1436 // Create database
1437 db = rocksdb_open(options, dbname, &err);
1438 CheckNoError(err);
1439
1440 rocksdb_memory_consumers_t* consumers;
1441 consumers = rocksdb_memory_consumers_create();
1442 rocksdb_memory_consumers_add_db(consumers, db);
1443 rocksdb_memory_consumers_add_cache(consumers, cache);
1444
1445 // take memory usage report before write-read operation
1446 rocksdb_memory_usage_t* mu1;
1447 mu1 = rocksdb_approximate_memory_usage_create(consumers, &err);
1448 CheckNoError(err);
1449
1450 // Put data (this should affect memtables)
1451 rocksdb_put(db, woptions, "memory", 6, "test", 4, &err);
1452 CheckNoError(err);
1453 CheckGet(db, roptions, "memory", "test");
1454
1455 // take memory usage report after write-read operation
1456 rocksdb_memory_usage_t* mu2;
1457 mu2 = rocksdb_approximate_memory_usage_create(consumers, &err);
1458 CheckNoError(err);
1459
1460 // amount of memory used within memtables should grow
1461 CheckCondition(rocksdb_approximate_memory_usage_get_mem_table_total(mu2) >=
1462 rocksdb_approximate_memory_usage_get_mem_table_total(mu1));
1463 CheckCondition(rocksdb_approximate_memory_usage_get_mem_table_unflushed(mu2) >=
1464 rocksdb_approximate_memory_usage_get_mem_table_unflushed(mu1));
1465
1466 rocksdb_memory_consumers_destroy(consumers);
1467 rocksdb_approximate_memory_usage_destroy(mu1);
1468 rocksdb_approximate_memory_usage_destroy(mu2);
1469 rocksdb_close(db);
1470 rocksdb_destroy_db(options, dbname, &err);
1471 CheckNoError(err);
1472 }
1473
1474 StartPhase("cuckoo_options");
1475 {
1476 rocksdb_cuckoo_table_options_t* cuckoo_options;
1477 cuckoo_options = rocksdb_cuckoo_options_create();
1478 rocksdb_cuckoo_options_set_hash_ratio(cuckoo_options, 0.5);
1479 rocksdb_cuckoo_options_set_max_search_depth(cuckoo_options, 200);
1480 rocksdb_cuckoo_options_set_cuckoo_block_size(cuckoo_options, 10);
1481 rocksdb_cuckoo_options_set_identity_as_first_hash(cuckoo_options, 1);
1482 rocksdb_cuckoo_options_set_use_module_hash(cuckoo_options, 0);
1483 rocksdb_options_set_cuckoo_table_factory(options, cuckoo_options);
1484
1485 db = rocksdb_open(options, dbname, &err);
1486 CheckNoError(err);
1487
1488 rocksdb_cuckoo_options_destroy(cuckoo_options);
1489 }
1490
1491 StartPhase("options");
1492 {
1493 rocksdb_options_t* o;
1494 o = rocksdb_options_create();
1495
1496 // Set and check options.
1497 rocksdb_options_set_allow_ingest_behind(o, 1);
1498 CheckCondition(1 == rocksdb_options_get_allow_ingest_behind(o));
1499
1500 rocksdb_options_compaction_readahead_size(o, 10);
1501 CheckCondition(10 == rocksdb_options_get_compaction_readahead_size(o));
1502
1503 rocksdb_options_set_create_if_missing(o, 1);
1504 CheckCondition(1 == rocksdb_options_get_create_if_missing(o));
1505
1506 rocksdb_options_set_create_missing_column_families(o, 1);
1507 CheckCondition(1 == rocksdb_options_get_create_missing_column_families(o));
1508
1509 rocksdb_options_set_error_if_exists(o, 1);
1510 CheckCondition(1 == rocksdb_options_get_error_if_exists(o));
1511
1512 rocksdb_options_set_paranoid_checks(o, 1);
1513 CheckCondition(1 == rocksdb_options_get_paranoid_checks(o));
1514
1515 rocksdb_options_set_info_log_level(o, 3);
1516 CheckCondition(3 == rocksdb_options_get_info_log_level(o));
1517
1518 rocksdb_options_set_write_buffer_size(o, 100);
1519 CheckCondition(100 == rocksdb_options_get_write_buffer_size(o));
1520
1521 rocksdb_options_set_db_write_buffer_size(o, 1000);
1522 CheckCondition(1000 == rocksdb_options_get_db_write_buffer_size(o));
1523
1524 rocksdb_options_set_max_open_files(o, 21);
1525 CheckCondition(21 == rocksdb_options_get_max_open_files(o));
1526
1527 rocksdb_options_set_max_file_opening_threads(o, 5);
1528 CheckCondition(5 == rocksdb_options_get_max_file_opening_threads(o));
1529
1530 rocksdb_options_set_max_total_wal_size(o, 400);
1531 CheckCondition(400 == rocksdb_options_get_max_total_wal_size(o));
1532
1533 rocksdb_options_set_num_levels(o, 7);
1534 CheckCondition(7 == rocksdb_options_get_num_levels(o));
1535
1536 rocksdb_options_set_level0_file_num_compaction_trigger(o, 4);
1537 CheckCondition(4 ==
1538 rocksdb_options_get_level0_file_num_compaction_trigger(o));
1539
1540 rocksdb_options_set_level0_slowdown_writes_trigger(o, 6);
1541 CheckCondition(6 == rocksdb_options_get_level0_slowdown_writes_trigger(o));
1542
1543 rocksdb_options_set_level0_stop_writes_trigger(o, 8);
1544 CheckCondition(8 == rocksdb_options_get_level0_stop_writes_trigger(o));
1545
1546 rocksdb_options_set_target_file_size_base(o, 256);
1547 CheckCondition(256 == rocksdb_options_get_target_file_size_base(o));
1548
1549 rocksdb_options_set_target_file_size_multiplier(o, 3);
1550 CheckCondition(3 == rocksdb_options_get_target_file_size_multiplier(o));
1551
1552 rocksdb_options_set_max_bytes_for_level_base(o, 1024);
1553 CheckCondition(1024 == rocksdb_options_get_max_bytes_for_level_base(o));
1554
1555 rocksdb_options_set_level_compaction_dynamic_level_bytes(o, 1);
1556 CheckCondition(1 ==
1557 rocksdb_options_get_level_compaction_dynamic_level_bytes(o));
1558
1559 rocksdb_options_set_max_bytes_for_level_multiplier(o, 2.0);
1560 CheckCondition(2.0 ==
1561 rocksdb_options_get_max_bytes_for_level_multiplier(o));
1562
1563 rocksdb_options_set_skip_stats_update_on_db_open(o, 1);
1564 CheckCondition(1 == rocksdb_options_get_skip_stats_update_on_db_open(o));
1565
1566 rocksdb_options_set_skip_checking_sst_file_sizes_on_db_open(o, 1);
1567 CheckCondition(
1568 1 == rocksdb_options_get_skip_checking_sst_file_sizes_on_db_open(o));
1569
1570 rocksdb_options_set_max_write_buffer_number(o, 97);
1571 CheckCondition(97 == rocksdb_options_get_max_write_buffer_number(o));
1572
1573 rocksdb_options_set_min_write_buffer_number_to_merge(o, 23);
1574 CheckCondition(23 ==
1575 rocksdb_options_get_min_write_buffer_number_to_merge(o));
1576
1577 rocksdb_options_set_max_write_buffer_number_to_maintain(o, 64);
1578 CheckCondition(64 ==
1579 rocksdb_options_get_max_write_buffer_number_to_maintain(o));
1580
1581 rocksdb_options_set_max_write_buffer_size_to_maintain(o, 50000);
1582 CheckCondition(50000 ==
1583 rocksdb_options_get_max_write_buffer_size_to_maintain(o));
1584
1585 rocksdb_options_set_enable_pipelined_write(o, 1);
1586 CheckCondition(1 == rocksdb_options_get_enable_pipelined_write(o));
1587
1588 rocksdb_options_set_unordered_write(o, 1);
1589 CheckCondition(1 == rocksdb_options_get_unordered_write(o));
1590
1591 rocksdb_options_set_max_subcompactions(o, 123456);
1592 CheckCondition(123456 == rocksdb_options_get_max_subcompactions(o));
1593
1594 rocksdb_options_set_max_background_jobs(o, 2);
1595 CheckCondition(2 == rocksdb_options_get_max_background_jobs(o));
1596
1597 rocksdb_options_set_max_background_compactions(o, 3);
1598 CheckCondition(3 == rocksdb_options_get_max_background_compactions(o));
1599
1600 rocksdb_options_set_base_background_compactions(o, 4);
1601 CheckCondition(4 == rocksdb_options_get_base_background_compactions(o));
1602
1603 rocksdb_options_set_max_background_flushes(o, 5);
1604 CheckCondition(5 == rocksdb_options_get_max_background_flushes(o));
1605
1606 rocksdb_options_set_max_log_file_size(o, 6);
1607 CheckCondition(6 == rocksdb_options_get_max_log_file_size(o));
1608
1609 rocksdb_options_set_log_file_time_to_roll(o, 7);
1610 CheckCondition(7 == rocksdb_options_get_log_file_time_to_roll(o));
1611
1612 rocksdb_options_set_keep_log_file_num(o, 8);
1613 CheckCondition(8 == rocksdb_options_get_keep_log_file_num(o));
1614
1615 rocksdb_options_set_recycle_log_file_num(o, 9);
1616 CheckCondition(9 == rocksdb_options_get_recycle_log_file_num(o));
1617
1618 rocksdb_options_set_soft_rate_limit(o, 2.0);
1619 CheckCondition(2.0 == rocksdb_options_get_soft_rate_limit(o));
1620
1621 rocksdb_options_set_hard_rate_limit(o, 4.0);
1622 CheckCondition(4.0 == rocksdb_options_get_hard_rate_limit(o));
1623
1624 rocksdb_options_set_soft_pending_compaction_bytes_limit(o, 10);
1625 CheckCondition(10 ==
1626 rocksdb_options_get_soft_pending_compaction_bytes_limit(o));
1627
1628 rocksdb_options_set_hard_pending_compaction_bytes_limit(o, 11);
1629 CheckCondition(11 ==
1630 rocksdb_options_get_hard_pending_compaction_bytes_limit(o));
1631
1632 rocksdb_options_set_rate_limit_delay_max_milliseconds(o, 1);
1633 CheckCondition(1 ==
1634 rocksdb_options_get_rate_limit_delay_max_milliseconds(o));
1635
1636 rocksdb_options_set_max_manifest_file_size(o, 12);
1637 CheckCondition(12 == rocksdb_options_get_max_manifest_file_size(o));
1638
1639 rocksdb_options_set_table_cache_numshardbits(o, 13);
1640 CheckCondition(13 == rocksdb_options_get_table_cache_numshardbits(o));
1641
1642 rocksdb_options_set_arena_block_size(o, 14);
1643 CheckCondition(14 == rocksdb_options_get_arena_block_size(o));
1644
1645 rocksdb_options_set_use_fsync(o, 1);
1646 CheckCondition(1 == rocksdb_options_get_use_fsync(o));
1647
1648 rocksdb_options_set_WAL_ttl_seconds(o, 15);
1649 CheckCondition(15 == rocksdb_options_get_WAL_ttl_seconds(o));
1650
1651 rocksdb_options_set_WAL_size_limit_MB(o, 16);
1652 CheckCondition(16 == rocksdb_options_get_WAL_size_limit_MB(o));
1653
1654 rocksdb_options_set_manifest_preallocation_size(o, 17);
1655 CheckCondition(17 == rocksdb_options_get_manifest_preallocation_size(o));
1656
1657 rocksdb_options_set_allow_mmap_reads(o, 1);
1658 CheckCondition(1 == rocksdb_options_get_allow_mmap_reads(o));
1659
1660 rocksdb_options_set_allow_mmap_writes(o, 1);
1661 CheckCondition(1 == rocksdb_options_get_allow_mmap_writes(o));
1662
1663 rocksdb_options_set_use_direct_reads(o, 1);
1664 CheckCondition(1 == rocksdb_options_get_use_direct_reads(o));
1665
1666 rocksdb_options_set_use_direct_io_for_flush_and_compaction(o, 1);
1667 CheckCondition(
1668 1 == rocksdb_options_get_use_direct_io_for_flush_and_compaction(o));
1669
1670 rocksdb_options_set_is_fd_close_on_exec(o, 1);
1671 CheckCondition(1 == rocksdb_options_get_is_fd_close_on_exec(o));
1672
1673 rocksdb_options_set_skip_log_error_on_recovery(o, 1);
1674 CheckCondition(1 == rocksdb_options_get_skip_log_error_on_recovery(o));
1675
1676 rocksdb_options_set_stats_dump_period_sec(o, 18);
1677 CheckCondition(18 == rocksdb_options_get_stats_dump_period_sec(o));
1678
1679 rocksdb_options_set_stats_persist_period_sec(o, 5);
1680 CheckCondition(5 == rocksdb_options_get_stats_persist_period_sec(o));
1681
1682 rocksdb_options_set_advise_random_on_open(o, 1);
1683 CheckCondition(1 == rocksdb_options_get_advise_random_on_open(o));
1684
1685 rocksdb_options_set_access_hint_on_compaction_start(o, 3);
1686 CheckCondition(3 == rocksdb_options_get_access_hint_on_compaction_start(o));
1687
1688 rocksdb_options_set_use_adaptive_mutex(o, 1);
1689 CheckCondition(1 == rocksdb_options_get_use_adaptive_mutex(o));
1690
1691 rocksdb_options_set_bytes_per_sync(o, 19);
1692 CheckCondition(19 == rocksdb_options_get_bytes_per_sync(o));
1693
1694 rocksdb_options_set_wal_bytes_per_sync(o, 20);
1695 CheckCondition(20 == rocksdb_options_get_wal_bytes_per_sync(o));
1696
1697 rocksdb_options_set_writable_file_max_buffer_size(o, 21);
1698 CheckCondition(21 == rocksdb_options_get_writable_file_max_buffer_size(o));
1699
1700 rocksdb_options_set_allow_concurrent_memtable_write(o, 1);
1701 CheckCondition(1 == rocksdb_options_get_allow_concurrent_memtable_write(o));
1702
1703 rocksdb_options_set_enable_write_thread_adaptive_yield(o, 1);
1704 CheckCondition(1 ==
1705 rocksdb_options_get_enable_write_thread_adaptive_yield(o));
1706
1707 rocksdb_options_set_max_sequential_skip_in_iterations(o, 22);
1708 CheckCondition(22 ==
1709 rocksdb_options_get_max_sequential_skip_in_iterations(o));
1710
1711 rocksdb_options_set_disable_auto_compactions(o, 1);
1712 CheckCondition(1 == rocksdb_options_get_disable_auto_compactions(o));
1713
1714 rocksdb_options_set_optimize_filters_for_hits(o, 1);
1715 CheckCondition(1 == rocksdb_options_get_optimize_filters_for_hits(o));
1716
1717 rocksdb_options_set_delete_obsolete_files_period_micros(o, 23);
1718 CheckCondition(23 ==
1719 rocksdb_options_get_delete_obsolete_files_period_micros(o));
1720
1721 rocksdb_options_set_memtable_prefix_bloom_size_ratio(o, 2.0);
1722 CheckCondition(2.0 ==
1723 rocksdb_options_get_memtable_prefix_bloom_size_ratio(o));
1724
1725 rocksdb_options_set_max_compaction_bytes(o, 24);
1726 CheckCondition(24 == rocksdb_options_get_max_compaction_bytes(o));
1727
1728 rocksdb_options_set_memtable_huge_page_size(o, 25);
1729 CheckCondition(25 == rocksdb_options_get_memtable_huge_page_size(o));
1730
1731 rocksdb_options_set_max_successive_merges(o, 26);
1732 CheckCondition(26 == rocksdb_options_get_max_successive_merges(o));
1733
1734 rocksdb_options_set_bloom_locality(o, 27);
1735 CheckCondition(27 == rocksdb_options_get_bloom_locality(o));
1736
1737 rocksdb_options_set_inplace_update_support(o, 1);
1738 CheckCondition(1 == rocksdb_options_get_inplace_update_support(o));
1739
1740 rocksdb_options_set_inplace_update_num_locks(o, 28);
1741 CheckCondition(28 == rocksdb_options_get_inplace_update_num_locks(o));
1742
1743 rocksdb_options_set_report_bg_io_stats(o, 1);
1744 CheckCondition(1 == rocksdb_options_get_report_bg_io_stats(o));
1745
1746 rocksdb_options_set_wal_recovery_mode(o, 2);
1747 CheckCondition(2 == rocksdb_options_get_wal_recovery_mode(o));
1748
1749 rocksdb_options_set_compression(o, 5);
1750 CheckCondition(5 == rocksdb_options_get_compression(o));
1751
1752 rocksdb_options_set_bottommost_compression(o, 4);
1753 CheckCondition(4 == rocksdb_options_get_bottommost_compression(o));
1754
1755 rocksdb_options_set_compaction_style(o, 2);
1756 CheckCondition(2 == rocksdb_options_get_compaction_style(o));
1757
1758 rocksdb_options_set_atomic_flush(o, 1);
1759 CheckCondition(1 == rocksdb_options_get_atomic_flush(o));
1760
1761 // Create a copy that should be equal to the original.
1762 rocksdb_options_t* copy;
1763 copy = rocksdb_options_create_copy(o);
1764
1765 CheckCondition(1 == rocksdb_options_get_allow_ingest_behind(copy));
1766 CheckCondition(10 == rocksdb_options_get_compaction_readahead_size(copy));
1767 CheckCondition(1 == rocksdb_options_get_create_if_missing(copy));
1768 CheckCondition(1 ==
1769 rocksdb_options_get_create_missing_column_families(copy));
1770 CheckCondition(1 == rocksdb_options_get_error_if_exists(copy));
1771 CheckCondition(1 == rocksdb_options_get_paranoid_checks(copy));
1772 CheckCondition(3 == rocksdb_options_get_info_log_level(copy));
1773 CheckCondition(100 == rocksdb_options_get_write_buffer_size(copy));
1774 CheckCondition(1000 == rocksdb_options_get_db_write_buffer_size(copy));
1775 CheckCondition(21 == rocksdb_options_get_max_open_files(copy));
1776 CheckCondition(5 == rocksdb_options_get_max_file_opening_threads(copy));
1777 CheckCondition(400 == rocksdb_options_get_max_total_wal_size(copy));
1778 CheckCondition(7 == rocksdb_options_get_num_levels(copy));
1779 CheckCondition(
1780 4 == rocksdb_options_get_level0_file_num_compaction_trigger(copy));
1781 CheckCondition(6 ==
1782 rocksdb_options_get_level0_slowdown_writes_trigger(copy));
1783 CheckCondition(8 == rocksdb_options_get_level0_stop_writes_trigger(copy));
1784 CheckCondition(256 == rocksdb_options_get_target_file_size_base(copy));
1785 CheckCondition(3 == rocksdb_options_get_target_file_size_multiplier(copy));
1786 CheckCondition(1024 == rocksdb_options_get_max_bytes_for_level_base(copy));
1787 CheckCondition(
1788 1 == rocksdb_options_get_level_compaction_dynamic_level_bytes(copy));
1789 CheckCondition(2.0 ==
1790 rocksdb_options_get_max_bytes_for_level_multiplier(copy));
1791 CheckCondition(1 == rocksdb_options_get_skip_stats_update_on_db_open(copy));
1792 CheckCondition(
1793 1 == rocksdb_options_get_skip_checking_sst_file_sizes_on_db_open(copy));
1794 CheckCondition(97 == rocksdb_options_get_max_write_buffer_number(copy));
1795 CheckCondition(23 ==
1796 rocksdb_options_get_min_write_buffer_number_to_merge(copy));
1797 CheckCondition(
1798 64 == rocksdb_options_get_max_write_buffer_number_to_maintain(copy));
1799 CheckCondition(50000 ==
1800 rocksdb_options_get_max_write_buffer_size_to_maintain(copy));
1801 CheckCondition(1 == rocksdb_options_get_enable_pipelined_write(copy));
1802 CheckCondition(1 == rocksdb_options_get_unordered_write(copy));
1803 CheckCondition(123456 == rocksdb_options_get_max_subcompactions(copy));
1804 CheckCondition(2 == rocksdb_options_get_max_background_jobs(copy));
1805 CheckCondition(3 == rocksdb_options_get_max_background_compactions(copy));
1806 CheckCondition(4 == rocksdb_options_get_base_background_compactions(copy));
1807 CheckCondition(5 == rocksdb_options_get_max_background_flushes(copy));
1808 CheckCondition(6 == rocksdb_options_get_max_log_file_size(copy));
1809 CheckCondition(7 == rocksdb_options_get_log_file_time_to_roll(copy));
1810 CheckCondition(8 == rocksdb_options_get_keep_log_file_num(copy));
1811 CheckCondition(9 == rocksdb_options_get_recycle_log_file_num(copy));
1812 CheckCondition(2.0 == rocksdb_options_get_soft_rate_limit(copy));
1813 CheckCondition(4.0 == rocksdb_options_get_hard_rate_limit(copy));
1814 CheckCondition(
1815 10 == rocksdb_options_get_soft_pending_compaction_bytes_limit(copy));
1816 CheckCondition(
1817 11 == rocksdb_options_get_hard_pending_compaction_bytes_limit(copy));
1818 CheckCondition(1 ==
1819 rocksdb_options_get_rate_limit_delay_max_milliseconds(copy));
1820 CheckCondition(12 == rocksdb_options_get_max_manifest_file_size(copy));
1821 CheckCondition(13 == rocksdb_options_get_table_cache_numshardbits(copy));
1822 CheckCondition(14 == rocksdb_options_get_arena_block_size(copy));
1823 CheckCondition(1 == rocksdb_options_get_use_fsync(copy));
1824 CheckCondition(15 == rocksdb_options_get_WAL_ttl_seconds(copy));
1825 CheckCondition(16 == rocksdb_options_get_WAL_size_limit_MB(copy));
1826 CheckCondition(17 == rocksdb_options_get_manifest_preallocation_size(copy));
1827 CheckCondition(1 == rocksdb_options_get_allow_mmap_reads(copy));
1828 CheckCondition(1 == rocksdb_options_get_allow_mmap_writes(copy));
1829 CheckCondition(1 == rocksdb_options_get_use_direct_reads(copy));
1830 CheckCondition(
1831 1 == rocksdb_options_get_use_direct_io_for_flush_and_compaction(copy));
1832 CheckCondition(1 == rocksdb_options_get_is_fd_close_on_exec(copy));
1833 CheckCondition(1 == rocksdb_options_get_skip_log_error_on_recovery(copy));
1834 CheckCondition(18 == rocksdb_options_get_stats_dump_period_sec(copy));
1835 CheckCondition(5 == rocksdb_options_get_stats_persist_period_sec(copy));
1836 CheckCondition(1 == rocksdb_options_get_advise_random_on_open(copy));
1837 CheckCondition(3 ==
1838 rocksdb_options_get_access_hint_on_compaction_start(copy));
1839 CheckCondition(1 == rocksdb_options_get_use_adaptive_mutex(copy));
1840 CheckCondition(19 == rocksdb_options_get_bytes_per_sync(copy));
1841 CheckCondition(20 == rocksdb_options_get_wal_bytes_per_sync(copy));
1842 CheckCondition(21 ==
1843 rocksdb_options_get_writable_file_max_buffer_size(copy));
1844 CheckCondition(1 ==
1845 rocksdb_options_get_allow_concurrent_memtable_write(copy));
1846 CheckCondition(
1847 1 == rocksdb_options_get_enable_write_thread_adaptive_yield(copy));
1848 CheckCondition(22 ==
1849 rocksdb_options_get_max_sequential_skip_in_iterations(copy));
1850 CheckCondition(1 == rocksdb_options_get_disable_auto_compactions(copy));
1851 CheckCondition(1 == rocksdb_options_get_optimize_filters_for_hits(copy));
1852 CheckCondition(
1853 23 == rocksdb_options_get_delete_obsolete_files_period_micros(copy));
1854 CheckCondition(2.0 ==
1855 rocksdb_options_get_memtable_prefix_bloom_size_ratio(copy));
1856 CheckCondition(24 == rocksdb_options_get_max_compaction_bytes(copy));
1857 CheckCondition(25 == rocksdb_options_get_memtable_huge_page_size(copy));
1858 CheckCondition(26 == rocksdb_options_get_max_successive_merges(copy));
1859 CheckCondition(27 == rocksdb_options_get_bloom_locality(copy));
1860 CheckCondition(1 == rocksdb_options_get_inplace_update_support(copy));
1861 CheckCondition(28 == rocksdb_options_get_inplace_update_num_locks(copy));
1862 CheckCondition(1 == rocksdb_options_get_report_bg_io_stats(copy));
1863 CheckCondition(2 == rocksdb_options_get_wal_recovery_mode(copy));
1864 CheckCondition(5 == rocksdb_options_get_compression(copy));
1865 CheckCondition(4 == rocksdb_options_get_bottommost_compression(copy));
1866 CheckCondition(2 == rocksdb_options_get_compaction_style(copy));
1867 CheckCondition(1 == rocksdb_options_get_atomic_flush(copy));
1868
1869 // Copies should be independent.
1870 rocksdb_options_set_allow_ingest_behind(copy, 0);
1871 CheckCondition(0 == rocksdb_options_get_allow_ingest_behind(copy));
1872 CheckCondition(1 == rocksdb_options_get_allow_ingest_behind(o));
1873
1874 rocksdb_options_compaction_readahead_size(copy, 20);
1875 CheckCondition(20 == rocksdb_options_get_compaction_readahead_size(copy));
1876 CheckCondition(10 == rocksdb_options_get_compaction_readahead_size(o));
1877
1878 rocksdb_options_set_create_if_missing(copy, 0);
1879 CheckCondition(0 == rocksdb_options_get_create_if_missing(copy));
1880 CheckCondition(1 == rocksdb_options_get_create_if_missing(o));
1881
1882 rocksdb_options_set_create_missing_column_families(copy, 0);
1883 CheckCondition(0 ==
1884 rocksdb_options_get_create_missing_column_families(copy));
1885 CheckCondition(1 == rocksdb_options_get_create_missing_column_families(o));
1886
1887 rocksdb_options_set_error_if_exists(copy, 0);
1888 CheckCondition(0 == rocksdb_options_get_error_if_exists(copy));
1889 CheckCondition(1 == rocksdb_options_get_error_if_exists(o));
1890
1891 rocksdb_options_set_paranoid_checks(copy, 0);
1892 CheckCondition(0 == rocksdb_options_get_paranoid_checks(copy));
1893 CheckCondition(1 == rocksdb_options_get_paranoid_checks(o));
1894
1895 rocksdb_options_set_info_log_level(copy, 2);
1896 CheckCondition(2 == rocksdb_options_get_info_log_level(copy));
1897 CheckCondition(3 == rocksdb_options_get_info_log_level(o));
1898
1899 rocksdb_options_set_write_buffer_size(copy, 200);
1900 CheckCondition(200 == rocksdb_options_get_write_buffer_size(copy));
1901 CheckCondition(100 == rocksdb_options_get_write_buffer_size(o));
1902
1903 rocksdb_options_set_db_write_buffer_size(copy, 2000);
1904 CheckCondition(2000 == rocksdb_options_get_db_write_buffer_size(copy));
1905 CheckCondition(1000 == rocksdb_options_get_db_write_buffer_size(o));
1906
1907 rocksdb_options_set_max_open_files(copy, 42);
1908 CheckCondition(42 == rocksdb_options_get_max_open_files(copy));
1909 CheckCondition(21 == rocksdb_options_get_max_open_files(o));
1910
1911 rocksdb_options_set_max_file_opening_threads(copy, 3);
1912 CheckCondition(3 == rocksdb_options_get_max_file_opening_threads(copy));
1913 CheckCondition(5 == rocksdb_options_get_max_file_opening_threads(o));
1914
1915 rocksdb_options_set_max_total_wal_size(copy, 4000);
1916 CheckCondition(4000 == rocksdb_options_get_max_total_wal_size(copy));
1917 CheckCondition(400 == rocksdb_options_get_max_total_wal_size(o));
1918
1919 rocksdb_options_set_num_levels(copy, 6);
1920 CheckCondition(6 == rocksdb_options_get_num_levels(copy));
1921 CheckCondition(7 == rocksdb_options_get_num_levels(o));
1922
1923 rocksdb_options_set_level0_file_num_compaction_trigger(copy, 14);
1924 CheckCondition(
1925 14 == rocksdb_options_get_level0_file_num_compaction_trigger(copy));
1926 CheckCondition(4 ==
1927 rocksdb_options_get_level0_file_num_compaction_trigger(o));
1928
1929 rocksdb_options_set_level0_slowdown_writes_trigger(copy, 61);
1930 CheckCondition(61 ==
1931 rocksdb_options_get_level0_slowdown_writes_trigger(copy));
1932 CheckCondition(6 == rocksdb_options_get_level0_slowdown_writes_trigger(o));
1933
1934 rocksdb_options_set_level0_stop_writes_trigger(copy, 17);
1935 CheckCondition(17 == rocksdb_options_get_level0_stop_writes_trigger(copy));
1936 CheckCondition(8 == rocksdb_options_get_level0_stop_writes_trigger(o));
1937
1938 rocksdb_options_set_target_file_size_base(copy, 128);
1939 CheckCondition(128 == rocksdb_options_get_target_file_size_base(copy));
1940 CheckCondition(256 == rocksdb_options_get_target_file_size_base(o));
1941
1942 rocksdb_options_set_target_file_size_multiplier(copy, 13);
1943 CheckCondition(13 == rocksdb_options_get_target_file_size_multiplier(copy));
1944 CheckCondition(3 == rocksdb_options_get_target_file_size_multiplier(o));
1945
1946 rocksdb_options_set_max_bytes_for_level_base(copy, 900);
1947 CheckCondition(900 == rocksdb_options_get_max_bytes_for_level_base(copy));
1948 CheckCondition(1024 == rocksdb_options_get_max_bytes_for_level_base(o));
1949
1950 rocksdb_options_set_level_compaction_dynamic_level_bytes(copy, 0);
1951 CheckCondition(
1952 0 == rocksdb_options_get_level_compaction_dynamic_level_bytes(copy));
1953 CheckCondition(1 ==
1954 rocksdb_options_get_level_compaction_dynamic_level_bytes(o));
1955
1956 rocksdb_options_set_max_bytes_for_level_multiplier(copy, 8.0);
1957 CheckCondition(8.0 ==
1958 rocksdb_options_get_max_bytes_for_level_multiplier(copy));
1959 CheckCondition(2.0 ==
1960 rocksdb_options_get_max_bytes_for_level_multiplier(o));
1961
1962 rocksdb_options_set_skip_stats_update_on_db_open(copy, 0);
1963 CheckCondition(0 == rocksdb_options_get_skip_stats_update_on_db_open(copy));
1964 CheckCondition(1 == rocksdb_options_get_skip_stats_update_on_db_open(o));
1965
1966 rocksdb_options_set_skip_checking_sst_file_sizes_on_db_open(copy, 0);
1967 CheckCondition(
1968 0 == rocksdb_options_get_skip_checking_sst_file_sizes_on_db_open(copy));
1969 CheckCondition(
1970 1 == rocksdb_options_get_skip_checking_sst_file_sizes_on_db_open(o));
1971
1972 rocksdb_options_set_max_write_buffer_number(copy, 2000);
1973 CheckCondition(2000 == rocksdb_options_get_max_write_buffer_number(copy));
1974 CheckCondition(97 == rocksdb_options_get_max_write_buffer_number(o));
1975
1976 rocksdb_options_set_min_write_buffer_number_to_merge(copy, 146);
1977 CheckCondition(146 ==
1978 rocksdb_options_get_min_write_buffer_number_to_merge(copy));
1979 CheckCondition(23 ==
1980 rocksdb_options_get_min_write_buffer_number_to_merge(o));
1981
1982 rocksdb_options_set_max_write_buffer_number_to_maintain(copy, 128);
1983 CheckCondition(
1984 128 == rocksdb_options_get_max_write_buffer_number_to_maintain(copy));
1985 CheckCondition(64 ==
1986 rocksdb_options_get_max_write_buffer_number_to_maintain(o));
1987
1988 rocksdb_options_set_max_write_buffer_size_to_maintain(copy, 9000);
1989 CheckCondition(9000 ==
1990 rocksdb_options_get_max_write_buffer_size_to_maintain(copy));
1991 CheckCondition(50000 ==
1992 rocksdb_options_get_max_write_buffer_size_to_maintain(o));
1993
1994 rocksdb_options_set_enable_pipelined_write(copy, 0);
1995 CheckCondition(0 == rocksdb_options_get_enable_pipelined_write(copy));
1996 CheckCondition(1 == rocksdb_options_get_enable_pipelined_write(o));
1997
1998 rocksdb_options_set_unordered_write(copy, 0);
1999 CheckCondition(0 == rocksdb_options_get_unordered_write(copy));
2000 CheckCondition(1 == rocksdb_options_get_unordered_write(o));
2001
2002 rocksdb_options_set_max_subcompactions(copy, 90001);
2003 CheckCondition(90001 == rocksdb_options_get_max_subcompactions(copy));
2004 CheckCondition(123456 == rocksdb_options_get_max_subcompactions(o));
2005
2006 rocksdb_options_set_max_background_jobs(copy, 12);
2007 CheckCondition(12 == rocksdb_options_get_max_background_jobs(copy));
2008 CheckCondition(2 == rocksdb_options_get_max_background_jobs(o));
2009
2010 rocksdb_options_set_max_background_compactions(copy, 13);
2011 CheckCondition(13 == rocksdb_options_get_max_background_compactions(copy));
2012 CheckCondition(3 == rocksdb_options_get_max_background_compactions(o));
2013
2014 rocksdb_options_set_base_background_compactions(copy, 14);
2015 CheckCondition(14 == rocksdb_options_get_base_background_compactions(copy));
2016 CheckCondition(4 == rocksdb_options_get_base_background_compactions(o));
2017
2018 rocksdb_options_set_max_background_flushes(copy, 15);
2019 CheckCondition(15 == rocksdb_options_get_max_background_flushes(copy));
2020 CheckCondition(5 == rocksdb_options_get_max_background_flushes(o));
2021
2022 rocksdb_options_set_max_log_file_size(copy, 16);
2023 CheckCondition(16 == rocksdb_options_get_max_log_file_size(copy));
2024 CheckCondition(6 == rocksdb_options_get_max_log_file_size(o));
2025
2026 rocksdb_options_set_log_file_time_to_roll(copy, 17);
2027 CheckCondition(17 == rocksdb_options_get_log_file_time_to_roll(copy));
2028 CheckCondition(7 == rocksdb_options_get_log_file_time_to_roll(o));
2029
2030 rocksdb_options_set_keep_log_file_num(copy, 18);
2031 CheckCondition(18 == rocksdb_options_get_keep_log_file_num(copy));
2032 CheckCondition(8 == rocksdb_options_get_keep_log_file_num(o));
2033
2034 rocksdb_options_set_recycle_log_file_num(copy, 19);
2035 CheckCondition(19 == rocksdb_options_get_recycle_log_file_num(copy));
2036 CheckCondition(9 == rocksdb_options_get_recycle_log_file_num(o));
2037
2038 rocksdb_options_set_soft_rate_limit(copy, 4.0);
2039 CheckCondition(4.0 == rocksdb_options_get_soft_rate_limit(copy));
2040 CheckCondition(2.0 == rocksdb_options_get_soft_rate_limit(o));
2041
2042 rocksdb_options_set_hard_rate_limit(copy, 2.0);
2043 CheckCondition(2.0 == rocksdb_options_get_hard_rate_limit(copy));
2044 CheckCondition(4.0 == rocksdb_options_get_hard_rate_limit(o));
2045
2046 rocksdb_options_set_soft_pending_compaction_bytes_limit(copy, 110);
2047 CheckCondition(
2048 110 == rocksdb_options_get_soft_pending_compaction_bytes_limit(copy));
2049 CheckCondition(10 ==
2050 rocksdb_options_get_soft_pending_compaction_bytes_limit(o));
2051
2052 rocksdb_options_set_hard_pending_compaction_bytes_limit(copy, 111);
2053 CheckCondition(
2054 111 == rocksdb_options_get_hard_pending_compaction_bytes_limit(copy));
2055 CheckCondition(11 ==
2056 rocksdb_options_get_hard_pending_compaction_bytes_limit(o));
2057
2058 rocksdb_options_set_rate_limit_delay_max_milliseconds(copy, 0);
2059 CheckCondition(0 ==
2060 rocksdb_options_get_rate_limit_delay_max_milliseconds(copy));
2061 CheckCondition(1 ==
2062 rocksdb_options_get_rate_limit_delay_max_milliseconds(o));
2063
2064 rocksdb_options_set_max_manifest_file_size(copy, 112);
2065 CheckCondition(112 == rocksdb_options_get_max_manifest_file_size(copy));
2066 CheckCondition(12 == rocksdb_options_get_max_manifest_file_size(o));
2067
2068 rocksdb_options_set_table_cache_numshardbits(copy, 113);
2069 CheckCondition(113 == rocksdb_options_get_table_cache_numshardbits(copy));
2070 CheckCondition(13 == rocksdb_options_get_table_cache_numshardbits(o));
2071
2072 rocksdb_options_set_arena_block_size(copy, 114);
2073 CheckCondition(114 == rocksdb_options_get_arena_block_size(copy));
2074 CheckCondition(14 == rocksdb_options_get_arena_block_size(o));
2075
2076 rocksdb_options_set_use_fsync(copy, 0);
2077 CheckCondition(0 == rocksdb_options_get_use_fsync(copy));
2078 CheckCondition(1 == rocksdb_options_get_use_fsync(o));
2079
2080 rocksdb_options_set_WAL_ttl_seconds(copy, 115);
2081 CheckCondition(115 == rocksdb_options_get_WAL_ttl_seconds(copy));
2082 CheckCondition(15 == rocksdb_options_get_WAL_ttl_seconds(o));
2083
2084 rocksdb_options_set_WAL_size_limit_MB(copy, 116);
2085 CheckCondition(116 == rocksdb_options_get_WAL_size_limit_MB(copy));
2086 CheckCondition(16 == rocksdb_options_get_WAL_size_limit_MB(o));
2087
2088 rocksdb_options_set_manifest_preallocation_size(copy, 117);
2089 CheckCondition(117 ==
2090 rocksdb_options_get_manifest_preallocation_size(copy));
2091 CheckCondition(17 == rocksdb_options_get_manifest_preallocation_size(o));
2092
2093 rocksdb_options_set_allow_mmap_reads(copy, 0);
2094 CheckCondition(0 == rocksdb_options_get_allow_mmap_reads(copy));
2095 CheckCondition(1 == rocksdb_options_get_allow_mmap_reads(o));
2096
2097 rocksdb_options_set_allow_mmap_writes(copy, 0);
2098 CheckCondition(0 == rocksdb_options_get_allow_mmap_writes(copy));
2099 CheckCondition(1 == rocksdb_options_get_allow_mmap_writes(o));
2100
2101 rocksdb_options_set_use_direct_reads(copy, 0);
2102 CheckCondition(0 == rocksdb_options_get_use_direct_reads(copy));
2103 CheckCondition(1 == rocksdb_options_get_use_direct_reads(o));
2104
2105 rocksdb_options_set_use_direct_io_for_flush_and_compaction(copy, 0);
2106 CheckCondition(
2107 0 == rocksdb_options_get_use_direct_io_for_flush_and_compaction(copy));
2108 CheckCondition(
2109 1 == rocksdb_options_get_use_direct_io_for_flush_and_compaction(o));
2110
2111 rocksdb_options_set_is_fd_close_on_exec(copy, 0);
2112 CheckCondition(0 == rocksdb_options_get_is_fd_close_on_exec(copy));
2113 CheckCondition(1 == rocksdb_options_get_is_fd_close_on_exec(o));
2114
2115 rocksdb_options_set_skip_log_error_on_recovery(copy, 0);
2116 CheckCondition(0 == rocksdb_options_get_skip_log_error_on_recovery(copy));
2117 CheckCondition(1 == rocksdb_options_get_skip_log_error_on_recovery(o));
2118
2119 rocksdb_options_set_stats_dump_period_sec(copy, 218);
2120 CheckCondition(218 == rocksdb_options_get_stats_dump_period_sec(copy));
2121 CheckCondition(18 == rocksdb_options_get_stats_dump_period_sec(o));
2122
2123 rocksdb_options_set_stats_persist_period_sec(copy, 600);
2124 CheckCondition(600 == rocksdb_options_get_stats_persist_period_sec(copy));
2125 CheckCondition(5 == rocksdb_options_get_stats_persist_period_sec(o));
2126
2127 rocksdb_options_set_advise_random_on_open(copy, 0);
2128 CheckCondition(0 == rocksdb_options_get_advise_random_on_open(copy));
2129 CheckCondition(1 == rocksdb_options_get_advise_random_on_open(o));
2130
2131 rocksdb_options_set_access_hint_on_compaction_start(copy, 2);
2132 CheckCondition(2 ==
2133 rocksdb_options_get_access_hint_on_compaction_start(copy));
2134 CheckCondition(3 == rocksdb_options_get_access_hint_on_compaction_start(o));
2135
2136 rocksdb_options_set_use_adaptive_mutex(copy, 0);
2137 CheckCondition(0 == rocksdb_options_get_use_adaptive_mutex(copy));
2138 CheckCondition(1 == rocksdb_options_get_use_adaptive_mutex(o));
2139
2140 rocksdb_options_set_bytes_per_sync(copy, 219);
2141 CheckCondition(219 == rocksdb_options_get_bytes_per_sync(copy));
2142 CheckCondition(19 == rocksdb_options_get_bytes_per_sync(o));
2143
2144 rocksdb_options_set_wal_bytes_per_sync(copy, 120);
2145 CheckCondition(120 == rocksdb_options_get_wal_bytes_per_sync(copy));
2146 CheckCondition(20 == rocksdb_options_get_wal_bytes_per_sync(o));
2147
2148 rocksdb_options_set_writable_file_max_buffer_size(copy, 121);
2149 CheckCondition(121 ==
2150 rocksdb_options_get_writable_file_max_buffer_size(copy));
2151 CheckCondition(21 == rocksdb_options_get_writable_file_max_buffer_size(o));
2152
2153 rocksdb_options_set_allow_concurrent_memtable_write(copy, 0);
2154 CheckCondition(0 ==
2155 rocksdb_options_get_allow_concurrent_memtable_write(copy));
2156 CheckCondition(1 == rocksdb_options_get_allow_concurrent_memtable_write(o));
2157
2158 rocksdb_options_set_enable_write_thread_adaptive_yield(copy, 0);
2159 CheckCondition(
2160 0 == rocksdb_options_get_enable_write_thread_adaptive_yield(copy));
2161 CheckCondition(1 ==
2162 rocksdb_options_get_enable_write_thread_adaptive_yield(o));
2163
2164 rocksdb_options_set_max_sequential_skip_in_iterations(copy, 122);
2165 CheckCondition(122 ==
2166 rocksdb_options_get_max_sequential_skip_in_iterations(copy));
2167 CheckCondition(22 ==
2168 rocksdb_options_get_max_sequential_skip_in_iterations(o));
2169
2170 rocksdb_options_set_disable_auto_compactions(copy, 0);
2171 CheckCondition(0 == rocksdb_options_get_disable_auto_compactions(copy));
2172 CheckCondition(1 == rocksdb_options_get_disable_auto_compactions(o));
2173
2174 rocksdb_options_set_optimize_filters_for_hits(copy, 0);
2175 CheckCondition(0 == rocksdb_options_get_optimize_filters_for_hits(copy));
2176 CheckCondition(1 == rocksdb_options_get_optimize_filters_for_hits(o));
2177
2178 rocksdb_options_set_delete_obsolete_files_period_micros(copy, 123);
2179 CheckCondition(
2180 123 == rocksdb_options_get_delete_obsolete_files_period_micros(copy));
2181 CheckCondition(23 ==
2182 rocksdb_options_get_delete_obsolete_files_period_micros(o));
2183
2184 rocksdb_options_set_memtable_prefix_bloom_size_ratio(copy, 4.0);
2185 CheckCondition(4.0 ==
2186 rocksdb_options_get_memtable_prefix_bloom_size_ratio(copy));
2187 CheckCondition(2.0 ==
2188 rocksdb_options_get_memtable_prefix_bloom_size_ratio(o));
2189
2190 rocksdb_options_set_max_compaction_bytes(copy, 124);
2191 CheckCondition(124 == rocksdb_options_get_max_compaction_bytes(copy));
2192 CheckCondition(24 == rocksdb_options_get_max_compaction_bytes(o));
2193
2194 rocksdb_options_set_memtable_huge_page_size(copy, 125);
2195 CheckCondition(125 == rocksdb_options_get_memtable_huge_page_size(copy));
2196 CheckCondition(25 == rocksdb_options_get_memtable_huge_page_size(o));
2197
2198 rocksdb_options_set_max_successive_merges(copy, 126);
2199 CheckCondition(126 == rocksdb_options_get_max_successive_merges(copy));
2200 CheckCondition(26 == rocksdb_options_get_max_successive_merges(o));
2201
2202 rocksdb_options_set_bloom_locality(copy, 127);
2203 CheckCondition(127 == rocksdb_options_get_bloom_locality(copy));
2204 CheckCondition(27 == rocksdb_options_get_bloom_locality(o));
2205
2206 rocksdb_options_set_inplace_update_support(copy, 0);
2207 CheckCondition(0 == rocksdb_options_get_inplace_update_support(copy));
2208 CheckCondition(1 == rocksdb_options_get_inplace_update_support(o));
2209
2210 rocksdb_options_set_inplace_update_num_locks(copy, 128);
2211 CheckCondition(128 == rocksdb_options_get_inplace_update_num_locks(copy));
2212 CheckCondition(28 == rocksdb_options_get_inplace_update_num_locks(o));
2213
2214 rocksdb_options_set_report_bg_io_stats(copy, 0);
2215 CheckCondition(0 == rocksdb_options_get_report_bg_io_stats(copy));
2216 CheckCondition(1 == rocksdb_options_get_report_bg_io_stats(o));
2217
2218 rocksdb_options_set_wal_recovery_mode(copy, 1);
2219 CheckCondition(1 == rocksdb_options_get_wal_recovery_mode(copy));
2220 CheckCondition(2 == rocksdb_options_get_wal_recovery_mode(o));
2221
2222 rocksdb_options_set_compression(copy, 4);
2223 CheckCondition(4 == rocksdb_options_get_compression(copy));
2224 CheckCondition(5 == rocksdb_options_get_compression(o));
2225
2226 rocksdb_options_set_bottommost_compression(copy, 3);
2227 CheckCondition(3 == rocksdb_options_get_bottommost_compression(copy));
2228 CheckCondition(4 == rocksdb_options_get_bottommost_compression(o));
2229
2230 rocksdb_options_set_compaction_style(copy, 1);
2231 CheckCondition(1 == rocksdb_options_get_compaction_style(copy));
2232 CheckCondition(2 == rocksdb_options_get_compaction_style(o));
2233
2234 rocksdb_options_set_atomic_flush(copy, 0);
2235 CheckCondition(0 == rocksdb_options_get_atomic_flush(copy));
2236 CheckCondition(1 == rocksdb_options_get_atomic_flush(o));
2237
2238 rocksdb_options_destroy(copy);
2239 rocksdb_options_destroy(o);
2240 }
2241
2242 StartPhase("read_options");
2243 {
2244 rocksdb_readoptions_t* ro;
2245 ro = rocksdb_readoptions_create();
2246
2247 rocksdb_readoptions_set_verify_checksums(ro, 1);
2248 CheckCondition(1 == rocksdb_readoptions_get_verify_checksums(ro));
2249
2250 rocksdb_readoptions_set_fill_cache(ro, 1);
2251 CheckCondition(1 == rocksdb_readoptions_get_fill_cache(ro));
2252
2253 rocksdb_readoptions_set_read_tier(ro, 2);
2254 CheckCondition(2 == rocksdb_readoptions_get_read_tier(ro));
2255
2256 rocksdb_readoptions_set_tailing(ro, 1);
2257 CheckCondition(1 == rocksdb_readoptions_get_tailing(ro));
2258
2259 rocksdb_readoptions_set_readahead_size(ro, 100);
2260 CheckCondition(100 == rocksdb_readoptions_get_readahead_size(ro));
2261
2262 rocksdb_readoptions_set_prefix_same_as_start(ro, 1);
2263 CheckCondition(1 == rocksdb_readoptions_get_prefix_same_as_start(ro));
2264
2265 rocksdb_readoptions_set_pin_data(ro, 1);
2266 CheckCondition(1 == rocksdb_readoptions_get_pin_data(ro));
2267
2268 rocksdb_readoptions_set_total_order_seek(ro, 1);
2269 CheckCondition(1 == rocksdb_readoptions_get_total_order_seek(ro));
2270
2271 rocksdb_readoptions_set_max_skippable_internal_keys(ro, 200);
2272 CheckCondition(200 ==
2273 rocksdb_readoptions_get_max_skippable_internal_keys(ro));
2274
2275 rocksdb_readoptions_set_background_purge_on_iterator_cleanup(ro, 1);
2276 CheckCondition(
2277 1 == rocksdb_readoptions_get_background_purge_on_iterator_cleanup(ro));
2278
2279 rocksdb_readoptions_set_ignore_range_deletions(ro, 1);
2280 CheckCondition(1 == rocksdb_readoptions_get_ignore_range_deletions(ro));
2281
2282 rocksdb_readoptions_destroy(ro);
2283 }
2284
2285 StartPhase("write_options");
2286 {
2287 rocksdb_writeoptions_t* wo;
2288 wo = rocksdb_writeoptions_create();
2289
2290 rocksdb_writeoptions_set_sync(wo, 1);
2291 CheckCondition(1 == rocksdb_writeoptions_get_sync(wo));
2292
2293 rocksdb_writeoptions_disable_WAL(wo, 1);
2294 CheckCondition(1 == rocksdb_writeoptions_get_disable_WAL(wo));
2295
2296 rocksdb_writeoptions_set_ignore_missing_column_families(wo, 1);
2297 CheckCondition(1 ==
2298 rocksdb_writeoptions_get_ignore_missing_column_families(wo));
2299
2300 rocksdb_writeoptions_set_no_slowdown(wo, 1);
2301 CheckCondition(1 == rocksdb_writeoptions_get_no_slowdown(wo));
2302
2303 rocksdb_writeoptions_set_low_pri(wo, 1);
2304 CheckCondition(1 == rocksdb_writeoptions_get_low_pri(wo));
2305
2306 rocksdb_writeoptions_set_memtable_insert_hint_per_batch(wo, 1);
2307 CheckCondition(1 ==
2308 rocksdb_writeoptions_get_memtable_insert_hint_per_batch(wo));
2309
2310 rocksdb_writeoptions_destroy(wo);
2311 }
2312
2313 StartPhase("compact_options");
2314 {
2315 rocksdb_compactoptions_t* co;
2316 co = rocksdb_compactoptions_create();
2317
2318 rocksdb_compactoptions_set_exclusive_manual_compaction(co, 1);
2319 CheckCondition(1 ==
2320 rocksdb_compactoptions_get_exclusive_manual_compaction(co));
2321
2322 rocksdb_compactoptions_set_bottommost_level_compaction(co, 1);
2323 CheckCondition(1 ==
2324 rocksdb_compactoptions_get_bottommost_level_compaction(co));
2325
2326 rocksdb_compactoptions_set_change_level(co, 1);
2327 CheckCondition(1 == rocksdb_compactoptions_get_change_level(co));
2328
2329 rocksdb_compactoptions_set_target_level(co, 1);
2330 CheckCondition(1 == rocksdb_compactoptions_get_target_level(co));
2331
2332 rocksdb_compactoptions_destroy(co);
2333 }
2334
2335 StartPhase("flush_options");
2336 {
2337 rocksdb_flushoptions_t* fo;
2338 fo = rocksdb_flushoptions_create();
2339
2340 rocksdb_flushoptions_set_wait(fo, 1);
2341 CheckCondition(1 == rocksdb_flushoptions_get_wait(fo));
2342
2343 rocksdb_flushoptions_destroy(fo);
2344 }
2345
2346 StartPhase("cache_options");
2347 {
2348 rocksdb_cache_t* co;
2349 co = rocksdb_cache_create_lru(100);
2350 CheckCondition(100 == rocksdb_cache_get_capacity(co));
2351
2352 rocksdb_cache_set_capacity(co, 200);
2353 CheckCondition(200 == rocksdb_cache_get_capacity(co));
2354
2355 rocksdb_cache_destroy(co);
2356 }
2357
2358 StartPhase("env");
2359 {
2360 rocksdb_env_t* e;
2361 e = rocksdb_create_default_env();
2362
2363 rocksdb_env_set_background_threads(e, 10);
2364 CheckCondition(10 == rocksdb_env_get_background_threads(e));
2365
2366 rocksdb_env_set_high_priority_background_threads(e, 20);
2367 CheckCondition(20 == rocksdb_env_get_high_priority_background_threads(e));
2368
2369 rocksdb_env_set_low_priority_background_threads(e, 30);
2370 CheckCondition(30 == rocksdb_env_get_low_priority_background_threads(e));
2371
2372 rocksdb_env_set_bottom_priority_background_threads(e, 40);
2373 CheckCondition(40 == rocksdb_env_get_bottom_priority_background_threads(e));
2374
2375 rocksdb_env_destroy(e);
2376 }
2377
2378 StartPhase("universal_compaction_options");
2379 {
2380 rocksdb_universal_compaction_options_t* uco;
2381 uco = rocksdb_universal_compaction_options_create();
2382
2383 rocksdb_universal_compaction_options_set_size_ratio(uco, 5);
2384 CheckCondition(5 ==
2385 rocksdb_universal_compaction_options_get_size_ratio(uco));
2386
2387 rocksdb_universal_compaction_options_set_min_merge_width(uco, 15);
2388 CheckCondition(
2389 15 == rocksdb_universal_compaction_options_get_min_merge_width(uco));
2390
2391 rocksdb_universal_compaction_options_set_max_merge_width(uco, 25);
2392 CheckCondition(
2393 25 == rocksdb_universal_compaction_options_get_max_merge_width(uco));
2394
2395 rocksdb_universal_compaction_options_set_max_size_amplification_percent(uco,
2396 35);
2397 CheckCondition(
2398 35 ==
2399 rocksdb_universal_compaction_options_get_max_size_amplification_percent(
2400 uco));
2401
2402 rocksdb_universal_compaction_options_set_compression_size_percent(uco, 45);
2403 CheckCondition(
2404 45 ==
2405 rocksdb_universal_compaction_options_get_compression_size_percent(uco));
2406
2407 rocksdb_universal_compaction_options_set_stop_style(uco, 1);
2408 CheckCondition(1 ==
2409 rocksdb_universal_compaction_options_get_stop_style(uco));
2410
2411 rocksdb_universal_compaction_options_destroy(uco);
2412 }
2413
2414 StartPhase("fifo_compaction_options");
2415 {
2416 rocksdb_fifo_compaction_options_t* fco;
2417 fco = rocksdb_fifo_compaction_options_create();
2418
2419 rocksdb_fifo_compaction_options_set_max_table_files_size(fco, 100000);
2420 CheckCondition(
2421 100000 ==
2422 rocksdb_fifo_compaction_options_get_max_table_files_size(fco));
2423
2424 rocksdb_fifo_compaction_options_destroy(fco);
2425 }
2426
2427 StartPhase("backupable_db_option");
2428 {
2429 rocksdb_backupable_db_options_t* bdo;
2430 bdo = rocksdb_backupable_db_options_create("path");
2431
2432 rocksdb_backupable_db_options_set_share_table_files(bdo, 1);
2433 CheckCondition(1 ==
2434 rocksdb_backupable_db_options_get_share_table_files(bdo));
2435
2436 rocksdb_backupable_db_options_set_sync(bdo, 1);
2437 CheckCondition(1 == rocksdb_backupable_db_options_get_sync(bdo));
2438
2439 rocksdb_backupable_db_options_set_destroy_old_data(bdo, 1);
2440 CheckCondition(1 ==
2441 rocksdb_backupable_db_options_get_destroy_old_data(bdo));
2442
2443 rocksdb_backupable_db_options_set_backup_log_files(bdo, 1);
2444 CheckCondition(1 ==
2445 rocksdb_backupable_db_options_get_backup_log_files(bdo));
2446
2447 rocksdb_backupable_db_options_set_backup_rate_limit(bdo, 123);
2448 CheckCondition(123 ==
2449 rocksdb_backupable_db_options_get_backup_rate_limit(bdo));
2450
2451 rocksdb_backupable_db_options_set_restore_rate_limit(bdo, 37);
2452 CheckCondition(37 ==
2453 rocksdb_backupable_db_options_get_restore_rate_limit(bdo));
2454
2455 rocksdb_backupable_db_options_set_max_background_operations(bdo, 20);
2456 CheckCondition(
2457 20 == rocksdb_backupable_db_options_get_max_background_operations(bdo));
2458
2459 rocksdb_backupable_db_options_set_callback_trigger_interval_size(bdo, 9000);
2460 CheckCondition(
2461 9000 ==
2462 rocksdb_backupable_db_options_get_callback_trigger_interval_size(bdo));
2463
2464 rocksdb_backupable_db_options_set_max_valid_backups_to_open(bdo, 40);
2465 CheckCondition(
2466 40 == rocksdb_backupable_db_options_get_max_valid_backups_to_open(bdo));
2467
2468 rocksdb_backupable_db_options_set_share_files_with_checksum_naming(bdo, 2);
2469 CheckCondition(
2470 2 == rocksdb_backupable_db_options_get_share_files_with_checksum_naming(
2471 bdo));
2472
2473 rocksdb_backupable_db_options_destroy(bdo);
2474 }
2475
2476 StartPhase("iterate_upper_bound");
2477 {
2478 // Create new empty database
2479 rocksdb_close(db);
2480 rocksdb_destroy_db(options, dbname, &err);
2481 CheckNoError(err);
2482
2483 rocksdb_options_set_prefix_extractor(options, NULL);
2484 db = rocksdb_open(options, dbname, &err);
2485 CheckNoError(err);
2486
2487 rocksdb_put(db, woptions, "a", 1, "0", 1, &err); CheckNoError(err);
2488 rocksdb_put(db, woptions, "foo", 3, "bar", 3, &err); CheckNoError(err);
2489 rocksdb_put(db, woptions, "foo1", 4, "bar1", 4, &err); CheckNoError(err);
2490 rocksdb_put(db, woptions, "g1", 2, "0", 1, &err); CheckNoError(err);
2491
2492 // testing basic case with no iterate_upper_bound and no prefix_extractor
2493 {
2494 rocksdb_readoptions_set_iterate_upper_bound(roptions, NULL, 0);
2495 rocksdb_iterator_t* iter = rocksdb_create_iterator(db, roptions);
2496
2497 rocksdb_iter_seek(iter, "foo", 3);
2498 CheckCondition(rocksdb_iter_valid(iter));
2499 CheckIter(iter, "foo", "bar");
2500
2501 rocksdb_iter_next(iter);
2502 CheckCondition(rocksdb_iter_valid(iter));
2503 CheckIter(iter, "foo1", "bar1");
2504
2505 rocksdb_iter_next(iter);
2506 CheckCondition(rocksdb_iter_valid(iter));
2507 CheckIter(iter, "g1", "0");
2508
2509 rocksdb_iter_destroy(iter);
2510 }
2511
2512 // testing iterate_upper_bound and forward iterator
2513 // to make sure it stops at bound
2514 {
2515 // iterate_upper_bound points beyond the last expected entry
2516 rocksdb_readoptions_set_iterate_upper_bound(roptions, "foo2", 4);
2517
2518 rocksdb_iterator_t* iter = rocksdb_create_iterator(db, roptions);
2519
2520 rocksdb_iter_seek(iter, "foo", 3);
2521 CheckCondition(rocksdb_iter_valid(iter));
2522 CheckIter(iter, "foo", "bar");
2523
2524 rocksdb_iter_next(iter);
2525 CheckCondition(rocksdb_iter_valid(iter));
2526 CheckIter(iter, "foo1", "bar1");
2527
2528 rocksdb_iter_next(iter);
2529 // should stop here...
2530 CheckCondition(!rocksdb_iter_valid(iter));
2531
2532 rocksdb_iter_destroy(iter);
2533 rocksdb_readoptions_set_iterate_upper_bound(roptions, NULL, 0);
2534 }
2535 }
2536
2537 StartPhase("transactions");
2538 {
2539 rocksdb_close(db);
2540 rocksdb_destroy_db(options, dbname, &err);
2541 CheckNoError(err);
2542
2543 // open a TransactionDB
2544 txn_db_options = rocksdb_transactiondb_options_create();
2545 txn_options = rocksdb_transaction_options_create();
2546 rocksdb_options_set_create_if_missing(options, 1);
2547 txn_db = rocksdb_transactiondb_open(options, txn_db_options, dbname, &err);
2548 CheckNoError(err);
2549
2550 // put outside a transaction
2551 rocksdb_transactiondb_put(txn_db, woptions, "foo", 3, "hello", 5, &err);
2552 CheckNoError(err);
2553 CheckTxnDBGet(txn_db, roptions, "foo", "hello");
2554
2555 // delete from outside transaction
2556 rocksdb_transactiondb_delete(txn_db, woptions, "foo", 3, &err);
2557 CheckNoError(err);
2558 CheckTxnDBGet(txn_db, roptions, "foo", NULL);
2559
2560 // write batch into TransactionDB
2561 rocksdb_writebatch_t* wb = rocksdb_writebatch_create();
2562 rocksdb_writebatch_put(wb, "foo", 3, "a", 1);
2563 rocksdb_writebatch_clear(wb);
2564 rocksdb_writebatch_put(wb, "bar", 3, "b", 1);
2565 rocksdb_writebatch_put(wb, "box", 3, "c", 1);
2566 rocksdb_writebatch_delete(wb, "bar", 3);
2567 rocksdb_transactiondb_write(txn_db, woptions, wb, &err);
2568 rocksdb_writebatch_destroy(wb);
2569 CheckTxnDBGet(txn_db, roptions, "box", "c");
2570 CheckNoError(err);
2571
2572 // begin a transaction
2573 txn = rocksdb_transaction_begin(txn_db, woptions, txn_options, NULL);
2574 // put
2575 rocksdb_transaction_put(txn, "foo", 3, "hello", 5, &err);
2576 CheckNoError(err);
2577 CheckTxnGet(txn, roptions, "foo", "hello");
2578 // delete
2579 rocksdb_transaction_delete(txn, "foo", 3, &err);
2580 CheckNoError(err);
2581 CheckTxnGet(txn, roptions, "foo", NULL);
2582
2583 rocksdb_transaction_put(txn, "foo", 3, "hello", 5, &err);
2584 CheckNoError(err);
2585
2586 // read from outside transaction, before commit
2587 CheckTxnDBGet(txn_db, roptions, "foo", NULL);
2588
2589 // commit
2590 rocksdb_transaction_commit(txn, &err);
2591 CheckNoError(err);
2592
2593 // read from outside transaction, after commit
2594 CheckTxnDBGet(txn_db, roptions, "foo", "hello");
2595
2596 // reuse old transaction
2597 txn = rocksdb_transaction_begin(txn_db, woptions, txn_options, txn);
2598
2599 // snapshot
2600 const rocksdb_snapshot_t* snapshot;
2601 snapshot = rocksdb_transactiondb_create_snapshot(txn_db);
2602 rocksdb_readoptions_set_snapshot(roptions, snapshot);
2603
2604 rocksdb_transactiondb_put(txn_db, woptions, "foo", 3, "hey", 3, &err);
2605 CheckNoError(err);
2606
2607 CheckTxnDBGet(txn_db, roptions, "foo", "hello");
2608 rocksdb_readoptions_set_snapshot(roptions, NULL);
2609 rocksdb_transactiondb_release_snapshot(txn_db, snapshot);
2610 CheckTxnDBGet(txn_db, roptions, "foo", "hey");
2611
2612 // iterate
2613 rocksdb_transaction_put(txn, "bar", 3, "hi", 2, &err);
2614 rocksdb_iterator_t* iter = rocksdb_transaction_create_iterator(txn, roptions);
2615 CheckCondition(!rocksdb_iter_valid(iter));
2616 rocksdb_iter_seek_to_first(iter);
2617 CheckCondition(rocksdb_iter_valid(iter));
2618 CheckIter(iter, "bar", "hi");
2619 rocksdb_iter_get_error(iter, &err);
2620 CheckNoError(err);
2621 rocksdb_iter_destroy(iter);
2622
2623 // rollback
2624 rocksdb_transaction_rollback(txn, &err);
2625 CheckNoError(err);
2626 CheckTxnDBGet(txn_db, roptions, "bar", NULL);
2627
2628 // save point
2629 rocksdb_transaction_put(txn, "foo1", 4, "hi1", 3, &err);
2630 rocksdb_transaction_set_savepoint(txn);
2631 CheckTxnGet(txn, roptions, "foo1", "hi1");
2632 rocksdb_transaction_put(txn, "foo2", 4, "hi2", 3, &err);
2633 CheckTxnGet(txn, roptions, "foo2", "hi2");
2634
2635 // rollback to savepoint
2636 rocksdb_transaction_rollback_to_savepoint(txn, &err);
2637 CheckNoError(err);
2638 CheckTxnGet(txn, roptions, "foo2", NULL);
2639 CheckTxnGet(txn, roptions, "foo1", "hi1");
2640 CheckTxnDBGet(txn_db, roptions, "foo1", NULL);
2641 CheckTxnDBGet(txn_db, roptions, "foo2", NULL);
2642 rocksdb_transaction_commit(txn, &err);
2643 CheckNoError(err);
2644 CheckTxnDBGet(txn_db, roptions, "foo1", "hi1");
2645 CheckTxnDBGet(txn_db, roptions, "foo2", NULL);
2646
2647 // Column families.
2648 rocksdb_column_family_handle_t* cfh;
2649 cfh = rocksdb_transactiondb_create_column_family(txn_db, options,
2650 "txn_db_cf", &err);
2651 CheckNoError(err);
2652
2653 rocksdb_transactiondb_put_cf(txn_db, woptions, cfh, "cf_foo", 6, "cf_hello",
2654 8, &err);
2655 CheckNoError(err);
2656 CheckTxnDBGetCF(txn_db, roptions, cfh, "cf_foo", "cf_hello");
2657
2658 rocksdb_transactiondb_delete_cf(txn_db, woptions, cfh, "cf_foo", 6, &err);
2659 CheckNoError(err);
2660 CheckTxnDBGetCF(txn_db, roptions, cfh, "cf_foo", NULL);
2661
2662 rocksdb_column_family_handle_destroy(cfh);
2663
2664 // close and destroy
2665 rocksdb_transaction_destroy(txn);
2666 rocksdb_transactiondb_close(txn_db);
2667 rocksdb_destroy_db(options, dbname, &err);
2668 CheckNoError(err);
2669 rocksdb_transaction_options_destroy(txn_options);
2670 rocksdb_transactiondb_options_destroy(txn_db_options);
2671 }
2672
2673 StartPhase("optimistic_transactions");
2674 {
2675 rocksdb_options_t* db_options = rocksdb_options_create();
2676 rocksdb_options_set_create_if_missing(db_options, 1);
2677 rocksdb_options_set_allow_concurrent_memtable_write(db_options, 1);
2678 otxn_db = rocksdb_optimistictransactiondb_open(db_options, dbname, &err);
2679 otxn_options = rocksdb_optimistictransaction_options_create();
2680 rocksdb_transaction_t* txn1 = rocksdb_optimistictransaction_begin(
2681 otxn_db, woptions, otxn_options, NULL);
2682 rocksdb_transaction_t* txn2 = rocksdb_optimistictransaction_begin(
2683 otxn_db, woptions, otxn_options, NULL);
2684 rocksdb_transaction_put(txn1, "key", 3, "value", 5, &err);
2685 CheckNoError(err);
2686 rocksdb_transaction_put(txn2, "key1", 4, "value1", 6, &err);
2687 CheckNoError(err);
2688 CheckTxnGet(txn1, roptions, "key", "value");
2689 rocksdb_transaction_commit(txn1, &err);
2690 CheckNoError(err);
2691 rocksdb_transaction_commit(txn2, &err);
2692 CheckNoError(err);
2693 rocksdb_transaction_destroy(txn1);
2694 rocksdb_transaction_destroy(txn2);
2695
2696 // Check column family
2697 db = rocksdb_optimistictransactiondb_get_base_db(otxn_db);
2698 rocksdb_put(db, woptions, "key", 3, "value", 5, &err);
2699 CheckNoError(err);
2700 rocksdb_column_family_handle_t *cfh1, *cfh2;
2701 cfh1 = rocksdb_create_column_family(db, db_options, "txn_db_cf1", &err);
2702 cfh2 = rocksdb_create_column_family(db, db_options, "txn_db_cf2", &err);
2703 txn = rocksdb_optimistictransaction_begin(otxn_db, woptions, otxn_options,
2704 NULL);
2705 rocksdb_transaction_put_cf(txn, cfh1, "key_cf1", 7, "val_cf1", 7, &err);
2706 CheckNoError(err);
2707 rocksdb_transaction_put_cf(txn, cfh2, "key_cf2", 7, "val_cf2", 7, &err);
2708 CheckNoError(err);
2709 rocksdb_transaction_commit(txn, &err);
2710 CheckNoError(err);
2711 txn = rocksdb_optimistictransaction_begin(otxn_db, woptions, otxn_options,
2712 txn);
2713 CheckGetCF(db, roptions, cfh1, "key_cf1", "val_cf1");
2714 CheckTxnGetCF(txn, roptions, cfh1, "key_cf1", "val_cf1");
2715
2716 // Check iterator with column family
2717 rocksdb_transaction_put_cf(txn, cfh1, "key1_cf", 7, "val1_cf", 7, &err);
2718 CheckNoError(err);
2719 rocksdb_iterator_t* iter =
2720 rocksdb_transaction_create_iterator_cf(txn, roptions, cfh1);
2721 CheckCondition(!rocksdb_iter_valid(iter));
2722 rocksdb_iter_seek_to_first(iter);
2723 CheckCondition(rocksdb_iter_valid(iter));
2724 CheckIter(iter, "key1_cf", "val1_cf");
2725 rocksdb_iter_get_error(iter, &err);
2726 CheckNoError(err);
2727 rocksdb_iter_destroy(iter);
2728
2729 rocksdb_transaction_destroy(txn);
2730 rocksdb_column_family_handle_destroy(cfh1);
2731 rocksdb_column_family_handle_destroy(cfh2);
2732 rocksdb_optimistictransactiondb_close_base_db(db);
2733 rocksdb_optimistictransactiondb_close(otxn_db);
2734
2735 // Check open optimistic transaction db with column families
2736 size_t cf_len;
2737 char** column_fams =
2738 rocksdb_list_column_families(db_options, dbname, &cf_len, &err);
2739 CheckNoError(err);
2740 CheckEqual("default", column_fams[0], 7);
2741 CheckEqual("txn_db_cf1", column_fams[1], 10);
2742 CheckEqual("txn_db_cf2", column_fams[2], 10);
2743 CheckCondition(cf_len == 3);
2744 rocksdb_list_column_families_destroy(column_fams, cf_len);
2745
2746 const char* cf_names[3] = {"default", "txn_db_cf1", "txn_db_cf2"};
2747 rocksdb_options_t* cf_options = rocksdb_options_create();
2748 const rocksdb_options_t* cf_opts[3] = {cf_options, cf_options, cf_options};
2749
2750 rocksdb_options_set_error_if_exists(cf_options, 0);
2751 rocksdb_column_family_handle_t* cf_handles[3];
2752 otxn_db = rocksdb_optimistictransactiondb_open_column_families(
2753 db_options, dbname, 3, cf_names, cf_opts, cf_handles, &err);
2754 CheckNoError(err);
2755 rocksdb_transaction_t* txn_cf = rocksdb_optimistictransaction_begin(
2756 otxn_db, woptions, otxn_options, NULL);
2757 CheckTxnGetCF(txn_cf, roptions, cf_handles[0], "key", "value");
2758 CheckTxnGetCF(txn_cf, roptions, cf_handles[1], "key_cf1", "val_cf1");
2759 CheckTxnGetCF(txn_cf, roptions, cf_handles[2], "key_cf2", "val_cf2");
2760 rocksdb_transaction_destroy(txn_cf);
2761 rocksdb_options_destroy(cf_options);
2762 rocksdb_column_family_handle_destroy(cf_handles[0]);
2763 rocksdb_column_family_handle_destroy(cf_handles[1]);
2764 rocksdb_column_family_handle_destroy(cf_handles[2]);
2765 rocksdb_optimistictransactiondb_close(otxn_db);
2766 rocksdb_destroy_db(db_options, dbname, &err);
2767 rocksdb_options_destroy(db_options);
2768 rocksdb_optimistictransaction_options_destroy(otxn_options);
2769 CheckNoError(err);
2770 }
2771
2772 // Simple sanity check that setting memtable rep works.
2773 StartPhase("memtable_reps");
2774 {
2775 // Create database with vector memtable.
2776 rocksdb_options_set_memtable_vector_rep(options);
2777 db = rocksdb_open(options, dbname, &err);
2778 CheckNoError(err);
2779
2780 // Create database with hash skiplist memtable.
2781 rocksdb_close(db);
2782 rocksdb_destroy_db(options, dbname, &err);
2783 CheckNoError(err);
2784
2785 rocksdb_options_set_hash_skip_list_rep(options, 5000, 4, 4);
2786 db = rocksdb_open(options, dbname, &err);
2787 CheckNoError(err);
2788 }
2789
2790 // Check that secondary instance works.
2791 StartPhase("open_as_secondary");
2792 {
2793 rocksdb_close(db);
2794 rocksdb_destroy_db(options, dbname, &err);
2795
2796 rocksdb_options_t* db_options = rocksdb_options_create();
2797 rocksdb_options_set_create_if_missing(db_options, 1);
2798 db = rocksdb_open(db_options, dbname, &err);
2799 CheckNoError(err);
2800 rocksdb_t* db1;
2801 rocksdb_options_t* opts = rocksdb_options_create();
2802 rocksdb_options_set_max_open_files(opts, -1);
2803 rocksdb_options_set_create_if_missing(opts, 1);
2804 snprintf(secondary_path, sizeof(secondary_path),
2805 "%s/rocksdb_c_test_secondary-%d", GetTempDir(), ((int)geteuid()));
2806 db1 = rocksdb_open_as_secondary(opts, dbname, secondary_path, &err);
2807 CheckNoError(err);
2808
2809 rocksdb_writeoptions_set_sync(woptions, 0);
2810 rocksdb_writeoptions_disable_WAL(woptions, 1);
2811 rocksdb_put(db, woptions, "key0", 4, "value0", 6, &err);
2812 CheckNoError(err);
2813 rocksdb_flushoptions_t* flush_opts = rocksdb_flushoptions_create();
2814 rocksdb_flushoptions_set_wait(flush_opts, 1);
2815 rocksdb_flush(db, flush_opts, &err);
2816 CheckNoError(err);
2817 rocksdb_try_catch_up_with_primary(db1, &err);
2818 CheckNoError(err);
2819 rocksdb_readoptions_t* ropts = rocksdb_readoptions_create();
2820 rocksdb_readoptions_set_verify_checksums(ropts, 1);
2821 rocksdb_readoptions_set_snapshot(ropts, NULL);
2822 CheckGet(db, ropts, "key0", "value0");
2823 CheckGet(db1, ropts, "key0", "value0");
2824
2825 rocksdb_writeoptions_disable_WAL(woptions, 0);
2826 rocksdb_put(db, woptions, "key1", 4, "value1", 6, &err);
2827 CheckNoError(err);
2828 rocksdb_try_catch_up_with_primary(db1, &err);
2829 CheckNoError(err);
2830 CheckGet(db1, ropts, "key0", "value0");
2831 CheckGet(db1, ropts, "key1", "value1");
2832
2833 rocksdb_close(db1);
2834 rocksdb_destroy_db(opts, secondary_path, &err);
2835 CheckNoError(err);
2836
2837 rocksdb_options_destroy(db_options);
2838 rocksdb_options_destroy(opts);
2839 rocksdb_readoptions_destroy(ropts);
2840 rocksdb_flushoptions_destroy(flush_opts);
2841 }
2842
2843 // Simple sanity check that options setting db_paths work.
2844 StartPhase("open_db_paths");
2845 {
2846 rocksdb_close(db);
2847 rocksdb_destroy_db(options, dbname, &err);
2848
2849 const rocksdb_dbpath_t* paths[1] = {dbpath};
2850 rocksdb_options_set_db_paths(options, paths, 1);
2851 db = rocksdb_open(options, dbname, &err);
2852 CheckNoError(err);
2853 }
2854
2855 StartPhase("cancel_all_background_work");
2856 rocksdb_cancel_all_background_work(db, 1);
2857
2858 StartPhase("cleanup");
2859 rocksdb_close(db);
2860 rocksdb_options_destroy(options);
2861 rocksdb_block_based_options_destroy(table_options);
2862 rocksdb_readoptions_destroy(roptions);
2863 rocksdb_writeoptions_destroy(woptions);
2864 rocksdb_compactoptions_destroy(coptions);
2865 rocksdb_cache_destroy(cache);
2866 rocksdb_comparator_destroy(cmp);
2867 rocksdb_dbpath_destroy(dbpath);
2868 rocksdb_env_destroy(env);
2869
2870 fprintf(stderr, "PASS\n");
2871 return 0;
2872 }
2873
2874 #else
2875
2876 int main() {
2877 fprintf(stderr, "SKIPPED\n");
2878 return 0;
2879 }
2880
2881 #endif // !ROCKSDB_LITE