diff options
Diffstat (limited to 'src/mongo/db/storage')
10 files changed, 39 insertions, 48 deletions
diff --git a/src/mongo/db/storage/recovery_unit.h b/src/mongo/db/storage/recovery_unit.h index 6ac1a4375c6..fed9d478540 100644 --- a/src/mongo/db/storage/recovery_unit.h +++ b/src/mongo/db/storage/recovery_unit.h @@ -409,6 +409,12 @@ public: return {}; } + /** + * MongoDB must update documents with non-decreasing timestamp values. A storage engine is + * allowed to assert when this contract is violated. An untimestamped write is a subset of these + * violations, which may be necessary in limited circumstances. This API can be called before a + * transaction begins to suppress this subset of errors. + */ virtual void allowUntimestampedWrite() {} /** diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_begin_transaction_block.cpp b/src/mongo/db/storage/wiredtiger/wiredtiger_begin_transaction_block.cpp index e91b228505a..abb0617c124 100644 --- a/src/mongo/db/storage/wiredtiger/wiredtiger_begin_transaction_block.cpp +++ b/src/mongo/db/storage/wiredtiger/wiredtiger_begin_transaction_block.cpp @@ -49,7 +49,7 @@ WiredTigerBeginTxnBlock::WiredTigerBeginTxnBlock( PrepareConflictBehavior prepareConflictBehavior, RoundUpPreparedTimestamps roundUpPreparedTimestamps, RoundUpReadTimestamp roundUpReadTimestamp, - bool allowUntimestampedWrite) + UntimestampedWriteAssertion allowUntimestampedWrite) : _session(session) { invariant(!_rollback); @@ -70,7 +70,7 @@ WiredTigerBeginTxnBlock::WiredTigerBeginTxnBlock( } builder << "),"; } - if (allowUntimestampedWrite) { + if (allowUntimestampedWrite == UntimestampedWriteAssertion::kSuppress) { builder << "no_timestamp=true,"; } diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_begin_transaction_block.h b/src/mongo/db/storage/wiredtiger/wiredtiger_begin_transaction_block.h index ed9b7789be0..4faf831727e 100644 --- a/src/mongo/db/storage/wiredtiger/wiredtiger_begin_transaction_block.h +++ b/src/mongo/db/storage/wiredtiger/wiredtiger_begin_transaction_block.h @@ -58,12 +58,13 @@ public: // earlier. enum class RoundUpPreparedTimestamps { kNoRound, kRound }; - WiredTigerBeginTxnBlock( - WT_SESSION* session, - PrepareConflictBehavior prepareConflictBehavior, - RoundUpPreparedTimestamps roundUpPreparedTimestamps, - RoundUpReadTimestamp roundUpReadTimestamp, - bool allowUntimestampedWrite); + enum class UntimestampedWriteAssertion { kSuppress, kEnforce }; + + WiredTigerBeginTxnBlock(WT_SESSION* session, + PrepareConflictBehavior prepareConflictBehavior, + RoundUpPreparedTimestamps roundUpPreparedTimestamps, + RoundUpReadTimestamp roundUpReadTimestamp, + UntimestampedWriteAssertion allowUntimestampedWrite); WiredTigerBeginTxnBlock(WT_SESSION* session, const char* config); ~WiredTigerBeginTxnBlock(); diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_begin_transaction_block_bm.cpp b/src/mongo/db/storage/wiredtiger/wiredtiger_begin_transaction_block_bm.cpp index 7033ff3931a..3557b8d29fa 100644 --- a/src/mongo/db/storage/wiredtiger/wiredtiger_begin_transaction_block_bm.cpp +++ b/src/mongo/db/storage/wiredtiger/wiredtiger_begin_transaction_block_bm.cpp @@ -127,13 +127,13 @@ using mongo::WiredTigerBeginTxnBlock; template <PrepareConflictBehavior behavior, RoundUpPreparedTimestamps round> void BM_WiredTigerBeginTxnBlockWithArgs(benchmark::State& state) { WiredTigerTestHelper helper; - const bool allowUntimestampedWrite = false; for (auto _ : state) { - WiredTigerBeginTxnBlock beginTxn(helper.wtSession(), - behavior, - round, - RoundUpReadTimestamp::kNoRoundError, - allowUntimestampedWrite); + WiredTigerBeginTxnBlock beginTxn( + helper.wtSession(), + behavior, + round, + RoundUpReadTimestamp::kNoRoundError, + WiredTigerBeginTxnBlock::UntimestampedWriteAssertion::kEnforce); } } diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_index.cpp b/src/mongo/db/storage/wiredtiger/wiredtiger_index.cpp index 5714609a722..df275526c30 100644 --- a/src/mongo/db/storage/wiredtiger/wiredtiger_index.cpp +++ b/src/mongo/db/storage/wiredtiger/wiredtiger_index.cpp @@ -162,12 +162,7 @@ StatusWith<std::string> WiredTigerIndex::generateCreateString( ss << "prefix_compression=true,"; } - if ( // TODO (SERVER-60753): Remove special handling for index build during recovery. - collectionNamespace.ns() == "config.system.indexBuilds") { - ss << "write_timestamp_usage=mixed_mode,"; - } else { - ss << "write_timestamp_usage=ordered,"; - } + // Report errors on writes without ordered timestamps. ss << "assert=(write_timestamp=on),"; ss << "verbose=[write_timestamp],"; diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_record_store.cpp b/src/mongo/db/storage/wiredtiger/wiredtiger_record_store.cpp index 5481f840590..e05ae7ae795 100644 --- a/src/mongo/db/storage/wiredtiger/wiredtiger_record_store.cpp +++ b/src/mongo/db/storage/wiredtiger/wiredtiger_record_store.cpp @@ -796,20 +796,7 @@ StatusWith<std::string> WiredTigerRecordStore::generateCreateString( ss << "split_pct=90,"; ss << "leaf_value_max=64MB,"; - if (nss.isOplog()) { - // For the above clauses we do not assert any particular `write_timestamp_usage`. In - // particular for the oplog, WT removes all timestamp information. There's nothing in - // MDB's control to assert against. - } else if ( - // Side table drains are not timestamped. - ident.startsWith("internal-") || - // TODO (SERVER-60753): Remove special handling for index build during recovery. This - // includes the following _mdb_catalog ident. - nss == NamespaceString::kIndexBuildEntryNamespace || ident.startsWith("_mdb_catalog")) { - ss << "write_timestamp_usage=mixed_mode,"; - } else { - ss << "write_timestamp_usage=ordered,"; - } + // Report errors on writes without ordered timestamps. ss << "assert=(write_timestamp=on),"; ss << "verbose=[write_timestamp],"; diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_recovery_unit.cpp b/src/mongo/db/storage/wiredtiger/wiredtiger_recovery_unit.cpp index 4d93dbd3c17..e121856c916 100644 --- a/src/mongo/db/storage/wiredtiger/wiredtiger_recovery_unit.cpp +++ b/src/mongo/db/storage/wiredtiger/wiredtiger_recovery_unit.cpp @@ -520,7 +520,7 @@ void WiredTigerRecoveryUnit::_txnClose(bool commit) { _isOplogReader = false; _oplogVisibleTs = boost::none; _orderedCommit = true; // Default value is true; we assume all writes are ordered. - _allowUntimestampedWrite = false; + _untimestampedWriteAssertion = WiredTigerBeginTxnBlock::UntimestampedWriteAssertion::kEnforce; } Status WiredTigerRecoveryUnit::majorityCommittedSnapshotAvailable() const { @@ -611,7 +611,7 @@ void WiredTigerRecoveryUnit::_txnOpen() { _prepareConflictBehavior, _roundUpPreparedTimestamps, RoundUpReadTimestamp::kNoRoundError, - _allowUntimestampedWrite) + _untimestampedWriteAssertion) .done(); break; } @@ -620,7 +620,7 @@ void WiredTigerRecoveryUnit::_txnOpen() { session, _prepareConflictBehavior, _roundUpPreparedTimestamps, - _allowUntimestampedWrite); + _untimestampedWriteAssertion); break; } case ReadSource::kLastApplied: { @@ -643,7 +643,7 @@ void WiredTigerRecoveryUnit::_txnOpen() { _prepareConflictBehavior, _roundUpPreparedTimestamps, RoundUpReadTimestamp::kNoRoundError, - _allowUntimestampedWrite); + _untimestampedWriteAssertion); auto status = txnOpen.setReadSnapshot(_readAtTimestamp); if (!status.isOK() && status.code() == ErrorCodes::BadValue) { @@ -672,7 +672,7 @@ Timestamp WiredTigerRecoveryUnit::_beginTransactionAtAllDurableTimestamp(WT_SESS _prepareConflictBehavior, _roundUpPreparedTimestamps, RoundUpReadTimestamp::kRound, - _allowUntimestampedWrite); + _untimestampedWriteAssertion); Timestamp txnTimestamp = _sessionCache->getKVEngine()->getAllDurableTimestamp(); auto status = txnOpen.setReadSnapshot(txnTimestamp); fassert(50948, status); @@ -700,7 +700,7 @@ void WiredTigerRecoveryUnit::_beginTransactionAtLastAppliedTimestamp(WT_SESSION* _prepareConflictBehavior, _roundUpPreparedTimestamps, RoundUpReadTimestamp::kNoRoundError, - _allowUntimestampedWrite); + _untimestampedWriteAssertion); LOGV2_DEBUG(4847500, 2, "no read timestamp available for kLastApplied"); txnOpen.done(); return; @@ -710,7 +710,7 @@ void WiredTigerRecoveryUnit::_beginTransactionAtLastAppliedTimestamp(WT_SESSION* _prepareConflictBehavior, _roundUpPreparedTimestamps, RoundUpReadTimestamp::kRound, - _allowUntimestampedWrite); + _untimestampedWriteAssertion); auto status = txnOpen.setReadSnapshot(_readAtTimestamp); fassert(4847501, status); @@ -766,7 +766,7 @@ Timestamp WiredTigerRecoveryUnit::_beginTransactionAtNoOverlapTimestamp(WT_SESSI _prepareConflictBehavior, _roundUpPreparedTimestamps, RoundUpReadTimestamp::kNoRoundError, - _allowUntimestampedWrite); + _untimestampedWriteAssertion); LOGV2_DEBUG(4452900, 1, "no read timestamp available for kNoOverlap"); txnOpen.done(); return readTimestamp; @@ -776,7 +776,7 @@ Timestamp WiredTigerRecoveryUnit::_beginTransactionAtNoOverlapTimestamp(WT_SESSI _prepareConflictBehavior, _roundUpPreparedTimestamps, RoundUpReadTimestamp::kRound, - _allowUntimestampedWrite); + _untimestampedWriteAssertion); auto status = txnOpen.setReadSnapshot(readTimestamp); fassert(51066, status); diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_recovery_unit.h b/src/mongo/db/storage/wiredtiger/wiredtiger_recovery_unit.h index c16a6ce9b29..5397b91fb91 100644 --- a/src/mongo/db/storage/wiredtiger/wiredtiger_recovery_unit.h +++ b/src/mongo/db/storage/wiredtiger/wiredtiger_recovery_unit.h @@ -150,7 +150,8 @@ public: void allowUntimestampedWrite() override { invariant(!_isActive()); - _allowUntimestampedWrite = true; + _untimestampedWriteAssertion = + WiredTigerBeginTxnBlock::UntimestampedWriteAssertion::kSuppress; } void setTimestampReadSource(ReadSource source, @@ -316,7 +317,8 @@ private: boost::optional<Timestamp> _lastTimestampSet; Timestamp _readAtTimestamp; Timestamp _catalogConflictTimestamp; - bool _allowUntimestampedWrite = false; + WiredTigerBeginTxnBlock::UntimestampedWriteAssertion _untimestampedWriteAssertion = + WiredTigerBeginTxnBlock::UntimestampedWriteAssertion::kEnforce; std::unique_ptr<Timer> _timer; bool _isOplogReader = false; boost::optional<int64_t> _oplogVisibleTs = boost::none; diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_snapshot_manager.cpp b/src/mongo/db/storage/wiredtiger/wiredtiger_snapshot_manager.cpp index 2e093d59ea1..819e19992ca 100644 --- a/src/mongo/db/storage/wiredtiger/wiredtiger_snapshot_manager.cpp +++ b/src/mongo/db/storage/wiredtiger/wiredtiger_snapshot_manager.cpp @@ -84,7 +84,7 @@ Timestamp WiredTigerSnapshotManager::beginTransactionOnCommittedSnapshot( WT_SESSION* session, PrepareConflictBehavior prepareConflictBehavior, RoundUpPreparedTimestamps roundUpPreparedTimestamps, - bool allowUntimestampedWrite) const { + WiredTigerBeginTxnBlock::UntimestampedWriteAssertion untimestampedWriteAssertion) const { auto committedSnapshot = [this]() { stdx::lock_guard<Latch> lock(_committedSnapshotMutex); @@ -104,7 +104,7 @@ Timestamp WiredTigerSnapshotManager::beginTransactionOnCommittedSnapshot( prepareConflictBehavior, roundUpPreparedTimestamps, RoundUpReadTimestamp::kRound, - allowUntimestampedWrite); + untimestampedWriteAssertion); auto status = txnOpen.setReadSnapshot(committedSnapshot); fassert(30635, status); diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_snapshot_manager.h b/src/mongo/db/storage/wiredtiger/wiredtiger_snapshot_manager.h index 088bf7a50f9..b3cf9b4d030 100644 --- a/src/mongo/db/storage/wiredtiger/wiredtiger_snapshot_manager.h +++ b/src/mongo/db/storage/wiredtiger/wiredtiger_snapshot_manager.h @@ -68,7 +68,7 @@ public: WT_SESSION* session, PrepareConflictBehavior prepareConflictBehavior, RoundUpPreparedTimestamps roundUpPreparedTimestamps, - bool allowUntimestampedWrite) const; + WiredTigerBeginTxnBlock::UntimestampedWriteAssertion untimestampedWriteAssertion) const; /** * Returns lowest SnapshotName that could possibly be used by a future call to |