summaryrefslogtreecommitdiff
path: root/src/third_party/wiredtiger/src/lsm/lsm_tree.c
diff options
context:
space:
mode:
authorMichael Cahill <michael.cahill@mongodb.com>2015-09-25 16:53:44 +1000
committerMichael Cahill <michael.cahill@mongodb.com>2015-09-25 16:53:44 +1000
commit4898cb582633fd686c3057824ce0d1713284d15d (patch)
tree1d4400fcabbd4a46e105f7aa67dd84829eea38ba /src/third_party/wiredtiger/src/lsm/lsm_tree.c
parente5bd1ecd48d78900bafd64022200f94eb7be24c7 (diff)
downloadmongo-4898cb582633fd686c3057824ce0d1713284d15d.tar.gz
Import wiredtiger-wiredtiger-2.6.1-1231-g10208e8.tar.gz from wiredtiger branch mongodb-3.2
Diffstat (limited to 'src/third_party/wiredtiger/src/lsm/lsm_tree.c')
-rw-r--r--src/third_party/wiredtiger/src/lsm/lsm_tree.c107
1 files changed, 54 insertions, 53 deletions
diff --git a/src/third_party/wiredtiger/src/lsm/lsm_tree.c b/src/third_party/wiredtiger/src/lsm/lsm_tree.c
index 46db76e099c..bd54202de5e 100644
--- a/src/third_party/wiredtiger/src/lsm/lsm_tree.c
+++ b/src/third_party/wiredtiger/src/lsm/lsm_tree.c
@@ -11,7 +11,7 @@
static int __lsm_tree_cleanup_old(WT_SESSION_IMPL *, const char *);
static int __lsm_tree_open_check(WT_SESSION_IMPL *, WT_LSM_TREE *);
static int __lsm_tree_open(
- WT_SESSION_IMPL *, const char *, int, WT_LSM_TREE **);
+ WT_SESSION_IMPL *, const char *, bool, WT_LSM_TREE **);
static int __lsm_tree_set_name(WT_SESSION_IMPL *, WT_LSM_TREE *, const char *);
/*
@@ -19,7 +19,7 @@ static int __lsm_tree_set_name(WT_SESSION_IMPL *, WT_LSM_TREE *, const char *);
* Free an LSM tree structure.
*/
static int
-__lsm_tree_discard(WT_SESSION_IMPL *session, WT_LSM_TREE *lsm_tree, int final)
+__lsm_tree_discard(WT_SESSION_IMPL *session, WT_LSM_TREE *lsm_tree, bool final)
{
WT_DECL_RET;
WT_LSM_CHUNK *chunk;
@@ -143,7 +143,7 @@ __wt_lsm_tree_close_all(WT_SESSION_IMPL *session)
*/
(void)__wt_atomic_add32(&lsm_tree->refcnt, 1);
WT_TRET(__lsm_tree_close(session, lsm_tree));
- WT_TRET(__lsm_tree_discard(session, lsm_tree, 1));
+ WT_TRET(__lsm_tree_discard(session, lsm_tree, true));
}
return (ret);
@@ -239,7 +239,7 @@ __lsm_tree_cleanup_old(WT_SESSION_IMPL *session, const char *uri)
WT_DECL_RET;
const char *cfg[] =
{ WT_CONFIG_BASE(session, WT_SESSION_drop), "force", NULL };
- int exists;
+ bool exists;
WT_RET(__wt_exist(session, uri + strlen("file:"), &exists));
if (exists)
@@ -304,7 +304,7 @@ __wt_lsm_tree_setup_bloom(
*/
int
__wt_lsm_tree_create(WT_SESSION_IMPL *session,
- const char *uri, int exclusive, const char *config)
+ const char *uri, bool exclusive, const char *config)
{
WT_CONFIG_ITEM cval;
WT_DECL_ITEM(buf);
@@ -316,7 +316,7 @@ __wt_lsm_tree_create(WT_SESSION_IMPL *session,
/* If the tree is open, it already exists. */
WT_WITH_HANDLE_LIST_LOCK(session,
- ret = __wt_lsm_tree_get(session, uri, 0, &lsm_tree));
+ ret = __wt_lsm_tree_get(session, uri, false, &lsm_tree));
if (ret == 0) {
__wt_lsm_tree_release(session, lsm_tree);
return (exclusive ? EEXIST : 0);
@@ -433,7 +433,7 @@ __wt_lsm_tree_create(WT_SESSION_IMPL *session,
WT_ERR(__wt_lsm_meta_write(session, lsm_tree));
/* Discard our partially populated handle. */
- ret = __lsm_tree_discard(session, lsm_tree, 0);
+ ret = __lsm_tree_discard(session, lsm_tree, false);
lsm_tree = NULL;
/*
@@ -443,12 +443,12 @@ __wt_lsm_tree_create(WT_SESSION_IMPL *session,
*/
if (ret == 0)
WT_WITH_HANDLE_LIST_LOCK(session,
- ret = __lsm_tree_open(session, uri, 1, &lsm_tree));
+ ret = __lsm_tree_open(session, uri, true, &lsm_tree));
if (ret == 0)
__wt_lsm_tree_release(session, lsm_tree);
if (0) {
-err: WT_TRET(__lsm_tree_discard(session, lsm_tree, 0));
+err: WT_TRET(__lsm_tree_discard(session, lsm_tree, false));
}
__wt_scr_free(session, &buf);
return (ret);
@@ -463,7 +463,7 @@ err: WT_TRET(__lsm_tree_discard(session, lsm_tree, 0));
*/
static int
__lsm_tree_find(WT_SESSION_IMPL *session,
- const char *uri, int exclusive, WT_LSM_TREE **treep)
+ const char *uri, bool exclusive, WT_LSM_TREE **treep)
{
WT_LSM_TREE *lsm_tree;
@@ -555,7 +555,7 @@ __lsm_tree_open_check(WT_SESSION_IMPL *session, WT_LSM_TREE *lsm_tree)
*/
static int
__lsm_tree_open(WT_SESSION_IMPL *session,
- const char *uri, int exclusive, WT_LSM_TREE **treep)
+ const char *uri, bool exclusive, WT_LSM_TREE **treep)
{
WT_CONNECTION_IMPL *conn;
WT_DECL_RET;
@@ -611,7 +611,7 @@ __lsm_tree_open(WT_SESSION_IMPL *session,
*treep = lsm_tree;
if (0) {
-err: WT_TRET(__lsm_tree_discard(session, lsm_tree, 0));
+err: WT_TRET(__lsm_tree_discard(session, lsm_tree, false));
}
return (ret);
}
@@ -622,7 +622,7 @@ err: WT_TRET(__lsm_tree_discard(session, lsm_tree, 0));
*/
int
__wt_lsm_tree_get(WT_SESSION_IMPL *session,
- const char *uri, int exclusive, WT_LSM_TREE **treep)
+ const char *uri, bool exclusive, WT_LSM_TREE **treep)
{
WT_DECL_RET;
@@ -632,7 +632,8 @@ __wt_lsm_tree_get(WT_SESSION_IMPL *session,
if (ret == WT_NOTFOUND)
ret = __lsm_tree_open(session, uri, exclusive, treep);
- WT_ASSERT(session, ret != 0 || exclusive == (*treep)->exclusive);
+ WT_ASSERT(session, ret != 0 ||
+ (exclusive ? 1 : 0) == (*treep)->exclusive);
return (ret);
}
@@ -676,7 +677,7 @@ __wt_lsm_tree_release(WT_SESSION_IMPL *session, WT_LSM_TREE *lsm_tree)
*/
void
__wt_lsm_tree_throttle(
- WT_SESSION_IMPL *session, WT_LSM_TREE *lsm_tree, int decrease_only)
+ WT_SESSION_IMPL *session, WT_LSM_TREE *lsm_tree, bool decrease_only)
{
WT_LSM_CHUNK *last_chunk, **cp, *ondisk, *prev_chunk;
uint64_t cache_sz, cache_used, oldtime, record_count, timediff;
@@ -819,13 +820,13 @@ __wt_lsm_tree_switch(WT_SESSION_IMPL *session, WT_LSM_TREE *lsm_tree)
WT_DECL_RET;
WT_LSM_CHUNK *chunk, *last_chunk;
uint32_t chunks_moved, nchunks, new_id;
- int first_switch;
+ bool first_switch;
WT_RET(__wt_lsm_tree_writelock(session, lsm_tree));
nchunks = lsm_tree->nchunks;
- first_switch = nchunks == 0 ? 1 : 0;
+ first_switch = nchunks == 0;
/*
* Check if a switch is still needed: we may have raced while waiting
@@ -839,7 +840,7 @@ __wt_lsm_tree_switch(WT_SESSION_IMPL *session, WT_LSM_TREE *lsm_tree)
goto err;
/* Update the throttle time. */
- __wt_lsm_tree_throttle(session, lsm_tree, 0);
+ __wt_lsm_tree_throttle(session, lsm_tree, false);
new_id = __wt_atomic_add32(&lsm_tree->last, 1);
@@ -948,13 +949,13 @@ __wt_lsm_tree_drop(
WT_LSM_CHUNK *chunk;
WT_LSM_TREE *lsm_tree;
u_int i;
- int locked;
+ bool locked;
- locked = 0;
+ locked = false;
/* Get the LSM tree. */
WT_WITH_HANDLE_LIST_LOCK(session,
- ret = __wt_lsm_tree_get(session, name, 1, &lsm_tree));
+ ret = __wt_lsm_tree_get(session, name, true, &lsm_tree));
WT_RET(ret);
/* Shut down the LSM worker. */
@@ -962,7 +963,7 @@ __wt_lsm_tree_drop(
/* Prevent any new opens. */
WT_ERR(__wt_lsm_tree_writelock(session, lsm_tree));
- locked = 1;
+ locked = true;
/* Drop the chunks. */
for (i = 0; i < lsm_tree->nchunks; i++) {
@@ -983,14 +984,14 @@ __wt_lsm_tree_drop(
__wt_schema_drop(session, chunk->bloom_uri, cfg));
}
- locked = 0;
+ locked = false;
WT_ERR(__wt_lsm_tree_writeunlock(session, lsm_tree));
ret = __wt_metadata_remove(session, name);
err: if (locked)
WT_TRET(__wt_lsm_tree_writeunlock(session, lsm_tree));
WT_WITH_HANDLE_LIST_LOCK(session,
- WT_TRET(__lsm_tree_discard(session, lsm_tree, 0)));
+ WT_TRET(__lsm_tree_discard(session, lsm_tree, false)));
return (ret);
}
@@ -1007,14 +1008,14 @@ __wt_lsm_tree_rename(WT_SESSION_IMPL *session,
WT_LSM_TREE *lsm_tree;
const char *old;
u_int i;
- int locked;
+ bool locked;
old = NULL;
- locked = 0;
+ locked = false;
/* Get the LSM tree. */
WT_WITH_HANDLE_LIST_LOCK(session,
- ret = __wt_lsm_tree_get(session, olduri, 1, &lsm_tree));
+ ret = __wt_lsm_tree_get(session, olduri, true, &lsm_tree));
WT_RET(ret);
/* Shut down the LSM worker. */
@@ -1022,7 +1023,7 @@ __wt_lsm_tree_rename(WT_SESSION_IMPL *session,
/* Prevent any new opens. */
WT_ERR(__wt_lsm_tree_writelock(session, lsm_tree));
- locked = 1;
+ locked = true;
/* Set the new name. */
WT_ERR(__lsm_tree_set_name(session, lsm_tree, newuri));
@@ -1051,7 +1052,7 @@ __wt_lsm_tree_rename(WT_SESSION_IMPL *session,
}
WT_ERR(__wt_lsm_meta_write(session, lsm_tree));
- locked = 0;
+ locked = false;
WT_ERR(__wt_lsm_tree_writeunlock(session, lsm_tree));
WT_ERR(__wt_metadata_remove(session, olduri));
@@ -1064,7 +1065,7 @@ err: if (locked)
* tree will create a new one.
*/
WT_WITH_HANDLE_LIST_LOCK(session,
- WT_TRET(__lsm_tree_discard(session, lsm_tree, 0)));
+ WT_TRET(__lsm_tree_discard(session, lsm_tree, false)));
return (ret);
}
@@ -1079,15 +1080,15 @@ __wt_lsm_tree_truncate(
WT_DECL_RET;
WT_LSM_CHUNK *chunk;
WT_LSM_TREE *lsm_tree;
- int locked;
+ bool locked;
WT_UNUSED(cfg);
chunk = NULL;
- locked = 0;
+ locked = false;
/* Get the LSM tree. */
WT_WITH_HANDLE_LIST_LOCK(session,
- ret = __wt_lsm_tree_get(session, name, 1, &lsm_tree));
+ ret = __wt_lsm_tree_get(session, name, true, &lsm_tree));
WT_RET(ret);
/* Shut down the LSM worker. */
@@ -1095,7 +1096,7 @@ __wt_lsm_tree_truncate(
/* Prevent any new opens. */
WT_ERR(__wt_lsm_tree_writelock(session, lsm_tree));
- locked = 1;
+ locked = true;
/* Create the new chunk. */
WT_ERR(__wt_calloc_one(session, &chunk));
@@ -1108,7 +1109,7 @@ __wt_lsm_tree_truncate(
WT_ERR(__wt_lsm_meta_write(session, lsm_tree));
- locked = 0;
+ locked = false;
WT_ERR(__wt_lsm_tree_writeunlock(session, lsm_tree));
__wt_lsm_tree_release(session, lsm_tree);
@@ -1126,7 +1127,7 @@ err: if (locked)
* in a valid (not truncated) tree.
*/
WT_WITH_HANDLE_LIST_LOCK(session,
- WT_TRET(__lsm_tree_discard(session, lsm_tree, 0)));
+ WT_TRET(__lsm_tree_discard(session, lsm_tree, false)));
}
return (ret);
}
@@ -1202,7 +1203,7 @@ __wt_lsm_tree_writeunlock(WT_SESSION_IMPL *session, WT_LSM_TREE *lsm_tree)
* Compact an LSM tree called via __wt_schema_worker.
*/
int
-__wt_lsm_compact(WT_SESSION_IMPL *session, const char *name, int *skip)
+__wt_lsm_compact(WT_SESSION_IMPL *session, const char *name, bool *skipp)
{
WT_DECL_RET;
WT_LSM_CHUNK *chunk;
@@ -1210,9 +1211,9 @@ __wt_lsm_compact(WT_SESSION_IMPL *session, const char *name, int *skip)
time_t begin, end;
uint64_t progress;
uint32_t i;
- int compacting, flushing, locked, ref;
+ bool compacting, flushing, locked, ref;
- compacting = flushing = locked = ref = 0;
+ compacting = flushing = locked = ref = false;
chunk = NULL;
/*
* This function is applied to all matching sources: ignore anything
@@ -1222,10 +1223,10 @@ __wt_lsm_compact(WT_SESSION_IMPL *session, const char *name, int *skip)
return (0);
/* Tell __wt_schema_worker not to look inside the LSM tree. */
- *skip = 1;
+ *skipp = true;
WT_WITH_HANDLE_LIST_LOCK(session,
- ret = __wt_lsm_tree_get(session, name, 0, &lsm_tree));
+ ret = __wt_lsm_tree_get(session, name, false, &lsm_tree));
WT_RET(ret);
if (!F_ISSET(S2C(session), WT_CONN_LSM_MERGE))
@@ -1261,7 +1262,7 @@ __wt_lsm_compact(WT_SESSION_IMPL *session, const char *name, int *skip)
/* Lock the tree: single-thread compaction. */
WT_ERR(__wt_lsm_tree_writelock(session, lsm_tree));
- locked = 1;
+ locked = true;
/* Clear any merge throttle: compact throws out that calculation. */
lsm_tree->merge_throttle = 0;
@@ -1286,10 +1287,10 @@ __wt_lsm_compact(WT_SESSION_IMPL *session, const char *name, int *skip)
* So we need to add a reference to keep it available.
*/
(void)__wt_atomic_add32(&chunk->refcnt, 1);
- ref = 1;
+ ref = true;
}
- locked = 0;
+ locked = false;
WT_ERR(__wt_lsm_tree_writeunlock(session, lsm_tree));
if (chunk != NULL) {
@@ -1297,7 +1298,7 @@ __wt_lsm_compact(WT_SESSION_IMPL *session, const char *name, int *skip)
"Compact force flush %s flags 0x%" PRIx32
" chunk %u flags 0x%"
PRIx32, name, lsm_tree->flags, chunk->id, chunk->flags));
- flushing = 1;
+ flushing = true;
/*
* Make sure the in-memory chunk gets flushed do not push a
* switch, because we don't want to create a new in-memory
@@ -1310,7 +1311,7 @@ __wt_lsm_compact(WT_SESSION_IMPL *session, const char *name, int *skip)
* If there is no chunk to flush, go straight to the
* compacting state.
*/
- compacting = 1;
+ compacting = true;
progress = lsm_tree->merge_progressing;
F_SET(lsm_tree, WT_LSM_TREE_COMPACTING);
WT_ERR(__wt_verbose(session, WT_VERB_LSM,
@@ -1334,8 +1335,8 @@ __wt_lsm_compact(WT_SESSION_IMPL *session, const char *name, int *skip)
name, chunk->id,
lsm_tree->merge_progressing));
(void)__wt_atomic_sub32(&chunk->refcnt, 1);
- flushing = ref = 0;
- compacting = 1;
+ flushing = ref = false;
+ compacting = true;
F_SET(lsm_tree, WT_LSM_TREE_COMPACTING);
progress = lsm_tree->merge_progressing;
} else {
@@ -1411,17 +1412,17 @@ int
__wt_lsm_tree_worker(WT_SESSION_IMPL *session,
const char *uri,
int (*file_func)(WT_SESSION_IMPL *, const char *[]),
- int (*name_func)(WT_SESSION_IMPL *, const char *, int *),
+ int (*name_func)(WT_SESSION_IMPL *, const char *, bool *),
const char *cfg[], uint32_t open_flags)
{
WT_DECL_RET;
WT_LSM_CHUNK *chunk;
WT_LSM_TREE *lsm_tree;
u_int i;
- int exclusive, locked;
+ bool exclusive, locked;
- locked = 0;
- exclusive = FLD_ISSET(open_flags, WT_DHANDLE_EXCLUSIVE) ? 1 : 0;
+ locked = false;
+ exclusive = FLD_ISSET(open_flags, WT_DHANDLE_EXCLUSIVE);
WT_WITH_HANDLE_LIST_LOCK(session,
ret = __wt_lsm_tree_get(session, uri, exclusive, &lsm_tree));
WT_RET(ret);
@@ -1434,7 +1435,7 @@ __wt_lsm_tree_worker(WT_SESSION_IMPL *session,
WT_ERR(exclusive ?
__wt_lsm_tree_writelock(session, lsm_tree) :
__wt_lsm_tree_readlock(session, lsm_tree));
- locked = 1;
+ locked = true;
for (i = 0; i < lsm_tree->nchunks; i++) {
chunk = lsm_tree->chunk[i];
if (file_func == __wt_checkpoint &&