From ac77a440f9df976234c2fe92c6726348e592ca8d Mon Sep 17 00:00:00 2001 From: Jason Chan Date: Mon, 8 Apr 2019 12:55:52 -0400 Subject: SERVER-39793 Update the state in transaction table for running transactions on secondary --- src/mongo/db/repl/sync_tail_test_fixture.cpp | 29 ++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'src/mongo/db/repl/sync_tail_test_fixture.cpp') diff --git a/src/mongo/db/repl/sync_tail_test_fixture.cpp b/src/mongo/db/repl/sync_tail_test_fixture.cpp index 7811b128fc8..9e9b5ed6fab 100644 --- a/src/mongo/db/repl/sync_tail_test_fixture.cpp +++ b/src/mongo/db/repl/sync_tail_test_fixture.cpp @@ -34,6 +34,7 @@ #include "mongo/db/catalog/document_validation.h" #include "mongo/db/curop.h" #include "mongo/db/db_raii.h" +#include "mongo/db/dbdirectclient.h" #include "mongo/db/op_observer_registry.h" #include "mongo/db/repl/drop_pending_collection_reaper.h" #include "mongo/db/repl/replication_consistency_markers_mock.h" @@ -248,6 +249,34 @@ Status SyncTailTest::runOpsInitialSync(std::vector ops) { return Status::OK(); } +void checkTxnTable(OperationContext* opCtx, + const LogicalSessionId& lsid, + const TxnNumber& txnNum, + const repl::OpTime& expectedOpTime, + Date_t expectedWallClock, + boost::optional expectedStartOpTime, + boost::optional expectedState) { + DBDirectClient client(opCtx); + auto result = client.findOne(NamespaceString::kSessionTransactionsTableNamespace.ns(), + {BSON(SessionTxnRecord::kSessionIdFieldName << lsid.toBSON())}); + ASSERT_FALSE(result.isEmpty()); + + auto txnRecord = + SessionTxnRecord::parse(IDLParserErrorContext("parse txn record for test"), result); + + ASSERT_EQ(txnNum, txnRecord.getTxnNum()); + ASSERT_EQ(expectedOpTime, txnRecord.getLastWriteOpTime()); + ASSERT_EQ(expectedWallClock, txnRecord.getLastWriteDate()); + if (expectedStartOpTime) { + ASSERT(txnRecord.getStartOpTime()); + ASSERT_EQ(*expectedStartOpTime, *txnRecord.getStartOpTime()); + } else { + ASSERT(!txnRecord.getStartOpTime()); + } + if (expectedState) { + ASSERT(*expectedState == txnRecord.getState()); + } +} } // namespace repl } // namespace mongo -- cgit v1.2.1