mirror of
https://github.com/mongodb/mongo.git
synced 2024-12-01 09:32:32 +01:00
Revert "SERVER-24817 Make ShardLocal wait for writes it performed when doing majority reads"
This reverts commit 88daeb804d
.
This commit is contained in:
parent
598b6fa7c2
commit
ed19a4a874
@ -37,14 +37,12 @@
|
||||
#include "mongo/client/remote_command_targeter.h"
|
||||
#include "mongo/db/curop.h"
|
||||
#include "mongo/db/dbdirectclient.h"
|
||||
#include "mongo/db/repl/read_concern_response.h"
|
||||
#include "mongo/db/repl/repl_client_info.h"
|
||||
#include "mongo/db/repl/replica_set_config.h"
|
||||
#include "mongo/db/repl/replication_coordinator_global.h"
|
||||
#include "mongo/rpc/get_status_from_command_result.h"
|
||||
#include "mongo/rpc/unique_message.h"
|
||||
#include "mongo/util/log.h"
|
||||
#include "mongo/util/scopeguard.h"
|
||||
|
||||
namespace mongo {
|
||||
|
||||
@ -96,29 +94,10 @@ bool ShardLocal::isRetriableError(ErrorCodes::Error code, RetryPolicy options) {
|
||||
}
|
||||
}
|
||||
|
||||
void ShardLocal::_updateLastOpTimeFromClient(OperationContext* txn) {
|
||||
repl::OpTime lastOpTimeFromClient =
|
||||
repl::ReplClientInfo::forClient(txn->getClient()).getLastOp();
|
||||
if (lastOpTimeFromClient.isNull()) {
|
||||
return;
|
||||
}
|
||||
|
||||
stdx::lock_guard<stdx::mutex> lk(_mutex);
|
||||
invariant(lastOpTimeFromClient >= _lastOpTime);
|
||||
_lastOpTime = lastOpTimeFromClient;
|
||||
}
|
||||
|
||||
repl::OpTime ShardLocal::_getLastOpTime() {
|
||||
stdx::lock_guard<stdx::mutex> lk(_mutex);
|
||||
return _lastOpTime;
|
||||
}
|
||||
|
||||
StatusWith<Shard::CommandResponse> ShardLocal::_runCommand(OperationContext* txn,
|
||||
const ReadPreferenceSetting& unused,
|
||||
const std::string& dbName,
|
||||
const BSONObj& cmdObj) {
|
||||
ON_BLOCK_EXIT([this, &txn] { _updateLastOpTimeFromClient(txn); });
|
||||
|
||||
try {
|
||||
DBDirectClient client(txn);
|
||||
rpc::UniqueReply commandResponse = client.runCommandWithMetadata(
|
||||
@ -155,21 +134,16 @@ StatusWith<Shard::QueryResponse> ShardLocal::_exhaustiveFindOnConfig(
|
||||
// Set up operation context with majority read snapshot so correct optime can be retrieved.
|
||||
Status status = txn->recoveryUnit()->setReadFromMajorityCommittedSnapshot();
|
||||
|
||||
// Wait for any writes performed by this ShardLocal instance to be committed and visible.
|
||||
auto readConcernResponse = replCoord->waitUntilOpTime(
|
||||
txn, repl::ReadConcernArgs{_getLastOpTime(), readConcernLevel});
|
||||
if (!readConcernResponse.getStatus().isOK()) {
|
||||
if (readConcernResponse.getStatus() == ErrorCodes::ShutdownInProgress ||
|
||||
ErrorCodes::isInterruption(readConcernResponse.getStatus().code())) {
|
||||
return readConcernResponse.getStatus();
|
||||
}
|
||||
fassertStatusOK(40188, readConcernResponse.getStatus());
|
||||
// Wait until a snapshot is available.
|
||||
while (status == ErrorCodes::ReadConcernMajorityNotAvailableYet) {
|
||||
LOG(1) << "Waiting for ReadFromMajorityCommittedSnapshot to become available";
|
||||
replCoord->waitUntilSnapshotCommitted(txn, SnapshotName::min());
|
||||
status = txn->recoveryUnit()->setReadFromMajorityCommittedSnapshot();
|
||||
}
|
||||
|
||||
// Inform the storage engine to read from the committed snapshot for the rest of this
|
||||
// operation.
|
||||
status = txn->recoveryUnit()->setReadFromMajorityCommittedSnapshot();
|
||||
fassertStatusOK(40189, status);
|
||||
if (!status.isOK()) {
|
||||
return status;
|
||||
}
|
||||
} else {
|
||||
invariant(readConcernLevel == repl::ReadConcernLevel::kLocalReadConcern);
|
||||
}
|
||||
|
@ -30,9 +30,7 @@
|
||||
|
||||
#include "mongo/base/disallow_copying.h"
|
||||
#include "mongo/client/dbclientinterface.h"
|
||||
#include "mongo/db/repl/optime.h"
|
||||
#include "mongo/s/client/shard.h"
|
||||
#include "mongo/stdx/mutex.h"
|
||||
|
||||
namespace mongo {
|
||||
|
||||
@ -77,23 +75,6 @@ private:
|
||||
const BSONObj& query,
|
||||
const BSONObj& sort,
|
||||
boost::optional<long long> limit) final;
|
||||
|
||||
/**
|
||||
* Checks if an OpTime was set on the current Client (ie if the current operation performed a
|
||||
* write) and if so updates _lastOpTime to the OpTime from the write that was just performed.
|
||||
*/
|
||||
void _updateLastOpTimeFromClient(OperationContext* txn);
|
||||
|
||||
repl::OpTime _getLastOpTime();
|
||||
|
||||
// Guards _lastOpTime below.
|
||||
stdx::mutex _mutex;
|
||||
|
||||
// Stores the optime that was generated by the last operation to perform a write that was run
|
||||
// through _runCommand. Used in _exhaustiveFindOnConfig for waiting for that optime to be
|
||||
// committed so that readConcern majority reads will read the writes that were performed without
|
||||
// a w:majority write concern.
|
||||
repl::OpTime _lastOpTime{};
|
||||
};
|
||||
|
||||
} // namespace mongo
|
||||
|
Loading…
Reference in New Issue
Block a user