diff options
author | Randolph Tan <randolph@10gen.com> | 2019-02-04 11:39:22 -0500 |
---|---|---|
committer | Randolph Tan <randolph@10gen.com> | 2019-02-07 10:32:42 -0500 |
commit | 1ae75d69fddc6ee9d5cc4f9df8b7732337555469 (patch) | |
tree | f2dc6cb49ad7f2dc6da5285a0023c0c40de243c2 /src/mongo/db | |
parent | cacfd57510ea8b14ef9c6c210f572779ccbe7973 (diff) | |
download | mongo-1ae75d69fddc6ee9d5cc4f9df8b7732337555469.tar.gz |
SERVER-38844 SessionMigrationSource should explicitly ignore config.transactions entry meant for transactions
Diffstat (limited to 'src/mongo/db')
-rw-r--r-- | src/mongo/db/s/session_catalog_migration_source.cpp | 3 | ||||
-rw-r--r-- | src/mongo/db/s/session_catalog_migration_source_test.cpp | 42 |
2 files changed, 44 insertions, 1 deletions
diff --git a/src/mongo/db/s/session_catalog_migration_source.cpp b/src/mongo/db/s/session_catalog_migration_source.cpp index 1bb745083ff..54f2450fd4b 100644 --- a/src/mongo/db/s/session_catalog_migration_source.cpp +++ b/src/mongo/db/s/session_catalog_migration_source.cpp @@ -124,9 +124,10 @@ repl::OplogEntry makeSentinelOplogEntry(OperationSessionInfo sessionInfo, Date_t SessionCatalogMigrationSource::SessionCatalogMigrationSource(OperationContext* opCtx, NamespaceString ns) : _ns(std::move(ns)), _rollbackIdAtInit(repl::ReplicationProcess::get(opCtx)->getRollbackID()) { + // Exclude entries for transaction. + Query query(BSON(SessionTxnRecord::kStateFieldName << BSON("$exists" << false))); // Sort is not needed for correctness. This is just for making it easier to write deterministic // tests. - Query query; query.sort(BSON("_id" << 1)); DBDirectClient client(opCtx); diff --git a/src/mongo/db/s/session_catalog_migration_source_test.cpp b/src/mongo/db/s/session_catalog_migration_source_test.cpp index 07e5adb86b7..2aeb3c5d843 100644 --- a/src/mongo/db/s/session_catalog_migration_source_test.cpp +++ b/src/mongo/db/s/session_catalog_migration_source_test.cpp @@ -651,5 +651,47 @@ TEST_F(SessionCatalogMigrationSourceTest, ShouldAssertWhenRollbackDetected) { ASSERT_TRUE(migrationSource.hasMoreOplog()); } +TEST_F(SessionCatalogMigrationSourceTest, TransactionEntriesShouldBeIgnored) { + auto insertOplog = makeOplogEntry( + repl::OpTime(Timestamp(52, 345), 2), // optime + repl::OpTypeEnum::kInsert, // op type + BSON("x" << 30), // o + boost::none, // o2 + Date_t::now(), // wall clock time + 0, // statement id + repl::OpTime(Timestamp(0, 0), 0)); // optime of previous write within same transaction + + SessionTxnRecord retryableWriteRecord; + retryableWriteRecord.setSessionId(makeLogicalSessionIdForTest()); + retryableWriteRecord.setTxnNum(1); + retryableWriteRecord.setLastWriteOpTime(insertOplog.getOpTime()); + retryableWriteRecord.setLastWriteDate(*insertOplog.getWallClockTime()); + + DBDirectClient client(opCtx()); + client.insert(NamespaceString::kSessionTransactionsTableNamespace.ns(), + retryableWriteRecord.toBSON()); + + SessionTxnRecord txnRecord; + txnRecord.setSessionId(makeLogicalSessionIdForTest()); + txnRecord.setTxnNum(20); + txnRecord.setLastWriteOpTime(repl::OpTime(Timestamp(12, 34), 5)); + txnRecord.setLastWriteDate(Date_t::now()); + txnRecord.setState(DurableTxnStateEnum::kCommitted); + + client.insert(NamespaceString::kSessionTransactionsTableNamespace.ns(), txnRecord.toBSON()); + + insertOplogEntry(insertOplog); + + SessionCatalogMigrationSource migrationSource(opCtx(), kNs); + ASSERT_TRUE(migrationSource.fetchNextOplog(opCtx())); + + ASSERT_TRUE(migrationSource.hasMoreOplog()); + auto nextOplogResult = migrationSource.getLastFetchedOplog(); + ASSERT_FALSE(nextOplogResult.shouldWaitForMajority); + // Cannot compare directly because of SERVER-31356 + ASSERT_BSONOBJ_EQ(insertOplog.toBSON(), nextOplogResult.oplog->toBSON()); + ASSERT_FALSE(migrationSource.fetchNextOplog(opCtx())); +} + } // namespace } // namespace mongo |