summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKeith Bostic <keith.bostic@mongodb.com>2017-07-30 23:47:28 -0400
committerAlex Gorrod <alexander.gorrod@mongodb.com>2017-09-21 15:35:06 +1000
commitf8b0f13f800331b92848b27e30640a74d49aa583 (patch)
tree28d10cef1422460c0ca995d63ba088b0204becb1
parent3b6c35e22c457368763ff538706969472e1b2a14 (diff)
downloadmongo-f8b0f13f800331b92848b27e30640a74d49aa583.tar.gz
WT-3470 Avoid a metadata cursor open for table open/drop (#3542)
Restructure __schema_open_table to release the metadata cursor quickly, otherwise we are forced to open a new metadata cursor when checking on the column groups. (cherry picked from commit 9405bee7e217be76af6f2459b2dad487933fd3cb)
-rw-r--r--src/meta/meta_table.c13
-rw-r--r--src/schema/schema_open.c39
2 files changed, 32 insertions, 20 deletions
diff --git a/src/meta/meta_table.c b/src/meta/meta_table.c
index aca69d0e6a2..895b8a9c565 100644
--- a/src/meta/meta_table.c
+++ b/src/meta/meta_table.c
@@ -230,12 +230,23 @@ __wt_metadata_remove(WT_SESSION_IMPL *session, const char *key)
WT_RET_MSG(session, EINVAL,
"%s: remove not supported on the turtle file", key);
+ /*
+ * Take, release, and reacquire the metadata cursor. It's complicated,
+ * but that way the underlying meta-tracking function doesn't have to
+ * open a second metadata cursor, it can use the session's cached one.
+ */
WT_RET(__wt_metadata_cursor(session, &cursor));
cursor->set_key(cursor, key);
WT_ERR(cursor->search(cursor));
+ WT_ERR(__wt_metadata_cursor_release(session, &cursor));
+
if (WT_META_TRACKING(session))
WT_ERR(__wt_meta_track_update(session, key));
- WT_ERR(cursor->remove(cursor));
+
+ WT_ERR(__wt_metadata_cursor(session, &cursor));
+ cursor->set_key(cursor, key);
+ ret = cursor->remove(cursor);
+
err: WT_TRET(__wt_metadata_cursor_release(session, &cursor));
return (ret);
}
diff --git a/src/schema/schema_open.c b/src/schema/schema_open.c
index 44bd66e011a..081650d74a8 100644
--- a/src/schema/schema_open.c
+++ b/src/schema/schema_open.c
@@ -425,37 +425,40 @@ __schema_open_table(WT_SESSION_IMPL *session,
WT_DECL_RET;
WT_TABLE *table;
const char *tconfig;
- char *tablename;
*tablep = NULL;
cursor = NULL;
table = NULL;
- tablename = NULL;
WT_ASSERT(session, F_ISSET(session, WT_SESSION_LOCKED_TABLE));
+ WT_ERR(__wt_calloc_one(session, &table));
+ table->name_hash = __wt_hash_city64(name, namelen);
+
WT_ERR(__wt_scr_alloc(session, 0, &buf));
WT_ERR(__wt_buf_fmt(session, buf, "table:%.*s", (int)namelen, name));
- WT_ERR(__wt_strndup(session, buf->data, buf->size, &tablename));
+ WT_ERR(__wt_strndup(session, buf->data, buf->size, &table->name));
+ /*
+ * Don't hold the metadata cursor pinned, we call functions that use it
+ * to retrieve column group information.
+ */
WT_ERR(__wt_metadata_cursor(session, &cursor));
- cursor->set_key(cursor, tablename);
- WT_ERR(cursor->search(cursor));
- WT_ERR(cursor->get_value(cursor, &tconfig));
-
- WT_ERR(__wt_calloc_one(session, &table));
- table->name = tablename;
- tablename = NULL;
- table->name_hash = __wt_hash_city64(name, namelen);
-
- WT_ERR(__wt_config_getones(session, tconfig, "columns", &cval));
+ cursor->set_key(cursor, table->name);
+ if ((ret = cursor->search(cursor)) == 0 &&
+ (ret = cursor->get_value(cursor, &tconfig)) == 0)
+ ret = __wt_strdup(session, tconfig, &table->config);
+ WT_TRET(__wt_metadata_cursor_release(session, &cursor));
+ WT_ERR(ret);
- WT_ERR(__wt_config_getones(session, tconfig, "key_format", &cval));
+ WT_ERR(__wt_config_getones(session, table->config, "columns", &cval));
+ WT_ERR(__wt_config_getones(
+ session, table->config, "key_format", &cval));
WT_ERR(__wt_strndup(session, cval.str, cval.len, &table->key_format));
- WT_ERR(__wt_config_getones(session, tconfig, "value_format", &cval));
+ WT_ERR(__wt_config_getones(
+ session, table->config, "value_format", &cval));
WT_ERR(__wt_strndup(session, cval.str, cval.len, &table->value_format));
- WT_ERR(__wt_strdup(session, tconfig, &table->config));
/* Point to some items in the copy to save re-parsing. */
WT_ERR(__wt_config_getones(session, table->config,
@@ -491,7 +494,7 @@ __schema_open_table(WT_SESSION_IMPL *session,
if (table->ncolgroups > 0 && table->is_simple)
WT_ERR_MSG(session, EINVAL,
- "%s requires a table with named columns", tablename);
+ "%s requires a table with named columns", table->name);
WT_ERR(__wt_calloc_def(session, WT_COLGROUPS(table), &table->cgroups));
WT_ERR(__wt_schema_open_colgroups(session, table));
@@ -509,9 +512,7 @@ __schema_open_table(WT_SESSION_IMPL *session,
if (0) {
err: WT_TRET(__wt_schema_destroy_table(session, &table));
}
- WT_TRET(__wt_metadata_cursor_release(session, &cursor));
- __wt_free(session, tablename);
__wt_scr_free(session, &buf);
return (ret);
}