summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGregory Wlodarek <gregory.wlodarek@mongodb.com>2022-02-01 21:09:29 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2022-02-01 23:18:54 +0000
commit5d4891f796acae59b5126cdee56c99814a0b13b8 (patch)
tree40708133d8c1421f55d4d653db71a19ef142498e
parent8179b894d05ef5eba789205daecc43efde4a32fa (diff)
downloadmongo-5d4891f796acae59b5126cdee56c99814a0b13b8.tar.gz
SERVER-61203 Implement the WiredTiger version cursor in the record store
-rw-r--r--src/mongo/db/storage/devnull/devnull_kv_engine.cpp3
-rw-r--r--src/mongo/db/storage/devnull/ephemeral_catalog_record_store.h2
-rw-r--r--src/mongo/db/storage/ephemeral_for_test/ephemeral_for_test_record_store.h2
-rw-r--r--src/mongo/db/storage/record_store.h5
-rw-r--r--src/mongo/db/storage/wiredtiger/wiredtiger_record_store.cpp66
-rw-r--r--src/mongo/db/storage/wiredtiger/wiredtiger_record_store.h2
6 files changed, 80 insertions, 0 deletions
diff --git a/src/mongo/db/storage/devnull/devnull_kv_engine.cpp b/src/mongo/db/storage/devnull/devnull_kv_engine.cpp
index 0bc5800eb3a..93b2c958d02 100644
--- a/src/mongo/db/storage/devnull/devnull_kv_engine.cpp
+++ b/src/mongo/db/storage/devnull/devnull_kv_engine.cpp
@@ -133,6 +133,9 @@ public:
MONGO_UNREACHABLE;
}
+ virtual void printRecordMetadata(OperationContext* opCtx, const RecordId& recordId) const {
+ MONGO_UNREACHABLE;
+ }
std::unique_ptr<SeekableRecordCursor> getCursor(OperationContext* opCtx,
bool forward) const final {
diff --git a/src/mongo/db/storage/devnull/ephemeral_catalog_record_store.h b/src/mongo/db/storage/devnull/ephemeral_catalog_record_store.h
index 536d4b8d9c8..75855df238e 100644
--- a/src/mongo/db/storage/devnull/ephemeral_catalog_record_store.h
+++ b/src/mongo/db/storage/devnull/ephemeral_catalog_record_store.h
@@ -83,6 +83,8 @@ public:
const char* damageSource,
const mutablebson::DamageVector& damages);
+ virtual void printRecordMetadata(OperationContext* opCtx, const RecordId& recordId) const {}
+
std::unique_ptr<SeekableRecordCursor> getCursor(OperationContext* opCtx,
bool forward) const final;
diff --git a/src/mongo/db/storage/ephemeral_for_test/ephemeral_for_test_record_store.h b/src/mongo/db/storage/ephemeral_for_test/ephemeral_for_test_record_store.h
index 18a438303f5..9bd663661cb 100644
--- a/src/mongo/db/storage/ephemeral_for_test/ephemeral_for_test_record_store.h
+++ b/src/mongo/db/storage/ephemeral_for_test/ephemeral_for_test_record_store.h
@@ -88,6 +88,8 @@ public:
const char* damageSource,
const mutablebson::DamageVector& damages);
+ virtual void printRecordMetadata(OperationContext* opCtx, const RecordId& recordId) const {}
+
std::unique_ptr<SeekableRecordCursor> getCursor(OperationContext* opCtx,
bool forward) const final;
diff --git a/src/mongo/db/storage/record_store.h b/src/mongo/db/storage/record_store.h
index bcae0bf68d0..85b1fa14d2b 100644
--- a/src/mongo/db/storage/record_store.h
+++ b/src/mongo/db/storage/record_store.h
@@ -412,6 +412,11 @@ public:
const mutablebson::DamageVector& damages) = 0;
/**
+ * Prints any storage engine provided metadata for the record with 'recordId'.
+ */
+ virtual void printRecordMetadata(OperationContext* opCtx, const RecordId& recordId) const = 0;
+
+ /**
* Returns a new cursor over this record store.
*
* The cursor is logically positioned before the first (or last if !forward) Record in the
diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_record_store.cpp b/src/mongo/db/storage/wiredtiger/wiredtiger_record_store.cpp
index d3ed7dd9351..d988707fbb3 100644
--- a/src/mongo/db/storage/wiredtiger/wiredtiger_record_store.cpp
+++ b/src/mongo/db/storage/wiredtiger/wiredtiger_record_store.cpp
@@ -1633,6 +1633,72 @@ StatusWith<RecordData> WiredTigerRecordStore::updateWithDamages(
return RecordData(static_cast<const char*>(value.data), value.size).getOwned();
}
+void WiredTigerRecordStore::printRecordMetadata(OperationContext* opCtx,
+ const RecordId& recordId) const {
+ LOGV2(6120300, "Printing record metadata", "recordId"_attr = recordId);
+
+ // Printing the record metadata requires a new session. We cannot open other cursors when there
+ // are open history store cursors in the session.
+ WiredTigerSession session(_kvEngine->getConnection());
+
+ // Per the version cursor API:
+ // - A version cursor can only be called with the read timestamp as the oldest timestamp.
+ // - If there is no oldest timestamp, the version cursor can only be called with a read
+ // timestamp of 1.
+ Timestamp oldestTs = _kvEngine->getOldestTimestamp();
+ const std::string config = "read_timestamp={:x},roundup_timestamps=(read=true)"_format(
+ oldestTs.isNull() ? 1 : oldestTs.asULL());
+ WiredTigerBeginTxnBlock beginTxn(session.getSession(), config.c_str());
+
+ // Open a version cursor. This is a debug cursor that enables iteration through the history of
+ // values for a given record.
+ WT_CURSOR* cursor = session.getNewCursor(_uri, "debug=(dump_version=true)");
+
+ CursorKey key = makeCursorKey(recordId, _keyFormat);
+ setKey(cursor, &key);
+
+ int ret = cursor->search(cursor);
+ while (ret != WT_NOTFOUND) {
+ invariantWTOK(ret);
+
+ uint64_t startTs = 0, startDurableTs = 0, stopTs = 0, stopDurableTs = 0;
+ uint64_t startTxnId = 0, stopTxnId = 0;
+ uint8_t flags = 0, location = 0, prepare = 0, type = 0;
+ WT_ITEM value;
+
+ invariantWTOK(cursor->get_value(cursor,
+ &startTxnId,
+ &startTs,
+ &startDurableTs,
+ &stopTxnId,
+ &stopTs,
+ &stopDurableTs,
+ &type,
+ &prepare,
+ &flags,
+ &location,
+ &value));
+
+ RecordData recordData(static_cast<const char*>(value.data), value.size);
+ LOGV2(6120301,
+ "WiredTiger record metadata",
+ "recordId"_attr = recordId,
+ "startTxnId"_attr = startTxnId,
+ "startTs"_attr = Timestamp(startTs),
+ "startDurableTs"_attr = Timestamp(startDurableTs),
+ "stopTxnId"_attr = stopTxnId,
+ "stopTs"_attr = Timestamp(stopTs),
+ "stopDurableTs"_attr = Timestamp(stopDurableTs),
+ "type"_attr = type,
+ "prepare"_attr = prepare,
+ "flags"_attr = flags,
+ "location"_attr = location,
+ "value"_attr = redact(recordData.toBson()));
+
+ ret = cursor->next(cursor);
+ }
+}
+
std::unique_ptr<RecordCursor> WiredTigerRecordStore::getRandomCursor(
OperationContext* opCtx) const {
return std::make_unique<RandomCursor>(opCtx, *this, "");
diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_record_store.h b/src/mongo/db/storage/wiredtiger/wiredtiger_record_store.h
index 7369138051d..f2ab84e3f67 100644
--- a/src/mongo/db/storage/wiredtiger/wiredtiger_record_store.h
+++ b/src/mongo/db/storage/wiredtiger/wiredtiger_record_store.h
@@ -167,6 +167,8 @@ public:
const char* damageSource,
const mutablebson::DamageVector& damages);
+ virtual void printRecordMetadata(OperationContext* opCtx, const RecordId& recordId) const;
+
virtual std::unique_ptr<SeekableRecordCursor> getCursor(OperationContext* opCtx,
bool forward) const = 0;