summaryrefslogtreecommitdiff
path: root/src/mongo/db
diff options
context:
space:
mode:
authorLamont Nelson <lamont.nelson@mongodb.com>2019-09-06 21:26:48 +0000
committerLamont Nelson <lamont.nelson@mongodb.com>2019-09-10 15:27:54 -0400
commit8f231ff570b1de07e33a6f87f72d17180b4b7d89 (patch)
tree0849ed40ce3fb01aba8a558096594ad03e65cdc4 /src/mongo/db
parent6c2e7dd59395c04ac00caf45e239b0949caef183 (diff)
downloadmongo-8f231ff570b1de07e33a6f87f72d17180b4b7d89.tar.gz
SERVER-41615: set flag to denote that the coordinator has recovered.
(cherry picked from commit 398471a4fde3cdd7ca57f6bbf601ad66998b1150)
Diffstat (limited to 'src/mongo/db')
-rw-r--r--src/mongo/db/s/single_transaction_coordinator_stats.cpp6
-rw-r--r--src/mongo/db/s/single_transaction_coordinator_stats.h5
-rw-r--r--src/mongo/db/s/transaction_coordinator.cpp6
-rw-r--r--src/mongo/db/s/transaction_coordinator_metrics_observer.cpp6
-rw-r--r--src/mongo/db/s/transaction_coordinator_metrics_observer.h5
-rw-r--r--src/mongo/db/s/transaction_coordinator_test.cpp33
6 files changed, 56 insertions, 5 deletions
diff --git a/src/mongo/db/s/single_transaction_coordinator_stats.cpp b/src/mongo/db/s/single_transaction_coordinator_stats.cpp
index 1ef6209f3c9..585e1c97188 100644
--- a/src/mongo/db/s/single_transaction_coordinator_stats.cpp
+++ b/src/mongo/db/s/single_transaction_coordinator_stats.cpp
@@ -96,6 +96,10 @@ void SingleTransactionCoordinatorStats::setDeletingCoordinatorDocStartTime(
_deletingCoordinatorDocStartWallClockTime = curWallClockTime;
}
+void SingleTransactionCoordinatorStats::setRecoveredFromFailover() {
+ _hasRecoveredFromFailover = true;
+}
+
Microseconds SingleTransactionCoordinatorStats::getDurationSinceCreation(
TickSource* tickSource, TickSource::Tick curTick) const {
invariant(_createTime);
@@ -198,6 +202,7 @@ void SingleTransactionCoordinatorStats::reportMetrics(BSONObjBuilder& parent,
invariant(_createTime);
parent.append("commitStartTime", _createWallClockTime);
+ parent.append("hasRecoveredFromFailover", _hasRecoveredFromFailover);
if (_writingParticipantListStartTime) {
const auto statValue = getWritingParticipantListDuration(tickSource, curTick);
@@ -243,5 +248,4 @@ void SingleTransactionCoordinatorStats::reportLastClient(BSONObjBuilder& parent)
parent.append("appName", _lastClientInfo.appName);
parent.append("clientMetadata", _lastClientInfo.clientMetadata);
}
-
} // namespace mongo
diff --git a/src/mongo/db/s/single_transaction_coordinator_stats.h b/src/mongo/db/s/single_transaction_coordinator_stats.h
index 1856bf9b054..a6d8be9b54f 100644
--- a/src/mongo/db/s/single_transaction_coordinator_stats.h
+++ b/src/mongo/db/s/single_transaction_coordinator_stats.h
@@ -281,6 +281,10 @@ public:
invariant(client);
_lastClientInfo.update(client);
}
+ /*
+ * Marks this transaction coordinator has having recovered from failure.
+ */
+ void setRecoveredFromFailover();
private:
Date_t _createWallClockTime;
@@ -307,6 +311,7 @@ private:
TickSource::Tick _endTime{0};
LastClientInfo _lastClientInfo;
+ bool _hasRecoveredFromFailover = false;
};
} // namespace mongo
diff --git a/src/mongo/db/s/transaction_coordinator.cpp b/src/mongo/db/s/transaction_coordinator.cpp
index 7cfe3f90231..903ac4a71fc 100644
--- a/src/mongo/db/s/transaction_coordinator.cpp
+++ b/src/mongo/db/s/transaction_coordinator.cpp
@@ -145,7 +145,6 @@ TransactionCoordinator::TransactionCoordinator(OperationContext* operationContex
_step = Step::kWritingParticipantList;
- // TODO: The duration will be meaningless after failover.
_transactionCoordinatorMetricsObserver->onStartWritingParticipantList(
ServerTransactionCoordinatorsMetrics::get(_serviceContext),
_serviceContext->getTickSource(),
@@ -184,7 +183,6 @@ TransactionCoordinator::TransactionCoordinator(OperationContext* operationContex
_step = Step::kWaitingForVotes;
- // TODO: The duration will be meaningless after failover.
_transactionCoordinatorMetricsObserver->onStartWaitingForVotes(
ServerTransactionCoordinatorsMetrics::get(_serviceContext),
_serviceContext->getTickSource(),
@@ -226,7 +224,6 @@ TransactionCoordinator::TransactionCoordinator(OperationContext* operationContex
_step = Step::kWritingDecision;
- // TODO: The duration will be meaningless after failover.
_transactionCoordinatorMetricsObserver->onStartWritingDecision(
ServerTransactionCoordinatorsMetrics::get(_serviceContext),
_serviceContext->getTickSource(),
@@ -259,7 +256,6 @@ TransactionCoordinator::TransactionCoordinator(OperationContext* operationContex
_step = Step::kWaitingForDecisionAcks;
- // TODO: The duration will be meaningless after failover.
_transactionCoordinatorMetricsObserver->onStartWaitingForDecisionAcks(
ServerTransactionCoordinatorsMetrics::get(_serviceContext),
_serviceContext->getTickSource(),
@@ -342,6 +338,8 @@ void TransactionCoordinator::continueCommit(const TransactionCoordinatorDocument
if (!_reserveKickOffCommitPromise())
return;
+ _transactionCoordinatorMetricsObserver->onRecoveryFromFailover();
+
_participants = std::move(doc.getParticipants());
if (doc.getDecision()) {
_participantsDurable = true;
diff --git a/src/mongo/db/s/transaction_coordinator_metrics_observer.cpp b/src/mongo/db/s/transaction_coordinator_metrics_observer.cpp
index 42b82236430..dffdfdcba19 100644
--- a/src/mongo/db/s/transaction_coordinator_metrics_observer.cpp
+++ b/src/mongo/db/s/transaction_coordinator_metrics_observer.cpp
@@ -51,6 +51,12 @@ void TransactionCoordinatorMetricsObserver::onCreate(
serverTransactionCoordinatorsMetrics->incrementTotalCreated();
}
+
+void TransactionCoordinatorMetricsObserver::onRecoveryFromFailover() {
+ _singleTransactionCoordinatorStats.setRecoveredFromFailover();
+}
+
+
void TransactionCoordinatorMetricsObserver::onStartWritingParticipantList(
ServerTransactionCoordinatorsMetrics* serverTransactionCoordinatorsMetrics,
TickSource* tickSource,
diff --git a/src/mongo/db/s/transaction_coordinator_metrics_observer.h b/src/mongo/db/s/transaction_coordinator_metrics_observer.h
index 9d73e64f6c7..535c865da0b 100644
--- a/src/mongo/db/s/transaction_coordinator_metrics_observer.h
+++ b/src/mongo/db/s/transaction_coordinator_metrics_observer.h
@@ -50,6 +50,11 @@ public:
Date_t curWallClockTime);
/**
+ * Called when the transaction coordinator has recovered and continues the commit.
+ */
+ void onRecoveryFromFailover();
+
+ /**
* Updates relevant metrics when a transaction coordinator is about to write the participant
* list.
*/
diff --git a/src/mongo/db/s/transaction_coordinator_test.cpp b/src/mongo/db/s/transaction_coordinator_test.cpp
index 4d7487db52d..f91977bf16e 100644
--- a/src/mongo/db/s/transaction_coordinator_test.cpp
+++ b/src/mongo/db/s/transaction_coordinator_test.cpp
@@ -2324,6 +2324,39 @@ TEST_F(TransactionCoordinatorMetricsTest,
checkServerStatus();
}
+TEST_F(TransactionCoordinatorMetricsTest, RecoveryFromFailureIndicatedInReportState) {
+ TransactionCoordinator coordinator(
+ operationContext(),
+ _lsid,
+ _txnNumber,
+ std::make_unique<txn::AsyncWorkScheduler>(getServiceContext()),
+ Date_t::max());
+
+ const auto assertRecoveryFlag = [&coordinator](bool expectedFlagValue) {
+ BSONObjBuilder builder;
+ coordinator.reportState(builder);
+ auto reportDoc = builder.obj();
+ auto coordinatorDoc = reportDoc.getObjectField("twoPhaseCommitCoordinator");
+ ASSERT_EQ(coordinatorDoc.getBoolField("hasRecoveredFromFailover"), expectedFlagValue);
+ };
+
+ assertRecoveryFlag(false);
+
+ TransactionCoordinatorDocument coordinatorDoc;
+ coordinatorDoc.setParticipants(kTwoShardIdList);
+ coordinator.continueCommit(coordinatorDoc);
+
+ assertRecoveryFlag(true);
+
+ assertPrepareSentAndRespondWithSuccess();
+ assertPrepareSentAndRespondWithSuccess();
+
+ assertCommitSentAndRespondWithSuccess();
+ assertCommitSentAndRespondWithSuccess();
+
+ coordinator.onCompletion().get();
+}
+
TEST_F(TransactionCoordinatorMetricsTest, ClientInformationIncludedInReportState) {
const auto expectedAppName = std::string("Foo");
associateClientMetadata(getClient(), expectedAppName);