Skip to content

Commit a351f48

Browse files
committed
SERVER-41469 Enforce w:1 for creation of transactions table on step-up
1 parent b173534 commit a351f48

8 files changed

+36
-30
lines changed

src/mongo/db/SConscript

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1793,6 +1793,7 @@ envWithAsio.CppUnitTest(
17931793
'repl/mock_repl_coord_server_fixture',
17941794
'repl/oplog_interface_local',
17951795
'repl/repl_coordinator_interface',
1796+
'repl/storage_interface_impl',
17961797
'repl/replmocks',
17971798
'server_options_servers',
17981799
'service_context',

src/mongo/db/op_observer_impl_test.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
#include "mongo/db/repl/oplog_interface_local.h"
4343
#include "mongo/db/repl/repl_client_info.h"
4444
#include "mongo/db/repl/replication_coordinator_mock.h"
45-
#include "mongo/db/repl/storage_interface_mock.h"
45+
#include "mongo/db/repl/storage_interface_impl.h"
4646
#include "mongo/db/service_context_d_test_fixture.h"
4747
#include "mongo/db/session_catalog_mongod.h"
4848
#include "mongo/db/storage/ephemeral_for_test/ephemeral_for_test_recovery_unit.h"
@@ -65,7 +65,8 @@ class OpObserverTest : public ServiceContextMongoDTest {
6565

6666
auto service = getServiceContext();
6767
auto opCtx = cc().makeOperationContext();
68-
repl::StorageInterface::set(service, std::make_unique<repl::StorageInterfaceMock>());
68+
// onStepUp() relies on the storage interface to create the config.transactions table.
69+
repl::StorageInterface::set(service, std::make_unique<repl::StorageInterfaceImpl>());
6970

7071
// Set up ReplicationCoordinator and create oplog.
7172
repl::ReplicationCoordinator::set(

src/mongo/db/repl/do_txn_test.cpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@
4141
#include "mongo/db/repl/repl_client_info.h"
4242
#include "mongo/db/repl/replication_coordinator_mock.h"
4343
#include "mongo/db/repl/storage_interface_impl.h"
44-
#include "mongo/db/repl/storage_interface_mock.h"
4544
#include "mongo/db/s/op_observer_sharding_impl.h"
4645
#include "mongo/db/service_context_d_test_fixture.h"
4746
#include "mongo/db/session_catalog_mongod.h"
@@ -156,6 +155,9 @@ void DoTxnTest::setUp() {
156155
auto replCoord = ReplicationCoordinator::get(_opCtx.get());
157156
ASSERT_OK(replCoord->setFollowerMode(MemberState::RS_PRIMARY));
158157

158+
// onStepUp() relies on the storage interface to create the config.transactions table.
159+
repl::StorageInterface::set(service, std::make_unique<StorageInterfaceImpl>());
160+
159161
// Set up session catalog
160162
MongoDSessionCatalog::onStepUp(_opCtx.get());
161163

@@ -173,11 +175,6 @@ void DoTxnTest::setUp() {
173175
// collections.
174176
_storage = std::make_unique<StorageInterfaceImpl>();
175177

176-
// We also need to give replication a StorageInterface for checking out the transaction.
177-
// The test storage engine doesn't support the necessary call (getPointInTimeReadTimestamp()),
178-
// so we use a mock.
179-
repl::StorageInterface::set(service, std::make_unique<StorageInterfaceMock>());
180-
181178
// Set up the transaction and session.
182179
_opCtx->setLogicalSessionId(makeLogicalSessionIdForTest());
183180
_opCtx->setTxnNumber(0); // TxnNumber can always be 0 because we have a new session.

src/mongo/db/s/SConscript

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,7 @@ env.CppUnitTest(
384384
'$BUILD_DIR/mongo/db/ops/write_ops_exec',
385385
'$BUILD_DIR/mongo/db/query/query_request',
386386
'$BUILD_DIR/mongo/db/repl/mock_repl_coord_server_fixture',
387+
'$BUILD_DIR/mongo/db/repl/storage_interface_impl',
387388
'$BUILD_DIR/mongo/s/catalog/dist_lock_manager_mock',
388389
'$BUILD_DIR/mongo/s/catalog/sharding_catalog_client_impl',
389390
'$BUILD_DIR/mongo/s/catalog/sharding_catalog_client_mock',

src/mongo/db/s/session_catalog_migration_destination_test.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
#include "mongo/db/ops/write_ops_exec.h"
4343
#include "mongo/db/ops/write_ops_gen.h"
4444
#include "mongo/db/repl/oplog_entry.h"
45+
#include "mongo/db/repl/storage_interface_impl.h"
4546
#include "mongo/db/s/migration_session_id.h"
4647
#include "mongo/db/s/session_catalog_migration_destination.h"
4748
#include "mongo/db/server_options.h"
@@ -131,7 +132,9 @@ class SessionCatalogMigrationDestinationTest : public ShardServerTestFixture {
131132
RemoteCommandTargeterMock::get(donorShard->getTargeter())
132133
->setFindHostReturnValue(kDonorConnStr.getServers()[0]);
133134
}
134-
135+
// onStepUp() relies on the storage interface to create the config.transactions table.
136+
repl::StorageInterface::set(getServiceContext(),
137+
std::make_unique<repl::StorageInterfaceImpl>());
135138
MongoDSessionCatalog::onStepUp(operationContext());
136139
LogicalSessionCache::set(getServiceContext(), std::make_unique<LogicalSessionCacheNoop>());
137140
}

src/mongo/db/session_catalog_mongod.cpp

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
#include "mongo/db/namespace_string.h"
4242
#include "mongo/db/operation_context.h"
4343
#include "mongo/db/ops/write_ops.h"
44+
#include "mongo/db/repl/storage_interface_impl.h"
4445
#include "mongo/db/service_context.h"
4546
#include "mongo/db/session_txn_record_gen.h"
4647
#include "mongo/db/sessions_collection.h"
@@ -175,23 +176,11 @@ int removeSessionsTransactionRecords(OperationContext* opCtx,
175176
}
176177

177178
void createTransactionTable(OperationContext* opCtx) {
178-
const size_t initialExtentSize = 0;
179-
const bool capped = false;
180-
const bool maxSize = 0;
181-
BSONObj result;
182-
183-
DBDirectClient client(opCtx);
184-
185-
if (client.createCollection(NamespaceString::kSessionTransactionsTableNamespace.ns(),
186-
initialExtentSize,
187-
capped,
188-
maxSize,
189-
&result)) {
190-
return;
191-
}
192-
193-
const auto status = getStatusFromCommandResult(result);
194-
179+
auto serviceCtx = opCtx->getServiceContext();
180+
CollectionOptions options;
181+
auto status =
182+
repl::StorageInterface::get(serviceCtx)
183+
->createCollection(opCtx, NamespaceString::kSessionTransactionsTableNamespace, options);
195184
if (status == ErrorCodes::NamespaceExists) {
196185
return;
197186
}

src/mongo/db/transaction_participant_retryable_writes_test.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
#include "mongo/db/repl/oplog.h"
4242
#include "mongo/db/repl/oplog_entry.h"
4343
#include "mongo/db/repl/optime.h"
44+
#include "mongo/db/repl/storage_interface_impl.h"
4445
#include "mongo/db/server_options.h"
4546
#include "mongo/db/server_transactions_metrics.h"
4647
#include "mongo/db/service_context.h"
@@ -167,10 +168,9 @@ class TransactionParticipantRetryableWritesTest : public MockReplCoordServerFixt
167168
protected:
168169
void setUp() {
169170
MockReplCoordServerFixture::setUp();
170-
171-
MongoDSessionCatalog::onStepUp(opCtx());
172-
173171
const auto service = opCtx()->getServiceContext();
172+
repl::StorageInterface::set(service, std::make_unique<repl::StorageInterfaceImpl>());
173+
MongoDSessionCatalog::onStepUp(opCtx());
174174

175175
const auto opObserverRegistry = dynamic_cast<OpObserverRegistry*>(service->getOpObserver());
176176
opObserverRegistry->addObserver(std::make_unique<OpObserverMock>());

src/mongo/db/transaction_participant_test.cpp

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@
4242
#include "mongo/db/repl/oplog.h"
4343
#include "mongo/db/repl/oplog_entry.h"
4444
#include "mongo/db/repl/optime.h"
45+
#include "mongo/db/repl/storage_interface_impl.h"
46+
#include "mongo/db/repl/storage_interface_mock.h"
4547
#include "mongo/db/server_transactions_metrics.h"
4648
#include "mongo/db/service_context.h"
4749
#include "mongo/db/session_catalog_mongod.h"
@@ -226,9 +228,18 @@ class TxnParticipantTest : public MockReplCoordServerFixture {
226228
protected:
227229
void setUp() override {
228230
MockReplCoordServerFixture::setUp();
231+
const auto service = opCtx()->getServiceContext();
232+
auto _storageInterfaceImpl = std::make_unique<repl::StorageInterfaceImpl>();
233+
234+
// onStepUp() relies on the storage interface to create the config.transactions table.
235+
repl::StorageInterface::set(service, std::move(_storageInterfaceImpl));
229236
MongoDSessionCatalog::onStepUp(opCtx());
230237

231-
const auto service = opCtx()->getServiceContext();
238+
// We use the mocked storage interface here since StorageInterfaceImpl does not support
239+
// getPointInTimeReadTimestamp().
240+
auto _storageInterfaceMock = std::make_unique<repl::StorageInterfaceMock>();
241+
repl::StorageInterface::set(service, std::move(_storageInterfaceMock));
242+
232243
OpObserverRegistry* opObserverRegistry =
233244
dynamic_cast<OpObserverRegistry*>(service->getOpObserver());
234245
auto mockObserver = std::make_unique<OpObserverMock>();
@@ -1520,6 +1531,9 @@ TEST_F(TxnParticipantTest, ReacquireLocksForPreparedTransactionsOnStepUp) {
15201531

15211532
// Step-up will restore the locks of prepared transactions.
15221533
ASSERT(opCtx()->writesAreReplicated());
1534+
const auto service = opCtx()->getServiceContext();
1535+
// onStepUp() relies on the storage interface to create the config.transactions table.
1536+
repl::StorageInterface::set(service, std::make_unique<repl::StorageInterfaceImpl>());
15231537
MongoDSessionCatalog::onStepUp(opCtx());
15241538
{
15251539
auto sessionCheckout = checkOutSession({});

0 commit comments

Comments
 (0)