summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorHuayu Ouyang <huayu.ouyang@mongodb.com>2021-04-07 21:17:28 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2021-04-19 23:44:19 +0000
commit49d2a22fc712873c26d4daf387b116ea50a1c2c5 (patch)
treec597bfd34499197659728b3318433377c9bff9f1 /src
parent3fa7f2ae9aad0e9754209fcbcc45851b8acc7b40 (diff)
downloadmongo-49d2a22fc712873c26d4daf387b116ea50a1c2c5.tar.gz
SERVER-55700 Update kImplicitDefault in WriteConcernOptions
Diffstat (limited to 'src')
-rw-r--r--src/mongo/db/read_concern_mongod.cpp2
-rw-r--r--src/mongo/db/read_write_concern_provenance.h6
-rw-r--r--src/mongo/db/read_write_concern_provenance_test.cpp6
-rw-r--r--src/mongo/db/s/balancer/migration_manager.cpp2
-rw-r--r--src/mongo/db/s/migration_chunk_cloner_source_legacy.cpp4
-rw-r--r--src/mongo/db/sessions_collection.cpp6
-rw-r--r--src/mongo/db/write_concern.cpp5
-rw-r--r--src/mongo/db/write_concern_options.cpp4
-rw-r--r--src/mongo/db/write_concern_options.h2
-rw-r--r--src/mongo/idl/basic_types.idl1
-rw-r--r--src/mongo/s/commands/strategy.cpp11
11 files changed, 36 insertions, 13 deletions
diff --git a/src/mongo/db/read_concern_mongod.cpp b/src/mongo/db/read_concern_mongod.cpp
index bc208fed2a2..8cc004b8f64 100644
--- a/src/mongo/db/read_concern_mongod.cpp
+++ b/src/mongo/db/read_concern_mongod.cpp
@@ -178,7 +178,7 @@ Status makeNoopWriteIfNeeded(OperationContext* opCtx, LogicalTime clusterTime) {
<< 1 << "maxClusterTime" << clusterTime.asTimestamp() << "data"
<< BSON("noop write for afterClusterTime read concern" << 1)
<< WriteConcernOptions::kWriteConcernField
- << WriteConcernOptions::kImplicitDefault),
+ << WriteConcernOptions::kInternalWriteDefault),
onRemoteCmdScheduled,
onRemoteCmdComplete);
diff --git a/src/mongo/db/read_write_concern_provenance.h b/src/mongo/db/read_write_concern_provenance.h
index 686d1843d6d..0679b311821 100644
--- a/src/mongo/db/read_write_concern_provenance.h
+++ b/src/mongo/db/read_write_concern_provenance.h
@@ -70,6 +70,11 @@ namespace mongo {
* Only applicable to write concern, and indicates that it originated from the (deprecated)
* 'settings.getLastErrorDefaults' field of the replica set configuration.
*
+ * - "internalWriteDefault":
+ * Only applicable to write concern on internal writes, and indicates that the internal client
+ * did not supply an explicit write concern, so this write concern represents the corresponding
+ * server default for internal writes, ie. {w: 1, wtimeout: 0}.
+ *
* A ReadWriteConcernProvenance object may only have a single Source value throughout its lifetime;
* once the Source has been set, attempting to change it will trigger an invariant. This ensures
* the integrity of the provenance value as the operation makes its way through the server (and
@@ -83,6 +88,7 @@ public:
static constexpr StringData kImplicitDefault = "implicitDefault"_sd;
static constexpr StringData kCustomDefault = "customDefault"_sd;
static constexpr StringData kGetLastErrorDefaults = "getLastErrorDefaults"_sd;
+ static constexpr StringData kInternalWriteDefault = "internalWriteDefault"_sd;
ReadWriteConcernProvenance() = default;
diff --git a/src/mongo/db/read_write_concern_provenance_test.cpp b/src/mongo/db/read_write_concern_provenance_test.cpp
index 5b04f468ef4..184dc98dff5 100644
--- a/src/mongo/db/read_write_concern_provenance_test.cpp
+++ b/src/mongo/db/read_write_concern_provenance_test.cpp
@@ -67,6 +67,12 @@ TEST(ReadWriteConcernProvenanceTest, GetLastErrorDefaults) {
ASSERT_FALSE(provenance.isClientSupplied());
}
+TEST(ReadWriteConcernProvenanceTest, InternalWriteDefault) {
+ ReadWriteConcernProvenance provenance(ReadWriteConcernProvenance::Source::internalWriteDefault);
+ ASSERT_TRUE(provenance.hasSource());
+ ASSERT_FALSE(provenance.isClientSupplied());
+}
+
TEST(ReadWriteConcernProvenanceTest, SetSourceFromUnsetToUnset) {
ReadWriteConcernProvenance provenance;
provenance.setSource(boost::none);
diff --git a/src/mongo/db/s/balancer/migration_manager.cpp b/src/mongo/db/s/balancer/migration_manager.cpp
index c75e0ce2446..8ab7933ef24 100644
--- a/src/mongo/db/s/balancer/migration_manager.cpp
+++ b/src/mongo/db/s/balancer/migration_manager.cpp
@@ -485,7 +485,7 @@ std::shared_ptr<Notification<RemoteCommandResponse>> MigrationManager::_schedule
// server default writeConcern.
if (!builder.hasField(WriteConcernOptions::kWriteConcernField)) {
builder.append(WriteConcernOptions::kWriteConcernField,
- WriteConcernOptions::kImplicitDefault);
+ WriteConcernOptions::kInternalWriteDefault);
}
stdx::lock_guard<Latch> lock(_mutex);
diff --git a/src/mongo/db/s/migration_chunk_cloner_source_legacy.cpp b/src/mongo/db/s/migration_chunk_cloner_source_legacy.cpp
index 367b10bcb71..e6815d05889 100644
--- a/src/mongo/db/s/migration_chunk_cloner_source_legacy.cpp
+++ b/src/mongo/db/s/migration_chunk_cloner_source_legacy.cpp
@@ -299,10 +299,10 @@ Status MigrationChunkClonerSourceLegacy::startClone(OperationContext* opCtx,
// Commands sent to shards that accept writeConcern, must always have writeConcern. So if the
// StartChunkCloneRequest didn't add writeConcern (from secondaryThrottle), then we add the
- // implicit server default writeConcern.
+ // internal server default writeConcern.
if (!cmdBuilder.hasField(WriteConcernOptions::kWriteConcernField)) {
cmdBuilder.append(WriteConcernOptions::kWriteConcernField,
- WriteConcernOptions::kImplicitDefault);
+ WriteConcernOptions::kInternalWriteDefault);
}
auto startChunkCloneResponseStatus = _callRecipient(cmdBuilder.obj());
diff --git a/src/mongo/db/sessions_collection.cpp b/src/mongo/db/sessions_collection.cpp
index 9864cc11aa9..88c75302220 100644
--- a/src/mongo/db/sessions_collection.cpp
+++ b/src/mongo/db/sessions_collection.cpp
@@ -278,8 +278,8 @@ BSONObj SessionsCollection::generateCreateIndexesCmd() {
CreateIndexesCommand createIndexes(NamespaceString::kLogicalSessionsNamespace);
createIndexes.setIndexes({index.toBSON()});
- return createIndexes.toBSON(
- BSON(WriteConcernOptions::kWriteConcernField << WriteConcernOptions::kImplicitDefault));
+ return createIndexes.toBSON(BSON(WriteConcernOptions::kWriteConcernField
+ << WriteConcernOptions::kInternalWriteDefault));
}
BSONObj SessionsCollection::generateCollModCmd() {
@@ -293,7 +293,7 @@ BSONObj SessionsCollection::generateCollModCmd() {
indexBuilder.done();
collModCmdBuilder.append(WriteConcernOptions::kWriteConcernField,
- WriteConcernOptions::kImplicitDefault);
+ WriteConcernOptions::kInternalWriteDefault);
collModCmdBuilder.done();
return collModCmdBuilder.obj();
diff --git a/src/mongo/db/write_concern.cpp b/src/mongo/db/write_concern.cpp
index 6c49846706c..3b4c020431e 100644
--- a/src/mongo/db/write_concern.cpp
+++ b/src/mongo/db/write_concern.cpp
@@ -165,6 +165,8 @@ StatusWith<WriteConcernOptions> extractWriteConcern(OperationContext* opCtx,
provenance.setSource(ReadWriteConcernProvenance::Source::customDefault);
} else if (getLastErrorDefaultsWasApplied) {
provenance.setSource(ReadWriteConcernProvenance::Source::getLastErrorDefaults);
+ } else if (opCtx->getClient()->isInDirectClient() || isInternalClient) {
+ provenance.setSource(ReadWriteConcernProvenance::Source::internalWriteDefault);
} else {
provenance.setSource(ReadWriteConcernProvenance::Source::implicitDefault);
}
@@ -179,7 +181,8 @@ StatusWith<WriteConcernOptions> extractWriteConcern(OperationContext* opCtx,
// does not specify writeConcern when writing to the config server.
writeConcern = {
WriteConcernOptions::kMajority, WriteConcernOptions::SyncMode::UNSET, Seconds(30)};
- writeConcern.getProvenance().setSource(ReadWriteConcernProvenance::Source::implicitDefault);
+ writeConcern.getProvenance().setSource(
+ ReadWriteConcernProvenance::Source::internalWriteDefault);
} else {
Status wcStatus = validateWriteConcern(opCtx, writeConcern);
if (!wcStatus.isOK()) {
diff --git a/src/mongo/db/write_concern_options.cpp b/src/mongo/db/write_concern_options.cpp
index cd129ec2cf0..0a09aa802ff 100644
--- a/src/mongo/db/write_concern_options.cpp
+++ b/src/mongo/db/write_concern_options.cpp
@@ -76,10 +76,10 @@ const BSONObj WriteConcernOptions::Acknowledged(BSON("w" << W_NORMAL));
const BSONObj WriteConcernOptions::Unacknowledged(BSON("w" << W_NONE));
const BSONObj WriteConcernOptions::Majority(BSON("w" << WriteConcernOptions::kMajority));
-// The "kImplicitDefault" write concern, used by internal operations, is deliberately empty (no
+// The "kInternalWriteDefault" write concern, used by internal operations, is deliberately empty (no
// 'w' or 'wtimeout' specified). This allows internal operations to specify a write concern, while
// still allowing it to be either w:1 or automatically upconverted to w:majority on configsvrs.
-const BSONObj WriteConcernOptions::kImplicitDefault;
+const BSONObj WriteConcernOptions::kInternalWriteDefault;
constexpr Seconds WriteConcernOptions::kWriteConcernTimeoutSystem;
constexpr Seconds WriteConcernOptions::kWriteConcernTimeoutMigration;
diff --git a/src/mongo/db/write_concern_options.h b/src/mongo/db/write_concern_options.h
index 870646fb528..96227f75122 100644
--- a/src/mongo/db/write_concern_options.h
+++ b/src/mongo/db/write_concern_options.h
@@ -54,7 +54,7 @@ public:
static const BSONObj Acknowledged;
static const BSONObj Unacknowledged;
static const BSONObj Majority;
- static const BSONObj kImplicitDefault;
+ static const BSONObj kInternalWriteDefault;
static constexpr StringData kWriteConcernField = "writeConcern"_sd;
static const char kMajority[]; // = "majority"
diff --git a/src/mongo/idl/basic_types.idl b/src/mongo/idl/basic_types.idl
index 1bac48374f5..37a7f86a0d0 100644
--- a/src/mongo/idl/basic_types.idl
+++ b/src/mongo/idl/basic_types.idl
@@ -254,6 +254,7 @@ enums:
implicitDefault: "implicitDefault"
customDefault: "customDefault"
getLastErrorDefaults: "getLastErrorDefaults"
+ internalWriteDefault: "internalWriteDefault"
CollationCaseFirst:
description: Sort order of case differences.
diff --git a/src/mongo/s/commands/strategy.cpp b/src/mongo/s/commands/strategy.cpp
index 814befda717..073ba3231fe 100644
--- a/src/mongo/s/commands/strategy.cpp
+++ b/src/mongo/s/commands/strategy.cpp
@@ -646,10 +646,15 @@ Status ParseAndRunCommand::RunInvocation::_setup() {
bool clientSuppliedWriteConcern = !_parc->_wc->usedDefault;
bool customDefaultWriteConcernWasApplied = false;
+ bool isInternalClient =
+ (opCtx->getClient()->session() &&
+ (opCtx->getClient()->session()->getTags() & transport::Session::kInternalClient));
if (supportsWriteConcern && !clientSuppliedWriteConcern &&
- (!TransactionRouter::get(opCtx) || isTransactionCommand(_parc->_commandName))) {
- // This command supports WC, but wasn't given one - so apply the default, if there is one.
+ (!TransactionRouter::get(opCtx) || isTransactionCommand(_parc->_commandName)) &&
+ !opCtx->getClient()->isInDirectClient() && !isInternalClient) {
+ // This command is not from a DBDirectClient or internal client, and supports WC, but
+ // wasn't given one - so apply the default, if there is one.
if (const auto wcDefault = ReadWriteConcernDefaults::get(opCtx->getServiceContext())
.getDefaultWriteConcern(opCtx)) {
_parc->_wc = *wcDefault;
@@ -685,6 +690,8 @@ Status ParseAndRunCommand::RunInvocation::_setup() {
provenance.setSource(ReadWriteConcernProvenance::Source::clientSupplied);
} else if (customDefaultWriteConcernWasApplied) {
provenance.setSource(ReadWriteConcernProvenance::Source::customDefault);
+ } else if (opCtx->getClient()->isInDirectClient() || isInternalClient) {
+ provenance.setSource(ReadWriteConcernProvenance::Source::internalWriteDefault);
} else {
provenance.setSource(ReadWriteConcernProvenance::Source::implicitDefault);
}