diff options
author | Benety Goh <benety@mongodb.com> | 2020-02-14 13:27:00 -0500 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2020-02-14 18:53:40 +0000 |
commit | 7900aecab9210ef5a0e690239aad569bc6dfac5f (patch) | |
tree | e32d682ff596d8f7cbb296e7167adefa666644e9 /src/mongo/db/repl | |
parent | 542de84ec1e17520bd0d99d54a024ff0e0bc3de2 (diff) | |
download | mongo-7900aecab9210ef5a0e690239aad569bc6dfac5f.tar.gz |
SERVER-45885 ReplicationCoordinator::canAcceptWritesFor() accepts NamespaceStringOrUUID
Interface change only - invariants if UUID is provided.
Diffstat (limited to 'src/mongo/db/repl')
7 files changed, 28 insertions, 20 deletions
diff --git a/src/mongo/db/repl/replication_coordinator.h b/src/mongo/db/repl/replication_coordinator.h index 42b5e7503c8..9984d3803f3 100644 --- a/src/mongo/db/repl/replication_coordinator.h +++ b/src/mongo/db/repl/replication_coordinator.h @@ -260,13 +260,15 @@ public: * The result of this function should be consistent with canAcceptWritesForDatabase() * for the database the namespace refers to, with additional checks on the collection. */ - virtual bool canAcceptWritesFor(OperationContext* opCtx, const NamespaceString& ns) = 0; + virtual bool canAcceptWritesFor(OperationContext* opCtx, + const NamespaceStringOrUUID& nsOrUUID) = 0; /** * Version which does not check for the RSTL. Do not use in new code. Without the RSTL held, * the return value may be inaccurate by the time the function returns. */ - virtual bool canAcceptWritesFor_UNSAFE(OperationContext* opCtx, const NamespaceString& ns) = 0; + virtual bool canAcceptWritesFor_UNSAFE(OperationContext* opCtx, + const NamespaceStringOrUUID& nsOrUUID) = 0; /** * Checks if the current replica set configuration can satisfy the given write concern. diff --git a/src/mongo/db/repl/replication_coordinator_impl.cpp b/src/mongo/db/repl/replication_coordinator_impl.cpp index ba2d3a58528..7d0eb26c66c 100644 --- a/src/mongo/db/repl/replication_coordinator_impl.cpp +++ b/src/mongo/db/repl/replication_coordinator_impl.cpp @@ -2513,15 +2513,16 @@ bool ReplicationCoordinatorImpl::canAcceptNonLocalWrites() const { } bool ReplicationCoordinatorImpl::canAcceptWritesFor(OperationContext* opCtx, - const NamespaceString& ns) { - invariant(opCtx->lockState()->isRSTLLocked(), ns.ns()); - return canAcceptWritesFor_UNSAFE(opCtx, ns); + const NamespaceStringOrUUID& nsOrUUID) { + invariant(opCtx->lockState()->isRSTLLocked(), nsOrUUID.toString()); + return canAcceptWritesFor_UNSAFE(opCtx, nsOrUUID); } bool ReplicationCoordinatorImpl::canAcceptWritesFor_UNSAFE(OperationContext* opCtx, - const NamespaceString& ns) { - StringData dbName = ns.db(); - bool canWriteToDB = canAcceptWritesForDatabase_UNSAFE(opCtx, dbName); + const NamespaceStringOrUUID& nsOrUUID) { + invariant(nsOrUUID.nss(), nsOrUUID.toString()); + const auto& ns = *nsOrUUID.nss(); + bool canWriteToDB = canAcceptWritesForDatabase_UNSAFE(opCtx, nsOrUUID.db()); if (!canWriteToDB && !ns.isSystemDotProfile()) { return false; diff --git a/src/mongo/db/repl/replication_coordinator_impl.h b/src/mongo/db/repl/replication_coordinator_impl.h index e252ce389a5..39be77acb89 100644 --- a/src/mongo/db/repl/replication_coordinator_impl.h +++ b/src/mongo/db/repl/replication_coordinator_impl.h @@ -143,8 +143,10 @@ public: virtual bool canAcceptWritesForDatabase(OperationContext* opCtx, StringData dbName); virtual bool canAcceptWritesForDatabase_UNSAFE(OperationContext* opCtx, StringData dbName); - bool canAcceptWritesFor(OperationContext* opCtx, const NamespaceString& ns) override; - bool canAcceptWritesFor_UNSAFE(OperationContext* opCtx, const NamespaceString& ns) override; + bool canAcceptWritesFor(OperationContext* opCtx, + const NamespaceStringOrUUID& nsorUUID) override; + bool canAcceptWritesFor_UNSAFE(OperationContext* opCtx, + const NamespaceStringOrUUID& nsOrUUID) override; virtual Status checkIfWriteConcernCanBeSatisfied(const WriteConcernOptions& writeConcern) const; diff --git a/src/mongo/db/repl/replication_coordinator_mock.cpp b/src/mongo/db/repl/replication_coordinator_mock.cpp index 074a4e20103..b8ff01aefa4 100644 --- a/src/mongo/db/repl/replication_coordinator_mock.cpp +++ b/src/mongo/db/repl/replication_coordinator_mock.cpp @@ -178,14 +178,14 @@ bool ReplicationCoordinatorMock::canAcceptWritesForDatabase_UNSAFE(OperationCont } bool ReplicationCoordinatorMock::canAcceptWritesFor(OperationContext* opCtx, - const NamespaceString& ns) { + const NamespaceStringOrUUID& nsOrUUID) { // TODO - return canAcceptWritesForDatabase(opCtx, ns.db()); + return canAcceptWritesForDatabase(opCtx, nsOrUUID.db()); } bool ReplicationCoordinatorMock::canAcceptWritesFor_UNSAFE(OperationContext* opCtx, - const NamespaceString& ns) { - return canAcceptWritesFor(opCtx, ns); + const NamespaceStringOrUUID& nsOrUUID) { + return canAcceptWritesFor(opCtx, nsOrUUID); } Status ReplicationCoordinatorMock::checkCanServeReadsFor(OperationContext* opCtx, diff --git a/src/mongo/db/repl/replication_coordinator_mock.h b/src/mongo/db/repl/replication_coordinator_mock.h index 2b24406bfb2..80a368d25a2 100644 --- a/src/mongo/db/repl/replication_coordinator_mock.h +++ b/src/mongo/db/repl/replication_coordinator_mock.h @@ -110,9 +110,11 @@ public: virtual bool canAcceptWritesForDatabase_UNSAFE(OperationContext* opCtx, StringData dbName); - bool canAcceptWritesFor(OperationContext* opCtx, const NamespaceString& ns) override; + bool canAcceptWritesFor(OperationContext* opCtx, + const NamespaceStringOrUUID& nsOrUUID) override; - bool canAcceptWritesFor_UNSAFE(OperationContext* opCtx, const NamespaceString& ns) override; + bool canAcceptWritesFor_UNSAFE(OperationContext* opCtx, + const NamespaceStringOrUUID& nsOrUUID) override; virtual Status checkIfWriteConcernCanBeSatisfied(const WriteConcernOptions& writeConcern) const; diff --git a/src/mongo/db/repl/replication_coordinator_noop.cpp b/src/mongo/db/repl/replication_coordinator_noop.cpp index 0107f1a1aae..14089bcba5b 100644 --- a/src/mongo/db/repl/replication_coordinator_noop.cpp +++ b/src/mongo/db/repl/replication_coordinator_noop.cpp @@ -80,12 +80,12 @@ bool ReplicationCoordinatorNoOp::canAcceptWritesForDatabase_UNSAFE(OperationCont } bool ReplicationCoordinatorNoOp::canAcceptWritesFor_UNSAFE(OperationContext* opCtx, - const NamespaceString& ns) { + const NamespaceStringOrUUID& nsOrUUID) { MONGO_UNREACHABLE; } bool ReplicationCoordinatorNoOp::canAcceptWritesFor(OperationContext* opCtx, - const NamespaceString& ns) { + const NamespaceStringOrUUID& nsOrUUID) { MONGO_UNREACHABLE; } diff --git a/src/mongo/db/repl/replication_coordinator_noop.h b/src/mongo/db/repl/replication_coordinator_noop.h index d5e17658516..4c63d307335 100644 --- a/src/mongo/db/repl/replication_coordinator_noop.h +++ b/src/mongo/db/repl/replication_coordinator_noop.h @@ -72,8 +72,9 @@ public: bool canAcceptWritesForDatabase(OperationContext* opCtx, StringData dbName) final; bool canAcceptWritesForDatabase_UNSAFE(OperationContext* opCtx, StringData dbName) final; - bool canAcceptWritesFor(OperationContext* opCtx, const NamespaceString& ns) final; - bool canAcceptWritesFor_UNSAFE(OperationContext* opCtx, const NamespaceString& ns) final; + bool canAcceptWritesFor(OperationContext* opCtx, const NamespaceStringOrUUID& nsOrUUID) final; + bool canAcceptWritesFor_UNSAFE(OperationContext* opCtx, + const NamespaceStringOrUUID& nsOrUUID) final; Status checkCanServeReadsFor(OperationContext* opCtx, const NamespaceString& ns, |