@@ -63,17 +63,16 @@ __wt_hs_get_btree(WT_SESSION_IMPL *session, WT_BTREE **hs_btreep)
6363{
6464 WT_DECL_RET ;
6565 uint32_t session_flags ;
66- bool is_owner ;
6766
6867 * hs_btreep = NULL ;
6968 session_flags = 0 ; /* [-Werror=maybe-uninitialized] */
7069
71- WT_RET (__wt_hs_cursor (session , & session_flags , & is_owner ));
70+ WT_RET (__wt_hs_cursor_open (session , & session_flags ));
7271
7372 * hs_btreep = CUR2BT (session -> hs_cursor );
7473 WT_ASSERT (session , * hs_btreep != NULL );
7574
76- WT_TRET (__wt_hs_cursor_close (session , session_flags , is_owner ));
75+ WT_TRET (__wt_hs_cursor_close (session , session_flags ));
7776
7877 return (ret );
7978}
@@ -212,54 +211,32 @@ __wt_hs_destroy(WT_SESSION_IMPL *session)
212211 * Open a new history store table cursor.
213212 */
214213int
215- __wt_hs_cursor_open (WT_SESSION_IMPL * session )
214+ __wt_hs_cursor_open (WT_SESSION_IMPL * session , uint32_t * session_flags )
216215{
217216 WT_CURSOR * cursor ;
218217 WT_DECL_RET ;
219218 const char * open_cursor_cfg [] = {WT_CONFIG_BASE (session , WT_SESSION_open_cursor ), NULL };
220219
220+ /* Not allowed to open a cursor if you already have one */
221+ WT_ASSERT (session , session -> hs_cursor == NULL && !F_ISSET (session , WT_SESSION_HS_CURSOR ));
222+
221223 WT_WITHOUT_DHANDLE (
222224 session , ret = __wt_open_cursor (session , WT_HS_URI , NULL , open_cursor_cfg , & cursor ));
223225 WT_RET (ret );
224226
225227 /* History store cursors should always ignore tombstones. */
226228 F_SET (cursor , WT_CURSTD_IGNORE_TOMBSTONE );
227229
228- session -> hs_cursor = cursor ;
229- F_SET (session , WT_SESSION_HS_CURSOR );
230-
231- return (0 );
232- }
233-
234- /*
235- * __wt_hs_cursor --
236- * Return a history store cursor, open one if not already open.
237- */
238- int
239- __wt_hs_cursor (WT_SESSION_IMPL * session , uint32_t * session_flags , bool * is_owner )
240- {
241230 /*
242- * We don't want to get tapped for eviction after we start using the history store cursor; save
243- * a copy of the current eviction state, we'll turn eviction off before we return.
244- *
245- * Don't cache history store table pages, we're here because of eviction problems and there's no
246- * reason to believe history store pages will be useful more than once.
231+ * We don't want to get tapped for eviction after we start using the history store cursor. Save
232+ * a copy of the current flag values. We'll restore them when the cursor is closed.
247233 */
248234 * session_flags = F_MASK (session , WT_HS_SESSION_FLAGS );
249- * is_owner = false;
250-
251- /* Open a cursor if this session doesn't already have one. */
252- if (!F_ISSET (session , WT_SESSION_HS_CURSOR )) {
253- /* The caller is responsible for closing this cursor. */
254- * is_owner = true;
255- WT_RET (__wt_hs_cursor_open (session ));
256- }
257-
258- WT_ASSERT (session , session -> hs_cursor != NULL );
259-
260- /* Configure session to access the history store table. */
261235 F_SET (session , WT_HS_SESSION_FLAGS );
262236
237+ session -> hs_cursor = cursor ;
238+ F_SET (session , WT_SESSION_HS_CURSOR );
239+
263240 return (0 );
264241}
265242
@@ -268,25 +245,13 @@ __wt_hs_cursor(WT_SESSION_IMPL *session, uint32_t *session_flags, bool *is_owner
268245 * Discard a history store cursor.
269246 */
270247int
271- __wt_hs_cursor_close (WT_SESSION_IMPL * session , uint32_t session_flags , bool is_owner )
248+ __wt_hs_cursor_close (WT_SESSION_IMPL * session , uint32_t session_flags )
272249{
273- /* Nothing to do if the session doesn't have a HS cursor opened. */
274- if (!F_ISSET (session , WT_SESSION_HS_CURSOR )) {
275- WT_ASSERT (session , session -> hs_cursor == NULL );
276- return (0 );
277- }
278- WT_ASSERT (session , session -> hs_cursor != NULL );
250+ /* Should only be called when session has an open history store cursor */
251+ WT_ASSERT (session , session -> hs_cursor != NULL && F_ISSET (session , WT_SESSION_HS_CURSOR ));
279252
280253 /*
281- * If we're not the owner, we're not responsible for closing this cursor. Reset the cursor to
282- * avoid pinning the page in cache.
283- */
284- if (!is_owner )
285- return (session -> hs_cursor -> reset (session -> hs_cursor ));
286-
287- /*
288- * We turned off caching and eviction while the history store cursor was in use, restore the
289- * session's flags.
254+ * Restore previous values of history store session flags.
290255 */
291256 F_CLR (session , WT_HS_SESSION_FLAGS );
292257 F_SET (session , session_flags );
@@ -1225,7 +1190,7 @@ __wt_hs_find_upd(WT_SESSION_IMPL *session, WT_ITEM *key, const char *value_forma
12251190 uint32_t hs_btree_id , session_flags ;
12261191 uint8_t * p , recno_key_buf [WT_INTPACK64_MAXSIZE ], upd_type ;
12271192 int cmp ;
1228- bool is_owner , modify ;
1193+ bool modify ;
12291194
12301195 hs_cursor = NULL ;
12311196 mod_upd = upd = NULL ;
@@ -1237,7 +1202,6 @@ __wt_hs_find_upd(WT_SESSION_IMPL *session, WT_ITEM *key, const char *value_forma
12371202 hs_btree_id = S2BT (session )-> id ;
12381203 session_flags = 0 ; /* [-Werror=maybe-uninitialized] */
12391204 WT_NOT_READ (modify , false);
1240- is_owner = false;
12411205
12421206 WT_STAT_CONN_INCR (session , cursor_search_hs );
12431207 WT_STAT_DATA_INCR (session , cursor_search_hs );
@@ -1258,7 +1222,7 @@ __wt_hs_find_upd(WT_SESSION_IMPL *session, WT_ITEM *key, const char *value_forma
12581222 WT_ERR (__wt_scr_alloc (session , 0 , & hs_value ));
12591223
12601224 /* Open a history store table cursor. */
1261- WT_ERR (__wt_hs_cursor (session , & session_flags , & is_owner ));
1225+ WT_ERR (__wt_hs_cursor_open (session , & session_flags ));
12621226 hs_cursor = session -> hs_cursor ;
12631227 hs_cbt = (WT_CURSOR_BTREE * )hs_cursor ;
12641228
@@ -1423,7 +1387,7 @@ __wt_hs_find_upd(WT_SESSION_IMPL *session, WT_ITEM *key, const char *value_forma
14231387 __wt_scr_free (session , & hs_value );
14241388 WT_ASSERT (session , hs_key .mem == NULL && hs_key .memsize == 0 );
14251389
1426- WT_TRET (__wt_hs_cursor_close (session , session_flags , is_owner ));
1390+ WT_TRET (__wt_hs_cursor_close (session , session_flags ));
14271391
14281392 __wt_free_update_list (session , & mod_upd );
14291393 while (modifies .size > 0 ) {
@@ -1519,26 +1483,14 @@ __wt_hs_delete_key_from_ts(
15191483 WT_SESSION_IMPL * session , uint32_t btree_id , const WT_ITEM * key , wt_timestamp_t ts )
15201484{
15211485 WT_DECL_RET ;
1522- uint32_t session_flags ;
1523- bool is_owner ;
1524-
1525- session_flags = session -> flags ;
1526-
1527- /*
1528- * Some code paths such as schema removal involve deleting keys in metadata and assert that we
1529- * shouldn't be opening new dhandles. We won't ever need to blow away history store content in
1530- * these cases so let's just return early here.
1531- */
1532- if (F_ISSET (session , WT_SESSION_NO_DATA_HANDLES ))
1533- return (0 );
15341486
1535- WT_RET (__wt_hs_cursor (session , & session_flags , & is_owner ));
1487+ /* If the operation can't open new handles, it should have figured that out before here. */
1488+ WT_ASSERT (session , !F_ISSET (session , WT_SESSION_NO_DATA_HANDLES ));
15361489
15371490 /* The tree structure can change while we try to insert the mod list, retry if that happens. */
15381491 while ((ret = __hs_delete_key_from_ts_int (session , btree_id , key , ts )) == WT_RESTART )
15391492 WT_STAT_CONN_INCR (session , cache_hs_insert_restart );
15401493
1541- WT_TRET (__wt_hs_cursor_close (session , session_flags , is_owner ));
15421494 return (ret );
15431495}
15441496
@@ -1915,7 +1867,7 @@ __wt_history_store_verify(WT_SESSION_IMPL *session)
19151867 uint64_t hs_counter ;
19161868 uint32_t btree_id , session_flags ;
19171869 char * uri_data ;
1918- bool is_owner , stop ;
1870+ bool stop ;
19191871
19201872 /* We should never reach here if working in context of the default session. */
19211873 WT_ASSERT (session , S2C (session )-> default_session != session );
@@ -1925,10 +1877,9 @@ __wt_history_store_verify(WT_SESSION_IMPL *session)
19251877 btree_id = WT_BTREE_ID_INVALID ;
19261878 session_flags = 0 ; /* [-Wconditional-uninitialized] */
19271879 uri_data = NULL ;
1928- is_owner = false; /* [-Wconditional-uninitialized] */
19291880
19301881 WT_ERR (__wt_scr_alloc (session , 0 , & buf ));
1931- WT_ERR (__wt_hs_cursor (session , & session_flags , & is_owner ));
1882+ WT_ERR (__wt_hs_cursor_open (session , & session_flags ));
19321883 cursor = session -> hs_cursor ;
19331884 WT_ERR_NOTFOUND_OK (__wt_hs_cursor_next (session , cursor ), true);
19341885 stop = ret == WT_NOTFOUND ? true : false;
@@ -1960,7 +1911,7 @@ __wt_history_store_verify(WT_SESSION_IMPL *session)
19601911 WT_ERR_NOTFOUND_OK (ret , false);
19611912 }
19621913err :
1963- WT_TRET (__wt_hs_cursor_close (session , session_flags , is_owner ));
1914+ WT_TRET (__wt_hs_cursor_close (session , session_flags ));
19641915
19651916 __wt_scr_free (session , & buf );
19661917 WT_ASSERT (session , hs_key .mem == NULL && hs_key .memsize == 0 );
0 commit comments