diff options
author | Michael Cahill <michael.cahill@wiredtiger.com> | 2013-12-10 17:05:57 +1100 |
---|---|---|
committer | Michael Cahill <michael.cahill@wiredtiger.com> | 2013-12-10 17:05:57 +1100 |
commit | 0b086e7aa06ada2e8bb5815220d8d3562d351f31 (patch) | |
tree | 40ca078ef78409a9dd51575da57f77663f87bcf0 /src | |
parent | 41102ae2a8b4fb9953f1d4110d667608338e749a (diff) | |
download | mongo-0b086e7aa06ada2e8bb5815220d8d3562d351f31.tar.gz |
Avoid bouncing the session cursor count between zero and one when searching an LSM tree: increment the session's cursor count at the beginnging of an LSM search and decrement at the end. This also means we can get rid of the special purpose "cache busy" flag.
Diffstat (limited to 'src')
-rw-r--r-- | src/btree/bt_cursor.c | 6 | ||||
-rw-r--r-- | src/include/cache.i | 3 | ||||
-rw-r--r-- | src/include/cursor.i | 95 | ||||
-rw-r--r-- | src/include/flags.h | 1 | ||||
-rw-r--r-- | src/lsm/lsm_cursor.c | 8 |
5 files changed, 66 insertions, 47 deletions
diff --git a/src/btree/bt_cursor.c b/src/btree/bt_cursor.c index 4c5a921a8f7..bad22be6954 100644 --- a/src/btree/bt_cursor.c +++ b/src/btree/bt_cursor.c @@ -126,7 +126,7 @@ __wt_btcur_reset(WT_CURSOR_BTREE *cbt) WT_STAT_FAST_CONN_INCR(session, cursor_reset); WT_STAT_FAST_DATA_INCR(session, cursor_reset); - ret = __cursor_leave(cbt); + ret = __curfile_leave(cbt); __cursor_search_clear(cbt); return (ret); @@ -337,7 +337,7 @@ err: if (ret == WT_RESTART) goto retry; /* Insert doesn't maintain a position across calls, clear resources. */ if (ret == 0) - WT_TRET(__cursor_leave(cbt)); + WT_TRET(__curfile_leave(cbt)); if (ret != 0) WT_TRET(__cursor_error_resolve(cbt)); return (ret); @@ -760,7 +760,7 @@ __wt_btcur_close(WT_CURSOR_BTREE *cbt) session = (WT_SESSION_IMPL *)cbt->iface.session; - ret = __cursor_leave(cbt); + ret = __curfile_leave(cbt); __wt_buf_free(session, &cbt->tmp); return (ret); diff --git a/src/include/cache.i b/src/include/cache.i index 7d2bba21717..1fc37763aae 100644 --- a/src/include/cache.i +++ b/src/include/cache.i @@ -63,8 +63,7 @@ __wt_cache_full_check(WT_SESSION_IMPL *session) */ txn_global = &S2C(session)->txn_global; txn_state = &txn_global->states[session->id]; - busy = F_ISSET(session, WT_SESSION_CACHE_BUSY) || - txn_state->id != WT_TXN_NONE || + busy = txn_state->id != WT_TXN_NONE || session->nhazard > 0 || (txn_state->snap_min != WT_TXN_NONE && txn_global->current != txn_global->oldest_id); diff --git a/src/include/cursor.i b/src/include/cursor.i index a0f7de4c243..400b698abec 100644 --- a/src/include/cursor.i +++ b/src/include/cursor.i @@ -43,63 +43,84 @@ __cursor_search_clear(WT_CURSOR_BTREE *cbt) } /* - * __cursor_leave -- - * Clear a cursor's position. + * __cursor_enter -- + * Activate a cursor. */ static inline int -__cursor_leave(WT_CURSOR_BTREE *cbt) +__cursor_enter(WT_SESSION_IMPL *session) { - WT_CURSOR *cursor; - WT_SESSION_IMPL *session; - - cursor = &cbt->iface; - session = (WT_SESSION_IMPL *)cursor->session; - /* - * If the cursor was active, decrement the count of active cursors in - * the session. When that goes to zero, there are no active cursors, - * and we can release any snapshot we're holding for read committed - * isolation. + * If there are no other cursors positioned in the session, check + * whether the cache is full and then get a snapshot if necessary. */ - if (F_ISSET(cbt, WT_CBT_ACTIVE)) { - WT_ASSERT(session, session->ncursors > 0); - if (--session->ncursors == 0) - __wt_txn_read_last(session); - F_CLR(cbt, WT_CBT_ACTIVE); + if (session->ncursors == 0) { + WT_RET(__wt_cache_full_check(session)); + __wt_txn_read_first(session); } + ++session->ncursors; + return (0); +} +/* + * __cursor_leave -- + * Deactivate a cursor. + */ +static inline int +__cursor_leave(WT_SESSION_IMPL *session) +{ /* - * Release any page references we're holding. This can trigger - * eviction (e.g., forced eviction of big pages), so it is important to - * do it after releasing our snapshot above. + * Decrement the count of active cursors in the session. When that + * goes to zero, there are no active cursors, and we can release any + * snapshot we're holding for read committed isolation. */ - WT_RET(__wt_page_release(session, cbt->page)); - cbt->page = NULL; + WT_ASSERT(session, session->ncursors > 0); + if (--session->ncursors == 0) + __wt_txn_read_last(session); return (0); } /* - * __cursor_enter -- - * Setup the cursor's state for a new call. + * __curfile_enter -- + * Activate a file cursor. + */ +static inline int +__curfile_enter(WT_CURSOR_BTREE *cbt) +{ + WT_SESSION_IMPL *session; + + session = (WT_SESSION_IMPL *)cbt->iface.session; + + WT_RET(__cursor_enter(session)); + F_SET(cbt, WT_CBT_ACTIVE); + return (0); +} + +/* + * __curfile_leave -- + * Clear a file cursor's position. */ static inline int -__cursor_enter(WT_CURSOR_BTREE *cbt) +__curfile_leave(WT_CURSOR_BTREE *cbt) { WT_SESSION_IMPL *session; session = (WT_SESSION_IMPL *)cbt->iface.session; + /* If the cursor was active, deactivate it. */ + if (F_ISSET(cbt, WT_CBT_ACTIVE)) { + WT_RET(__cursor_leave(session)); + F_CLR(cbt, WT_CBT_ACTIVE); + } + /* - * If there are no other cursors positioned in the session, check - * whether the cache is full and then get a snapshot if necessary. + * Release any page references we're holding. This can trigger + * eviction (e.g., forced eviction of big pages), so it is important to + * do it after releasing our snapshot above. */ - if (session->ncursors == 0) { - WT_RET(__wt_cache_full_check(session)); - __wt_txn_read_first(session); - } - ++session->ncursors; - F_SET(cbt, WT_CBT_ACTIVE); + WT_RET(__wt_page_release(session, cbt->page)); + cbt->page = NULL; + return (0); } @@ -115,9 +136,9 @@ __cursor_func_init(WT_CURSOR_BTREE *cbt, int reenter) session = (WT_SESSION_IMPL *)cbt->iface.session; if (reenter) - WT_RET(__cursor_leave(cbt)); + WT_RET(__curfile_leave(cbt)); if (!F_ISSET(cbt, WT_CBT_ACTIVE)) - WT_RET(__cursor_enter(cbt)); + WT_RET(__curfile_enter(cbt)); __wt_txn_cursor_op(session); return (0); } @@ -133,7 +154,7 @@ __cursor_error_resolve(WT_CURSOR_BTREE *cbt) * On error, we can't iterate, so clear the cursor's position and * release any page references we're holding. */ - WT_RET(__cursor_leave(cbt)); + WT_RET(__curfile_leave(cbt)); /* Clear the cursor's search state. */ __cursor_search_clear(cbt); diff --git a/src/include/flags.h b/src/include/flags.h index cd8de157cbf..a1fb35725f4 100644 --- a/src/include/flags.h +++ b/src/include/flags.h @@ -18,7 +18,6 @@ #define WT_LOGSCAN_RECOVER 0x00000001 #define WT_LOG_DSYNC 0x00000002 #define WT_LOG_FSYNC 0x00000001 -#define WT_SESSION_CACHE_BUSY 0x00000100 #define WT_SESSION_INTERNAL 0x00000080 #define WT_SESSION_LOGGING_DISABLED 0x00000040 #define WT_SESSION_LOGGING_INMEM 0x00000020 diff --git a/src/lsm/lsm_cursor.c b/src/lsm/lsm_cursor.c index 6c89204da6f..d984ff4586f 100644 --- a/src/lsm/lsm_cursor.c +++ b/src/lsm/lsm_cursor.c @@ -21,21 +21,21 @@ clsm = (WT_CURSOR_LSM *)cursor; \ CURSOR_API_CALL(cursor, session, n, NULL); \ WT_ERR(__clsm_enter(clsm, 0)); \ - F_SET(session, WT_SESSION_CACHE_BUSY) + WT_ERR(__cursor_enter(session)) #define WT_LSM_UPDATE_ENTER(clsm, cursor, session, n) \ clsm = (WT_CURSOR_LSM *)cursor; \ CURSOR_UPDATE_API_CALL(cursor, session, n, NULL); \ WT_ERR(__clsm_enter(clsm, 1)); \ - F_SET(session, WT_SESSION_CACHE_BUSY) + WT_ERR(__cursor_enter(session)) #define WT_LSM_LEAVE(session) \ API_END(session); \ - F_CLR(session, WT_SESSION_CACHE_BUSY); \ + WT_TRET(__cursor_leave(session)) #define WT_LSM_UPDATE_LEAVE(clsm, session, ret) \ CURSOR_UPDATE_API_END(session, ret); \ - F_CLR(session, WT_SESSION_CACHE_BUSY) + WT_TRET(__cursor_leave(session)) static int __clsm_open_cursors(WT_CURSOR_LSM *, int, u_int, uint32_t); static int __clsm_lookup(WT_CURSOR_LSM *); |