summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMichael Cahill <michael.cahill@wiredtiger.com>2015-02-24 14:44:48 +1100
committerMichael Cahill <michael.cahill@wiredtiger.com>2015-02-24 14:44:48 +1100
commit2fdfb2bbed56e42e1717e567828c68d0b2eb868d (patch)
treeb0d473e439a9c2a725926b9a7d3b7aaaa0642735 /src
parentce89b608835561b11ce4e525a5ebdad86558f115 (diff)
downloadmongo-2fdfb2bbed56e42e1717e567828c68d0b2eb868d.tar.gz
Review places that set/clear session->dhandle, replace with macros. Change callers to save/restore if they need to release a handle after a call.
Diffstat (limited to 'src')
-rw-r--r--src/conn/conn_dhandle.c21
-rw-r--r--src/conn/conn_stat.c8
-rw-r--r--src/cursor/cur_stat.c9
-rw-r--r--src/evict/evict_lru.c2
-rw-r--r--src/include/dhandle.h13
-rw-r--r--src/meta/meta_apply.c3
-rw-r--r--src/schema/schema_worker.c3
-rw-r--r--src/txn/txn_ckpt.c5
8 files changed, 37 insertions, 27 deletions
diff --git a/src/conn/conn_dhandle.c b/src/conn/conn_dhandle.c
index 8ed656d6416..a5512352f2c 100644
--- a/src/conn/conn_dhandle.c
+++ b/src/conn/conn_dhandle.c
@@ -475,16 +475,15 @@ __conn_btree_apply_internal(WT_SESSION_IMPL *session, WT_DATA_HANDLE *dhandle,
WT_DECL_RET;
/*
- * We need to pull the handle into the session handle
- * cache and make sure it's referenced to stop other
- * internal code dropping the handle (e.g in LSM when
- * cleaning up obsolete chunks). Holding the metadata
- * lock isn't enough.
+ * We need to pull the handle into the session handle cache and make
+ * sure it's referenced to stop other internal code dropping the handle
+ * (e.g in LSM when cleaning up obsolete chunks).
*/
ret = __wt_session_get_btree(session,
dhandle->name, dhandle->checkpoint, NULL, 0);
if (ret == 0) {
- ret = func(session, cfg);
+ WT_SAVE_DHANDLE(session,
+ ret = func(session, cfg));
if (WT_META_TRACKING(session))
WT_TRET(__wt_meta_track_handle_lock(session, 0));
else
@@ -550,12 +549,11 @@ __wt_conn_btree_apply_single(WT_SESSION_IMPL *session,
int (*func)(WT_SESSION_IMPL *, const char *[]), const char *cfg[])
{
WT_CONNECTION_IMPL *conn;
- WT_DATA_HANDLE *dhandle, *saved_dhandle;
+ WT_DATA_HANDLE *dhandle;
WT_DECL_RET;
uint64_t bucket, hash;
conn = S2C(session);
- saved_dhandle = session->dhandle;
WT_ASSERT(session, F_ISSET(session, WT_SESSION_HANDLE_LIST_LOCKED));
@@ -578,15 +576,14 @@ __wt_conn_btree_apply_single(WT_SESSION_IMPL *session,
*/
__wt_spin_lock(session, &dhandle->close_lock);
if (F_ISSET(dhandle, WT_DHANDLE_OPEN)) {
- session->dhandle = dhandle;
- ret = func(session, cfg);
+ WT_WITH_DHANDLE(session, dhandle,
+ ret = func(session, cfg));
}
__wt_spin_unlock(session, &dhandle->close_lock);
WT_ERR(ret);
}
-err: session->dhandle = saved_dhandle;
- return (ret);
+err: return (ret);
}
/*
diff --git a/src/conn/conn_stat.c b/src/conn/conn_stat.c
index be2172ea8d8..67814dc330b 100644
--- a/src/conn/conn_stat.c
+++ b/src/conn/conn_stat.c
@@ -193,6 +193,7 @@ static int
__statlog_apply(WT_SESSION_IMPL *session, const char *cfg[])
{
WT_DATA_HANDLE *dhandle;
+ WT_DECL_RET;
char **p;
WT_UNUSED(cfg);
@@ -201,8 +202,11 @@ __statlog_apply(WT_SESSION_IMPL *session, const char *cfg[])
/* Check for a match on the set of sources. */
for (p = S2C(session)->stat_sources; *p != NULL; ++p)
- if (WT_PREFIX_MATCH(dhandle->name, *p))
- return (__statlog_dump(session, dhandle->name, 0));
+ if (WT_PREFIX_MATCH(dhandle->name, *p)) {
+ WT_WITHOUT_DHANDLE(session,
+ ret = __statlog_dump(session, dhandle->name, 0));
+ WT_RET(ret);
+ }
return (0);
}
diff --git a/src/cursor/cur_stat.c b/src/cursor/cur_stat.c
index a473de39a33..bebce217a6a 100644
--- a/src/cursor/cur_stat.c
+++ b/src/cursor/cur_stat.c
@@ -335,20 +335,17 @@ static int
__curstat_file_init(WT_SESSION_IMPL *session,
const char *uri, const char *cfg[], WT_CURSOR_STAT *cst)
{
- WT_DATA_HANDLE *dhandle, *saved_dhandle;
+ WT_DATA_HANDLE *dhandle;
WT_DECL_RET;
- /* Our caller may have their own open handles, don't overwrite them. */
- saved_dhandle = session->dhandle;
-
WT_RET(__wt_session_get_btree_ckpt(session, uri, cfg, 0));
+ dhandle = session->dhandle;
/*
* Fill in the data source statistics, and copy them to the cursor.
* Optionally clear the data source statistics.
*/
if ((ret = __wt_btree_stat_init(session, cst)) == 0) {
- dhandle = session->dhandle;
cst->u.dsrc_stats = dhandle->stats;
if (F_ISSET(cst, WT_CONN_STAT_CLEAR))
__wt_stat_refresh_dsrc_stats(&dhandle->stats);
@@ -357,8 +354,8 @@ __curstat_file_init(WT_SESSION_IMPL *session,
/* Release the handle, we're done with it. */
WT_TRET(__wt_session_release_btree(session));
+ WT_RET(ret);
- session->dhandle = saved_dhandle;
return (ret);
}
diff --git a/src/evict/evict_lru.c b/src/evict/evict_lru.c
index 83a9aa5c8c5..9f549d1f2fe 100644
--- a/src/evict/evict_lru.c
+++ b/src/evict/evict_lru.c
@@ -979,7 +979,7 @@ retry: while (slot < max_entries && ret == 0) {
* exclusive access when a handle is being closed.
*/
if (!F_ISSET(btree, WT_BTREE_NO_EVICTION)) {
- WT_WITH_BTREE(session, btree,
+ WT_WITH_DHANDLE(session, dhandle,
ret = __evict_walk_file(session, &slot, flags));
WT_ASSERT(session, session->split_gen == 0);
}
diff --git a/src/include/dhandle.h b/src/include/dhandle.h
index 423bb84d00d..300e8e735b9 100644
--- a/src/include/dhandle.h
+++ b/src/include/dhandle.h
@@ -6,6 +6,10 @@
* See the file LICENSE for redistribution information.
*/
+/*
+ * Helpers for calling a function with a data handle in session->dhandle
+ * then restoring afterwards.
+ */
#define WT_WITH_DHANDLE(s, d, e) do { \
WT_DATA_HANDLE *__saved_dhandle = (s)->dhandle; \
(s)->dhandle = (d); \
@@ -15,6 +19,15 @@
#define WT_WITH_BTREE(s, b, e) WT_WITH_DHANDLE(s, (b)->dhandle, e)
+/* Call a function without the caller's data handle, restore afterwards. */
+#define WT_WITHOUT_DHANDLE(s, e) WT_WITH_DHANDLE(s, NULL, e)
+
+/*
+ * Call a function with the caller's data handle, restore it afterwards in case
+ * it is overwritten.
+ */
+#define WT_SAVE_DHANDLE(s, e) WT_WITH_DHANDLE(s, (s)->dhandle, e)
+
/*
* WT_DATA_HANDLE --
* A handle for a generic named data source.
diff --git a/src/meta/meta_apply.c b/src/meta/meta_apply.c
index 8ef5cc38db4..6d08ce3aa6a 100644
--- a/src/meta/meta_apply.c
+++ b/src/meta/meta_apply.c
@@ -43,7 +43,8 @@ __wt_meta_btree_apply(WT_SESSION_IMPL *session,
*/
ret = __wt_session_get_btree(session, uri, NULL, NULL, 0);
if (ret == 0) {
- ret = func(session, cfg);
+ WT_SAVE_DHANDLE(session,
+ ret = func(session, cfg));
if (WT_META_TRACKING(session))
WT_TRET(
__wt_meta_track_handle_lock(session, 0));
diff --git a/src/schema/schema_worker.c b/src/schema/schema_worker.c
index 94eb3170175..3dfd068cf9c 100644
--- a/src/schema/schema_worker.c
+++ b/src/schema/schema_worker.c
@@ -57,7 +57,8 @@ __wt_schema_worker(WT_SESSION_IMPL *session,
WT_ERR(__wt_session_get_btree_ckpt(
session, uri, cfg, open_flags));
- ret = file_func(session, cfg);
+ WT_SAVE_DHANDLE(session,
+ ret = file_func(session, cfg));
WT_TRET(__wt_session_release_btree(session));
}
} else if (WT_PREFIX_MATCH(uri, "colgroup:")) {
diff --git a/src/txn/txn_ckpt.c b/src/txn/txn_ckpt.c
index eae21d0b9f5..fb590e1a297 100644
--- a/src/txn/txn_ckpt.c
+++ b/src/txn/txn_ckpt.c
@@ -237,7 +237,6 @@ __checkpoint_data_source(WT_SESSION_IMPL *session, const char *cfg[])
int
__wt_checkpoint_list(WT_SESSION_IMPL *session, const char *cfg[])
{
- WT_DATA_HANDLE *saved_dhandle;
WT_DECL_RET;
const char *name;
@@ -253,7 +252,6 @@ __wt_checkpoint_list(WT_SESSION_IMPL *session, const char *cfg[])
/* Not strictly necessary, but cleaner to clear the current handle. */
name = session->dhandle->name;
- saved_dhandle = session->dhandle;
session->dhandle = NULL;
/* Record busy file names, we'll deal with them in the checkpoint. */
@@ -264,8 +262,7 @@ __wt_checkpoint_list(WT_SESSION_IMPL *session, const char *cfg[])
WT_ERR(__wt_strdup(session, name,
&session->ckpt_handle[session->ckpt_handle_next++].name));
-err: session->dhandle = saved_dhandle;
- return (ret);
+err: return (ret);
}
/*