diff options
Diffstat (limited to 'src/third_party/wiredtiger/src/cursor/cur_file.c')
-rw-r--r-- | src/third_party/wiredtiger/src/cursor/cur_file.c | 69 |
1 files changed, 37 insertions, 32 deletions
diff --git a/src/third_party/wiredtiger/src/cursor/cur_file.c b/src/third_party/wiredtiger/src/cursor/cur_file.c index 0b26b931f6c..80093fceb02 100644 --- a/src/third_party/wiredtiger/src/cursor/cur_file.c +++ b/src/third_party/wiredtiger/src/cursor/cur_file.c @@ -552,43 +552,48 @@ __curfile_reopen(WT_CURSOR *cursor, bool check_only) WT_SESSION_IMPL *session; bool is_dead; - is_dead = false; cbt = (WT_CURSOR_BTREE *)cursor; - session = (WT_SESSION_IMPL *)cursor->session; dhandle = cbt->dhandle; + session = (WT_SESSION_IMPL *)cursor->session; - if (!WT_DHANDLE_CAN_REOPEN(dhandle)) - ret = WT_NOTFOUND; - if (!check_only) { - session->dhandle = dhandle; - WT_TRET(__wt_session_lock_dhandle(session, 0, &is_dead)); + if (check_only) + return (WT_DHANDLE_CAN_REOPEN(dhandle) ? 0 : WT_NOTFOUND); - /* - * If we get a busy return, the data handle may be involved - * in an exclusive operation. We'll treat it in the same - * way as a dead handle: fail the reopen, and flag the - * cursor so that the handle won't be unlocked when it - * is subsequently closed. - */ - if (is_dead || ret == EBUSY) { - F_SET(cursor, WT_CURSTD_DEAD); - ret = WT_NOTFOUND; - } - __wt_cursor_reopen(cursor, dhandle); + session->dhandle = dhandle; - /* - * The btree handle may have been reopened since we last - * accessed it. Reset fields in the cursor that point to - * memory owned by the btree handle. - */ - if (ret == 0) { - WT_ASSERT(session, - dhandle->type == WT_DHANDLE_TYPE_BTREE); - cbt->btree = dhandle->handle; - cursor->internal_uri = cbt->btree->dhandle->name; - cursor->key_format = cbt->btree->key_format; - cursor->value_format = cbt->btree->value_format; - } + /* + * Lock the handle: we're only interested in open handles, any other + * state disqualifies the cache. + */ + ret = __wt_session_lock_dhandle(session, 0, &is_dead); + if (!is_dead && ret == 0 && !F_ISSET(dhandle, WT_DHANDLE_OPEN)) { + WT_RET(__wt_session_release_dhandle(session)); + ret = __wt_set_return(session, EBUSY); + } + + /* + * The data handle may not be available, in which case handle it like a + * dead handle: fail the reopen, and flag the cursor so that the handle + * won't be unlocked when subsequently closed. + */ + if (is_dead || ret == EBUSY) { + F_SET(cursor, WT_CURSTD_DEAD); + ret = WT_NOTFOUND; + } + __wt_cursor_reopen(cursor, dhandle); + + /* + * The btree handle may have been reopened since we last accessed it. + * Reset fields in the cursor that point to memory owned by the btree + * handle. + */ + if (ret == 0) { + WT_ASSERT(session, + dhandle->type == WT_DHANDLE_TYPE_BTREE); + cbt->btree = dhandle->handle; + cursor->internal_uri = cbt->btree->dhandle->name; + cursor->key_format = cbt->btree->key_format; + cursor->value_format = cbt->btree->value_format; } return (ret); } |