diff options
author | Luke Chen <luke.chen@mongodb.com> | 2023-02-16 15:46:25 +1100 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2023-02-16 05:22:48 +0000 |
commit | 23b3dd8f1a4346905ff7d8181f824d71c715ab65 (patch) | |
tree | cacf83fa0b47c10a06f76eb0b9e66a29f3f2f4de /src | |
parent | eb9bbc53af8813ef7465cc8d1d6b63765576401a (diff) | |
download | mongo-23b3dd8f1a4346905ff7d8181f824d71c715ab65.tar.gz |
Import wiredtiger: 810623549d67393926596e4d6f9c92c02f770125 from branch mongodb-6.0r6.0.5-rc0r6.0.4-rc1
ref: 6d5a0660a2..810623549d
for: 6.0.5
WT-10584 Add missing read barriers in __cursor_skip_prev
Diffstat (limited to 'src')
-rw-r--r-- | src/third_party/wiredtiger/import.data | 2 | ||||
-rw-r--r-- | src/third_party/wiredtiger/src/btree/bt_curprev.c | 31 |
2 files changed, 27 insertions, 6 deletions
diff --git a/src/third_party/wiredtiger/import.data b/src/third_party/wiredtiger/import.data index aeed7bf4371..2dc397ad3de 100644 --- a/src/third_party/wiredtiger/import.data +++ b/src/third_party/wiredtiger/import.data @@ -2,5 +2,5 @@ "vendor": "wiredtiger", "github": "wiredtiger/wiredtiger.git", "branch": "mongodb-6.0", - "commit": "6d5a0660a2fde923e7d40871b7b7ef32c919240a" + "commit": "810623549d67393926596e4d6f9c92c02f770125" } diff --git a/src/third_party/wiredtiger/src/btree/bt_curprev.c b/src/third_party/wiredtiger/src/btree/bt_curprev.c index ce9a49986a7..58ed292d88e 100644 --- a/src/third_party/wiredtiger/src/btree/bt_curprev.c +++ b/src/third_party/wiredtiger/src/btree/bt_curprev.c @@ -34,7 +34,7 @@ static inline int __cursor_skip_prev(WT_CURSOR_BTREE *cbt) { - WT_INSERT *current, *ins; + WT_INSERT *current, *ins, *next_ins; WT_ITEM key; WT_SESSION_IMPL *session; uint64_t recno; @@ -82,7 +82,13 @@ restart: for (; i >= 0; i--) { cbt->ins_stack[i] = NULL; cbt->next_stack[i] = NULL; - ins = cbt->ins_head->head[i]; + /* + * Compiler may replace the usage of the variable with another read in the following + * code. + * + * Place a read barrier to avoid this issue. + */ + WT_ORDERED_READ(ins, cbt->ins_head->head[i]); if (ins != NULL && ins != current) break; } @@ -98,11 +104,26 @@ restart: cbt->next_stack[0] = NULL; goto restart; } - if (ins->next[i] != current) /* Stay at this level */ - ins = ins->next[i]; + /* + * CPU may reorder the read and return a stale value. This can lead us to wrongly skip a + * value in the lower levels of the skip list. + * + * For example, if we have A -> C initially for both level 0 and level 1 and we concurrently + * insert B into both level 0 and level 1. If B is visible on level 1 to this thread, it + * must also be visible on level 0. Otherwise, we would record an inconsistent stack. + * + * Place a read barrier to avoid this issue. + */ + WT_ORDERED_READ(next_ins, ins->next[i]); + if (next_ins != current) /* Stay at this level */ + ins = next_ins; else { /* Drop down a level */ + /* + * It is possible that we read an old value that is inconsistent to the higher levels of + * the skip list due to CPU read reordering. Add a read barrier to avoid this issue. + */ + WT_ORDERED_READ(cbt->next_stack[i], ins->next[i]); cbt->ins_stack[i] = &ins->next[i]; - cbt->next_stack[i] = ins->next[i]; --i; } } |