summaryrefslogtreecommitdiff
path: root/src/session
diff options
context:
space:
mode:
authorMichael Cahill <michael.cahill@wiredtiger.com>2012-09-07 17:35:28 +1000
committerMichael Cahill <michael.cahill@wiredtiger.com>2012-09-07 17:35:28 +1000
commit89fab42cc89002f3cf17a07702c33b944cdd0c00 (patch)
tree69a4a9973ee7f4e86f53e106580d0d3b9c370891 /src/session
parent1ceed8b8f6df16fae57ce29ec721165e6ab888da (diff)
downloadmongo-89fab42cc89002f3cf17a07702c33b944cdd0c00.tar.gz
Add a macro that optionally gets the schema lock.
Diffstat (limited to 'src/session')
-rw-r--r--src/session/session_api.c41
-rw-r--r--src/session/session_btree.c13
2 files changed, 30 insertions, 24 deletions
diff --git a/src/session/session_api.c b/src/session/session_api.c
index df65ab3c0b3..e04c4f04fb2 100644
--- a/src/session/session_api.c
+++ b/src/session/session_api.c
@@ -26,17 +26,34 @@ __session_reset_cursors(WT_SESSION_IMPL *session)
/*
* __session_close --
+ * Close any cached handles in a session. Called holding the schema lock.
+ */
+static int
+__session_close_cache(WT_SESSION_IMPL *session)
+{
+ WT_BTREE_SESSION *btree_session;
+ WT_DECL_RET;
+
+ while ((btree_session = TAILQ_FIRST(&session->btrees)) != NULL)
+ WT_TRET(__wt_session_discard_btree(session, btree_session));
+
+ WT_TRET(__wt_schema_close_tables(session));
+
+ return (ret);
+}
+
+/*
+ * __session_close --
* WT_SESSION->close method.
*/
static int
__session_close(WT_SESSION *wt_session, const char *config)
{
- WT_BTREE_SESSION *btree_session;
WT_CONNECTION_IMPL *conn;
WT_CURSOR *cursor;
WT_DECL_RET;
WT_SESSION_IMPL *session;
- int needlock;
+ int tret;
conn = (WT_CONNECTION_IMPL *)wt_session->connection;
session = (WT_SESSION_IMPL *)wt_session;
@@ -54,17 +71,15 @@ __session_close(WT_SESSION *wt_session, const char *config)
WT_ASSERT(session, session->ncursors == 0);
- /* Acquire the schema lock: we may be closing btree handles. */
- __wt_spin_lock(session, &S2C(session)->schema_lock);
- F_SET(session, WT_SESSION_SCHEMA_LOCKED);
-
- while ((btree_session = TAILQ_FIRST(&session->btrees)) != NULL)
- WT_TRET(__wt_session_discard_btree(session, btree_session));
-
- WT_TRET(__wt_schema_close_tables(session));
-
- F_CLR(session, WT_SESSION_SCHEMA_LOCKED);
- __wt_spin_unlock(session, &S2C(session)->schema_lock);
+ /*
+ * Acquire the schema lock: we may be closing btree handles.
+ *
+ * Note that in some special cases, the schema may already be locked
+ * (e.g., if this session is an LSM tree worker and the tree is being
+ * dropped).
+ */
+ WT_WITH_SCHEMA_LOCK_OPT(session, tret = __session_close_cache(session));
+ WT_TRET(tret);
/* Discard metadata tracking. */
__wt_meta_track_discard(session);
diff --git a/src/session/session_btree.c b/src/session/session_btree.c
index 8f13cc99cc6..77ee9b9b559 100644
--- a/src/session/session_btree.c
+++ b/src/session/session_btree.c
@@ -193,7 +193,6 @@ __wt_session_get_btree(WT_SESSION_IMPL *session,
WT_BTREE *btree;
WT_BTREE_SESSION *btree_session;
WT_DECL_RET;
- int needlock;
btree = NULL;
@@ -236,16 +235,8 @@ __wt_session_get_btree(WT_SESSION_IMPL *session,
* If we don't already hold the schema lock, get it now so that we
* can find and/or open the handle.
*/
- needlock = !F_ISSET(session, WT_SESSION_SCHEMA_LOCKED);
- if (needlock) {
- __wt_spin_lock(session, &S2C(session)->schema_lock);
- F_SET(session, WT_SESSION_SCHEMA_LOCKED);
- }
- ret = __wt_conn_btree_get(session, uri, checkpoint, cfg, flags);
- if (needlock) {
- F_CLR(session, WT_SESSION_SCHEMA_LOCKED);
- __wt_spin_unlock(session, &S2C(session)->schema_lock);
- }
+ WT_WITH_SCHEMA_LOCK_OPT(session,
+ ret = __wt_conn_btree_get(session, uri, checkpoint, cfg, flags));
WT_RET(ret);
if (btree_session == NULL)