Skip to content

Commit

Permalink
Merge pull request #336 from wiredtiger/lsm-checkpoint-open
Browse files Browse the repository at this point in the history
Bug fixes for LSM open and handle locking
  • Loading branch information
agorrod committed Sep 24, 2012
2 parents 085bcd3 + b7ca3fa commit ac35d03
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 14 deletions.
21 changes: 14 additions & 7 deletions src/conn/conn_btree.c
Original file line number Diff line number Diff line change
Expand Up @@ -422,14 +422,22 @@ __wt_conn_btree_close_all(WT_SESSION_IMPL *session, const char *name)
WT_DECL_RET;

conn = S2C(session);
saved_btree = session->btree;

WT_ASSERT(session, F_ISSET(session, WT_SESSION_SCHEMA_LOCKED));

/*
* Make sure the caller's handle is tracked, so it will be unlocked
* even if we failed to get all of the remaining handles we need.
*/
if ((saved_btree = session->btree) != NULL && WT_META_TRACKING(session))
WT_ERR(__wt_meta_track_handle_lock(session, 0));

TAILQ_FOREACH(btree, &conn->btqh, q) {
if (strcmp(btree->name, name) != 0)
continue;

WT_SET_BTREE_IN_SESSION(session, btree);

/*
* The caller may have this tree locked to prevent
* concurrent schema operations.
Expand All @@ -439,12 +447,10 @@ __wt_conn_btree_close_all(WT_SESSION_IMPL *session, const char *name)
else {
WT_ERR(__wt_try_writelock(session, btree->rwlock));
F_SET(btree, WT_BTREE_EXCLUSIVE);
if (WT_META_TRACKING(session))
WT_ERR(__wt_meta_track_handle_lock(session, 0));
}

session->btree = btree;
if (WT_META_TRACKING(session))
WT_ERR(__wt_meta_track_handle_lock(session, 0));

/*
* We have an exclusive lock, which means there are no
* cursors open at this point. Close the handle, if
Expand All @@ -467,12 +473,13 @@ __wt_conn_btree_close_all(WT_SESSION_IMPL *session, const char *name)

if (!WT_META_TRACKING(session))
WT_TRET(__wt_session_release_btree(session));
session->btree = NULL;

WT_CLEAR_BTREE_IN_SESSION(session);
WT_ERR(ret);
}

err: return (ret);
err: WT_CLEAR_BTREE_IN_SESSION(session);
return (ret);
}

/*
Expand Down
18 changes: 15 additions & 3 deletions src/lsm/lsm_cursor.c
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,8 @@ __clsm_open_cursors(WT_CURSOR_LSM *clsm)
WT_LSM_CHUNK *chunk;
WT_LSM_TREE *lsm_tree;
WT_SESSION_IMPL *session;
const char *ckpt_cfg[] = { "checkpoint=WiredTigerCheckpoint", NULL };
const char *ckpt_cfg[] = API_CONF_DEFAULTS(session, open_cursor,
"checkpoint=WiredTigerCheckpoint");
int i, nchunks;

session = (WT_SESSION_IMPL *)clsm->iface.session;
Expand Down Expand Up @@ -152,9 +153,20 @@ __clsm_open_cursors(WT_CURSOR_LSM *clsm)
* Once all cursors switch, the in-memory tree can be evicted.
*/
chunk = lsm_tree->chunk[i];
WT_ERR(__wt_curfile_open(session,
ret = __wt_curfile_open(session,
chunk->uri, &clsm->iface,
F_ISSET(chunk, WT_LSM_CHUNK_ONDISK) ? ckpt_cfg : NULL, cp));
F_ISSET(chunk, WT_LSM_CHUNK_ONDISK) ? ckpt_cfg : NULL, cp);

/*
* XXX kludge: we may have an empty chunk where no checkpoint
* was written. If so, try to open the ordinary handle on that
* chunk instead.
*/
if (ret == WT_NOTFOUND && F_ISSET(chunk, WT_LSM_CHUNK_ONDISK))
ret = __wt_curfile_open(session,
chunk->uri, &clsm->iface, NULL, cp);
WT_ERR(ret);

if (chunk->bloom_uri != NULL && !F_ISSET(clsm, WT_CLSM_MERGE))
WT_ERR(__wt_bloom_open(session, chunk->bloom_uri,
lsm_tree->bloom_bit_count,
Expand Down
5 changes: 4 additions & 1 deletion src/lsm/lsm_tree.c
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ __wt_lsm_tree_create(WT_SESSION_IMPL *session,
lsm_tree->file_config = __wt_buf_steal(session, buf, NULL);

/* Create the first chunk and flush the metadata. */
WT_ERR(__wt_lsm_tree_switch(session, lsm_tree));
WT_ERR(__wt_lsm_meta_write(session, lsm_tree));

/* Discard our partially populated handle. */
__lsm_tree_discard(session, lsm_tree);
Expand Down Expand Up @@ -273,6 +273,9 @@ __lsm_tree_open(
lsm_tree->filename = lsm_tree->name + strlen("lsm:");
WT_ERR(__wt_lsm_meta_read(session, lsm_tree));

if (lsm_tree->nchunks == 0)
WT_ERR(__wt_lsm_tree_switch(session, lsm_tree));

/* Set the generation number so cursors are opened on first usage. */
lsm_tree->dsk_gen = 1;

Expand Down
2 changes: 1 addition & 1 deletion src/lsm/lsm_worker.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ __wt_lsm_worker(void *arg)
WT_LSM_CHUNK *chunk, **chunk_array;
WT_LSM_TREE *lsm_tree;
WT_SESSION_IMPL *session;
const char *cfg[] = { "name=,drop=", NULL };
const char *cfg[] = API_CONF_DEFAULTS(session, checkpoint, NULL);
size_t chunk_alloc;
int i, nchunks, progress;

Expand Down
11 changes: 9 additions & 2 deletions src/schema/schema_drop.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,13 @@ __drop_tree(
WT_ERR(__wt_scr_alloc(session, 0, &buf));
WT_ERR(__wt_buf_set(
session, buf, btree->name, strlen(btree->name) + 1));
WT_ERR(__drop_file(session, buf->data, force, cfg));
WT_TRET(__drop_file(session, buf->data, force, cfg));

err: __wt_scr_free(&buf);
if (0) {
err: session->btree = btree;
(void)__wt_session_release_btree(session);
}
__wt_scr_free(&buf);

return (ret);
}
Expand Down Expand Up @@ -241,6 +245,9 @@ __wt_schema_drop(WT_SESSION_IMPL *session, const char *uri, const char *cfg[])

WT_RET(__wt_meta_track_on(session));

/* Be careful to ignore any btree handle in our caller. */
WT_CLEAR_BTREE_IN_SESSION(session);

if (WT_PREFIX_MATCH(uri, "colgroup:"))
ret = __drop_colgroup(session, uri, force, cfg);
else if (WT_PREFIX_MATCH(uri, "file:"))
Expand Down

0 comments on commit ac35d03

Please sign in to comment.