Skip to content

Commit 4073b59

Browse files
lukechEvergreen Agent
authored andcommitted
Import wiredtiger: d29619b755d79cb4406349e1309935b8c2fda2c2 from branch mongodb-4.6
ref: 54d5655b43..d29619b755 for: 4.5.1 WT-6274 SESSIONs shouldn't nest calls to get/release hs cursor WT-6421 Avoid parsing metadata checkpoint for clean files WT-6466 Don't reset the WT_SESSION timers when HS cursors are closed WT-6551 Avoid a timing problem at the beginning of a test for log preallocation
1 parent 5ce3746 commit 4073b59

File tree

28 files changed

+548
-319
lines changed

28 files changed

+548
-319
lines changed

src/third_party/wiredtiger/dist/s_stat

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ search=`sed \
2222

2323
# There are some fields that are used, but we can't detect it.
2424
cat << UNUSED_STAT_FIELDS
25+
btree_clean_checkpoint_timer
2526
lock_checkpoint_count
2627
lock_checkpoint_wait_application
2728
lock_checkpoint_wait_internal

src/third_party/wiredtiger/dist/stat_data.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -728,6 +728,7 @@ def __init__(self, name, desc, flags=''):
728728
# Btree statistics
729729
##########################################
730730
BtreeStat('btree_checkpoint_generation', 'btree checkpoint generation', 'no_clear,no_scale'),
731+
BtreeStat('btree_clean_checkpoint_timer', 'btree clean tree checkpoint expiration time', 'no_clear,no_scale'),
731732
BtreeStat('btree_column_deleted', 'column-store variable-size deleted values', 'no_scale,tree_walk'),
732733
BtreeStat('btree_column_fix', 'column-store fixed-size leaf pages', 'no_scale,tree_walk'),
733734
BtreeStat('btree_column_internal', 'column-store internal pages', 'no_scale,tree_walk'),
@@ -965,4 +966,4 @@ def __init__(self, name, desc, flags=''):
965966
SessionStat('write_time', 'page write from cache to disk time (usecs)'),
966967
]
967968

968-
session_stats = sorted(session_stats, key=attrgetter('desc'))
969+
session_stats = sorted(session_stats, key=attrgetter('desc'))

src/third_party/wiredtiger/import.data

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
"vendor": "wiredtiger",
33
"github": "wiredtiger/wiredtiger.git",
44
"branch": "mongodb-4.6",
5-
"commit": "54d5655b43b91028ee1c90eadd0969c863a9e7e5"
5+
"commit": "d29619b755d79cb4406349e1309935b8c2fda2c2"
66
}

src/third_party/wiredtiger/src/btree/bt_debug.c

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ struct __wt_dbg {
2121
WT_ITEM *hs_key; /* History store lookups */
2222
WT_ITEM *hs_value;
2323
uint32_t session_flags;
24-
bool hs_is_local, is_owner;
24+
bool hs_is_local;
2525

2626
/*
2727
* When using the standard event handlers, the debugging output has to do its own message
@@ -288,7 +288,7 @@ __debug_wrapup(WT_DBG *ds)
288288
msg = ds->msg;
289289

290290
if (ds->hs_is_local)
291-
WT_TRET(__wt_hs_cursor_close(session, ds->session_flags, ds->is_owner));
291+
WT_TRET(__wt_hs_cursor_close(session, ds->session_flags));
292292

293293
__wt_scr_free(session, &ds->key);
294294
__wt_scr_free(session, &ds->hs_key);
@@ -975,15 +975,14 @@ __wt_debug_cursor_tree_hs(void *cursor_arg, const char *ofile)
975975
WT_DECL_RET;
976976
WT_SESSION_IMPL *session;
977977
uint32_t session_flags;
978-
bool is_owner;
979978

980979
session = CUR2S(cursor_arg);
981980
session_flags = 0; /* [-Werror=maybe-uninitialized] */
982981

983-
WT_RET(__wt_hs_cursor(session, &session_flags, &is_owner));
982+
WT_RET(__wt_hs_cursor_open(session, &session_flags));
984983
cbt = (WT_CURSOR_BTREE *)session->hs_cursor;
985984
WT_WITH_BTREE(session, CUR2BT(cbt), ret = __wt_debug_tree_all(session, NULL, NULL, ofile));
986-
WT_TRET(__wt_hs_cursor_close(session, session_flags, is_owner));
985+
WT_TRET(__wt_hs_cursor_close(session, session_flags));
987986

988987
return (ret);
989988
}
@@ -1029,8 +1028,7 @@ __debug_page(WT_DBG *ds, WT_REF *ref, uint32_t flags)
10291028
* doesn't work, we may be running in-memory.
10301029
*/
10311030
if (!WT_IS_HS(S2BT(session))) {
1032-
if (session->hs_cursor == NULL &&
1033-
__wt_hs_cursor(session, &ds->session_flags, &ds->is_owner) == 0)
1031+
if (session->hs_cursor == NULL && __wt_hs_cursor_open(session, &ds->session_flags) == 0)
10341032
ds->hs_is_local = true;
10351033
if (session->hs_cursor != NULL) {
10361034
WT_RET(__wt_scr_alloc(session, 0, &ds->hs_key));

src/third_party/wiredtiger/src/btree/bt_vrfy.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ __wt_verify(WT_SESSION_IMPL *session, const char *cfg[])
173173
#if 0
174174
/* FIXME-WT-6263: Temporarily disable history store verification. */
175175
uint32_t session_flags;
176-
bool is_owner, skip_hs;
176+
bool skip_hs;
177177
#endif
178178

179179
btree = S2BT(session);
@@ -185,7 +185,6 @@ __wt_verify(WT_SESSION_IMPL *session, const char *cfg[])
185185
#if 0
186186
/* FIXME-WT-6263: Temporarily disable history store verification. */
187187
session_flags = 0; /* -Wuninitialized */
188-
is_owner = false; /* -Wuninitialized */
189188

190189
/*
191190
* Skip the history store explicit call if we're performing a metadata verification. The
@@ -283,9 +282,9 @@ __wt_verify(WT_SESSION_IMPL *session, const char *cfg[])
283282
*/
284283
if (ret == 0 && (ckpt + 1)->name == NULL && !skip_hs) {
285284
/* Open a history store cursor. */
286-
WT_ERR(__wt_hs_cursor(session, &session_flags, &is_owner));
285+
WT_ERR(__wt_hs_cursor_open(session, &session_flags);
287286
WT_TRET(__wt_history_store_verify_one(session));
288-
WT_TRET(__wt_hs_cursor_close(session, session_flags, is_owner));
287+
WT_TRET(__wt_hs_cursor_close(session, session_flags);
289288
/*
290289
* We cannot error out here. If we got an error verifying the history store, we need
291290
* to follow through with reacquiring the exclusive call below. We'll error out

src/third_party/wiredtiger/src/conn/conn_cache.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ __wt_cache_config(WT_SESSION_IMPL *session, bool reconfigure, const char *cfg[])
208208
*/
209209
if (reconfigure)
210210
WT_RET(__wt_thread_group_resize(session, &conn->evict_threads, conn->evict_threads_min,
211-
conn->evict_threads_max, WT_THREAD_CAN_WAIT | WT_THREAD_HS | WT_THREAD_PANIC_FAIL));
211+
conn->evict_threads_max, WT_THREAD_CAN_WAIT | WT_THREAD_PANIC_FAIL));
212212

213213
return (0);
214214
}

src/third_party/wiredtiger/src/evict/evict_lru.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,6 @@ __wt_evict_thread_run(WT_SESSION_IMPL *session, WT_THREAD *thread)
274274
WT_DECL_RET;
275275
uint32_t session_flags;
276276
bool did_work, was_intr;
277-
bool is_owner;
278277

279278
conn = S2C(session);
280279
cache = conn->cache;
@@ -284,10 +283,10 @@ __wt_evict_thread_run(WT_SESSION_IMPL *session, WT_THREAD *thread)
284283
* busy and then opens a different file (in this case, the HS file), it can deadlock with a
285284
* thread waiting for the first file to drain from the eviction queue. See WT-5946 for details.
286285
*/
287-
if (!F_ISSET(conn, WT_CONN_IN_MEMORY)) {
286+
if (session->hs_cursor == NULL && !F_ISSET(conn, WT_CONN_IN_MEMORY | WT_CONN_READONLY)) {
288287
session_flags = 0; /* [-Werror=maybe-uninitialized] */
289-
WT_RET(__wt_hs_cursor(session, &session_flags, &is_owner));
290-
WT_RET(__wt_hs_cursor_close(session, session_flags, is_owner));
288+
WT_RET(__wt_hs_cursor_open(session, &session_flags));
289+
WT_RET(__wt_hs_cursor_close(session, session_flags));
291290
}
292291

293292
if (conn->evict_server_running && __wt_spin_trylock(session, &cache->evict_pass_lock) == 0) {
@@ -493,7 +492,7 @@ __wt_evict_create(WT_SESSION_IMPL *session)
493492
/*
494493
* Create the eviction thread group. Set the group size to the maximum allowed sessions.
495494
*/
496-
session_flags = WT_THREAD_CAN_WAIT | WT_THREAD_HS | WT_THREAD_PANIC_FAIL;
495+
session_flags = WT_THREAD_CAN_WAIT | WT_THREAD_PANIC_FAIL;
497496
WT_RET(__wt_thread_group_create(session, &conn->evict_threads, "eviction-server",
498497
conn->evict_threads_min, conn->evict_threads_max, session_flags, __wt_evict_thread_chk,
499498
__wt_evict_thread_run, __wt_evict_thread_stop));

src/third_party/wiredtiger/src/evict/evict_page.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ __wt_evict(WT_SESSION_IMPL *session, WT_REF *ref, uint8_t previous_state, uint32
9696
WT_PAGE *page;
9797
uint64_t time_start, time_stop;
9898
uint32_t session_flags;
99-
bool clean_page, closing, force_evict_hs, inmem_split, is_owner, local_gen, tree_dead;
99+
bool clean_page, closing, force_evict_hs, inmem_split, local_gen, tree_dead;
100100

101101
conn = S2C(session);
102102
page = ref->page;
@@ -134,8 +134,8 @@ __wt_evict(WT_SESSION_IMPL *session, WT_REF *ref, uint8_t previous_state, uint32
134134
session->hs_cursor == NULL && !F_ISSET(session, WT_SESSION_NO_RECONCILE) &&
135135
session != conn->default_session) {
136136
session_flags = 0; /* [-Werror=maybe-uninitialized] */
137-
WT_RET(__wt_hs_cursor(session, &session_flags, &is_owner));
138-
WT_RET(__wt_hs_cursor_close(session, session_flags, is_owner));
137+
WT_RET(__wt_hs_cursor_open(session, &session_flags));
138+
WT_RET(__wt_hs_cursor_close(session, session_flags));
139139
}
140140

141141
/*

src/third_party/wiredtiger/src/history/hs.c

Lines changed: 23 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -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
*/
214213
int
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
*/
270247
int
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
}
19621913
err:
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);

src/third_party/wiredtiger/src/include/btree.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,21 @@ struct __wt_btree {
203203
*/
204204
uint64_t file_max;
205205

206+
/*
207+
* We maintain a timer for a clean file to avoid excessive checking of checkpoint information that
208+
* incurs a large processing penalty. We avoid that but will periodically incur the cost to clean up
209+
* checkpoints that can be deleted.
210+
*/
211+
#define WT_BTREE_CLEAN_CKPT(session, btree, val) \
212+
do { \
213+
(btree)->clean_ckpt_timer = (val); \
214+
WT_STAT_DATA_SET((session), btree_clean_checkpoint_timer, (val)); \
215+
} while (0)
216+
/* Statistics don't like UINT64_MAX, use INT64_MAX. It's still forever. */
217+
#define WT_BTREE_CLEAN_CKPT_FOREVER INT64_MAX
218+
#define WT_BTREE_CLEAN_MINUTES 10
219+
uint64_t clean_ckpt_timer;
220+
206221
/*
207222
* We flush pages from the tree (in order to make checkpoint faster), without a high-level lock.
208223
* To avoid multiple threads flushing at the same time, lock the tree.

0 commit comments

Comments
 (0)