From d3aaa32b20824bf24a5d2dcc6ff8b92d5152f5ed Mon Sep 17 00:00:00 2001 From: Leif Walsh Date: Wed, 17 Apr 2013 00:00:29 -0400 Subject: [PATCH] [t:4882] change compression type to be set before create this means you have to set the compression type before calling db->open and you can't change it after that we also log it now this bumps the version layout to BRT_LAYOUT_VERSION_20 git-svn-id: file:///svn/toku/tokudb@43511 c7de825b-a66e-492c-adef-691d508d4ae1 --- .globalrc | 2 +- newbrt/brt-internal.h | 1 + newbrt/brt-serialize.c | 89 ++++++++++--------- newbrt/brt.c | 16 ++-- newbrt/brt.h | 2 +- newbrt/brt_header.c | 4 +- newbrt/brt_layout_version.h | 1 + newbrt/brtdump.c | 1 + newbrt/logformat.c | 1 + newbrt/logger.c | 4 +- newbrt/logger.h | 2 +- newbrt/recover.c | 13 ++- newbrt/tests/benchmark-test.c | 3 +- newbrt/tests/brt-serialize-sub-block-test.c | 5 +- newbrt/tests/brt-test-cursor-2.c | 2 +- newbrt/tests/brt-test-cursor.c | 26 +++--- newbrt/tests/brt-test-header.c | 4 +- newbrt/tests/brt-test.c | 42 ++++----- newbrt/tests/brt-test0.c | 2 +- newbrt/tests/brt-test1.c | 2 +- newbrt/tests/brt-test2.c | 2 +- newbrt/tests/brt-test3.c | 4 +- newbrt/tests/brt-test4.c | 2 +- newbrt/tests/brt-test5.c | 2 +- newbrt/tests/is_empty.c | 8 +- newbrt/tests/keyrange.c | 2 +- newbrt/tests/le-cursor-provdel.c | 4 +- newbrt/tests/le-cursor-right.c | 8 +- newbrt/tests/le-cursor-walk.c | 4 +- newbrt/tests/make-tree.c | 2 +- newbrt/tests/msnfilter.c | 2 +- newbrt/tests/orthopush-flush.c | 2 +- newbrt/tests/shortcut.c | 2 +- newbrt/tests/test-brt-overflow.c | 2 +- newbrt/tests/test-checkpoint-during-flush.c | 4 +- newbrt/tests/test-checkpoint-during-merge.c | 4 +- .../tests/test-checkpoint-during-rebalance.c | 4 +- newbrt/tests/test-checkpoint-during-split.c | 4 +- newbrt/tests/test-del-inorder.c | 2 +- newbrt/tests/test-dirty-flushes-on-cleaner.c | 2 +- newbrt/tests/test-dump-brt.c | 2 +- newbrt/tests/test-flushes-on-cleaner.c | 2 +- newbrt/tests/test-inc-split.c | 2 +- newbrt/tests/test-merges-on-cleaner.c | 2 +- newbrt/tests/test-pick-child-to-flush.c | 2 +- newbrt/tests/test3681.c | 2 +- newbrt/tests/test3856.c | 5 +- newbrt/tests/test3884.c | 12 +-- newbrt/tests/test4115.c | 2 +- newbrt/tests/test4244.c | 2 +- newbrt/tests/test_logcursor.c | 4 +- newbrt/tests/upgrade_test_simple.c | 1 + newbrt/tests/verify-bad-msn.c | 2 +- newbrt/tests/verify-bad-pivots.c | 2 +- newbrt/tests/verify-dup-in-leaf.c | 2 +- newbrt/tests/verify-dup-pivots.c | 2 +- newbrt/tests/verify-misrouted-msgs.c | 2 +- newbrt/tests/verify-unsorted-leaf.c | 2 +- newbrt/tests/verify-unsorted-pivots.c | 2 +- src/tests/test_compression_methods.c | 13 +-- src/ydb_db.c | 16 +--- 61 files changed, 186 insertions(+), 183 deletions(-) diff --git a/.globalrc b/.globalrc index 8dd09f2385c..067e749bbec 100644 --- a/.globalrc +++ b/.globalrc @@ -1,2 +1,2 @@ default:\ - :skip=/windows/,/dbg/,/opt/,/build/,/gccdbg/,/gccopt/,/iccdbg/,/iccopt/,/NightlyRelease/,/NightlyCoverage/,/NightlyDebug/,/Debug/,/Release/,/Coverage/,/cov/: + :skip=/windows/,/dbg/,/opt/,/build/,/gccdbg/,/gccopt/,/iccdbg/,/iccopt/,/clangdbg/,/NightlyRelease/,/NightlyCoverage/,/NightlyDebug/,/Debug/,/Release/,/Coverage/,/cov/: diff --git a/newbrt/brt-internal.h b/newbrt/brt-internal.h index 16dd12963f5..9b4cfde5a00 100644 --- a/newbrt/brt-internal.h +++ b/newbrt/brt-internal.h @@ -425,6 +425,7 @@ struct brt { unsigned int nodesize; unsigned int basementnodesize; + enum toku_compression_method compression_method; unsigned int flags; BOOL did_set_flags; brt_compare_func compare_fun; diff --git a/newbrt/brt-serialize.c b/newbrt/brt-serialize.c index 4da76ea647b..33784451d2f 100644 --- a/newbrt/brt-serialize.c +++ b/newbrt/brt-serialize.c @@ -2502,52 +2502,53 @@ serialize_brt_header_min_size (u_int32_t version) { switch(version) { + case BRT_LAYOUT_VERSION_20: case BRT_LAYOUT_VERSION_19: size += 1; // compression method - size += sizeof(uint64_t); // highest_unused_msn_for_upgrade - case BRT_LAYOUT_VERSION_18: - size += sizeof(uint64_t); // time_of_last_optimize_begin - size += sizeof(uint64_t); // time_of_last_optimize_end - size += sizeof(uint32_t); // count_of_optimize_in_progress - size += sizeof(MSN); // msn_at_start_of_last_completed_optimize - size -= 8; // removed num_blocks_to_upgrade_14 - size -= 8; // removed num_blocks_to_upgrade_13 - case BRT_LAYOUT_VERSION_17: - size += 16; - invariant(sizeof(STAT64INFO_S) == 16); - case BRT_LAYOUT_VERSION_16: - case BRT_LAYOUT_VERSION_15: - size += 4; // basement node size - size += 8; // num_blocks_to_upgrade_14 (previously num_blocks_to_upgrade, now one int each for upgrade from 13, 14 - size += 8; // time of last verification - case BRT_LAYOUT_VERSION_14: - size += 8; //TXNID that created - case BRT_LAYOUT_VERSION_13: - size += ( 4 // build_id - +4 // build_id_original - +8 // time_of_creation - +8 // time_of_last_modification - ); - // fall through - case BRT_LAYOUT_VERSION_12: - size += (+8 // "tokudata" - +4 // version - +4 // original_version - +4 // size - +8 // byte order verification - +8 // checkpoint_count - +8 // checkpoint_lsn - +4 // tree's nodesize - +8 // translation_size_on_disk - +8 // translation_address_on_disk - +4 // checksum - +8 // Number of blocks in old version. - +8 // diskoff - +4 // flags - ); - break; - default: - lazy_assert(FALSE); + size += sizeof(uint64_t); // highest_unused_msn_for_upgrade + case BRT_LAYOUT_VERSION_18: + size += sizeof(uint64_t); // time_of_last_optimize_begin + size += sizeof(uint64_t); // time_of_last_optimize_end + size += sizeof(uint32_t); // count_of_optimize_in_progress + size += sizeof(MSN); // msn_at_start_of_last_completed_optimize + size -= 8; // removed num_blocks_to_upgrade_14 + size -= 8; // removed num_blocks_to_upgrade_13 + case BRT_LAYOUT_VERSION_17: + size += 16; + invariant(sizeof(STAT64INFO_S) == 16); + case BRT_LAYOUT_VERSION_16: + case BRT_LAYOUT_VERSION_15: + size += 4; // basement node size + size += 8; // num_blocks_to_upgrade_14 (previously num_blocks_to_upgrade, now one int each for upgrade from 13, 14 + size += 8; // time of last verification + case BRT_LAYOUT_VERSION_14: + size += 8; //TXNID that created + case BRT_LAYOUT_VERSION_13: + size += ( 4 // build_id + +4 // build_id_original + +8 // time_of_creation + +8 // time_of_last_modification + ); + // fall through + case BRT_LAYOUT_VERSION_12: + size += (+8 // "tokudata" + +4 // version + +4 // original_version + +4 // size + +8 // byte order verification + +8 // checkpoint_count + +8 // checkpoint_lsn + +4 // tree's nodesize + +8 // translation_size_on_disk + +8 // translation_address_on_disk + +4 // checksum + +8 // Number of blocks in old version. + +8 // diskoff + +4 // flags + ); + break; + default: + lazy_assert(FALSE); } lazy_assert(size <= BLOCK_ALLOCATOR_HEADER_RESERVE); return size; diff --git a/newbrt/brt.c b/newbrt/brt.c index a6fb977cb27..0673f424ede 100644 --- a/newbrt/brt.c +++ b/newbrt/brt.c @@ -3053,8 +3053,11 @@ mempool_malloc_from_omt(OMT omt, struct mempool *mp, size_t size, void **maybe_f /* ******************** open,close and create ********************** */ // Test only function (not used in running system). This one has no env -int toku_open_brt (const char *fname, int is_create, BRT *newbrt, int nodesize, int basementnodesize, CACHETABLE cachetable, TOKUTXN txn, - int (*compare_fun)(DB *, const DBT*,const DBT*)) { +int toku_open_brt (const char *fname, int is_create, BRT *newbrt, int nodesize, + int basementnodesize, + enum toku_compression_method compression_method, + CACHETABLE cachetable, TOKUTXN txn, + int (*compare_fun)(DB *, const DBT*,const DBT*)) { BRT brt; int r; const int only_create = 0; @@ -3064,6 +3067,7 @@ int toku_open_brt (const char *fname, int is_create, BRT *newbrt, int nodesize, return r; r = toku_brt_set_nodesize(brt, nodesize); assert_zero(r); r = toku_brt_set_basementnodesize(brt, basementnodesize); assert_zero(r); + r = toku_brt_set_compression_method(brt, compression_method); assert_zero(r); r = toku_brt_set_bt_compare(brt, compare_fun); assert_zero(r); r = toku_brt_open(brt, fname, is_create, only_create, cachetable, txn); @@ -3118,14 +3122,14 @@ static int brt_open_file(const char *fname, int *fdp) { int toku_brt_set_compression_method(BRT t, enum toku_compression_method method) { - t->h->compression_method = method; + t->compression_method = method; return 0; } int toku_brt_get_compression_method(BRT t, enum toku_compression_method *methodp) { - *methodp = t->h->compression_method; + *methodp = t->compression_method; return 0; } @@ -3272,7 +3276,7 @@ brt_open(BRT t, const char *fname_in_env, int is_create, int only_create, CACHET assert_zero(r); } txn_created = (BOOL)(txn!=NULL); - r = toku_logger_log_fcreate(txn, fname_in_env, reserved_filenum, mode, t->flags, t->nodesize, t->basementnodesize); + r = toku_logger_log_fcreate(txn, fname_in_env, reserved_filenum, mode, t->flags, t->nodesize, t->basementnodesize, t->compression_method); assert_zero(r); // only possible failure is panic, which we check above r = brt_create_file(t, fname_in_cwd, &fd); assert_zero(r); @@ -3309,6 +3313,7 @@ brt_open(BRT t, const char *fname_in_env, int is_create, int only_create, CACHET } t->nodesize = t->h->nodesize; /* inherit the pagesize from the file */ t->basementnodesize = t->h->basementnodesize; + t->compression_method = t->h->compression_method; if (!t->did_set_flags) { r = verify_builtin_comparisons_consistent(t, t->flags); if (r) { goto exit; } @@ -3566,6 +3571,7 @@ int toku_brt_create(BRT *brt_ptr) { brt->did_set_flags = FALSE; brt->nodesize = BRT_DEFAULT_NODE_SIZE; brt->basementnodesize = BRT_DEFAULT_BASEMENT_NODE_SIZE; + brt->compression_method = TOKU_DEFAULT_COMPRESSION_METHOD; brt->compare_fun = toku_builtin_compare_fun; brt->update_fun = NULL; *brt_ptr = brt; diff --git a/newbrt/brt.h b/newbrt/brt.h index c0b970440d0..d0ad1f4ec79 100644 --- a/newbrt/brt.h +++ b/newbrt/brt.h @@ -28,7 +28,7 @@ // When lock_only is true, the callback only does optional lock tree locking. typedef int(*BRT_GET_CALLBACK_FUNCTION)(ITEMLEN keylen, bytevec key, ITEMLEN vallen, bytevec val, void *extra, bool lock_only); -int toku_open_brt (const char *fname, int is_create, BRT *, int nodesize, int basementnodesize, CACHETABLE, TOKUTXN, int(*)(DB *,const DBT*,const DBT*)) __attribute__ ((warn_unused_result)); +int toku_open_brt (const char *fname, int is_create, BRT *, int nodesize, int basementnodesize, enum toku_compression_method compression_method, CACHETABLE, TOKUTXN, int(*)(DB *,const DBT*,const DBT*)) __attribute__ ((warn_unused_result)); int toku_brt_change_descriptor(BRT t, const DBT* old_descriptor, const DBT* new_descriptor, BOOL do_log, TOKUTXN txn, BOOL update_cmp_descriptor); int toku_update_descriptor(struct brt_header * h, DESCRIPTOR d, int fd); // Note: See the locking discussion in brt.c for toku_brt_change_descriptor and toku_update_descriptor. diff --git a/newbrt/brt_header.c b/newbrt/brt_header.c index 328c3bcd76b..5333c3f7ef2 100644 --- a/newbrt/brt_header.c +++ b/newbrt/brt_header.c @@ -366,6 +366,7 @@ brt_init_header_partial (BRT t, CACHEFILE cf, TOKUTXN txn) { t->h->cf = cf; t->h->nodesize = t->nodesize; t->h->basementnodesize = t->basementnodesize; + t->h->compression_method = t->compression_method; t->h->root_xid_that_created = txn ? txn->ancestor_txnid64 : TXNID_NONE; t->h->compare_fun = t->compare_fun; t->h->update_fun = t->update_fun; @@ -404,7 +405,6 @@ brt_init_header (BRT t, CACHEFILE cf, TOKUTXN txn) { //Assign blocknum for root block, also dirty the header toku_allocate_blocknum(t->h->blocktable, &root, t->h); t->h->root_blocknum = root; - t->h->compression_method = TOKU_DEFAULT_COMPRESSION_METHOD; toku_list_init(&t->h->live_brts); int r = toku_omt_create(&t->h->txns); @@ -639,6 +639,8 @@ brt_open_for_redirect(BRT *new_brtp, const char *fname_in_env, TOKUTXN txn, stru assert_zero(r); r = toku_brt_set_basementnodesize(t, old_h->basementnodesize); assert_zero(r); + r = toku_brt_set_compression_method(t, old_h->compression_method); + assert_zero(r); CACHETABLE ct = toku_cachefile_get_cachetable(old_h->cf); r = toku_brt_open_with_dict_id(t, fname_in_env, 0, 0, ct, txn, old_h->dict_id); assert_zero(r); diff --git a/newbrt/brt_layout_version.h b/newbrt/brt_layout_version.h index 228faff4c68..9898b365393 100644 --- a/newbrt/brt_layout_version.h +++ b/newbrt/brt_layout_version.h @@ -24,6 +24,7 @@ enum brt_layout_version_e { BRT_LAYOUT_VERSION_17 = 17, // Dr. No: Add STAT64INFO_S to brt_header BRT_LAYOUT_VERSION_18 = 18, // Dr. No: Add HOT info to brt_header BRT_LAYOUT_VERSION_19 = 19, // Doofenshmirtz: Add compression method, highest_unused_msn_for_upgrade + BRT_LAYOUT_VERSION_20 = 20, // Clayface: Add compression method to log_fcreate BRT_NEXT_VERSION, // the version after the current version BRT_LAYOUT_VERSION = BRT_NEXT_VERSION-1, // A hack so I don't have to change this line. BRT_LAYOUT_MIN_SUPPORTED_VERSION = BRT_LAYOUT_VERSION_13, // Minimum version supported diff --git a/newbrt/brtdump.c b/newbrt/brtdump.c index 54eab6656b6..0a3b0b9b2b5 100644 --- a/newbrt/brtdump.c +++ b/newbrt/brtdump.c @@ -104,6 +104,7 @@ dump_header (int f, struct brt_header **header, CACHEFILE cf) { printf(" checkpoint_lsn=%" PRId64 "\n", h->checkpoint_lsn.lsn); printf(" nodesize=%u\n", h->nodesize); printf(" basementnodesize=%u\n", h->basementnodesize); + printf(" compression_method=%u\n", (unsigned) h->compression_method); printf(" unnamed_root=%" PRId64 "\n", h->root_blocknum.b); printf(" flags=%u\n", h->flags); dump_descriptor(&h->descriptor); diff --git a/newbrt/logformat.c b/newbrt/logformat.c index c0ffe4e1729..f89a5e95fe3 100644 --- a/newbrt/logformat.c +++ b/newbrt/logformat.c @@ -143,6 +143,7 @@ const struct logtype logtypes[] = { {"u_int32_t", "treeflags", 0}, {"u_int32_t", "nodesize", 0}, {"u_int32_t", "basementnodesize", 0}, + {"u_int32_t", "compression_method", 0}, NULLFIELD}}, //TODO: #2037 Add dname {"fopen", 'O', FA{{"BYTESTRING", "iname", 0}, diff --git a/newbrt/logger.c b/newbrt/logger.c index e2acb6c3bec..bed964423df 100644 --- a/newbrt/logger.c +++ b/newbrt/logger.c @@ -859,12 +859,12 @@ int toku_logger_restart(TOKULOGGER logger, LSN lastlsn) } // fname is the iname -int toku_logger_log_fcreate (TOKUTXN txn, const char *fname, FILENUM filenum, u_int32_t mode, u_int32_t treeflags, u_int32_t nodesize, u_int32_t basementnodesize) { +int toku_logger_log_fcreate (TOKUTXN txn, const char *fname, FILENUM filenum, u_int32_t mode, u_int32_t treeflags, u_int32_t nodesize, u_int32_t basementnodesize, enum toku_compression_method compression_method) { if (txn==0) return 0; if (txn->logger->is_panicked) return EINVAL; BYTESTRING bs_fname = { .len=strlen(fname), .data = (char *) fname }; // fsync log on fcreate - int r = toku_log_fcreate (txn->logger, (LSN*)0, 1, toku_txn_get_txnid(txn), filenum, bs_fname, mode, treeflags, nodesize, basementnodesize); + int r = toku_log_fcreate (txn->logger, (LSN*)0, 1, toku_txn_get_txnid(txn), filenum, bs_fname, mode, treeflags, nodesize, basementnodesize, compression_method); return r; } diff --git a/newbrt/logger.h b/newbrt/logger.h index abe3c607185..c79d70374b7 100644 --- a/newbrt/logger.h +++ b/newbrt/logger.h @@ -58,7 +58,7 @@ int toku_logger_restart(TOKULOGGER logger, LSN lastlsn); // Returns: 0 if success int toku_logger_maybe_trim_log(TOKULOGGER logger, LSN oldest_open_lsn); -int toku_logger_log_fcreate (TOKUTXN txn, const char *fname, FILENUM filenum, u_int32_t mode, u_int32_t flags, u_int32_t nodesize, u_int32_t basementnodesize); +int toku_logger_log_fcreate (TOKUTXN txn, const char *fname, FILENUM filenum, u_int32_t mode, u_int32_t flags, u_int32_t nodesize, u_int32_t basementnodesize, enum toku_compression_method compression_method); int toku_logger_log_fdelete (TOKUTXN txn, const char *fname); int toku_logger_log_fopen (TOKUTXN txn, const char * fname, FILENUM filenum, uint32_t treeflags); diff --git a/newbrt/recover.c b/newbrt/recover.c index 7998f10cb9d..2b29822f909 100644 --- a/newbrt/recover.c +++ b/newbrt/recover.c @@ -267,7 +267,7 @@ static void recover_yield(voidfp f, void *fpthunk, void *UU(yieldthunk)) { // Open the file if it is not already open. If it is already open, then do nothing. static int internal_recover_fopen_or_fcreate (RECOVER_ENV renv, BOOL must_create, int UU(mode), BYTESTRING *bs_iname, FILENUM filenum, u_int32_t treeflags, - TOKUTXN txn, uint32_t nodesize, uint32_t basementnodesize, LSN max_acceptable_lsn) { + TOKUTXN txn, uint32_t nodesize, uint32_t basementnodesize, enum toku_compression_method compression_method, LSN max_acceptable_lsn) { int r; BRT brt = NULL; char *iname = fixup_fname(bs_iname); @@ -288,6 +288,11 @@ static int internal_recover_fopen_or_fcreate (RECOVER_ENV renv, BOOL must_create assert(r == 0); } + if (compression_method != TOKU_DEFAULT_COMPRESSION_METHOD) { + r = toku_brt_set_compression_method(brt, compression_method); + assert(r == 0); + } + // set the key compare functions if (!(treeflags & TOKU_DB_KEYCMP_BUILTIN) && renv->bt_compare) { r = toku_brt_set_bt_compare(brt, renv->bt_compare); @@ -452,7 +457,7 @@ static int toku_recover_fassociate (struct logtype_fassociate *l, RECOVER_ENV re r = toku_brt_open_recovery(t, ROLLBACK_CACHEFILE_NAME, false, false, renv->ct, (TOKUTXN)NULL, l->filenum, max_acceptable_lsn); renv->logger->rollback_cachefile = t->h->cf; } else { - r = internal_recover_fopen_or_fcreate(renv, FALSE, 0, &l->iname, l->filenum, l->treeflags, NULL, 0, 0, max_acceptable_lsn); + r = internal_recover_fopen_or_fcreate(renv, FALSE, 0, &l->iname, l->filenum, l->treeflags, NULL, 0, 0, TOKU_DEFAULT_COMPRESSION_METHOD, max_acceptable_lsn); assert(r==0); } } @@ -766,7 +771,7 @@ static int toku_recover_fcreate (struct logtype_fcreate *l, RECOVER_ENV renv) { toku_free(iname); BOOL must_create = TRUE; - r = internal_recover_fopen_or_fcreate(renv, must_create, l->mode, &l->iname, l->filenum, l->treeflags, txn, l->nodesize, l->basementnodesize, MAX_LSN); + r = internal_recover_fopen_or_fcreate(renv, must_create, l->mode, &l->iname, l->filenum, l->treeflags, txn, l->nodesize, l->basementnodesize, (enum toku_compression_method) l->compression_method, MAX_LSN); return r; } @@ -790,7 +795,7 @@ static int toku_recover_fopen (struct logtype_fopen *l, RECOVER_ENV renv) { char *fname = fixup_fname(&l->iname); assert(0!=strcmp(fname, ROLLBACK_CACHEFILE_NAME)); //Rollback cachefile can be opened only via fassociate. - r = internal_recover_fopen_or_fcreate(renv, must_create, 0, &l->iname, l->filenum, l->treeflags, txn, 0, 0, MAX_LSN); + r = internal_recover_fopen_or_fcreate(renv, must_create, 0, &l->iname, l->filenum, l->treeflags, txn, 0, 0, TOKU_DEFAULT_COMPRESSION_METHOD, MAX_LSN); toku_free(fname); return r; diff --git a/newbrt/tests/benchmark-test.c b/newbrt/tests/benchmark-test.c index 322a2a87a6e..0b62b000a40 100644 --- a/newbrt/tests/benchmark-test.c +++ b/newbrt/tests/benchmark-test.c @@ -20,6 +20,7 @@ enum { BASEMENT_NODE_SIZE = 128 * 1024 }; static int nodesize = NODE_SIZE; static int basementnodesize = BASEMENT_NODE_SIZE; +static enum toku_compression_method compression_method = TOKU_DEFAULT_COMPRESSION_METHOD; static int keysize = sizeof (long long); static int valsize = sizeof (long long); static int do_verify =0; /* Do a slow verify after every insert. */ @@ -34,7 +35,7 @@ static void setup (void) { int r; unlink(fname); r = toku_brt_create_cachetable(&ct, 0, ZERO_LSN, NULL_LOGGER); assert(r==0); - r = toku_open_brt(fname, 1, &t, nodesize, basementnodesize, ct, NULL_TXN, toku_builtin_compare_fun); assert(r==0); + r = toku_open_brt(fname, 1, &t, nodesize, basementnodesize, compression_method, ct, NULL_TXN, toku_builtin_compare_fun); assert(r==0); } static void toku_shutdown (void) { diff --git a/newbrt/tests/brt-serialize-sub-block-test.c b/newbrt/tests/brt-serialize-sub-block-test.c index a1eb3a2f9f8..980a2efde3d 100644 --- a/newbrt/tests/brt-serialize-sub-block-test.c +++ b/newbrt/tests/brt-serialize-sub-block-test.c @@ -15,6 +15,7 @@ static void test_sub_block(int n) { const char fname[]= __FILE__ ".brt"; const int nodesize = 4*1024*1024; const int basementnodesize = 128*1024; + const enum toku_compression_method compression_method = TOKU_DEFAULT_COMPRESSION_METHOD; TOKUTXN const null_txn = 0; @@ -28,7 +29,7 @@ static void test_sub_block(int n) { error = toku_brt_create_cachetable(&ct, 0, ZERO_LSN, NULL_LOGGER); assert(error == 0); - error = toku_open_brt(fname, TRUE, &brt, nodesize, basementnodesize, ct, null_txn, toku_builtin_compare_fun); + error = toku_open_brt(fname, TRUE, &brt, nodesize, basementnodesize, compression_method, ct, null_txn, toku_builtin_compare_fun); assert(error == 0); // insert keys 0, 1, 2, .. (n-1) @@ -47,7 +48,7 @@ static void test_sub_block(int n) { assert(error == 0); // verify the brt by walking a cursor through the rows - error = toku_open_brt(fname, FALSE, &brt, nodesize, basementnodesize, ct, null_txn, toku_builtin_compare_fun); + error = toku_open_brt(fname, FALSE, &brt, nodesize, basementnodesize, compression_method, ct, null_txn, toku_builtin_compare_fun); assert(error == 0); BRT_CURSOR cursor; diff --git a/newbrt/tests/brt-test-cursor-2.c b/newbrt/tests/brt-test-cursor-2.c index cb6c557767c..55fe2037636 100644 --- a/newbrt/tests/brt-test-cursor-2.c +++ b/newbrt/tests/brt-test-cursor-2.c @@ -35,7 +35,7 @@ static void test_multiple_brt_cursor_dbts(int n) { r = toku_brt_create_cachetable(&ct, 0, ZERO_LSN, NULL_LOGGER); assert(r==0); - r = toku_open_brt(fname, 1, &brt, 1<<12, 1<<9, ct, null_txn, toku_builtin_compare_fun); + r = toku_open_brt(fname, 1, &brt, 1<<12, 1<<9, TOKU_DEFAULT_COMPRESSION_METHOD, ct, null_txn, toku_builtin_compare_fun); assert(r==0); int i; diff --git a/newbrt/tests/brt-test-cursor.c b/newbrt/tests/brt-test-cursor.c index 61e1230fd6c..b00879e65fa 100644 --- a/newbrt/tests/brt-test-cursor.c +++ b/newbrt/tests/brt-test-cursor.c @@ -90,7 +90,7 @@ static void test_brt_cursor_first(int n) { r = toku_brt_create_cachetable(&ct, 0, ZERO_LSN, NULL_LOGGER); assert(r==0); - r = toku_open_brt(fname, 1, &brt, 1<<12, 1<<9, ct, null_txn, test_brt_cursor_keycompare); + r = toku_open_brt(fname, 1, &brt, 1<<12, 1<<9, TOKU_DEFAULT_COMPRESSION_METHOD, ct, null_txn, test_brt_cursor_keycompare); assert(r==0); /* insert a bunch of kv pairs */ @@ -131,7 +131,7 @@ static void test_brt_cursor_last(int n) { r = toku_brt_create_cachetable(&ct, 0, ZERO_LSN, NULL_LOGGER); assert(r==0); - r = toku_open_brt(fname, 1, &brt, 1<<12, 1<<9, ct, null_txn, test_brt_cursor_keycompare); + r = toku_open_brt(fname, 1, &brt, 1<<12, 1<<9, TOKU_DEFAULT_COMPRESSION_METHOD, ct, null_txn, test_brt_cursor_keycompare); assert(r==0); /* insert keys 0, 1, .. (n-1) */ @@ -172,7 +172,7 @@ static void test_brt_cursor_first_last(int n) { r = toku_brt_create_cachetable(&ct, 0, ZERO_LSN, NULL_LOGGER); assert(r==0); - r = toku_open_brt(fname, 1, &brt, 1<<12, 1<<9, ct, null_txn, test_brt_cursor_keycompare); + r = toku_open_brt(fname, 1, &brt, 1<<12, 1<<9, TOKU_DEFAULT_COMPRESSION_METHOD, ct, null_txn, test_brt_cursor_keycompare); assert(r==0); /* insert a bunch of kv pairs */ @@ -217,7 +217,7 @@ static void test_brt_cursor_rfirst(int n) { r = toku_brt_create_cachetable(&ct, 0, ZERO_LSN, NULL_LOGGER); assert(r==0); - r = toku_open_brt(fname, 1, &brt, 1<<12, 1<<9, ct, null_txn, test_brt_cursor_keycompare); + r = toku_open_brt(fname, 1, &brt, 1<<12, 1<<9, TOKU_DEFAULT_COMPRESSION_METHOD, ct, null_txn, test_brt_cursor_keycompare); assert(r==0); /* insert keys n-1, n-2, ... , 0 */ @@ -285,7 +285,7 @@ static void test_brt_cursor_walk(int n) { r = toku_brt_create_cachetable(&ct, 0, ZERO_LSN, NULL_LOGGER); assert(r==0); - r = toku_open_brt(fname, 1, &brt, 1<<12, 1<<9, ct, null_txn, test_brt_cursor_keycompare); + r = toku_open_brt(fname, 1, &brt, 1<<12, 1<<9, TOKU_DEFAULT_COMPRESSION_METHOD, ct, null_txn, test_brt_cursor_keycompare); assert(r==0); /* insert a bunch of kv pairs */ @@ -351,7 +351,7 @@ static void test_brt_cursor_rwalk(int n) { r = toku_brt_create_cachetable(&ct, 0, ZERO_LSN, NULL_LOGGER); assert(r==0); - r = toku_open_brt(fname, 1, &brt, 1<<12, 1<<9, ct, null_txn, test_brt_cursor_keycompare); + r = toku_open_brt(fname, 1, &brt, 1<<12, 1<<9, TOKU_DEFAULT_COMPRESSION_METHOD, ct, null_txn, test_brt_cursor_keycompare); assert(r==0); /* insert a bunch of kv pairs */ @@ -436,7 +436,7 @@ static void test_brt_cursor_rand(int n) { r = toku_brt_create_cachetable(&ct, 0, ZERO_LSN, NULL_LOGGER); assert(r==0); - r = toku_open_brt(fname, 1, &brt, 1<<12, 1<<9, ct, null_txn, test_brt_cursor_keycompare); + r = toku_open_brt(fname, 1, &brt, 1<<12, 1<<9, TOKU_DEFAULT_COMPRESSION_METHOD, ct, null_txn, test_brt_cursor_keycompare); assert(r==0); /* insert a bunch of kv pairs */ @@ -490,7 +490,7 @@ static void test_brt_cursor_split(int n) { r = toku_brt_create_cachetable(&ct, 0, ZERO_LSN, NULL_LOGGER); assert(r==0); - r = toku_open_brt(fname, 1, &brt, 1<<12, 1<<9, ct, null_txn, test_brt_cursor_keycompare); + r = toku_open_brt(fname, 1, &brt, 1<<12, 1<<9, TOKU_DEFAULT_COMPRESSION_METHOD, ct, null_txn, test_brt_cursor_keycompare); assert(r==0); /* insert a bunch of kv pairs */ @@ -566,7 +566,7 @@ static void test_multiple_brt_cursors(int n) { r = toku_brt_create_cachetable(&ct, 0, ZERO_LSN, NULL_LOGGER); assert(r==0); - r = toku_open_brt(fname, 1, &brt, 1<<12, 1<<9, ct, null_txn, test_brt_cursor_keycompare); + r = toku_open_brt(fname, 1, &brt, 1<<12, 1<<9, TOKU_DEFAULT_COMPRESSION_METHOD, ct, null_txn, test_brt_cursor_keycompare); assert(r==0); int i; @@ -615,7 +615,7 @@ static void test_multiple_brt_cursor_walk(int n) { r = toku_brt_create_cachetable(&ct, cachesize, ZERO_LSN, NULL_LOGGER); assert(r==0); - r = toku_open_brt(fname, 1, &brt, 1<<12, 1<<9, ct, null_txn, test_brt_cursor_keycompare); + r = toku_open_brt(fname, 1, &brt, 1<<12, 1<<9, TOKU_DEFAULT_COMPRESSION_METHOD, ct, null_txn, test_brt_cursor_keycompare); assert(r==0); int c; @@ -692,7 +692,7 @@ static void test_brt_cursor_set(int n, int cursor_op) { r = toku_brt_create_cachetable(&ct, 0, ZERO_LSN, NULL_LOGGER); assert(r==0); - r = toku_open_brt(fname, 1, &brt, 1<<12, 1<<9, ct, null_txn, test_brt_cursor_keycompare); + r = toku_open_brt(fname, 1, &brt, 1<<12, 1<<9, TOKU_DEFAULT_COMPRESSION_METHOD, ct, null_txn, test_brt_cursor_keycompare); assert(r==0); int i; @@ -764,7 +764,7 @@ static void test_brt_cursor_set_range(int n) { r = toku_brt_create_cachetable(&ct, 0, ZERO_LSN, NULL_LOGGER); assert(r==0); - r = toku_open_brt(fname, 1, &brt, 1<<12, 1<<9, ct, null_txn, test_brt_cursor_keycompare); + r = toku_open_brt(fname, 1, &brt, 1<<12, 1<<9, TOKU_DEFAULT_COMPRESSION_METHOD, ct, null_txn, test_brt_cursor_keycompare); assert(r==0); int i; @@ -828,7 +828,7 @@ static void test_brt_cursor_delete(int n) { error = toku_brt_create_cachetable(&ct, 0, ZERO_LSN, NULL_LOGGER); assert(error == 0); - error = toku_open_brt(fname, 1, &brt, 1<<12, 1<<9, ct, null_txn, test_brt_cursor_keycompare); + error = toku_open_brt(fname, 1, &brt, 1<<12, 1<<9, TOKU_DEFAULT_COMPRESSION_METHOD, ct, null_txn, test_brt_cursor_keycompare); assert(error == 0); error = toku_brt_cursor(brt, &cursor, NULL, FALSE, FALSE); diff --git a/newbrt/tests/brt-test-header.c b/newbrt/tests/brt-test-header.c index 28b2bf9d939..2d002e46bca 100644 --- a/newbrt/tests/brt-test-header.c +++ b/newbrt/tests/brt-test-header.c @@ -21,7 +21,7 @@ static void test_header (void) { r = toku_brt_create_cachetable(&ct, 0, ZERO_LSN, NULL_LOGGER); assert(r==0); unlink(fname); - r = toku_open_brt(fname, 1, &t, 1024, 256, ct, null_txn, toku_builtin_compare_fun); + r = toku_open_brt(fname, 1, &t, 1024, 256, TOKU_DEFAULT_COMPRESSION_METHOD, ct, null_txn, toku_builtin_compare_fun); assert(r==0); // now insert some info into the header struct brt_header *h = t->h; @@ -39,7 +39,7 @@ static void test_header (void) { // Now read dictionary back into memory and examine some header fields r = toku_brt_create_cachetable(&ct, 0, ZERO_LSN, NULL_LOGGER); assert(r==0); - r = toku_open_brt(fname, 0, &t, 1024, 256, ct, null_txn, toku_builtin_compare_fun); + r = toku_open_brt(fname, 0, &t, 1024, 256, TOKU_DEFAULT_COMPRESSION_METHOD, ct, null_txn, toku_builtin_compare_fun); assert(r==0); h = t->h; diff --git a/newbrt/tests/brt-test.c b/newbrt/tests/brt-test.c index 2aef45abfbf..377083d94dd 100644 --- a/newbrt/tests/brt-test.c +++ b/newbrt/tests/brt-test.c @@ -18,7 +18,7 @@ static void test_dump_empty_db (void) { r = toku_brt_create_cachetable(&ct, 0, ZERO_LSN, NULL_LOGGER); assert(r==0); unlink(fname); - r = toku_open_brt(fname, 1, &t, 1024, 256, ct, null_txn, toku_builtin_compare_fun); + r = toku_open_brt(fname, 1, &t, 1024, 256, TOKU_DEFAULT_COMPRESSION_METHOD, ct, null_txn, toku_builtin_compare_fun); assert(r==0); if (verbose) { r=toku_dump_brt(stdout, t); assert(r==0); } r = toku_close_brt_nolsn(t, 0); assert(r==0); @@ -38,8 +38,8 @@ static void test_multiple_files_of_size (int size) { unlink(n1); r = toku_brt_create_cachetable(&ct, 0, ZERO_LSN, NULL_LOGGER); assert(r==0); - r = toku_open_brt(n0, 1, &t0, size, size / 4, ct, null_txn, toku_builtin_compare_fun); assert(r==0); - r = toku_open_brt(n1, 1, &t1, size, size / 4, ct, null_txn, toku_builtin_compare_fun); assert(r==0); + r = toku_open_brt(n0, 1, &t0, size, size / 4, TOKU_DEFAULT_COMPRESSION_METHOD, ct, null_txn, toku_builtin_compare_fun); assert(r==0); + r = toku_open_brt(n1, 1, &t1, size, size / 4, TOKU_DEFAULT_COMPRESSION_METHOD, ct, null_txn, toku_builtin_compare_fun); assert(r==0); for (i=0; i<10000; i++) { char key[100],val[100]; DBT k,v; @@ -62,10 +62,10 @@ static void test_multiple_files_of_size (int size) { /* Now see if the data is all there. */ r = toku_brt_create_cachetable(&ct, 0, ZERO_LSN, NULL_LOGGER); assert(r==0); - r = toku_open_brt(n0, 0, &t0, 1<<12, 1<<9, ct, null_txn, toku_builtin_compare_fun); + r = toku_open_brt(n0, 0, &t0, 1<<12, 1<<9, TOKU_DEFAULT_COMPRESSION_METHOD, ct, null_txn, toku_builtin_compare_fun); if (verbose) printf("%s:%d r=%d\n", __FILE__, __LINE__,r); assert(r==0); - r = toku_open_brt(n1, 0, &t1, 1<<12, 1<<9, ct, null_txn, toku_builtin_compare_fun); assert(r==0); + r = toku_open_brt(n1, 0, &t1, 1<<12, 1<<9, TOKU_DEFAULT_COMPRESSION_METHOD, ct, null_txn, toku_builtin_compare_fun); assert(r==0); for (i=0; i<10000; i++) { char key[100],val[100]; @@ -98,7 +98,7 @@ static void test_multiple_brts_one_db_one_file (void) { unlink(fname); r = toku_brt_create_cachetable(&ct, 32, ZERO_LSN, NULL_LOGGER); assert(r==0); for (i=0; itxn_begin(env, 0, &txn, 0); CKERR(r); - { - // we should not be able to successfully do this on an unopened DB - r = db->set_compression_method(db, TOKU_NO_COMPRESSION); - assert(r != 0); - enum toku_compression_method m = (enum toku_compression_method) 999; - r = db->get_compression_method(db, &m); - assert(r != 0); - assert(m == 999); - } - r = db->open(db, txn, "foo.db", 0, DB_BTREE, DB_CREATE, S_IRWXU+S_IRWXG+S_IRWXO); - CKERR(r); if (set_method) { r = db->set_compression_method(db, method); CKERR(r); } + r = db->open(db, txn, "foo.db", 0, DB_BTREE, DB_CREATE, S_IRWXU+S_IRWXG+S_IRWXO); + CKERR(r); r = txn->commit(txn, 0); CKERR(r); } diff --git a/src/ydb_db.c b/src/ydb_db.c index 7d8b64d83ef..72f18caa599 100644 --- a/src/ydb_db.c +++ b/src/ydb_db.c @@ -575,26 +575,14 @@ toku_db_get_readpagesize(DB *db, u_int32_t *readpagesize_ptr) { static int toku_db_set_compression_method(DB *db, enum toku_compression_method compression_method) { HANDLE_PANICKED_DB(db); - int r; - // compression method is tracked in the brt header, so it must be open - if (!db_opened(db)) { - r = EINVAL; - } else { - r = toku_brt_set_compression_method(db->i->brt, compression_method); - } + int r = toku_brt_set_compression_method(db->i->brt, compression_method); return r; } static int toku_db_get_compression_method(DB *db, enum toku_compression_method *compression_method_ptr) { HANDLE_PANICKED_DB(db); - int r; - // compression method is tracked in the brt header, so it must be open - if (!db_opened(db)) { - r = EINVAL; - } else { - r = toku_brt_get_compression_method(db->i->brt, compression_method_ptr); - } + int r = toku_brt_get_compression_method(db->i->brt, compression_method_ptr); return r; }