Skip to content

Commit b8602c0

Browse files
committed
Import wiredtiger: 19fd4ed45b3a2a8c119b68015113630b0c060e5f from branch mongodb-4.4
ref: c29f4c6030..19fd4ed45b for: 4.3.1 WT-4460 Optimize for in-order, non-overlapping modifications WT-4956 Handle the case where 4 billion updates are made to a page without eviction
1 parent f659b76 commit b8602c0

File tree

17 files changed

+404
-189
lines changed

17 files changed

+404
-189
lines changed

src/third_party/wiredtiger/dist/s_string.ok

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1325,6 +1325,7 @@ unmodify
13251325
unordered
13261326
unpackv
13271327
unpadded
1328+
unreconciled
13281329
unreferenced
13291330
unregister
13301331
unsized

src/third_party/wiredtiger/import.data

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"commit": "c29f4c6030e37794b8c2c1195829ba2d14954677",
2+
"commit": "19fd4ed45b3a2a8c119b68015113630b0c060e5f",
33
"github": "wiredtiger/wiredtiger.git",
44
"vendor": "wiredtiger",
55
"branch": "mongodb-4.4"

src/third_party/wiredtiger/src/btree/bt_cursor.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1506,8 +1506,11 @@ __wt_btcur_modify(WT_CURSOR_BTREE *cbt, WT_MODIFY *entries, int nentries)
15061506
if (!F_ISSET(cursor, WT_CURSTD_KEY_INT) ||
15071507
!F_ISSET(cursor, WT_CURSTD_VALUE_INT))
15081508
WT_ERR(__wt_btcur_search(cbt));
1509+
1510+
WT_ERR(__wt_modify_pack(cursor, &modify, entries, nentries));
1511+
15091512
orig = cursor->value.size;
1510-
WT_ERR(__wt_modify_apply_api(session, cursor, entries, nentries));
1513+
WT_ERR(__wt_modify_apply(cursor, modify->data));
15111514
new = cursor->value.size;
15121515
WT_ERR(__cursor_size_chk(session, &cursor->value));
15131516

@@ -1527,8 +1530,7 @@ __wt_btcur_modify(WT_CURSOR_BTREE *cbt, WT_MODIFY *entries, int nentries)
15271530
F_CLR(cursor, WT_CURSTD_OVERWRITE);
15281531
if (cursor->value.size <= 64 || __cursor_chain_exceeded(cbt))
15291532
ret = __btcur_update(cbt, &cursor->value, WT_UPDATE_STANDARD);
1530-
else if ((ret =
1531-
__wt_modify_pack(session, &modify, entries, nentries)) == 0)
1533+
else
15321534
ret = __btcur_update(cbt, modify, WT_UPDATE_MODIFY);
15331535
if (overwrite)
15341536
F_SET(cursor, WT_CURSTD_OVERWRITE);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -889,7 +889,7 @@ __debug_page_metadata(WT_DBG *ds, WT_REF *ref)
889889
if (split_gen != 0)
890890
WT_RET(ds->f(ds, ", split-gen=%" PRIu64, split_gen));
891891
if (mod != NULL)
892-
WT_RET(ds->f(ds, ", write-gen=%" PRIu32, mod->write_gen));
892+
WT_RET(ds->f(ds, ", page-state=%" PRIu32, mod->page_state));
893893
WT_RET(ds->f(ds,
894894
", memory-size %" WT_SIZET_FMT, page->memory_footprint));
895895
WT_RET(ds->f(ds, "\n"));

