diff options
author | Ruoxin Xu <ruoxin.xu@mongodb.com> | 2020-03-06 23:32:52 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2020-03-19 12:06:50 +0000 |
commit | c00b8e8cd6935c2816ae7173359cd97818abd590 (patch) | |
tree | 60bd3071ce222fd1cc7d9fc99ab6fa28455fad64 /src/mongo/db | |
parent | fc50384c81d14e9db5c76385006b94f3eaa5e52b (diff) | |
download | mongo-c00b8e8cd6935c2816ae7173359cd97818abd590.tar.gz |
SERVER-43614 Added "_failPointMessage" field in CurOp for Failpoints used only.
Diffstat (limited to 'src/mongo/db')
-rw-r--r-- | src/mongo/db/curop.cpp | 4 | ||||
-rw-r--r-- | src/mongo/db/curop.h | 16 | ||||
-rw-r--r-- | src/mongo/db/curop_failpoint_helpers.cpp | 14 | ||||
-rw-r--r-- | src/mongo/db/curop_failpoint_helpers.h | 5 | ||||
-rw-r--r-- | src/mongo/db/curop_test.cpp | 15 | ||||
-rw-r--r-- | src/mongo/db/exhaust_cursor_currentop_integration_test.cpp | 15 |
6 files changed, 53 insertions, 16 deletions
diff --git a/src/mongo/db/curop.cpp b/src/mongo/db/curop.cpp index 1c20a27daea..09c0a673246 100644 --- a/src/mongo/db/curop.cpp +++ b/src/mongo/db/curop.cpp @@ -641,6 +641,10 @@ void CurOp::reportState(OperationContext* opCtx, BSONObjBuilder* builder, bool t } } + if (!_failPointMessage.empty()) { + builder->append("failpointMsg", _failPointMessage); + } + if (auto n = _debug.additiveMetrics.prepareReadConflicts.load(); n > 0) { builder->append("prepareReadConflicts", n); } diff --git a/src/mongo/db/curop.h b/src/mongo/db/curop.h index dc60bd37a86..8c8c66f5514 100644 --- a/src/mongo/db/curop.h +++ b/src/mongo/db/curop.h @@ -578,6 +578,13 @@ public: void reportState(OperationContext* opCtx, BSONObjBuilder* builder, bool truncateOps = false); /** + * Sets the message for FailPoints used. + */ + void setFailPointMessage_inlock(StringData message) { + _failPointMessage = message.toString(); + } + + /** * Sets the message for this CurOp. */ void setMessage_inlock(StringData message); @@ -592,6 +599,14 @@ public: ProgressMeter& setProgress_inlock(StringData name, unsigned long long progressMeterTotal = 0, int secondsBetween = 3); + + /* + * Gets the message for FailPoints used. + */ + const std::string& getFailPointMessage() const { + return _failPointMessage; + } + /** * Gets the message for this CurOp. */ @@ -682,6 +697,7 @@ private: BSONObj _opDescription; BSONObj _originatingCommand; // Used by getMore to display original command. OpDebug _debug; + std::string _failPointMessage; // Used to store FailPoint information. std::string _message; ProgressMeter _progressMeter; int _numYields{0}; diff --git a/src/mongo/db/curop_failpoint_helpers.cpp b/src/mongo/db/curop_failpoint_helpers.cpp index 5f2a4190de7..91f6f66db4e 100644 --- a/src/mongo/db/curop_failpoint_helpers.cpp +++ b/src/mongo/db/curop_failpoint_helpers.cpp @@ -36,24 +36,24 @@ namespace mongo { -std::string CurOpFailpointHelpers::updateCurOpMsg(OperationContext* opCtx, - const std::string& newMsg) { +std::string CurOpFailpointHelpers::updateCurOpFailPointMsg(OperationContext* opCtx, + const std::string& newMsg) { stdx::lock_guard<Client> lk(*opCtx->getClient()); - auto oldMsg = CurOp::get(opCtx)->getMessage(); - CurOp::get(opCtx)->setMessage_inlock(newMsg.c_str()); + auto oldMsg = CurOp::get(opCtx)->getFailPointMessage(); + CurOp::get(opCtx)->setFailPointMessage_inlock(newMsg.c_str()); return oldMsg; } void CurOpFailpointHelpers::waitWhileFailPointEnabled(FailPoint* failPoint, OperationContext* opCtx, - const std::string& curOpMsg, + const std::string& failpointMsg, const std::function<void()>& whileWaiting, bool checkForInterrupt, boost::optional<NamespaceString> nss) { invariant(failPoint); failPoint->executeIf( [&](const BSONObj& data) { - auto origCurOpMsg = updateCurOpMsg(opCtx, curOpMsg); + auto origCurOpFailpointMsg = updateCurOpFailPointMsg(opCtx, failpointMsg); const bool shouldCheckForInterrupt = checkForInterrupt || data["shouldCheckForInterrupt"].booleanSafe(); @@ -77,7 +77,7 @@ void CurOpFailpointHelpers::waitWhileFailPointEnabled(FailPoint* failPoint, opCtx->checkForInterrupt(); } } - updateCurOpMsg(opCtx, origCurOpMsg); + updateCurOpFailPointMsg(opCtx, origCurOpFailpointMsg); }, [&](const BSONObj& data) { StringData fpNss = data.getStringField("nss"); diff --git a/src/mongo/db/curop_failpoint_helpers.h b/src/mongo/db/curop_failpoint_helpers.h index a88bbc67e30..4a45d3a5cfa 100644 --- a/src/mongo/db/curop_failpoint_helpers.h +++ b/src/mongo/db/curop_failpoint_helpers.h @@ -39,7 +39,8 @@ public: * Helper function which sets the 'msg' field of the opCtx's CurOp to the specified string, and * returns the original value of the field. */ - static std::string updateCurOpMsg(OperationContext* opCtx, const std::string& newMsg); + static std::string updateCurOpFailPointMsg(OperationContext* opCtx, + const std::string& failpointMsg); /** * This helper function works much like FailPoint::pauseWhileSet(opCtx), but additionally @@ -59,7 +60,7 @@ public: */ static void waitWhileFailPointEnabled(FailPoint* failPoint, OperationContext* opCtx, - const std::string& curOpMsg, + const std::string& failpointMsg, const std::function<void()>& whileWaiting = nullptr, bool checkForInterrupt = false, boost::optional<NamespaceString> nss = boost::none); diff --git a/src/mongo/db/curop_test.cpp b/src/mongo/db/curop_test.cpp index 84d3db43edf..9120999c853 100644 --- a/src/mongo/db/curop_test.cpp +++ b/src/mongo/db/curop_test.cpp @@ -218,5 +218,20 @@ TEST(CurOpTest, OptionalAdditiveMetricsNotDisplayedIfUninitialized) { ASSERT_EQ(reportString, expectedReportString); } + +TEST(CurOpTest, ShouldNotReportFailpointMsgIfNotSet) { + QueryTestServiceContext serviceContext; + auto opCtx = serviceContext.makeOperationContext(); + + auto curop = CurOp::get(*opCtx); + + // Test the reported state should _not_ contain 'failpointMsg'. + BSONObjBuilder reportedStateWithoutFailpointMsg; + curop->reportState(opCtx.get(), &reportedStateWithoutFailpointMsg); + auto bsonObj = reportedStateWithoutFailpointMsg.done(); + + // bsonObj should _not_ contain 'failpointMsg' if a fail point is not set. + ASSERT_FALSE(bsonObj.hasField("failpointMsg")); +} } // namespace } // namespace mongo diff --git a/src/mongo/db/exhaust_cursor_currentop_integration_test.cpp b/src/mongo/db/exhaust_cursor_currentop_integration_test.cpp index 53e97568da1..e7c6001e99b 100644 --- a/src/mongo/db/exhaust_cursor_currentop_integration_test.cpp +++ b/src/mongo/db/exhaust_cursor_currentop_integration_test.cpp @@ -182,10 +182,11 @@ auto startExhaustQuery( void runOneGetMore(DBClientBase* conn, const std::unique_ptr<DBClientCursor>& queryCursor, int nDocsReturned) { - const auto curOpMatch = BSON("command.collection" << testNSS.coll() << "command.getMore" - << queryCursor->getCursorId() << "msg" - << "waitWithPinnedCursorDuringGetMoreBatch" - << "cursor.nDocsReturned" << nDocsReturned); + const auto curOpMatch = + BSON("command.collection" << testNSS.coll() << "command.getMore" + << queryCursor->getCursorId() << "failpointMsg" + << "waitWithPinnedCursorDuringGetMoreBatch" + << "cursor.nDocsReturned" << nDocsReturned); // Confirm that the initial getMore appears in the $currentOp output. ASSERT(confirmCurrentOpContents(conn, curOpMatch)); @@ -196,7 +197,7 @@ void runOneGetMore(DBClientBase* conn, // Confirm that the getMore completed its batch and hit the post-getMore failpoint. ASSERT(confirmCurrentOpContents( conn, - BSON("command.getMore" << queryCursor->getCursorId() << "msg" + BSON("command.getMore" << queryCursor->getCursorId() << "failpointMsg" << "waitBeforeUnpinningOrDeletingCursorAfterGetMoreBatch"))); // Re-enable the original failpoint to catch the next getMore, and release the current one. @@ -277,7 +278,7 @@ void testClientDisconnect(bool disconnectAfterGetMoreBatch) { // The next getMore will be an exhaust getMore. Confirm that the exhaust getMore appears in the // $currentOp output. auto curOpMatch = BSON("command.collection" << testNSS.coll() << "command.getMore" - << queryCursor->getCursorId() << "msg" + << queryCursor->getCursorId() << "failpointMsg" << "waitWithPinnedCursorDuringGetMoreBatch" << "cursor.nDocsReturned" << 3); ASSERT(confirmCurrentOpContents(conn.get(), curOpMatch)); @@ -288,7 +289,7 @@ void testClientDisconnect(bool disconnectAfterGetMoreBatch) { setWaitWithPinnedCursorDuringGetMoreBatchFailpoint(conn.get(), false); ASSERT(confirmCurrentOpContents(conn.get(), BSON("command.getMore" - << queryCursor->getCursorId() << "msg" + << queryCursor->getCursorId() << "failpointMsg" << "waitAfterCommandFinishesExecution"))); } |