diff options
author | Tommaso Tocci <tommaso.tocci@mongodb.com> | 2020-10-02 12:11:06 +0200 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2020-10-02 10:59:46 +0000 |
commit | e74a37aa35b12f4151d2faadad0991f31d897065 (patch) | |
tree | 509ed258f746dc8b13825eab2ab723a8b2586419 /src/mongo/db/storage/wiredtiger | |
parent | 49e617b554b2c6c144f29c1f3e97d49e4e1a6944 (diff) | |
download | mongo-e74a37aa35b12f4151d2faadad0991f31d897065.tar.gz |
Revert "SERVER-48771 Enforce constraints on multi timestamp storage transactions"
This reverts commit 0760780e4afa55be377c2a1a47b43e29132478df.
Diffstat (limited to 'src/mongo/db/storage/wiredtiger')
8 files changed, 36 insertions, 298 deletions
diff --git a/src/mongo/db/storage/wiredtiger/SConscript b/src/mongo/db/storage/wiredtiger/SConscript index cf3ca206a42..5d24feec685 100644 --- a/src/mongo/db/storage/wiredtiger/SConscript +++ b/src/mongo/db/storage/wiredtiger/SConscript @@ -41,7 +41,6 @@ if wiredtiger: 'oplog_stones_server_status_section.cpp', 'wiredtiger_begin_transaction_block.cpp', 'wiredtiger_cursor.cpp', - 'wiredtiger_cursor_helpers.cpp', 'wiredtiger_global_options.cpp', 'wiredtiger_index.cpp', 'wiredtiger_kv_engine.cpp', diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_cursor_helpers.cpp b/src/mongo/db/storage/wiredtiger/wiredtiger_cursor_helpers.cpp deleted file mode 100644 index 23aa7e9890e..00000000000 --- a/src/mongo/db/storage/wiredtiger/wiredtiger_cursor_helpers.cpp +++ /dev/null @@ -1,73 +0,0 @@ -/** - * Copyright (C) 2020-present MongoDB, Inc. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the Server Side Public License, version 1, - * as published by MongoDB, Inc. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * Server Side Public License for more details. - * - * You should have received a copy of the Server Side Public License - * along with this program. If not, see - * <http://www.mongodb.com/licensing/server-side-public-license>. - * - * As a special exception, the copyright holders give permission to link the - * code of portions of this program with the OpenSSL library under certain - * conditions as described in each individual source file and distribute - * linked combinations including the program with the OpenSSL library. You - * must comply with the Server Side Public License in all respects for - * all of the code used other than as permitted herein. If you modify file(s) - * with this exception, you may extend this exception to your version of the - * file(s), but you are not obligated to do so. If you do not wish to do so, - * delete this exception statement from your version. If you delete this - * exception statement from all source files in the program, then also delete - * it in the license file. - */ - -#include "mongo/platform/basic.h" - -#include "mongo/db/operation_context.h" -#include "mongo/db/storage/wiredtiger/wiredtiger_cursor_helpers.h" -#include "mongo/db/storage/wiredtiger/wiredtiger_recovery_unit.h" - -namespace mongo { - -int wiredTigerCursorInsert(OperationContext* opCtx, WT_CURSOR* cursor) { - int ret = cursor->insert(cursor); - if (kDebugBuild && MONGO_likely(ret == 0)) { - WiredTigerRecoveryUnit::get(opCtx)->setTxnModified(); - } - return ret; -} - -int wiredTigerCursorModify(OperationContext* opCtx, - WT_CURSOR* cursor, - WT_MODIFY* entries, - int nentries) { - int ret = cursor->modify(cursor, entries, nentries); - if (kDebugBuild && MONGO_likely(ret == 0)) { - WiredTigerRecoveryUnit::get(opCtx)->setTxnModified(); - } - return ret; -} - -int wiredTigerCursorUpdate(OperationContext* opCtx, WT_CURSOR* cursor) { - int ret = cursor->update(cursor); - if (kDebugBuild && MONGO_likely(ret == 0)) { - WiredTigerRecoveryUnit::get(opCtx)->setTxnModified(); - } - return ret; -} - -int wiredTigerCursorRemove(OperationContext* opCtx, WT_CURSOR* cursor) { - int ret = cursor->remove(cursor); - if (kDebugBuild && MONGO_likely(ret == 0)) { - WiredTigerRecoveryUnit::get(opCtx)->setTxnModified(); - } - return ret; -} - -} // namespace mongo diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_cursor_helpers.h b/src/mongo/db/storage/wiredtiger/wiredtiger_cursor_helpers.h deleted file mode 100644 index 97d2d097f73..00000000000 --- a/src/mongo/db/storage/wiredtiger/wiredtiger_cursor_helpers.h +++ /dev/null @@ -1,48 +0,0 @@ -/** - * Copyright (C) 2020-present MongoDB, Inc. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the Server Side Public License, version 1, - * as published by MongoDB, Inc. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * Server Side Public License for more details. - * - * You should have received a copy of the Server Side Public License - * along with this program. If not, see - * <http://www.mongodb.com/licensing/server-side-public-license>. - * - * As a special exception, the copyright holders give permission to link the - * code of portions of this program with the OpenSSL library under certain - * conditions as described in each individual source file and distribute - * linked combinations including the program with the OpenSSL library. You - * must comply with the Server Side Public License in all respects for - * all of the code used other than as permitted herein. If you modify file(s) - * with this exception, you may extend this exception to your version of the - * file(s), but you are not obligated to do so. If you do not wish to do so, - * delete this exception statement from your version. If you delete this - * exception statement from all source files in the program, then also delete - * it in the license file. - */ - -#pragma once - -#include <wiredtiger.h> - -namespace mongo { - -class OperationContext; - -// Helper functions that wrap around their respective WT_CURSOR data modification calls. These are -// used to change the RecoveryUnit's state when a write has been performed on the snapshot. -int wiredTigerCursorInsert(OperationContext* opCtx, WT_CURSOR* cursor); -int wiredTigerCursorModify(OperationContext* opCtx, - WT_CURSOR* cursor, - WT_MODIFY* entries, - int nentries); -int wiredTigerCursorUpdate(OperationContext* opCtx, WT_CURSOR* cursor); -int wiredTigerCursorRemove(OperationContext* opCtx, WT_CURSOR* cursor); - -} // namespace mongo diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_index.cpp b/src/mongo/db/storage/wiredtiger/wiredtiger_index.cpp index 0b0168f5f24..455a1569fe8 100644 --- a/src/mongo/db/storage/wiredtiger/wiredtiger_index.cpp +++ b/src/mongo/db/storage/wiredtiger/wiredtiger_index.cpp @@ -47,7 +47,6 @@ #include "mongo/db/service_context.h" #include "mongo/db/storage/index_entry_comparison.h" #include "mongo/db/storage/storage_options.h" -#include "mongo/db/storage/wiredtiger/wiredtiger_cursor_helpers.h" #include "mongo/db/storage/wiredtiger/wiredtiger_customization_hooks.h" #include "mongo/db/storage/wiredtiger/wiredtiger_global_options.h" #include "mongo/db/storage/wiredtiger/wiredtiger_record_store.h" @@ -660,7 +659,7 @@ public: _cursor->set_value(_cursor, valueItem.Get()); - invariantWTOK(wiredTigerCursorInsert(_opCtx, _cursor)); + invariantWTOK(_cursor->insert(_cursor)); return Status::OK(); } @@ -748,7 +747,7 @@ private: _cursor->set_value(_cursor, valueItem.Get()); - invariantWTOK(wiredTigerCursorInsert(_opCtx, _cursor)); + invariantWTOK(_cursor->insert(_cursor)); // Don't copy the key again if dups are allowed. if (!_dupsAllowed) @@ -812,7 +811,7 @@ private: setKey(_cursor, keyItem.Get()); _cursor->set_value(_cursor, valueItem.Get()); - invariantWTOK(wiredTigerCursorInsert(_opCtx, _cursor)); + invariantWTOK(_cursor->insert(_cursor)); _records.clear(); } @@ -1517,7 +1516,7 @@ Status WiredTigerIndexUnique::_insertTimestampUnsafe(OperationContext* opCtx, WiredTigerItem valueItem(value.getBuffer(), value.getSize()); setKey(c, keyItem.Get()); c->set_value(c, valueItem.Get()); - int ret = WT_OP_CHECK(wiredTigerCursorInsert(opCtx, c)); + int ret = WT_OP_CHECK(c->insert(c)); if (ret != WT_DUPLICATE_KEY) { if (ret == 0) { @@ -1571,7 +1570,7 @@ Status WiredTigerIndexUnique::_insertTimestampUnsafe(OperationContext* opCtx, valueItem = WiredTigerItem(value.getBuffer(), value.getSize()); c->set_value(c, valueItem.Get()); - Status status = wtRCToStatus(wiredTigerCursorUpdate(opCtx, c)); + Status status = wtRCToStatus(c->update(c)); if (!status.isOK()) return status; @@ -1599,7 +1598,7 @@ Status WiredTigerIndexUnique::_insertTimestampSafe(OperationContext* opCtx, // First phase inserts the prefix key to prohibit concurrent insertions of same key setKey(c, prefixKeyItem.Get()); c->set_value(c, emptyItem.Get()); - ret = WT_OP_CHECK(wiredTigerCursorInsert(opCtx, c)); + ret = WT_OP_CHECK(c->insert(c)); // An entry with prefix key already exists. This can happen only during rolling upgrade when // both timestamp unsafe and timestamp safe index format keys could be present. @@ -1618,7 +1617,7 @@ Status WiredTigerIndexUnique::_insertTimestampSafe(OperationContext* opCtx, // transactions, but will not conflict with any transaction that begins after this // operation commits. setKey(c, prefixKeyItem.Get()); - ret = WT_OP_CHECK(wiredTigerCursorRemove(opCtx, c)); + ret = WT_OP_CHECK(c->remove(c)); invariantWTOK(ret); // Second phase looks up for existence of key to avoid insertion of duplicate key @@ -1644,7 +1643,7 @@ Status WiredTigerIndexUnique::_insertTimestampSafe(OperationContext* opCtx, : WiredTigerItem(typeBits.getBuffer(), typeBits.getSize()); setKey(c, keyItem.Get()); c->set_value(c, valueItem.Get()); - ret = WT_OP_CHECK(wiredTigerCursorInsert(opCtx, c)); + ret = WT_OP_CHECK(c->insert(c)); // It is possible that this key is already present during a concurrent background index build. if (ret != WT_DUPLICATE_KEY) @@ -1675,15 +1674,15 @@ void WiredTigerIndexUnique::_unindexTimestampUnsafe(OperationContext* opCtx, WiredTigerItem keyItem(keyString.getBuffer(), sizeWithoutRecordId); setKey(c, keyItem.Get()); - auto triggerWriteConflictAtPoint = [this, opCtx, &keyItem](WT_CURSOR* point) { + auto triggerWriteConflictAtPoint = [this, &keyItem](WT_CURSOR* point) { // WT_NOTFOUND may occur during a background index build. Insert a dummy value and // delete it again to trigger a write conflict in case this is being concurrently // indexed by the background indexer. setKey(point, keyItem.Get()); point->set_value(point, emptyItem.Get()); - invariantWTOK(WT_OP_CHECK(wiredTigerCursorInsert(opCtx, point))); + invariantWTOK(WT_OP_CHECK(point->insert(point))); setKey(point, keyItem.Get()); - invariantWTOK(WT_OP_CHECK(wiredTigerCursorRemove(opCtx, point))); + invariantWTOK(WT_OP_CHECK(point->remove(point))); }; if (!dupsAllowed) { @@ -1707,7 +1706,7 @@ void WiredTigerIndexUnique::_unindexTimestampUnsafe(OperationContext* opCtx, KeyString::TypeBits::fromBuffer(getKeyStringVersion(), &br); fassert(40417, !br.remaining()); } - int ret = WT_OP_CHECK(wiredTigerCursorRemove(opCtx, c)); + int ret = WT_OP_CHECK(c->remove(c)); if (ret == WT_NOTFOUND) { triggerWriteConflictAtPoint(c); return; @@ -1740,7 +1739,7 @@ void WiredTigerIndexUnique::_unindexTimestampUnsafe(OperationContext* opCtx, if (records.empty() && !br.remaining()) { // This is the common case: we are removing the only id for this key. // Remove the whole entry. - invariantWTOK(WT_OP_CHECK(wiredTigerCursorRemove(opCtx, c))); + invariantWTOK(WT_OP_CHECK(c->remove(c))); return; } @@ -1779,7 +1778,7 @@ void WiredTigerIndexUnique::_unindexTimestampUnsafe(OperationContext* opCtx, WiredTigerItem valueItem = WiredTigerItem(newValue.getBuffer(), newValue.getSize()); c->set_value(c, valueItem.Get()); - invariantWTOK(wiredTigerCursorUpdate(opCtx, c)); + invariantWTOK(c->update(c)); } void WiredTigerIndexUnique::_unindexTimestampSafe(OperationContext* opCtx, @@ -1788,7 +1787,7 @@ void WiredTigerIndexUnique::_unindexTimestampSafe(OperationContext* opCtx, bool dupsAllowed) { WiredTigerItem item(keyString.getBuffer(), keyString.getSize()); setKey(c, item.Get()); - int ret = WT_OP_CHECK(wiredTigerCursorRemove(opCtx, c)); + int ret = WT_OP_CHECK(c->remove(c)); if (ret != WT_NOTFOUND) { invariantWTOK(ret); return; @@ -1803,7 +1802,7 @@ void WiredTigerIndexUnique::_unindexTimestampSafe(OperationContext* opCtx, WiredTigerItem keyItem(keyString.getBuffer(), sizeWithoutRecordId); setKey(c, keyItem.Get()); - ret = WT_OP_CHECK(wiredTigerCursorRemove(opCtx, c)); + ret = WT_OP_CHECK(c->remove(c)); if (ret != WT_NOTFOUND) { invariantWTOK(ret); return; @@ -1813,9 +1812,9 @@ void WiredTigerIndexUnique::_unindexTimestampSafe(OperationContext* opCtx, // by the background indexer. setKey(c, item.Get()); c->set_value(c, emptyItem.Get()); - invariantWTOK(WT_OP_CHECK(wiredTigerCursorInsert(opCtx, c))); + invariantWTOK(WT_OP_CHECK(c->insert(c))); setKey(c, item.Get()); - invariantWTOK(WT_OP_CHECK(wiredTigerCursorRemove(opCtx, c))); + invariantWTOK(WT_OP_CHECK(c->remove(c))); } // ------------------------------ @@ -1854,7 +1853,7 @@ Status WiredTigerIndexStandard::_insert(OperationContext* opCtx, setKey(c, keyItem.Get()); c->set_value(c, valueItem.Get()); - int ret = WT_OP_CHECK(wiredTigerCursorInsert(opCtx, c)); + int ret = WT_OP_CHECK(c->insert(c)); // If the record was already in the index, we just return OK. // This can happen, for example, when building a background index while documents are being @@ -1872,7 +1871,7 @@ void WiredTigerIndexStandard::_unindex(OperationContext* opCtx, invariant(dupsAllowed); WiredTigerItem item(keyString.getBuffer(), keyString.getSize()); setKey(c, item.Get()); - int ret = WT_OP_CHECK(wiredTigerCursorRemove(opCtx, c)); + int ret = WT_OP_CHECK(c->remove(c)); if (ret != WT_NOTFOUND) { invariantWTOK(ret); } else { @@ -1881,9 +1880,9 @@ void WiredTigerIndexStandard::_unindex(OperationContext* opCtx, // the background indexer. setKey(c, item.Get()); c->set_value(c, emptyItem.Get()); - invariantWTOK(WT_OP_CHECK(wiredTigerCursorInsert(opCtx, c))); + invariantWTOK(WT_OP_CHECK(c->insert(c))); setKey(c, item.Get()); - invariantWTOK(WT_OP_CHECK(wiredTigerCursorRemove(opCtx, c))); + invariantWTOK(WT_OP_CHECK(c->remove(c))); } } diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_record_store.cpp b/src/mongo/db/storage/wiredtiger/wiredtiger_record_store.cpp index 74e6bdc829b..83c7e0be7ed 100644 --- a/src/mongo/db/storage/wiredtiger/wiredtiger_record_store.cpp +++ b/src/mongo/db/storage/wiredtiger/wiredtiger_record_store.cpp @@ -55,7 +55,6 @@ #include "mongo/db/service_context.h" #include "mongo/db/storage/oplog_hack.h" #include "mongo/db/storage/wiredtiger/oplog_stone_parameters_gen.h" -#include "mongo/db/storage/wiredtiger/wiredtiger_cursor_helpers.h" #include "mongo/db/storage/wiredtiger/wiredtiger_customization_hooks.h" #include "mongo/db/storage/wiredtiger/wiredtiger_global_options.h" #include "mongo/db/storage/wiredtiger/wiredtiger_kv_engine.h" @@ -1055,7 +1054,7 @@ void WiredTigerRecordStore::deleteRecord(OperationContext* opCtx, const RecordId int64_t old_length = old_value.size; - ret = WT_OP_CHECK(wiredTigerCursorRemove(opCtx, c)); + ret = WT_OP_CHECK(c->remove(c)); invariantWTOK(ret); _changeNumRecords(opCtx, -1); @@ -1281,7 +1280,7 @@ int64_t WiredTigerRecordStore::_cappedDeleteAsNeeded_inlock(OperationContext* op if (--toRemove > 0) { firstRecordId = getKey(truncateEnd); } - invariantWTOK(wiredTigerCursorRemove(opCtx, truncateEnd)); + invariantWTOK(truncateEnd->remove(truncateEnd)); } ret = 0; } else { @@ -1496,7 +1495,7 @@ Status WiredTigerRecordStore::_insertRecords(OperationContext* opCtx, setKey(c, record.id); WiredTigerItem value(record.data.data(), record.data.size()); c->set_value(c, value.Get()); - int ret = WT_OP_CHECK(wiredTigerCursorInsert(opCtx, c)); + int ret = WT_OP_CHECK(c->insert(c)); if (ret) return wtRCToStatus(ret, "WiredTigerRecordStore::insertRecord"); } @@ -1628,9 +1627,8 @@ Status WiredTigerRecordStore::updateRecord(OperationContext* opCtx, if ((ret = wiredtiger_calc_modify( c->session, &old_value, value.Get(), kMaxDiffBytes, entries.data(), &nentries)) == 0) { - invariantWTOK(WT_OP_CHECK( - nentries == 0 ? c->reserve(c) - : wiredTigerCursorModify(opCtx, c, entries.data(), nentries))); + invariantWTOK(WT_OP_CHECK(nentries == 0 ? c->reserve(c) + : c->modify(c, entries.data(), nentries))); WT_ITEM new_value; dassert(nentries == 0 || (c->get_value(c, &new_value) == 0 && new_value.size == value.size && @@ -1643,7 +1641,7 @@ Status WiredTigerRecordStore::updateRecord(OperationContext* opCtx, if (!skip_update) { c->set_value(c, value.Get()); - ret = WT_OP_CHECK(wiredTigerCursorInsert(opCtx, c)); + ret = WT_OP_CHECK(c->insert(c)); } invariantWTOK(ret); @@ -1687,7 +1685,7 @@ StatusWith<RecordData> WiredTigerRecordStore::updateWithDamages( if (nentries == 0) invariantWTOK(WT_OP_CHECK(c->search(c))); else - invariantWTOK(WT_OP_CHECK(wiredTigerCursorModify(opCtx, c, entries.data(), nentries))); + invariantWTOK(WT_OP_CHECK(c->modify(c, entries.data(), nentries))); WT_ITEM value; invariantWTOK(c->get_value(c, &value)); diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_recovery_unit.cpp b/src/mongo/db/storage/wiredtiger/wiredtiger_recovery_unit.cpp index 9f06075bf62..55abc6df0e6 100644 --- a/src/mongo/db/storage/wiredtiger/wiredtiger_recovery_unit.cpp +++ b/src/mongo/db/storage/wiredtiger/wiredtiger_recovery_unit.cpp @@ -293,17 +293,6 @@ void WiredTigerRecoveryUnit::assertInActiveTxn() const { "currentState"_attr = _getState()); } -void WiredTigerRecoveryUnit::setTxnModified() { - if (_multiTimestampConstraintTracker.isTxnModified) { - return; - } - - _multiTimestampConstraintTracker.isTxnModified = true; - if (!_lastTimestampSet) { - _multiTimestampConstraintTracker.txnHasNonTimestampedWrite = true; - } -} - boost::optional<int64_t> WiredTigerRecoveryUnit::getOplogVisibilityTs() { if (!_isOplogReader) { return boost::none; @@ -382,23 +371,6 @@ void WiredTigerRecoveryUnit::refreshSnapshot() { void WiredTigerRecoveryUnit::_txnClose(bool commit) { invariant(_isActive(), toString(_getState())); - - if (!_multiTimestampConstraintTracker.ignoreAllMultiTimestampConstraints && - _multiTimestampConstraintTracker.txnHasNonTimestampedWrite && - _multiTimestampConstraintTracker.timestampOrder.size() >= 2) { - // The first write in this transaction was not timestamped. Other writes have used at least - // two different timestamps. This violates the multi timestamp constraint where if a - // transaction sets multiple timestamps, the first timestamp must be set prior to any - // writes. Vice-versa, if a transaction writes a document before setting a timestamp, it - // must not set multiple timestamps. - LOGV2_FATAL( - 4877100, - "Multi timestamp constraint violated. Transactions setting multiple timestamps " - "must set the first timestamp prior to any writes.", - "numTimestampsUsed"_attr = _multiTimestampConstraintTracker.timestampOrder.size(), - "lastSetTimestamp"_attr = _multiTimestampConstraintTracker.timestampOrder.top()); - } - WT_SESSION* s = _session->getSession(); if (_timer) { const int transactionTime = _timer->millis(); @@ -479,7 +451,7 @@ void WiredTigerRecoveryUnit::_txnClose(bool commit) { // transaction on a RecoveryUnit to call setTimestamp() and another to call // setCommitTimestamp(). _lastTimestampSet = boost::none; - _multiTimestampConstraintTracker = MultiTimestampConstraintTracker(); + _prepareTimestamp = Timestamp(); _durableTimestamp = Timestamp(); _catalogConflictTimestamp = Timestamp(); @@ -759,16 +731,6 @@ Timestamp WiredTigerRecoveryUnit::_getTransactionReadTimestamp(WT_SESSION* sessi return Timestamp(read_timestamp); } -void WiredTigerRecoveryUnit::_updateMultiTimestampConstraint(Timestamp timestamp) { - std::stack<Timestamp>& timestampOrder = _multiTimestampConstraintTracker.timestampOrder; - if (!timestampOrder.empty() && timestampOrder.top() == timestamp) { - // We're still on the same timestamp. - return; - } - - timestampOrder.push(timestamp); -} - Status WiredTigerRecoveryUnit::setTimestamp(Timestamp timestamp) { _ensureSession(); LOGV2_DEBUG(22415, @@ -786,7 +748,6 @@ Status WiredTigerRecoveryUnit::setTimestamp(Timestamp timestamp) { << " cannot be older than read timestamp " << _readAtTimestamp.toString()); - _updateMultiTimestampConstraint(timestamp); _lastTimestampSet = timestamp; // Starts the WT transaction associated with this session. diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_recovery_unit.h b/src/mongo/db/storage/wiredtiger/wiredtiger_recovery_unit.h index 3117c3855a5..292ebe8f049 100644 --- a/src/mongo/db/storage/wiredtiger/wiredtiger_recovery_unit.h +++ b/src/mongo/db/storage/wiredtiger/wiredtiger_recovery_unit.h @@ -34,7 +34,6 @@ #include <boost/optional.hpp> #include <cstdint> #include <memory> -#include <stack> #include <vector> #include "mongo/base/checked_cast.h" @@ -171,10 +170,6 @@ public: void refreshSnapshot() override; - void ignoreAllMultiTimestampConstraints() { - _multiTimestampConstraintTracker.ignoreAllMultiTimestampConstraints = true; - } - // ---- WT STUFF WiredTigerSession* getSession(); @@ -207,14 +202,6 @@ public: } void assertInActiveTxn() const; - /** - * This function must be called when a write operation is performed on the active transaction - * for the first time. - * - * Must be reset when the active transaction is either committed or rolled back. - */ - void setTxnModified(); - boost::optional<int64_t> getOplogVisibilityTs(); static WiredTigerRecoveryUnit* get(OperationContext* opCtx) { @@ -259,27 +246,11 @@ private: */ Timestamp _getTransactionReadTimestamp(WT_SESSION* session); - /** - * Keeps track of constraint violations on multi timestamp transactions. If a transaction sets - * multiple timestamps, the first timestamp must be set prior to any writes. Vice-versa, if a - * transaction writes a document before setting a timestamp, it must not set multiple - * timestamps. - */ - void _updateMultiTimestampConstraint(Timestamp timestamp); - WiredTigerSessionCache* _sessionCache; // not owned WiredTigerOplogManager* _oplogManager; // not owned UniqueWiredTigerSession _session; bool _isTimestamped = false; - // Helpers used to keep track of multi timestamp constraint violations on the transaction. - struct MultiTimestampConstraintTracker { - bool isTxnModified = false; - bool txnHasNonTimestampedWrite = false; - bool ignoreAllMultiTimestampConstraints = false; - std::stack<Timestamp> timestampOrder = {}; - } _multiTimestampConstraintTracker; - // Specifies which external source to use when setting read timestamps on transactions. ReadSource _timestampReadSource = ReadSource::kNoTimestamp; diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_recovery_unit_test.cpp b/src/mongo/db/storage/wiredtiger/wiredtiger_recovery_unit_test.cpp index fea22ef5d21..6b07b513177 100644 --- a/src/mongo/db/storage/wiredtiger/wiredtiger_recovery_unit_test.cpp +++ b/src/mongo/db/storage/wiredtiger/wiredtiger_recovery_unit_test.cpp @@ -30,12 +30,10 @@ #include "mongo/db/storage/wiredtiger/wiredtiger_recovery_unit.h" #include "mongo/base/checked_cast.h" -#include "mongo/config.h" #include "mongo/db/repl/repl_settings.h" #include "mongo/db/repl/replication_coordinator_mock.h" #include "mongo/db/service_context.h" #include "mongo/db/storage/recovery_unit_test_harness.h" -#include "mongo/db/storage/wiredtiger/wiredtiger_cursor_helpers.h" #include "mongo/db/storage/wiredtiger/wiredtiger_kv_engine.h" #include "mongo/db/storage/wiredtiger/wiredtiger_record_store.h" #include "mongo/db/storage/wiredtiger/wiredtiger_session_cache.h" @@ -273,7 +271,7 @@ TEST_F(WiredTigerRecoveryUnitTestFixture, getCursor(ru1, &cursor); cursor->set_key(cursor, "key"); cursor->set_value(cursor, "value"); - invariantWTOK(wiredTigerCursorInsert(clientAndCtx1.second.get(), cursor)); + invariantWTOK(cursor->insert(cursor)); ru1->setPrepareTimestamp({1, 1}); ru1->prepareUnitOfWork(); @@ -296,7 +294,7 @@ TEST_F(WiredTigerRecoveryUnitTestFixture, getCursor(ru1, &cursor); cursor->set_key(cursor, "key"); cursor->set_value(cursor, "value"); - invariantWTOK(wiredTigerCursorInsert(clientAndCtx1.second.get(), cursor)); + invariantWTOK(cursor->insert(cursor)); ru1->setPrepareTimestamp({1, 1}); ru1->prepareUnitOfWork(); @@ -320,7 +318,7 @@ TEST_F(WiredTigerRecoveryUnitTestFixture, WriteAllowedWhileIgnorePrepareFalse) { getCursor(ru1, &cursor); cursor->set_key(cursor, "key1"); cursor->set_value(cursor, "value1"); - invariantWTOK(wiredTigerCursorInsert(clientAndCtx1.second.get(), cursor)); + invariantWTOK(cursor->insert(cursor)); ru1->setPrepareTimestamp({1, 1}); ru1->prepareUnitOfWork(); @@ -339,7 +337,7 @@ TEST_F(WiredTigerRecoveryUnitTestFixture, WriteAllowedWhileIgnorePrepareFalse) { cursor->set_value(cursor, "value2"); // The write is allowed. - invariantWTOK(wiredTigerCursorInsert(clientAndCtx2.second.get(), cursor)); + invariantWTOK(cursor->insert(cursor)); ru1->abortUnitOfWork(); ru2->abortUnitOfWork(); @@ -352,7 +350,7 @@ TEST_F(WiredTigerRecoveryUnitTestFixture, WriteOnADocumentBeingPreparedTriggersW getCursor(ru1, &cursor); cursor->set_key(cursor, "key"); cursor->set_value(cursor, "value"); - invariantWTOK(wiredTigerCursorInsert(clientAndCtx1.second.get(), cursor)); + invariantWTOK(cursor->insert(cursor)); ru1->setPrepareTimestamp({1, 1}); ru1->prepareUnitOfWork(); @@ -361,7 +359,7 @@ TEST_F(WiredTigerRecoveryUnitTestFixture, WriteOnADocumentBeingPreparedTriggersW getCursor(ru2, &cursor); cursor->set_key(cursor, "key"); cursor->set_value(cursor, "value2"); - int ret = wiredTigerCursorInsert(clientAndCtx2.second.get(), cursor); + int ret = cursor->insert(cursor); ASSERT_EQ(WT_ROLLBACK, ret); ru1->abortUnitOfWork(); @@ -697,73 +695,6 @@ TEST_F(WiredTigerRecoveryUnitTestFixture, CommitWithoutDurableTimestamp) { } } -TEST_F(WiredTigerRecoveryUnitTestFixture, MultiTimestampConstraintsInternalState) { - Timestamp ts1(1, 1); - Timestamp ts2(2, 2); - - OperationContext* opCtx = clientAndCtx1.second.get(); - ru1->beginUnitOfWork(opCtx); - - // Perform an non timestamped write. - WT_CURSOR* cursor; - getCursor(ru1, &cursor); - cursor->set_key(cursor, "key"); - cursor->set_value(cursor, "value"); - invariantWTOK(wiredTigerCursorInsert(opCtx, cursor)); - - // Perform a write at ts1. - cursor->set_key(cursor, "key2"); - cursor->set_value(cursor, "value"); - ASSERT_OK(ru1->setTimestamp(ts1)); - invariantWTOK(wiredTigerCursorInsert(opCtx, cursor)); - - // Setting the timestamp again to the same value should not fail. - ASSERT_OK(ru1->setTimestamp(ts1)); - - // Committing the unit of work should reset the internal state for the multi timestamp - // constraint checks. - ru1->commitUnitOfWork(); - ru1->beginUnitOfWork(opCtx); - - // Perform a write at ts2. - cursor->set_key(cursor, "key3"); - cursor->set_value(cursor, "value"); - ASSERT_OK(ru1->setTimestamp(ts2)); - invariantWTOK(wiredTigerCursorInsert(opCtx, cursor)); - - ru1->commitUnitOfWork(); -} - -#ifdef MONGO_CONFIG_DEBUG_BUILD -DEATH_TEST_REGEX_F(WiredTigerRecoveryUnitTestFixture, - MultiTimestampConstraints, - "Fatal assertion.*4877100") { - Timestamp ts1(1, 1); - Timestamp ts2(2, 2); - - OperationContext* opCtx = clientAndCtx1.second.get(); - ru1->beginUnitOfWork(opCtx); - - // Perform an non timestamped write. - WT_CURSOR* cursor; - getCursor(ru1, &cursor); - cursor->set_key(cursor, "key"); - cursor->set_value(cursor, "value"); - invariantWTOK(wiredTigerCursorInsert(opCtx, cursor)); - - // Perform a write at ts1. - cursor->set_key(cursor, "key2"); - cursor->set_value(cursor, "value"); - ASSERT_OK(ru1->setTimestamp(ts1)); - invariantWTOK(wiredTigerCursorInsert(opCtx, cursor)); - - // Setting the timestamp again to a different value should detect that we're trying to set - // multiple timestamps with the first write being non timestamped. - ASSERT_OK(ru1->setTimestamp(ts2)); - ru1->commitUnitOfWork(); -} -#endif - DEATH_TEST_F(WiredTigerRecoveryUnitTestFixture, SetDurableTimestampTwice, "Trying to reset durable timestamp when it was already set.") { |