diff options
author | Kevin Pulo <kevin.pulo@mongodb.com> | 2020-02-20 04:50:44 +0000 |
---|---|---|
committer | evergreen <evergreen@mongodb.com> | 2020-02-20 04:50:44 +0000 |
commit | 7eb6f03dd34615f2774a2cb70dadeffadce4512e (patch) | |
tree | a8986ee344e486c9937b85f5dd28d865b5e0e5c4 /src/mongo/db/write_concern.cpp | |
parent | 35667cfb9ef6c4400eea314ec15da36d1880ebca (diff) | |
download | mongo-7eb6f03dd34615f2774a2cb70dadeffadce4512e.tar.gz |
SERVER-45623 improve diagnosability of default writeConcern
- Include the writeConcern in writeConcernErrors
- Add serverStatus counters for default writeConcern timeouts and unsatisfiability
Diffstat (limited to 'src/mongo/db/write_concern.cpp')
-rw-r--r-- | src/mongo/db/write_concern.cpp | 23 |
1 files changed, 21 insertions, 2 deletions
diff --git a/src/mongo/db/write_concern.cpp b/src/mongo/db/write_concern.cpp index e1fa1b4540f..31c9a47d489 100644 --- a/src/mongo/db/write_concern.cpp +++ b/src/mongo/db/write_concern.cpp @@ -65,6 +65,14 @@ static Counter64 gleWtimeouts; static ServerStatusMetricField<Counter64> gleWtimeoutsDisplay("getLastError.wtimeouts", &gleWtimeouts); +static Counter64 gleDefaultWtimeouts; +static ServerStatusMetricField<Counter64> gleDefaultWtimeoutsDisplay( + "getLastError.default.wtimeouts", &gleDefaultWtimeouts); + +static Counter64 gleDefaultUnsatisfiable; +static ServerStatusMetricField<Counter64> gleDefaultUnsatisfiableDisplay( + "getLastError.default.unsatisfiable", &gleDefaultUnsatisfiable); + MONGO_FAIL_POINT_DEFINE(hangBeforeWaitingForWriteConcern); bool commandSpecifiesWriteConcern(const BSONObj& cmdObj) { @@ -203,8 +211,7 @@ Status validateWriteConcern(OperationContext* opCtx, const WriteConcernOptions& return Status::OK(); } -void WriteConcernResult::appendTo(const WriteConcernOptions& writeConcern, - BSONObjBuilder* result) const { +void WriteConcernResult::appendTo(BSONObjBuilder* result) const { if (syncMillis >= 0) result->appendNumber("syncMillis", syncMillis); @@ -230,6 +237,8 @@ void WriteConcernResult::appendTo(const WriteConcernOptions& writeConcern, result->appendNull("writtenTo"); } + result->append("writeConcern", wcUsed.toBSON()); + if (err.empty()) result->appendNull("err"); else @@ -312,13 +321,23 @@ Status waitForWriteConcern(OperationContext* opCtx, replCoord->awaitReplication(opCtx, replOpTime, writeConcernWithPopulatedSyncMode); if (replStatus.status == ErrorCodes::WriteConcernFailed) { gleWtimeouts.increment(); + if (!writeConcern.getProvenance().isClientSupplied()) { + gleDefaultWtimeouts.increment(); + } result->err = "timeout"; result->wTimedOut = true; } + if (replStatus.status == ErrorCodes::UnsatisfiableWriteConcern) { + if (!writeConcern.getProvenance().isClientSupplied()) { + gleDefaultUnsatisfiable.increment(); + } + } gleWtimeStats.recordMillis(durationCount<Milliseconds>(replStatus.duration)); result->wTime = durationCount<Milliseconds>(replStatus.duration); + result->wcUsed = writeConcern; + return replStatus.status; } |