diff options
author | Kevin Pulo <kevin.pulo@mongodb.com> | 2019-12-20 02:20:39 +0000 |
---|---|---|
committer | evergreen <evergreen@mongodb.com> | 2019-12-20 02:20:39 +0000 |
commit | 8bf0a1988427e970c965994c629997a2a357dcd1 (patch) | |
tree | 01630147a3e49113ad95fb076eefc782508bbcd2 /src/mongo/db/write_concern.cpp | |
parent | 432f78a8316dcac41ea3085faa0d8c1afad450ff (diff) | |
download | mongo-8bf0a1988427e970c965994c629997a2a357dcd1.tar.gz |
SERVER-44538 Add read/write concern fields to logging/profiling
Diffstat (limited to 'src/mongo/db/write_concern.cpp')
-rw-r--r-- | src/mongo/db/write_concern.cpp | 25 |
1 files changed, 23 insertions, 2 deletions
diff --git a/src/mongo/db/write_concern.cpp b/src/mongo/db/write_concern.cpp index 2b532fed21e..dc49680b32d 100644 --- a/src/mongo/db/write_concern.cpp +++ b/src/mongo/db/write_concern.cpp @@ -89,7 +89,7 @@ StatusWith<WriteConcernOptions> extractWriteConcern(OperationContext* opCtx, // received by shard and config servers should always have WC explicitly specified. if (serverGlobalParams.clusterRole != ClusterRole::ShardServer && serverGlobalParams.clusterRole != ClusterRole::ConfigServer && - !opCtx->getClient()->isInDirectClient()) { + !opCtx->inMultiDocumentTransaction() && !opCtx->getClient()->isInDirectClient()) { auto wcDefault = ReadWriteConcernDefaults::get(opCtx->getServiceContext()) .getDefaultWriteConcern(opCtx); if (wcDefault) { @@ -98,7 +98,28 @@ StatusWith<WriteConcernOptions> extractWriteConcern(OperationContext* opCtx, return *wcDefault; } } - return repl::ReplicationCoordinator::get(opCtx)->getGetLastErrorDefault(); + + auto getLastErrorDefault = + repl::ReplicationCoordinator::get(opCtx)->getGetLastErrorDefault(); + // Since replication configs always include all fields (explicitly setting them to the + // default value if necessary), usedDefault and usedDefaultW are always false here, even + // if the getLastErrorDefaults has never actually been set (because the + // getLastErrorDefaults writeConcern has been explicitly read out of the replset + // config). + // + // In this case, where the getLastErrorDefault is "conceptually unset" (ie. identical to + // the implicit server default of { w: 1, wtimeout: 0 }), we would prefer if downstream + // code behaved as if no writeConcern had been applied (since in addition to "no" + // getLastErrorDefaults, there is no ReadWriteConcernDefaults writeConcern and the user + // did not specify a writeConcern). + // + // Therefore when the getLastErrorDefault is { w: 1, wtimeout: 0 } we force usedDefault + // and usedDefaultW to be true. + if (getLastErrorDefault.wNumNodes == 1 && getLastErrorDefault.wTimeout == 0) { + getLastErrorDefault.usedDefault = true; + getLastErrorDefault.usedDefaultW = true; + } + return getLastErrorDefault; })(); if (writeConcern.wNumNodes == 0 && writeConcern.wMode.empty()) { writeConcern.wNumNodes = 1; |