diff options
author | Lingzhi Deng <lingzhi.deng@mongodb.com> | 2019-04-05 10:52:43 -0400 |
---|---|---|
committer | Lingzhi Deng <lingzhi.deng@mongodb.com> | 2019-04-09 12:45:33 -0400 |
commit | decf670a6d7ec7a31c3820032188aab3fdc0fbd1 (patch) | |
tree | 6a719219ba181ca0d64b193c93ff003ba71f95d6 | |
parent | 9f40ea669153868ee1df20ff8952b4f264198ce1 (diff) | |
download | mongo-decf670a6d7ec7a31c3820032188aab3fdc0fbd1.tar.gz |
SERVER-40337: Remove oldestOpenUnpreparedReadTimestamp from serverStatus.transactions
This reverts most of the work done in 3bb72042c29ceac96ec628ee643cbc4db8e982ab
5 files changed, 9 insertions, 83 deletions
diff --git a/jstests/noPassthrough/server_transaction_metrics.js b/jstests/noPassthrough/server_transaction_metrics.js index 191619ca3fc..a3d870f8a50 100644 --- a/jstests/noPassthrough/server_transaction_metrics.js +++ b/jstests/noPassthrough/server_transaction_metrics.js @@ -28,11 +28,6 @@ assert(serverStatusResponse.transactions.hasOwnProperty("totalStarted"), "The 'transactions' field in serverStatus did not have the 'totalStarted' field\n" + tojson(serverStatusResponse.transactions)); - assert( - serverStatusResponse.transactions.hasOwnProperty("oldestOpenUnpreparedReadTimestamp"), - "The 'transactions' field in serverStatus did not have the " + - "'oldestOpenUnpreparedReadTimestamp' field\n" + - tojson(serverStatusResponse.transactions)); } // Verifies that the given value of the server status response is incremented in the way @@ -71,10 +66,8 @@ jsTest.log("Start a transaction and then commit it."); // Compare server status after starting a transaction with the server status before. - session.startTransaction({readConcern: {level: 'snapshot'}}); + session.startTransaction(); assert.commandWorked(sessionColl.insert({_id: "insert-1"})); - // Trigger the oldestOpenUnpreparedReadTimestamp to be set. - assert.eq(sessionColl.find({_id: "insert-1"}).itcount(), 1); let newStatus = assert.commandWorked(testDB.adminCommand({serverStatus: 1})); verifyServerStatusFields(newStatus); @@ -85,8 +78,6 @@ initialStatus.transactions, newStatus.transactions, "currentActive", 0); verifyServerStatusChange( initialStatus.transactions, newStatus.transactions, "currentInactive", 1); - // Verify that the oldestOpenUnpreparedReadTimestamp has been set. - assert.gt(newStatus.transactions.oldestOpenUnpreparedReadTimestamp, Timestamp(0, 0)); // Compare server status after the transaction commit with the server status before. session.commitTransaction(); @@ -102,18 +93,13 @@ initialStatus.transactions, newStatus.transactions, "currentActive", 0); verifyServerStatusChange( initialStatus.transactions, newStatus.transactions, "currentInactive", 0); - // Verify that the oldestOpenUnpreparedReadTimestamp is a null timestamp since the transaction - // has closed. - assert.eq(newStatus.transactions.oldestOpenUnpreparedReadTimestamp, Timestamp(0, 0)); // This transaction will abort. jsTest.log("Start a transaction and then abort it."); // Compare server status after starting a transaction with the server status before. - session.startTransaction({readConcern: {level: 'snapshot'}}); + session.startTransaction(); assert.commandWorked(sessionColl.insert({_id: "insert-2"})); - // Trigger the oldestOpenUnpreparedReadTimestamp to be set. - assert.eq(sessionColl.find({_id: "insert-2"}).itcount(), 1); newStatus = assert.commandWorked(testDB.adminCommand({serverStatus: 1})); verifyServerStatusFields(newStatus); @@ -124,8 +110,6 @@ initialStatus.transactions, newStatus.transactions, "currentActive", 0); verifyServerStatusChange( initialStatus.transactions, newStatus.transactions, "currentInactive", 1); - // Verify that the oldestOpenUnpreparedReadTimestamp has been set. - assert.gt(newStatus.transactions.oldestOpenUnpreparedReadTimestamp, Timestamp(0, 0)); // Compare server status after the transaction abort with the server status before. session.abortTransaction_forTesting(); @@ -142,19 +126,14 @@ initialStatus.transactions, newStatus.transactions, "currentActive", 0); verifyServerStatusChange( initialStatus.transactions, newStatus.transactions, "currentInactive", 0); - // Verify that the oldestOpenUnpreparedReadTimestamp is a null timestamp since the transaction - // has closed. - assert.eq(newStatus.transactions.oldestOpenUnpreparedReadTimestamp, Timestamp(0, 0)); // This transaction will abort due to a duplicate key insert. jsTest.log("Start a transaction that will abort on a duplicated key error."); // Compare server status after starting a transaction with the server status before. - session.startTransaction({readConcern: {level: 'snapshot'}}); + session.startTransaction(); // Inserting a new document will work fine, and the transaction starts. assert.commandWorked(sessionColl.insert({_id: "insert-3"})); - // Trigger the oldestOpenUnpreparedReadTimestamp to be set. - assert.eq(sessionColl.find({_id: "insert-3"}).itcount(), 1); newStatus = assert.commandWorked(testDB.adminCommand({serverStatus: 1})); verifyServerStatusFields(newStatus); @@ -165,8 +144,6 @@ initialStatus.transactions, newStatus.transactions, "currentActive", 0); verifyServerStatusChange( initialStatus.transactions, newStatus.transactions, "currentInactive", 1); - // Verify that the oldestOpenUnpreparedReadTimestamp has been set. - assert.gt(newStatus.transactions.oldestOpenUnpreparedReadTimestamp, Timestamp(0, 0)); // Compare server status after the transaction abort with the server status before. // The duplicated insert will fail, causing the transaction to abort. @@ -236,9 +213,6 @@ initialStatus.transactions, newStatus.transactions, "currentActive", 0); verifyServerStatusChange( initialStatus.transactions, newStatus.transactions, "currentInactive", 0); - // Verify that the oldestOpenUnpreparedReadTimestamp is a null timestamp since the transaction - // has closed. - assert.eq(newStatus.transactions.oldestOpenUnpreparedReadTimestamp, Timestamp(0, 0)); // End the session and stop the replica set. session.endSession(); diff --git a/jstests/noPassthrough/server_transaction_metrics_for_prepared_transactions.js b/jstests/noPassthrough/server_transaction_metrics_for_prepared_transactions.js index ba599d711cf..74a3f0a347e 100644 --- a/jstests/noPassthrough/server_transaction_metrics_for_prepared_transactions.js +++ b/jstests/noPassthrough/server_transaction_metrics_for_prepared_transactions.js @@ -25,10 +25,6 @@ assert(serverStatusResponse.transactions.hasOwnProperty("currentPrepared"), "Expected the serverStatus response to have a 'currentPrepared' field: " + tojson(serverStatusResponse)); - assert( - serverStatusResponse.transactions.hasOwnProperty("oldestOpenUnpreparedReadTimestamp"), - "Expected the serverStatus response to have a 'oldestOpenUnpreparedReadTimestamp' " + - "field: " + tojson(serverStatusResponse)); } /** @@ -93,29 +89,20 @@ const doc1 = {_id: 1, x: 1}; // Start transaction and prepare transaction. - session.startTransaction({readConcern: {level: 'snapshot'}}); + session.startTransaction(); assert.commandWorked(sessionColl.insert(doc1)); - // Trigger the oldestOpenUnpreparedReadTimestamp to be set. - assert.eq(sessionColl.find(doc1).itcount(), 1); - let newStatus = assert.commandWorked(testDB.adminCommand({serverStatus: 1})); - assert.gt(newStatus.transactions.oldestOpenUnpreparedReadTimestamp, Timestamp(0, 0)); - const prepareTimestampForCommit = PrepareHelpers.prepareTransaction(session); // Verify the total and current prepared transaction counter is updated and the oldest active // oplog entry timestamp is shown. - newStatus = assert.commandWorked(testDB.adminCommand({serverStatus: 1})); + let newStatus = assert.commandWorked(testDB.adminCommand({serverStatus: 1})); verifyServerStatusFields(newStatus); verifyServerStatusChange( initialStatus.transactions, newStatus.transactions, "totalPrepared", 1); verifyServerStatusChange( initialStatus.transactions, newStatus.transactions, "currentPrepared", 1); - // Verify that the oldestOpenUnpreparedReadTimestamp is a null timestamp since the transaction - // has been prepared. - assert.eq(newStatus.transactions.oldestOpenUnpreparedReadTimestamp, Timestamp(0, 0)); - // Verify that the prepare entry has the oldest timestamp of any active transaction // in the transactions table. verifyOldestActiveTransactionTimestamp(testDB, prepareTimestampForCommit); @@ -135,9 +122,6 @@ initialStatus.transactions, newStatus.transactions, "totalPreparedThenAborted", 0); verifyServerStatusChange( initialStatus.transactions, newStatus.transactions, "totalPrepared", 1); - // Verify that the oldestOpenUnpreparedReadTimestamp is a null timestamp since the transaction - // is closed. - assert.eq(newStatus.transactions.oldestOpenUnpreparedReadTimestamp, Timestamp(0, 0)); // Test server metrics for a prepared transaction that is aborted. jsTest.log("Prepare a transaction and then abort it"); @@ -145,14 +129,9 @@ const doc2 = {_id: 2, x: 2}; // Start transaction and prepare transaction. - session.startTransaction({readConcern: {level: 'snapshot'}}); + session.startTransaction(); assert.commandWorked(sessionColl.insert(doc2)); - // Trigger the oldestOpenUnpreparedReadTimestamp to be set. - assert.eq(sessionColl.find(doc2).itcount(), 1); - newStatus = assert.commandWorked(testDB.adminCommand({serverStatus: 1})); - assert.gt(newStatus.transactions.oldestOpenUnpreparedReadTimestamp, Timestamp(0, 0)); - const prepareTimestampForAbort = PrepareHelpers.prepareTransaction(session); // Verify that the total and current prepared counter is updated and the oldest active oplog @@ -164,10 +143,6 @@ verifyServerStatusChange( initialStatus.transactions, newStatus.transactions, "currentPrepared", 1); - // Verify that the oldestOpenUnpreparedReadTimestamp is a null timestamp since the transaction - // has been prepared. - assert.eq(newStatus.transactions.oldestOpenUnpreparedReadTimestamp, Timestamp(0, 0)); - // Verify that the prepare entry has the oldest timestamp of any active transaction // in the transactions table. verifyOldestActiveTransactionTimestamp(testDB, prepareTimestampForAbort); @@ -182,10 +157,6 @@ verifyServerStatusChange( initialStatus.transactions, newStatus.transactions, "currentPrepared", 0); - // Verify that the oldestOpenUnpreparedReadTimestamp is a null timestamp since the transaction - // is closed. - assert.eq(newStatus.transactions.oldestOpenUnpreparedReadTimestamp, Timestamp(0, 0)); - // Verify that other prepared transaction metrics have not changed. verifyServerStatusChange( initialStatus.transactions, newStatus.transactions, "totalPreparedThenCommitted", 1); diff --git a/src/mongo/db/server_transactions_metrics.cpp b/src/mongo/db/server_transactions_metrics.cpp index 54300a1ca26..1daa320782d 100644 --- a/src/mongo/db/server_transactions_metrics.cpp +++ b/src/mongo/db/server_transactions_metrics.cpp @@ -149,15 +149,7 @@ void ServerTransactionsMetrics::decrementCurrentPrepared() { _currentPrepared.fetchAndSubtract(1); } -Timestamp ServerTransactionsMetrics::_getOldestOpenUnpreparedReadTimestamp( - OperationContext* opCtx) { - // The history is not pinned in memory once a transaction has been prepared since reads - // are no longer possible. Therefore, the timestamp returned by the storage engine refers - // to the oldest read timestamp for any open unprepared transaction. - return opCtx->getServiceContext()->getStorageEngine()->getOldestOpenReadTimestamp(); -} - -void ServerTransactionsMetrics::updateStats(TransactionsStats* stats, OperationContext* opCtx) { +void ServerTransactionsMetrics::updateStats(TransactionsStats* stats) { stats->setCurrentActive(_currentActive.load()); stats->setCurrentInactive(_currentInactive.load()); stats->setCurrentOpen(_currentOpen.load()); @@ -168,8 +160,6 @@ void ServerTransactionsMetrics::updateStats(TransactionsStats* stats, OperationC stats->setTotalPreparedThenCommitted(_totalPreparedThenCommitted.load()); stats->setTotalPreparedThenAborted(_totalPreparedThenAborted.load()); stats->setCurrentPrepared(_currentPrepared.load()); - stats->setOldestOpenUnpreparedReadTimestamp( - ServerTransactionsMetrics::_getOldestOpenUnpreparedReadTimestamp(opCtx)); } namespace { @@ -192,7 +182,7 @@ public: // lifecycle within a session. Both are assigned transaction numbers, and so both are often // referred to as “transactions”. RetryableWritesStats::get(opCtx)->updateStats(&stats); - ServerTransactionsMetrics::get(opCtx)->updateStats(&stats, opCtx); + ServerTransactionsMetrics::get(opCtx)->updateStats(&stats); return stats.toBSON(); } diff --git a/src/mongo/db/server_transactions_metrics.h b/src/mongo/db/server_transactions_metrics.h index d5b829f6845..250b2c41931 100644 --- a/src/mongo/db/server_transactions_metrics.h +++ b/src/mongo/db/server_transactions_metrics.h @@ -90,16 +90,9 @@ public: /** * Appends the accumulated stats to a transactions stats object. */ - void updateStats(TransactionsStats* stats, OperationContext* opCtx); + void updateStats(TransactionsStats* stats); private: - /** - * Returns the oldest read timestamp in use by any open unprepared transaction. This will - * return a null timestamp if there is no oldest open unprepared read timestamp to be - * returned. - */ - static Timestamp _getOldestOpenUnpreparedReadTimestamp(OperationContext* opCtx); - // The number of multi-document transactions currently active. AtomicWord<unsigned long long> _currentActive{0}; diff --git a/src/mongo/db/transactions_stats.idl b/src/mongo/db/transactions_stats.idl index ad70e141d6f..c2a269d4a79 100644 --- a/src/mongo/db/transactions_stats.idl +++ b/src/mongo/db/transactions_stats.idl @@ -83,5 +83,3 @@ structs: currentPrepared: type: long default: 0 - oldestOpenUnpreparedReadTimestamp: - type: timestamp |