summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorKeith Bostic <keith.bostic@mongodb.com>2016-10-23 18:49:36 -0400
committerAlex Gorrod <alexander.gorrod@mongodb.com>2016-10-24 09:49:36 +1100
commit27b7bf6c0f4f1b5da42924409d932f9e57cccb25 (patch)
tree8af0263e20647f5328bee2fbea3b28e2d764b26a /src
parenta1327e2d6e568b843b9483984171ab18c00eaf26 (diff)
downloadmongo-27b7bf6c0f4f1b5da42924409d932f9e57cccb25.tar.gz
WT-2987 Fix a bug where opening a cursor on an incomplete table drops core (#3103)
Diffstat (limited to 'src')
-rw-r--r--src/cursor/cur_table.c39
1 files changed, 27 insertions, 12 deletions
diff --git a/src/cursor/cur_table.c b/src/cursor/cur_table.c
index 1b93b27f564..6543d54e90f 100644
--- a/src/cursor/cur_table.c
+++ b/src/cursor/cur_table.c
@@ -757,13 +757,36 @@ err: API_END_RET(session, ret);
}
/*
+ * __curtable_complete --
+ * Return failure if the table is not yet fully created.
+ */
+static int
+__curtable_complete(WT_SESSION_IMPL *session, WT_TABLE *table)
+{
+ WT_DECL_RET;
+ bool complete;
+
+ if (table->cg_complete)
+ return (0);
+
+ /* If the table is incomplete, wait on the table lock and recheck. */
+ complete = false;
+ WT_WITH_TABLE_LOCK(session, ret, complete = table->cg_complete);
+ WT_RET(ret);
+ if (!complete)
+ WT_RET_MSG(session, EINVAL,
+ "'%s' not available until all column groups are created",
+ table->name);
+ return (0);
+}
+
+/*
* __curtable_open_colgroups --
* Open cursors on column groups for a table cursor.
*/
static int
__curtable_open_colgroups(WT_CURSOR_TABLE *ctable, const char *cfg_arg[])
{
- WT_DECL_RET;
WT_SESSION_IMPL *session;
WT_TABLE *table;
WT_CURSOR **cp;
@@ -775,21 +798,11 @@ __curtable_open_colgroups(WT_CURSOR_TABLE *ctable, const char *cfg_arg[])
cfg_arg[0], cfg_arg[1], "dump=\"\",readonly=0", NULL, NULL
};
u_int i;
- bool complete;
session = (WT_SESSION_IMPL *)ctable->iface.session;
table = ctable->table;
- /* If the table is incomplete, wait on the table lock and recheck. */
- complete = table->cg_complete;
- if (!complete) {
- WT_WITH_TABLE_LOCK(session, ret, complete = table->cg_complete);
- WT_RET(ret);
- }
- if (!complete)
- WT_RET_MSG(session, EINVAL,
- "Can't use '%s' until all column groups are created",
- table->name);
+ WT_RET(__curtable_complete(session, table)); /* completeness check */
WT_RET(__wt_calloc_def(session,
WT_COLGROUPS(table), &ctable->cg_cursors));
@@ -887,6 +900,8 @@ __wt_curtable_open(WT_SESSION_IMPL *session,
size = WT_PTRDIFF(columns, tablename);
WT_RET(__wt_schema_get_table(session, tablename, size, false, &table));
+ WT_RET(__curtable_complete(session, table)); /* completeness check */
+
if (table->is_simple) {
/* Just return a cursor on the underlying data source. */
ret = __wt_open_cursor(session,