summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPierlauro Sciarelli <pierlauro.sciarelli@mongodb.com>2021-12-24 09:28:34 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2021-12-24 10:22:22 +0000
commitc37974e1a2f7e3762f4b8c10446869c833643859 (patch)
tree5521b836de1342f8342956b77cf164ffdc9ce034
parent4492e86c8bbff4098c929b613a53f1029e3bfda0 (diff)
downloadmongo-c37974e1a2f7e3762f4b8c10446869c833643859.tar.gz
SERVER-62243 Wait for vector clock document majority-commit without timeout
-rw-r--r--src/mongo/db/persistent_task_store.h28
-rw-r--r--src/mongo/db/persistent_task_store_test.cpp21
-rw-r--r--src/mongo/db/s/migration_coordinator.cpp2
-rw-r--r--src/mongo/db/s/migration_destination_manager.cpp7
-rw-r--r--src/mongo/db/s/migration_util.cpp5
-rw-r--r--src/mongo/db/s/migration_util.h2
-rw-r--r--src/mongo/db/s/rename_collection_participant_service.cpp6
-rw-r--r--src/mongo/db/s/sharding_ddl_coordinator.h4
-rw-r--r--src/mongo/db/vector_clock_mongod.cpp2
9 files changed, 48 insertions, 29 deletions
diff --git a/src/mongo/db/persistent_task_store.h b/src/mongo/db/persistent_task_store.h
index 34ae3164004..ab946e22c0f 100644
--- a/src/mongo/db/persistent_task_store.h
+++ b/src/mongo/db/persistent_task_store.h
@@ -45,11 +45,16 @@ using namespace fmt::literals;
namespace WriteConcerns {
-const WriteConcernOptions kMajorityWriteConcern{WriteConcernOptions::kMajority,
- WriteConcernOptions::SyncMode::UNSET,
- WriteConcernOptions::kWriteConcernTimeoutSharding};
+const WriteConcernOptions kMajorityWriteConcernShardingTimeout{
+ WriteConcernOptions::kMajority,
+ WriteConcernOptions::SyncMode::UNSET,
+ WriteConcernOptions::kWriteConcernTimeoutSharding};
-}
+const WriteConcernOptions kMajorityWriteConcernNoTimeout{WriteConcernOptions::kMajority,
+ WriteConcernOptions::SyncMode::UNSET,
+ WriteConcernOptions::kNoTimeout};
+
+} // namespace WriteConcerns
template <typename T>
class PersistentTaskStore {
@@ -61,7 +66,8 @@ public:
*/
void add(OperationContext* opCtx,
const T& task,
- const WriteConcernOptions& writeConcern = WriteConcerns::kMajorityWriteConcern) {
+ const WriteConcernOptions& writeConcern =
+ WriteConcerns::kMajorityWriteConcernShardingTimeout) {
DBDirectClient dbClient(opCtx);
const auto commandResponse = dbClient.runCommand([&] {
@@ -85,7 +91,8 @@ public:
void update(OperationContext* opCtx,
const BSONObj& filter,
const BSONObj& update,
- const WriteConcernOptions& writeConcern = WriteConcerns::kMajorityWriteConcern) {
+ const WriteConcernOptions& writeConcern =
+ WriteConcerns::kMajorityWriteConcernShardingTimeout) {
_update(opCtx, filter, update, /* upsert */ false, writeConcern);
}
@@ -96,7 +103,8 @@ public:
void upsert(OperationContext* opCtx,
const BSONObj& filter,
const BSONObj& update,
- const WriteConcernOptions& writeConcern = WriteConcerns::kMajorityWriteConcern) {
+ const WriteConcernOptions& writeConcern =
+ WriteConcerns::kMajorityWriteConcernShardingTimeout) {
_update(opCtx, filter, update, /* upsert */ true, writeConcern);
}
@@ -105,7 +113,8 @@ public:
*/
void remove(OperationContext* opCtx,
const BSONObj& filter,
- const WriteConcernOptions& writeConcern = WriteConcerns::kMajorityWriteConcern) {
+ const WriteConcernOptions& writeConcern =
+ WriteConcerns::kMajorityWriteConcernShardingTimeout) {
DBDirectClient dbClient(opCtx);
auto commandResponse = dbClient.runCommand([&] {
@@ -170,7 +179,8 @@ private:
const BSONObj& filter,
const BSONObj& update,
bool upsert,
- const WriteConcernOptions& writeConcern = WriteConcerns::kMajorityWriteConcern) {
+ const WriteConcernOptions& writeConcern =
+ WriteConcerns::kMajorityWriteConcernShardingTimeout) {
DBDirectClient dbClient(opCtx);
auto commandResponse = dbClient.update([&] {
diff --git a/src/mongo/db/persistent_task_store_test.cpp b/src/mongo/db/persistent_task_store_test.cpp
index dd995a3eda0..d7e193e9302 100644
--- a/src/mongo/db/persistent_task_store_test.cpp
+++ b/src/mongo/db/persistent_task_store_test.cpp
@@ -233,12 +233,13 @@ TEST_F(PersistentTaskStoreTest, TestUpsert) {
ASSERT_EQ(store.count(opCtx, query), 0);
// Test that an attempt to upsert from the update command throws an error.
- ASSERT_THROWS_CODE(store.update(opCtx, query, taskBson, WriteConcerns::kMajorityWriteConcern),
- DBException,
- ErrorCodes::NoMatchingDocument);
+ ASSERT_THROWS_CODE(
+ store.update(opCtx, query, taskBson, WriteConcerns::kMajorityWriteConcernShardingTimeout),
+ DBException,
+ ErrorCodes::NoMatchingDocument);
// Test that the document is created when upserted.
- store.upsert(opCtx, query, taskBson, WriteConcerns::kMajorityWriteConcern);
+ store.upsert(opCtx, query, taskBson, WriteConcerns::kMajorityWriteConcernShardingTimeout);
ASSERT_EQ(store.count(opCtx, query), 1);
@@ -249,15 +250,19 @@ TEST_F(PersistentTaskStoreTest, TestUpsert) {
});
// Verify that updates happen as expected with upsert and update
- store.upsert(
- opCtx, query, BSON("$inc" << BSON("min" << 1)), WriteConcerns::kMajorityWriteConcern);
+ store.upsert(opCtx,
+ query,
+ BSON("$inc" << BSON("min" << 1)),
+ WriteConcerns::kMajorityWriteConcernShardingTimeout);
store.forEach(opCtx, query, [&](const TestTask& t) {
ASSERT_EQ(t.min, 1);
return true;
});
- store.update(
- opCtx, query, BSON("$inc" << BSON("min" << 1)), WriteConcerns::kMajorityWriteConcern);
+ store.update(opCtx,
+ query,
+ BSON("$inc" << BSON("min" << 1)),
+ WriteConcerns::kMajorityWriteConcernShardingTimeout);
store.forEach(opCtx, query, [&](const TestTask& t) {
ASSERT_EQ(t.min, 2);
return true;
diff --git a/src/mongo/db/s/migration_coordinator.cpp b/src/mongo/db/s/migration_coordinator.cpp
index e5f21d6f9c0..5b983056cf3 100644
--- a/src/mongo/db/s/migration_coordinator.cpp
+++ b/src/mongo/db/s/migration_coordinator.cpp
@@ -126,7 +126,7 @@ void MigrationCoordinator::startMigration(OperationContext* opCtx) {
const auto currentTime = VectorClock::get(opCtx)->getTime();
donorDeletionTask.setTimestamp(currentTime.clusterTime().asTimestamp());
migrationutil::persistRangeDeletionTaskLocally(
- opCtx, donorDeletionTask, WriteConcerns::kMajorityWriteConcern);
+ opCtx, donorDeletionTask, WriteConcerns::kMajorityWriteConcernShardingTimeout);
}
void MigrationCoordinator::setMigrationDecision(DecisionEnum decision) {
diff --git a/src/mongo/db/s/migration_destination_manager.cpp b/src/mongo/db/s/migration_destination_manager.cpp
index 9c47e67e3b1..5c258daf09f 100644
--- a/src/mongo/db/s/migration_destination_manager.cpp
+++ b/src/mongo/db/s/migration_destination_manager.cpp
@@ -1230,8 +1230,11 @@ void MigrationDestinationManager::_migrateDriver(OperationContext* outerOpCtx,
WriteConcernResult ignoreResult;
auto latestOpTime =
repl::ReplClientInfo::forClient(outerOpCtx->getClient()).getLastOp();
- uassertStatusOK(waitForWriteConcern(
- outerOpCtx, latestOpTime, WriteConcerns::kMajorityWriteConcern, &ignoreResult));
+ uassertStatusOK(
+ waitForWriteConcern(outerOpCtx,
+ latestOpTime,
+ WriteConcerns::kMajorityWriteConcernShardingTimeout,
+ &ignoreResult));
});
timing->done(3);
diff --git a/src/mongo/db/s/migration_util.cpp b/src/mongo/db/s/migration_util.cpp
index a8dfbbbe235..05896b00291 100644
--- a/src/mongo/db/s/migration_util.cpp
+++ b/src/mongo/db/s/migration_util.cpp
@@ -518,7 +518,7 @@ void resubmitRangeDeletionsOnStepUp(ServiceContext* serviceContext) {
void dropRangeDeletionsCollection(OperationContext* opCtx) {
DBDirectClient client(opCtx);
client.dropCollection(NamespaceString::kRangeDeletionNamespace.toString(),
- WriteConcerns::kMajorityWriteConcern);
+ WriteConcerns::kMajorityWriteConcernShardingTimeout);
}
template <typename Callable>
@@ -1109,7 +1109,8 @@ void persistMigrationRecipientRecoveryDocument(
PersistentTaskStore<MigrationRecipientRecoveryDocument> store(
NamespaceString::kMigrationRecipientsNamespace);
try {
- store.add(opCtx, migrationRecipientDoc, WriteConcerns::kMajorityWriteConcern);
+ store.add(
+ opCtx, migrationRecipientDoc, WriteConcerns::kMajorityWriteConcernShardingTimeout);
} catch (const ExceptionFor<ErrorCodes::DuplicateKey>&) {
// Convert a DuplicateKey error to an anonymous error.
uasserted(6064502,
diff --git a/src/mongo/db/s/migration_util.h b/src/mongo/db/s/migration_util.h
index a96caf82374..2b16a601bb2 100644
--- a/src/mongo/db/s/migration_util.h
+++ b/src/mongo/db/s/migration_util.h
@@ -164,7 +164,7 @@ void persistAbortDecision(OperationContext* opCtx,
void deleteRangeDeletionTaskLocally(
OperationContext* opCtx,
const UUID& deletionTaskId,
- const WriteConcernOptions& writeConcern = WriteConcerns::kMajorityWriteConcern);
+ const WriteConcernOptions& writeConcern = WriteConcerns::kMajorityWriteConcernShardingTimeout);
/**
* Deletes the range deletion task document with the specified id from config.rangeDeletions on the
diff --git a/src/mongo/db/s/rename_collection_participant_service.cpp b/src/mongo/db/s/rename_collection_participant_service.cpp
index 568534c83cd..62da2326850 100644
--- a/src/mongo/db/s/rename_collection_participant_service.cpp
+++ b/src/mongo/db/s/rename_collection_participant_service.cpp
@@ -198,12 +198,12 @@ void RenameParticipantInstance::_enterPhase(Phase newPhase) {
PersistentTaskStore<StateDoc> store(NamespaceString::kShardingRenameParticipantsNamespace);
if (_doc.getPhase() == Phase::kUnset) {
- store.add(opCtx.get(), newDoc, WriteConcerns::kMajorityWriteConcern);
+ store.add(opCtx.get(), newDoc, WriteConcerns::kMajorityWriteConcernShardingTimeout);
} else {
store.update(opCtx.get(),
BSON(StateDoc::kFromNssFieldName << fromNss().ns()),
newDoc.toBSON(),
- WriteConcerns::kMajorityWriteConcern);
+ WriteConcerns::kMajorityWriteConcernShardingTimeout);
}
_doc = std::move(newDoc);
@@ -219,7 +219,7 @@ void RenameParticipantInstance::_removeStateDocument(OperationContext* opCtx) {
PersistentTaskStore<StateDoc> store(NamespaceString::kShardingRenameParticipantsNamespace);
store.remove(opCtx,
BSON(StateDoc::kFromNssFieldName << fromNss().ns()),
- WriteConcerns::kMajorityWriteConcern);
+ WriteConcerns::kMajorityWriteConcernShardingTimeout);
_doc = {};
}
diff --git a/src/mongo/db/s/sharding_ddl_coordinator.h b/src/mongo/db/s/sharding_ddl_coordinator.h
index b2eec9b42fb..8e9c7aa39f4 100644
--- a/src/mongo/db/s/sharding_ddl_coordinator.h
+++ b/src/mongo/db/s/sharding_ddl_coordinator.h
@@ -110,7 +110,7 @@ protected:
auto opCtx = cc().makeOperationContext();
PersistentTaskStore<StateDoc> store(NamespaceString::kShardingDDLCoordinatorsNamespace);
- store.add(opCtx.get(), newDoc, WriteConcerns::kMajorityWriteConcern);
+ store.add(opCtx.get(), newDoc, WriteConcerns::kMajorityWriteConcernShardingTimeout);
return std::move(newDoc);
}
@@ -122,7 +122,7 @@ protected:
store.update(opCtx,
BSON(StateDoc::kIdFieldName << newDoc.getId().toBSON()),
newDoc.toBSON(),
- WriteConcerns::kMajorityWriteConcern);
+ WriteConcerns::kMajorityWriteConcernShardingTimeout);
return std::move(newDoc);
}
diff --git a/src/mongo/db/vector_clock_mongod.cpp b/src/mongo/db/vector_clock_mongod.cpp
index 959e3e90e83..37825beb200 100644
--- a/src/mongo/db/vector_clock_mongod.cpp
+++ b/src/mongo/db/vector_clock_mongod.cpp
@@ -353,7 +353,7 @@ Future<void> VectorClockMongoD::_doWhileQueueNotEmptyOrError(ServiceContext* ser
store.upsert(opCtx,
BSON(VectorClockDocument::k_idFieldName << vcd.get_id()),
vcd.toBSON(),
- WriteConcerns::kMajorityWriteConcern);
+ WriteConcerns::kMajorityWriteConcernNoTimeout);
return vectorTime;
})
.getAsync([this, promise = std::move(p)](StatusWith<VectorTime> swResult) mutable {