From 27b7bf6c0f4f1b5da42924409d932f9e57cccb25 Mon Sep 17 00:00:00 2001 From: Keith Bostic Date: Sun, 23 Oct 2016 18:49:36 -0400 Subject: WT-2987 Fix a bug where opening a cursor on an incomplete table drops core (#3103) --- src/cursor/cur_table.c | 39 +++++++++++++++++++++++++++------------ 1 file changed, 27 insertions(+), 12 deletions(-) (limited to 'src') 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 @@ -756,6 +756,30 @@ __curtable_close(WT_CURSOR *cursor) 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. @@ -763,7 +787,6 @@ err: API_END_RET(session, ret); 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, -- cgit v1.2.1