summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJason Chan <jason.chan@10gen.com>2019-07-01 15:56:47 -0400
committerJason Chan <jason.chan@10gen.com>2019-07-19 13:04:32 -0400
commit56852d83dd92ab47063672bd48d94e4439f8c23e (patch)
tree44c3b3fb1df31a53bd5c316c2f1eafa0d9d1393c
parentd20da4216fbd9d87dd892dc5433a81bd49da5bd3 (diff)
downloadmongo-56852d83dd92ab47063672bd48d94e4439f8c23e.tar.gz
SERVER-41469 Enforce w:1 for creation of transactions table on step-up
(cherry picked from commit a351f48ad122ca59ed45e5df877ef398c099c938)
-rw-r--r--src/mongo/db/SConscript2
-rw-r--r--src/mongo/db/op_observer_impl_test.cpp5
-rw-r--r--src/mongo/db/repl/do_txn_test.cpp9
-rw-r--r--src/mongo/db/s/SConscript1
-rw-r--r--src/mongo/db/s/session_catalog_migration_destination_test.cpp5
-rw-r--r--src/mongo/db/session_catalog_mongod.cpp23
-rw-r--r--src/mongo/db/transaction_participant_retryable_writes_test.cpp6
-rw-r--r--src/mongo/db/transaction_participant_test.cpp16
8 files changed, 37 insertions, 30 deletions
diff --git a/src/mongo/db/SConscript b/src/mongo/db/SConscript
index dcdd31f7f2e..eb6379f9f3b 100644
--- a/src/mongo/db/SConscript
+++ b/src/mongo/db/SConscript
@@ -134,6 +134,7 @@ env.CppUnitTest(
'op_observer_impl',
'repl/oplog_interface_local',
'repl/replmocks',
+ 'repl/storage_interface_impl',
'service_context_d_test_fixture',
'transaction',
],
@@ -2095,6 +2096,7 @@ env.CppUnitTest(
'query_exec',
'repl/mock_repl_coord_server_fixture',
'repl/repl_coordinator_interface',
+ 'repl/storage_interface_impl',
'service_liaison_mock',
'sessions_collection_mock',
'sessions_collection',
diff --git a/src/mongo/db/op_observer_impl_test.cpp b/src/mongo/db/op_observer_impl_test.cpp
index a9596e623ec..147c1960e50 100644
--- a/src/mongo/db/op_observer_impl_test.cpp
+++ b/src/mongo/db/op_observer_impl_test.cpp
@@ -42,7 +42,7 @@
#include "mongo/db/repl/oplog_interface_local.h"
#include "mongo/db/repl/repl_client_info.h"
#include "mongo/db/repl/replication_coordinator_mock.h"
-#include "mongo/db/repl/storage_interface_mock.h"
+#include "mongo/db/repl/storage_interface_impl.h"
#include "mongo/db/service_context_d_test_fixture.h"
#include "mongo/db/session_catalog_mongod.h"
#include "mongo/db/storage/ephemeral_for_test/ephemeral_for_test_recovery_unit.h"
@@ -65,7 +65,8 @@ public:
auto service = getServiceContext();
auto opCtx = cc().makeOperationContext();
- repl::StorageInterface::set(service, stdx::make_unique<repl::StorageInterfaceMock>());
+ // onStepUp() relies on the storage interface to create the config.transactions table.
+ repl::StorageInterface::set(service, std::make_unique<repl::StorageInterfaceImpl>());
// Set up ReplicationCoordinator and create oplog.
repl::ReplicationCoordinator::set(
diff --git a/src/mongo/db/repl/do_txn_test.cpp b/src/mongo/db/repl/do_txn_test.cpp
index 810e7401da3..3b92a944ea0 100644
--- a/src/mongo/db/repl/do_txn_test.cpp
+++ b/src/mongo/db/repl/do_txn_test.cpp
@@ -39,7 +39,6 @@
#include "mongo/db/repl/repl_client_info.h"
#include "mongo/db/repl/replication_coordinator_mock.h"
#include "mongo/db/repl/storage_interface_impl.h"
-#include "mongo/db/repl/storage_interface_mock.h"
#include "mongo/db/s/op_observer_sharding_impl.h"
#include "mongo/db/service_context_d_test_fixture.h"
#include "mongo/db/session_catalog_mongod.h"
@@ -155,6 +154,9 @@ void DoTxnTest::setUp() {
auto replCoord = ReplicationCoordinator::get(_opCtx.get());
ASSERT_OK(replCoord->setFollowerMode(MemberState::RS_PRIMARY));
+ // onStepUp() relies on the storage interface to create the config.transactions table.
+ repl::StorageInterface::set(service, std::make_unique<StorageInterfaceImpl>());
+
// Set up session catalog
MongoDSessionCatalog::onStepUp(_opCtx.get());
@@ -172,11 +174,6 @@ void DoTxnTest::setUp() {
// collections.
_storage = stdx::make_unique<StorageInterfaceImpl>();
- // We also need to give replication a StorageInterface for checking out the transaction.
- // The test storage engine doesn't support the necessary call (getPointInTimeReadTimestamp()),
- // so we use a mock.
- repl::StorageInterface::set(service, stdx::make_unique<StorageInterfaceMock>());
-
// Set up the transaction and session.
_opCtx->setLogicalSessionId(makeLogicalSessionIdForTest());
_opCtx->setTxnNumber(0); // TxnNumber can always be 0 because we have a new session.
diff --git a/src/mongo/db/s/SConscript b/src/mongo/db/s/SConscript
index 7933f144286..31aa2875116 100644
--- a/src/mongo/db/s/SConscript
+++ b/src/mongo/db/s/SConscript
@@ -392,6 +392,7 @@ env.CppUnitTest(
'$BUILD_DIR/mongo/db/ops/write_ops_exec',
'$BUILD_DIR/mongo/db/query/query_request',
'$BUILD_DIR/mongo/db/repl/mock_repl_coord_server_fixture',
+ '$BUILD_DIR/mongo/db/repl/storage_interface_impl',
'$BUILD_DIR/mongo/s/catalog/dist_lock_manager_mock',
'$BUILD_DIR/mongo/s/catalog/sharding_catalog_client_impl',
'$BUILD_DIR/mongo/s/catalog/sharding_catalog_client_mock',
diff --git a/src/mongo/db/s/session_catalog_migration_destination_test.cpp b/src/mongo/db/s/session_catalog_migration_destination_test.cpp
index 2bdd5d3b62a..02e7d9a553a 100644
--- a/src/mongo/db/s/session_catalog_migration_destination_test.cpp
+++ b/src/mongo/db/s/session_catalog_migration_destination_test.cpp
@@ -40,6 +40,7 @@
#include "mongo/db/ops/write_ops_exec.h"
#include "mongo/db/ops/write_ops_gen.h"
#include "mongo/db/repl/oplog_entry.h"
+#include "mongo/db/repl/storage_interface_impl.h"
#include "mongo/db/s/migration_session_id.h"
#include "mongo/db/s/session_catalog_migration_destination.h"
#include "mongo/db/server_options.h"
@@ -130,7 +131,9 @@ public:
RemoteCommandTargeterMock::get(donorShard->getTargeter())
->setFindHostReturnValue(kDonorConnStr.getServers()[0]);
}
-
+ // onStepUp() relies on the storage interface to create the config.transactions table.
+ repl::StorageInterface::set(getServiceContext(),
+ std::make_unique<repl::StorageInterfaceImpl>());
MongoDSessionCatalog::onStepUp(operationContext());
LogicalSessionCache::set(getServiceContext(), stdx::make_unique<LogicalSessionCacheNoop>());
}
diff --git a/src/mongo/db/session_catalog_mongod.cpp b/src/mongo/db/session_catalog_mongod.cpp
index ee3a7b6bd47..e52a99383f1 100644
--- a/src/mongo/db/session_catalog_mongod.cpp
+++ b/src/mongo/db/session_catalog_mongod.cpp
@@ -41,6 +41,7 @@
#include "mongo/db/namespace_string.h"
#include "mongo/db/operation_context.h"
#include "mongo/db/ops/write_ops.h"
+#include "mongo/db/repl/storage_interface_impl.h"
#include "mongo/db/service_context.h"
#include "mongo/db/session_txn_record_gen.h"
#include "mongo/db/sessions_collection.h"
@@ -175,23 +176,11 @@ int removeSessionsTransactionRecords(OperationContext* opCtx,
}
void createTransactionTable(OperationContext* opCtx) {
- const size_t initialExtentSize = 0;
- const bool capped = false;
- const bool maxSize = 0;
- BSONObj result;
-
- DBDirectClient client(opCtx);
-
- if (client.createCollection(NamespaceString::kSessionTransactionsTableNamespace.ns(),
- initialExtentSize,
- capped,
- maxSize,
- &result)) {
- return;
- }
-
- const auto status = getStatusFromCommandResult(result);
-
+ auto serviceCtx = opCtx->getServiceContext();
+ CollectionOptions options;
+ auto status =
+ repl::StorageInterface::get(serviceCtx)
+ ->createCollection(opCtx, NamespaceString::kSessionTransactionsTableNamespace, options);
if (status == ErrorCodes::NamespaceExists) {
return;
}
diff --git a/src/mongo/db/transaction_participant_retryable_writes_test.cpp b/src/mongo/db/transaction_participant_retryable_writes_test.cpp
index c1644f39918..155935ddd47 100644
--- a/src/mongo/db/transaction_participant_retryable_writes_test.cpp
+++ b/src/mongo/db/transaction_participant_retryable_writes_test.cpp
@@ -39,6 +39,7 @@
#include "mongo/db/repl/oplog.h"
#include "mongo/db/repl/oplog_entry.h"
#include "mongo/db/repl/optime.h"
+#include "mongo/db/repl/storage_interface_impl.h"
#include "mongo/db/server_options.h"
#include "mongo/db/server_transactions_metrics.h"
#include "mongo/db/service_context.h"
@@ -166,10 +167,9 @@ class TransactionParticipantRetryableWritesTest : public MockReplCoordServerFixt
protected:
void setUp() {
MockReplCoordServerFixture::setUp();
-
- MongoDSessionCatalog::onStepUp(opCtx());
-
const auto service = opCtx()->getServiceContext();
+ repl::StorageInterface::set(service, std::make_unique<repl::StorageInterfaceImpl>());
+ MongoDSessionCatalog::onStepUp(opCtx());
const auto opObserverRegistry = dynamic_cast<OpObserverRegistry*>(service->getOpObserver());
opObserverRegistry->addObserver(stdx::make_unique<OpObserverMock>());
diff --git a/src/mongo/db/transaction_participant_test.cpp b/src/mongo/db/transaction_participant_test.cpp
index b2336fc4cc3..f4764ad0e8c 100644
--- a/src/mongo/db/transaction_participant_test.cpp
+++ b/src/mongo/db/transaction_participant_test.cpp
@@ -42,6 +42,8 @@
#include "mongo/db/repl/oplog.h"
#include "mongo/db/repl/oplog_entry.h"
#include "mongo/db/repl/optime.h"
+#include "mongo/db/repl/storage_interface_impl.h"
+#include "mongo/db/repl/storage_interface_mock.h"
#include "mongo/db/server_transactions_metrics.h"
#include "mongo/db/service_context.h"
#include "mongo/db/session_catalog_mongod.h"
@@ -227,9 +229,18 @@ class TxnParticipantTest : public MockReplCoordServerFixture {
protected:
void setUp() override {
MockReplCoordServerFixture::setUp();
+ const auto service = opCtx()->getServiceContext();
+ auto _storageInterfaceImpl = std::make_unique<repl::StorageInterfaceImpl>();
+
+ // onStepUp() relies on the storage interface to create the config.transactions table.
+ repl::StorageInterface::set(service, std::move(_storageInterfaceImpl));
MongoDSessionCatalog::onStepUp(opCtx());
- const auto service = opCtx()->getServiceContext();
+ // We use the mocked storage interface here since StorageInterfaceImpl does not support
+ // getPointInTimeReadTimestamp().
+ auto _storageInterfaceMock = std::make_unique<repl::StorageInterfaceMock>();
+ repl::StorageInterface::set(service, std::move(_storageInterfaceMock));
+
OpObserverRegistry* opObserverRegistry =
dynamic_cast<OpObserverRegistry*>(service->getOpObserver());
auto mockObserver = stdx::make_unique<OpObserverMock>();
@@ -1566,6 +1577,9 @@ TEST_F(TxnParticipantTest, ReacquireLocksForPreparedTransactionsOnStepUp) {
// Step-up will restore the locks of prepared transactions.
ASSERT(opCtx()->writesAreReplicated());
+ const auto service = opCtx()->getServiceContext();
+ // onStepUp() relies on the storage interface to create the config.transactions table.
+ repl::StorageInterface::set(service, std::make_unique<repl::StorageInterfaceImpl>());
MongoDSessionCatalog::onStepUp(opCtx());
{
auto sessionCheckout = checkOutSession({});