src/third_party/wiredtiger/src/btree/bt_ret.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ __wt_value_return_upd(WT_SESSION_IMPL *session,
250250
* updates.
251251
*/
252252
while (i > 0)
253-
WT_ERR(__wt_modify_apply(session, cursor, listp[--i]->data));
253+
WT_ERR(__wt_modify_apply(cursor, listp[--i]->data));
254254

255255
err: if (allocated_bytes != 0)
256256
__wt_free(session, listp);

src/third_party/wiredtiger/src/cursor/cur_std.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -931,7 +931,7 @@ __cursor_modify(WT_CURSOR *cursor, WT_MODIFY *entries, int nentries)
931931

932932
/* Get the current value, apply the modifications. */
933933
WT_ERR(cursor->search(cursor));
934-
WT_ERR(__wt_modify_apply_api(session, cursor, entries, nentries));
934+
WT_ERR(__wt_modify_apply_api(cursor, entries, nentries));
935935

936936
/* We know both key and value are set, "overwrite" doesn't matter. */
937937
ret = cursor->update(cursor);

src/third_party/wiredtiger/src/include/btmem.h

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -489,10 +489,21 @@ struct __wt_page_modify {
489489
WT_SPINLOCK page_lock; /* Page's spinlock */
490490

491491
/*
492-
* The write generation is incremented when a page is modified, a page
493-
* is clean if the write generation is 0.
492+
* The page state is incremented when a page is modified.
493+
*
494+
* WT_PAGE_CLEAN --
495+
* The page is clean.
496+
* WT_PAGE_DIRTY_FIRST --
497+
* The page is in this state after the first operation that marks a
498+
* page dirty, or when reconciliation is checking to see if it has
499+
* done enough work to be able to mark the page clean.
500+
* WT_PAGE_DIRTY --
501+
* Two or more updates have been added to the page.
494502
*/
495-
uint32_t write_gen;
503+
#define WT_PAGE_CLEAN 0
504+
#define WT_PAGE_DIRTY_FIRST 1
505+
#define WT_PAGE_DIRTY 2
506+
uint32_t page_state;
496507

497508
#define WT_PM_REC_EMPTY 1 /* Reconciliation: no replacement */
498509
#define WT_PM_REC_MULTIBLOCK 2 /* Reconciliation: multiple blocks */

src/third_party/wiredtiger/src/include/btree.i

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ __wt_page_is_empty(WT_PAGE *page)
3434
static inline bool
3535
__wt_page_evict_clean(WT_PAGE *page)
3636
{
37-
return (page->modify == NULL || (page->modify->write_gen == 0 &&
37+
return (page->modify == NULL ||
38+
(page->modify->page_state == WT_PAGE_CLEAN &&
3839
page->modify->rec_result == 0));
3940
}
4041

@@ -45,7 +46,8 @@ __wt_page_evict_clean(WT_PAGE *page)
4546
static inline bool
4647
__wt_page_is_modified(WT_PAGE *page)
4748
{
48-
return (page->modify != NULL && page->modify->write_gen != 0);
49+
return (page->modify != NULL &&
50+
page->modify->page_state != WT_PAGE_CLEAN);
4951
}
5052

5153
/*
@@ -496,19 +498,25 @@ __wt_page_only_modify_set(WT_SESSION_IMPL *session, WT_PAGE *page)
496498
WT_ASSERT(session, !F_ISSET(session->dhandle, WT_DHANDLE_DEAD));
497499

498500
last_running = 0;
499-
if (page->modify->write_gen == 0)
501+
if (page->modify->page_state == WT_PAGE_CLEAN)
500502
last_running = S2C(session)->txn_global.last_running;
501503

502504
/*
503-
* We depend on atomic-add being a write barrier, that is, a barrier to
504-
* ensure all changes to the page are flushed before updating the page
505-
* write generation and/or marking the tree dirty, otherwise checkpoints
505+
* We depend on the atomic operation being a write barrier, that is, a
506+
* barrier to ensure all changes to the page are flushed before updating
507+
* the page state and/or marking the tree dirty, otherwise checkpoints
506508
* and/or page reconciliation might be looking at a clean page/tree.
507509
*
508510
* Every time the page transitions from clean to dirty, update the cache
509511
* and transactional information.
512+
*
513+
* The page state can only ever be incremented above dirty by the number
514+
* of concurrently running threads, so the counter will never approach
515+
* the point where it would wrap.
510516
*/
511-
if (__wt_atomic_add32(&page->modify->write_gen, 1) == 1) {
517+
if (page->modify->page_state < WT_PAGE_DIRTY &&
518+
__wt_atomic_add32(&page->modify->page_state, 1) ==
519+
WT_PAGE_DIRTY_FIRST) {
512520
__wt_cache_dirty_incr(session, page);
513521

514522
/*
@@ -579,7 +587,17 @@ __wt_page_modify_clear(WT_SESSION_IMPL *session, WT_PAGE *page)
579587
* Allow the call to be made on clean pages.
580588
*/
581589
if (__wt_page_is_modified(page)) {
582-
page->modify->write_gen = 0;
590+
/*
591+
* The only part where ordering matters is during
592+
* reconciliation where updates on other threads are performing
593+
* writes to the page state that need to be visible to the
594+
* reconciliation thread.
595+
*
596+
* Since clearing of the page state is not going to be happening
597+
* during reconciliation on a separate thread, there's no write
598+
* barrier needed here.
599+
*/
600+
page->modify->page_state = WT_PAGE_CLEAN;
583601
__wt_cache_dirty_decr(session, page);
584602
}
585603
}

src/third_party/wiredtiger/src/include/extern.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -503,9 +503,9 @@ extern int __wt_metadata_search(WT_SESSION_IMPL *session, const char *key, char
503503
extern int __wt_metadata_set_base_write_gen(WT_SESSION_IMPL *session) WT_GCC_FUNC_DECL_ATTRIBUTE((warn_unused_result));
504504
extern int __wt_metadata_turtle_rewrite(WT_SESSION_IMPL *session) WT_GCC_FUNC_DECL_ATTRIBUTE((warn_unused_result));
505505
extern int __wt_metadata_update( WT_SESSION_IMPL *session, const char *key, const char *value) WT_GCC_FUNC_DECL_ATTRIBUTE((warn_unused_result));
506-
extern int __wt_modify_apply( WT_SESSION_IMPL *session, WT_CURSOR *cursor, const void *modify) WT_GCC_FUNC_DECL_ATTRIBUTE((warn_unused_result));
507-
extern int __wt_modify_apply_api(WT_SESSION_IMPL *session, WT_CURSOR *cursor, WT_MODIFY *entries, int nentries) WT_GCC_FUNC_DECL_ATTRIBUTE((visibility("default"))) WT_GCC_FUNC_DECL_ATTRIBUTE((warn_unused_result));
508-
extern int __wt_modify_pack(WT_SESSION_IMPL *session, WT_ITEM **modifyp, WT_MODIFY *entries, int nentries) WT_GCC_FUNC_DECL_ATTRIBUTE((warn_unused_result));
506+
extern int __wt_modify_apply(WT_CURSOR *cursor, const void *modify) WT_GCC_FUNC_DECL_ATTRIBUTE((warn_unused_result));
507+
extern int __wt_modify_apply_api(WT_CURSOR *cursor, WT_MODIFY *entries, int nentries) WT_GCC_FUNC_DECL_ATTRIBUTE((visibility("default"))) WT_GCC_FUNC_DECL_ATTRIBUTE((warn_unused_result));
508+
extern int __wt_modify_pack(WT_CURSOR *cursor, WT_ITEM **modifyp, WT_MODIFY *entries, int nentries) WT_GCC_FUNC_DECL_ATTRIBUTE((warn_unused_result));
509509
extern int __wt_msg(WT_SESSION_IMPL *session, const char *fmt, ...) WT_GCC_FUNC_DECL_ATTRIBUTE((cold)) WT_GCC_FUNC_DECL_ATTRIBUTE((format (printf, 2, 3))) WT_GCC_FUNC_DECL_ATTRIBUTE((warn_unused_result));
510510
extern int __wt_multi_to_ref(WT_SESSION_IMPL *session, WT_PAGE *page, WT_MULTI *multi, WT_REF **refp, size_t *incrp, bool closing) WT_GCC_FUNC_DECL_ATTRIBUTE((warn_unused_result));
511511
extern int __wt_name_check(WT_SESSION_IMPL *session, const char *str, size_t len) WT_GCC_FUNC_DECL_ATTRIBUTE((warn_unused_result));

src/third_party/wiredtiger/src/include/reconcile.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,6 @@ struct __wt_reconcile {
1919
WT_PAGE *page;
2020
uint32_t flags; /* Caller's configuration */
2121

22-
/*
23-
* Track start/stop write generation to decide if all changes to the
24-
* page are written.
25-
*/
26-
uint32_t orig_write_gen;
27-
2822
/*
2923
* Track start/stop checkpoint generations to decide if lookaside table
3024
* records are correct.

0 commit comments

Comments
 (0)