summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuke Chen <luke.chen@mongodb.com>2022-02-02 15:00:13 +1100
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2022-02-02 04:51:20 +0000
commit5f19771466dff7642eacbc2dfe4d4bfb1074b8a4 (patch)
treeaf896f5b01d36e188872e56b3da8b2241c73785d
parent82353853c2ab4747d8e64af5e2670b20e863c51c (diff)
downloadmongo-5f19771466dff7642eacbc2dfe4d4bfb1074b8a4.tar.gz
Import wiredtiger: 9e92b73891510149a24567249223e2ccc34abe91 from branch mongodb-master
ref: 5c6e571501..9e92b73891 for: 5.3.0 WT-8711 Block pinned timestamp from moving if there is an open version cursor
-rw-r--r--src/third_party/wiredtiger/examples/c/ex_cursor.c1
-rw-r--r--src/third_party/wiredtiger/import.data2
-rw-r--r--src/third_party/wiredtiger/src/cursor/cur_version.c33
-rw-r--r--src/third_party/wiredtiger/src/include/connection.h11
-rw-r--r--src/third_party/wiredtiger/src/include/txn.h1
-rw-r--r--src/third_party/wiredtiger/src/include/txn_inline.h6
-rw-r--r--src/third_party/wiredtiger/test/suite/test_cursor18.py24
-rw-r--r--src/third_party/wiredtiger/test/suite/test_cursor19.py2
8 files changed, 45 insertions, 35 deletions
diff --git a/src/third_party/wiredtiger/examples/c/ex_cursor.c b/src/third_party/wiredtiger/examples/c/ex_cursor.c
index 5957582ebdf..45381a91956 100644
--- a/src/third_party/wiredtiger/examples/c/ex_cursor.c
+++ b/src/third_party/wiredtiger/examples/c/ex_cursor.c
@@ -229,7 +229,6 @@ main(int argc, char *argv[])
error_check(cursor->close(cursor));
/* Create a version cursor. */
- error_check(session->begin_transaction(session, "read_timestamp=1"));
error_check(
session->open_cursor(session, "file:map.wt", NULL, "debug=(dump_version=true)", &cursor));
error_check(version_cursor_dump(cursor));
diff --git a/src/third_party/wiredtiger/import.data b/src/third_party/wiredtiger/import.data
index 6ced12b78e6..92dec15656a 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-master",
- "commit": "5c6e57150184b77be717446f3184ac32ac42dab9"
+ "commit": "9e92b73891510149a24567249223e2ccc34abe91"
}
diff --git a/src/third_party/wiredtiger/src/cursor/cur_version.c b/src/third_party/wiredtiger/src/cursor/cur_version.c
index 5fe0cff3754..4088a8dec0d 100644
--- a/src/third_party/wiredtiger/src/cursor/cur_version.c
+++ b/src/third_party/wiredtiger/src/cursor/cur_version.c
@@ -478,8 +478,6 @@ __curversion_search(WT_CURSOR *cursor)
WT_ROW *rip;
WT_SESSION_IMPL *session;
WT_TXN *txn;
- WT_TXN_SHARED *txn_shared;
- wt_timestamp_t oldest_ts;
version_cursor = (WT_CURSOR_VERSION *)cursor;
file_cursor = version_cursor->file_cursor;
@@ -487,22 +485,13 @@ __curversion_search(WT_CURSOR *cursor)
CURSOR_API_CALL(cursor, session, search, CUR2BT(cbt));
txn = session->txn;
- txn_shared = WT_SESSION_TXN_SHARED(session);
/*
- * Check that we have the current transaction's read timestamp pinged as the oldest timestamp to
- * ensure that the global visibility will not change during the life of this transaction.
+ * We need to run with snapshot isolation to ensure that the globally visibility does not move.
*/
- WT_ERR_NOTFOUND_OK(
- __wt_txn_get_pinned_timestamp(session, &oldest_ts, WT_TXN_TS_INCLUDE_OLDEST), true);
- if (!F_ISSET(txn, WT_TXN_SHARED_TS_READ) ||
- (ret == 0 && oldest_ts < txn_shared->read_timestamp))
- WT_ERR(__wt_txn_rollback_required(session,
- "version cursor can only be called with the read timestamp as the oldest timestamp"));
- if (ret == WT_NOTFOUND && txn_shared->read_timestamp > 1)
- WT_ERR(__wt_txn_rollback_required(session,
- "version cursor can only be called with read timestamp 1 if there is no oldest "
- "timestamp"));
+ if (txn->isolation != WT_ISO_SNAPSHOT)
+ WT_ERR(__wt_txn_rollback_required(
+ session, "version cursor can only be called with snapshot isolation"));
WT_ERR(__cursor_checkkey(file_cursor));
if (F_ISSET(file_cursor, WT_CURSTD_KEY_INT))
@@ -571,6 +560,7 @@ __curversion_close(WT_CURSOR *cursor)
hs_cursor = version_cursor->hs_cursor;
file_cursor = version_cursor->file_cursor;
CURSOR_API_CALL(cursor, session, close, NULL);
+
err:
version_cursor->next_upd = NULL;
if (file_cursor != NULL) {
@@ -583,6 +573,7 @@ err:
}
__wt_free(session, cursor->value_format);
__wt_cursor_close(cursor);
+ __wt_atomic_sub32(&S2C(session)->version_cursor_count, 1);
API_END_RET(session, ret);
}
@@ -620,12 +611,15 @@ __wt_curversion_open(WT_SESSION_IMPL *session, const char *uri, WT_CURSOR *owner
WT_CURSOR *cursor;
WT_CURSOR_VERSION *version_cursor;
WT_DECL_RET;
+ WT_TXN_GLOBAL *txn_global;
+ wt_timestamp_t pinned_ts;
/* The file cursor is read only. */
const char *file_cursor_cfg[] = {
WT_CONFIG_BASE(session, WT_SESSION_open_cursor), "read_only=true", NULL};
char *version_cursor_value_format;
size_t format_len;
+ txn_global = &S2C(session)->txn_global;
*cursorp = NULL;
WT_RET(__wt_calloc_one(session, &version_cursor));
cursor = (WT_CURSOR *)version_cursor;
@@ -633,6 +627,15 @@ __wt_curversion_open(WT_SESSION_IMPL *session, const char *uri, WT_CURSOR *owner
cursor->session = (WT_SESSION *)session;
version_cursor_value_format = NULL;
+ /* Freeze pinned timestamp when we open the first version cursor. */
+ __wt_writelock(session, &txn_global->rwlock);
+ if (S2C(session)->version_cursor_count == 0) {
+ __wt_txn_pinned_timestamp(session, &pinned_ts);
+ txn_global->version_cursor_pinned_timestamp = pinned_ts;
+ }
+ (void)__wt_atomic_add32(&S2C(session)->version_cursor_count, 1);
+ __wt_writeunlock(session, &txn_global->rwlock);
+
/* Open the file cursor to check the key and value format. */
WT_ERR(__wt_open_cursor(session, uri, NULL, file_cursor_cfg, &version_cursor->file_cursor));
cursor->key_format = version_cursor->file_cursor->key_format;
diff --git a/src/third_party/wiredtiger/src/include/connection.h b/src/third_party/wiredtiger/src/include/connection.h
index f1677f4f70c..f361eb28311 100644
--- a/src/third_party/wiredtiger/src/include/connection.h
+++ b/src/third_party/wiredtiger/src/include/connection.h
@@ -301,11 +301,12 @@ struct __wt_connection_impl {
/* Locked: handles in each bucket */
uint64_t *dh_bucket_count;
- uint64_t dhandle_count; /* Locked: handles in the queue */
- u_int open_btree_count; /* Locked: open writable btree count */
- uint32_t next_file_id; /* Locked: file ID counter */
- uint32_t open_file_count; /* Atomic: open file handle count */
- uint32_t open_cursor_count; /* Atomic: open cursor handle count */
+ uint64_t dhandle_count; /* Locked: handles in the queue */
+ u_int open_btree_count; /* Locked: open writable btree count */
+ uint32_t next_file_id; /* Locked: file ID counter */
+ uint32_t open_file_count; /* Atomic: open file handle count */
+ uint32_t open_cursor_count; /* Atomic: open cursor handle count */
+ uint32_t version_cursor_count; /* Atomic: open version cursor count */
/*
* WiredTiger allocates space for 50 simultaneous sessions (threads of control) by default.
diff --git a/src/third_party/wiredtiger/src/include/txn.h b/src/third_party/wiredtiger/src/include/txn.h
index 127ae0c2835..1370f9c59ff 100644
--- a/src/third_party/wiredtiger/src/include/txn.h
+++ b/src/third_party/wiredtiger/src/include/txn.h
@@ -134,6 +134,7 @@ struct __wt_txn_global {
wt_timestamp_t pinned_timestamp;
wt_timestamp_t recovery_timestamp;
wt_timestamp_t stable_timestamp;
+ wt_timestamp_t version_cursor_pinned_timestamp;
bool has_durable_timestamp;
bool has_oldest_timestamp;
bool has_pinned_timestamp;
diff --git a/src/third_party/wiredtiger/src/include/txn_inline.h b/src/third_party/wiredtiger/src/include/txn_inline.h
index 798818d7dab..68f3a523458 100644
--- a/src/third_party/wiredtiger/src/include/txn_inline.h
+++ b/src/third_party/wiredtiger/src/include/txn_inline.h
@@ -515,6 +515,12 @@ __wt_txn_pinned_timestamp(WT_SESSION_IMPL *session, wt_timestamp_t *pinned_tsp)
if (!txn_global->has_pinned_timestamp)
return;
+ /* If we have a version cursor open, use the pinned timestamp when it is opened. */
+ if (S2C(session)->version_cursor_count > 0) {
+ *pinned_tsp = txn_global->version_cursor_pinned_timestamp;
+ return;
+ }
+
*pinned_tsp = pinned_ts = txn_global->pinned_timestamp;
/*
diff --git a/src/third_party/wiredtiger/test/suite/test_cursor18.py b/src/third_party/wiredtiger/test/suite/test_cursor18.py
index f4f8c73f23f..2eb7028758f 100644
--- a/src/third_party/wiredtiger/test/suite/test_cursor18.py
+++ b/src/third_party/wiredtiger/test/suite/test_cursor18.py
@@ -77,7 +77,7 @@ class test_cursor18(wttest.WiredTigerTestCase):
self.session.commit_transaction("commit_timestamp=" + self.timestamp_str(5))
# Open a version cursor
- self.session.begin_transaction("read_timestamp=" + self.timestamp_str(1))
+ self.session.begin_transaction()
version_cursor = self.session.open_cursor(self.uri, None, "debug=(dump_version=true)")
version_cursor.set_key(1)
self.assertEquals(version_cursor.search(), 0)
@@ -104,7 +104,7 @@ class test_cursor18(wttest.WiredTigerTestCase):
self.session.rollback_transaction()
# Open a version cursor
- self.session.begin_transaction("read_timestamp=" + self.timestamp_str(1))
+ self.session.begin_transaction()
version_cursor = self.session.open_cursor(self.uri, None, "debug=(dump_version=true)")
version_cursor.set_key(1)
self.assertEquals(version_cursor.search(), 0)
@@ -138,7 +138,7 @@ class test_cursor18(wttest.WiredTigerTestCase):
self.session.rollback_transaction()
# Open a version cursor
- self.session.begin_transaction("read_timestamp=" + self.timestamp_str(1))
+ self.session.begin_transaction()
version_cursor = self.session.open_cursor(self.uri, None, "debug=(dump_version=true)")
version_cursor.set_key(1)
self.assertEquals(version_cursor.search(), 0)
@@ -168,7 +168,7 @@ class test_cursor18(wttest.WiredTigerTestCase):
self.session.commit_transaction("commit_timestamp=" + self.timestamp_str(5))
# Open a version cursor
- self.session.begin_transaction("read_timestamp=" + self.timestamp_str(1))
+ self.session.begin_transaction()
version_cursor = self.session.open_cursor(self.uri, None, "debug=(dump_version=true)")
version_cursor.set_key(1)
self.assertEquals(version_cursor.search(), 0)
@@ -197,7 +197,7 @@ class test_cursor18(wttest.WiredTigerTestCase):
self.session.rollback_transaction()
# Open a version cursor
- self.session.begin_transaction("read_timestamp=" + self.timestamp_str(1))
+ self.session.begin_transaction()
version_cursor = self.session.open_cursor(self.uri, None, "debug=(dump_version=true)")
version_cursor.set_key(1)
self.assertEquals(version_cursor.search(), 0)
@@ -234,7 +234,7 @@ class test_cursor18(wttest.WiredTigerTestCase):
self.session.commit_transaction("commit_timestamp=" + self.timestamp_str(10))
# Open a version cursor
- self.session.begin_transaction("read_timestamp=" + self.timestamp_str(1))
+ self.session.begin_transaction()
version_cursor = self.session.open_cursor(self.uri, None, "debug=(dump_version=true)")
version_cursor.set_key(1)
self.assertEquals(version_cursor.search(), 0)
@@ -269,7 +269,7 @@ class test_cursor18(wttest.WiredTigerTestCase):
self.session.commit_transaction("commit_timestamp=" + self.timestamp_str(20))
# Ensure that we are able to correctly traverse all versions of this new key.
- self.session.begin_transaction("read_timestamp=" + self.timestamp_str(1))
+ self.session.begin_transaction()
version_cursor.set_key(2)
self.assertEquals(version_cursor.search(), 0)
self.assertEquals(version_cursor.get_key(), 2)
@@ -304,7 +304,7 @@ class test_cursor18(wttest.WiredTigerTestCase):
self.session.rollback_transaction()
# Open a version cursor
- self.session.begin_transaction("read_timestamp=" + self.timestamp_str(1))
+ self.session.begin_transaction()
version_cursor = self.session.open_cursor(self.uri, None, "debug=(dump_version=true)")
version_cursor.set_key(1)
self.assertEquals(version_cursor.search(), 0)
@@ -331,7 +331,7 @@ class test_cursor18(wttest.WiredTigerTestCase):
self.session.rollback_transaction()
# Open a version cursor
- self.session.begin_transaction("read_timestamp=" + self.timestamp_str(1))
+ self.session.begin_transaction()
version_cursor = self.session.open_cursor(self.uri, None, "debug=(dump_version=true)")
version_cursor.set_key(1)
self.assertEquals(version_cursor.search(), 0)
@@ -372,7 +372,7 @@ class test_cursor18(wttest.WiredTigerTestCase):
session2.prepare_transaction("prepare_timestamp=" + self.timestamp_str(2))
# Open a version cursor
- self.session.begin_transaction("read_timestamp=" + self.timestamp_str(1))
+ self.session.begin_transaction()
version_cursor = self.session.open_cursor(self.uri, None, "debug=(dump_version=true)")
version_cursor.set_key(1)
self.assertEquals(version_cursor.search(), 0)
@@ -390,7 +390,7 @@ class test_cursor18(wttest.WiredTigerTestCase):
self.session.commit_transaction("commit_timestamp=" + self.timestamp_str(1))
# Open a version cursor
- self.session.begin_transaction("read_timestamp=" + self.timestamp_str(1))
+ self.session.begin_transaction()
version_cursor = self.session.open_cursor(self.uri, None, "debug=(dump_version=true)")
version_cursor.set_key(1)
self.assertEquals(version_cursor.search(), 0)
@@ -417,7 +417,7 @@ class test_cursor18(wttest.WiredTigerTestCase):
self.session.commit_transaction("commit_timestamp=" + self.timestamp_str(5))
# Open a version cursor
- self.session.begin_transaction("read_timestamp=" + self.timestamp_str(1))
+ self.session.begin_transaction()
version_cursor = self.session.open_cursor(self.uri, None, "debug=(dump_version=true)")
version_cursor.set_key(1)
self.assertEquals(version_cursor.search(), 0)
diff --git a/src/third_party/wiredtiger/test/suite/test_cursor19.py b/src/third_party/wiredtiger/test/suite/test_cursor19.py
index dd3c0164451..b3d56564ea7 100644
--- a/src/third_party/wiredtiger/test/suite/test_cursor19.py
+++ b/src/third_party/wiredtiger/test/suite/test_cursor19.py
@@ -127,7 +127,7 @@ class test_cursor19(wttest.WiredTigerTestCase):
self.session.commit_transaction("commit_timestamp=" + self.timestamp_str(30))
# Open a version cursor
- self.session.begin_transaction("read_timestamp=" + self.timestamp_str(1))
+ self.session.begin_transaction()
version_cursor = self.session.open_cursor(self.uri, None, "debug=(dump_version=true)")
version_cursor.set_key(1)
self.assertEquals(version_cursor.search(), 0)