diff options
author | Michael Cahill <michael.cahill@wiredtiger.com> | 2012-09-14 22:39:26 +1000 |
---|---|---|
committer | Michael Cahill <michael.cahill@wiredtiger.com> | 2012-09-14 22:39:26 +1000 |
commit | bb5eef33728573d2641dd801aa0df04710c32719 (patch) | |
tree | 15de719254c9772f9284f325812bf75c5a556ff5 | |
parent | 95d0aad048c52a925cf264949c3af24f0d85d43d (diff) | |
download | mongo-bb5eef33728573d2641dd801aa0df04710c32719.tar.gz |
Add an implementation of LSM truncate.
-rw-r--r-- | src/include/extern.h | 7 | ||||
-rw-r--r-- | src/lsm/lsm_dsrc.c | 12 | ||||
-rw-r--r-- | src/lsm/lsm_merge.c | 8 | ||||
-rw-r--r-- | src/lsm/lsm_tree.c | 44 |
4 files changed, 61 insertions, 10 deletions
diff --git a/src/include/extern.h b/src/include/extern.h index 4eac7187036..403069a0920 100644 --- a/src/include/extern.h +++ b/src/include/extern.h @@ -672,6 +672,10 @@ extern int __wt_clsm_open(WT_SESSION_IMPL *session, WT_CURSOR **cursorp); extern int __wt_lsm_init(WT_CONNECTION *wt_conn, const char *config); extern int __wt_lsm_cleanup(WT_CONNECTION *wt_conn); +extern int __wt_lsm_merge_update_tree(WT_SESSION_IMPL *session, + WT_LSM_TREE *lsm_tree, + int nchunks, + WT_LSM_CHUNK **chunkp); extern int __wt_lsm_major_merge(WT_SESSION_IMPL *session, WT_LSM_TREE *lsm_tree); extern int __wt_lsm_meta_read(WT_SESSION_IMPL *session, WT_LSM_TREE *lsm_tree); @@ -705,6 +709,9 @@ extern int __wt_lsm_tree_rename(WT_SESSION_IMPL *session, const char *oldname, const char *newname, const char *cfg[]); +extern int __wt_lsm_tree_truncate( WT_SESSION_IMPL *session, + const char *name, + const char *cfg[]); extern int __wt_lsm_tree_worker(WT_SESSION_IMPL *session, const char *uri, int (*func)(WT_SESSION_IMPL *, diff --git a/src/lsm/lsm_dsrc.c b/src/lsm/lsm_dsrc.c index f04848b3016..ed627ff9d4d 100644 --- a/src/lsm/lsm_dsrc.c +++ b/src/lsm/lsm_dsrc.c @@ -81,15 +81,15 @@ __lsm_rename(WT_DATA_SOURCE *dsrc, WT_SESSION *wt_session, * Implementation of the truncate operation for LSM trees. */ static int -__lsm_truncate(WT_DATA_SOURCE *dsrc, WT_SESSION *session, - const char *name, const char *cfg[]) +__lsm_truncate(WT_DATA_SOURCE *dsrc, WT_SESSION *wt_session, + const char *uri, const char *cfg[]) { + WT_SESSION_IMPL *session; + WT_UNUSED(dsrc); - WT_UNUSED(session); - WT_UNUSED(name); - WT_UNUSED(cfg); + session = (WT_SESSION_IMPL *)wt_session; - return (ENOTSUP); + return (__wt_lsm_tree_truncate(session, uri, cfg)); } /* diff --git a/src/lsm/lsm_merge.c b/src/lsm/lsm_merge.c index 7ade3b04d2e..db780193e1e 100644 --- a/src/lsm/lsm_merge.c +++ b/src/lsm/lsm_merge.c @@ -8,12 +8,12 @@ #include "wt_internal.h" /* - * __wt_merge_update_tree -- + * __wt_lsm_merge_update_tree -- * Merge a set of chunks and create a new one. * Must be called with the LSM lock held. */ -static int -__lsm_merge_update_tree(WT_SESSION_IMPL *session, +int +__wt_lsm_merge_update_tree(WT_SESSION_IMPL *session, WT_LSM_TREE *lsm_tree, int nchunks, WT_LSM_CHUNK **chunkp) { WT_LSM_CHUNK *chunk; @@ -174,7 +174,7 @@ __wt_lsm_major_merge(WT_SESSION_IMPL *session, WT_LSM_TREE *lsm_tree) WT_ERR(ret); __wt_spin_lock(session, &lsm_tree->lock); - ret = __lsm_merge_update_tree(session, lsm_tree, nchunks, &chunk); + ret = __wt_lsm_merge_update_tree(session, lsm_tree, nchunks, &chunk); chunk->uri = dest_uri; dest_uri = NULL; diff --git a/src/lsm/lsm_tree.c b/src/lsm/lsm_tree.c index 4ef9314d9dd..fb5d3eabe91 100644 --- a/src/lsm/lsm_tree.c +++ b/src/lsm/lsm_tree.c @@ -454,6 +454,50 @@ err: __wt_spin_unlock(session, &lsm_tree->lock); } /* + * __wt_lsm_tree_truncate -- + * Truncate an LSM tree. + */ +int +__wt_lsm_tree_truncate( + WT_SESSION_IMPL *session, const char *name, const char *cfg[]) +{ + WT_DECL_RET; + WT_LSM_CHUNK *chunk; + WT_LSM_TREE *lsm_tree; + + WT_UNUSED(cfg); + + /* Get the LSM tree. */ + WT_RET(__wt_lsm_tree_get(session, name, &lsm_tree)); + + /* Shut down the LSM worker. */ + WT_RET(__lsm_tree_close(session, lsm_tree)); + + /* Prevent any new opens. */ + WT_RET(__wt_spin_trylock(session, &lsm_tree->lock)); + + /* Mark all chunks old. */ + WT_ERR(__wt_lsm_merge_update_tree( + session, lsm_tree, lsm_tree->nchunks, &chunk)); + + /* Create the new chunk. */ + WT_ERR(__wt_lsm_tree_create_chunk( + session, lsm_tree, WT_ATOMIC_ADD(lsm_tree->last, 1), &chunk->uri)); + + WT_ERR(__wt_lsm_meta_write(session, lsm_tree)); + + WT_ERR(__lsm_tree_start_worker(session, lsm_tree)); + __wt_spin_unlock(session, &lsm_tree->lock); + + if (0) { +err: __wt_spin_unlock(session, &lsm_tree->lock); + __lsm_tree_discard(session, lsm_tree); + } + return (ret); +} + + +/* * __wt_lsm_tree_worker -- * Run a schema worker operation on each level of a LSM tree. */ |