diff options
author | Ben Caimano <ben.caimano@10gen.com> | 2020-10-16 22:47:21 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2020-10-20 18:57:54 +0000 |
commit | 77963415a45ac22d3f460c2c4ed8d826c618d719 (patch) | |
tree | 22404c85ab42db0c3eedf4f0b2b6d2d82a4495b3 /src/mongo/rpc | |
parent | ccf9e4a709141808476621583f2c3b986ebe29a3 (diff) | |
download | mongo-77963415a45ac22d3f460c2c4ed8d826c618d719.tar.gz |
SERVER-49336 Allow ClientMetadata to be accessed before it is finalized
Diffstat (limited to 'src/mongo/rpc')
-rw-r--r-- | src/mongo/rpc/metadata/client_metadata.cpp | 6 | ||||
-rw-r--r-- | src/mongo/rpc/metadata/client_metadata.h | 5 |
2 files changed, 6 insertions, 5 deletions
diff --git a/src/mongo/rpc/metadata/client_metadata.cpp b/src/mongo/rpc/metadata/client_metadata.cpp index a4b78080ec9..ccd11fb542e 100644 --- a/src/mongo/rpc/metadata/client_metadata.cpp +++ b/src/mongo/rpc/metadata/client_metadata.cpp @@ -472,7 +472,8 @@ bool ClientMetadata::tryFinalize(Client* client) { const ClientMetadata* ClientMetadata::getForClient(Client* client) noexcept { auto& state = getClientState(client); - if (!state.isFinalized || !state.meta) { + if (!state.meta) { + // If we haven't finalized, it's still okay to return our existing value. return nullptr; } return &state.meta.get(); @@ -514,7 +515,7 @@ void ClientMetadata::setFromMetadataForOperation(OperationContext* opCtx, BSONEl auto wasFinalized = std::exchange(state.isFinalized, true); uassert(ErrorCodes::ClientMetadataCannotBeMutated, "The client metadata document may only be set once per operation", - !wasFinalized); + !state.meta && !wasFinalized); state.meta = ClientMetadata::readFromMetadata(elem); } @@ -541,6 +542,7 @@ void ClientMetadata::setFromMetadata(Client* client, BSONElement& elem) { } auto lk = stdx::lock_guard(*client); + invariant(!state.meta, "ClientMetadata was previously set, it should be set precisely once"); state.meta = std::move(meta); } diff --git a/src/mongo/rpc/metadata/client_metadata.h b/src/mongo/rpc/metadata/client_metadata.h index ff17cf60720..3742cf21a35 100644 --- a/src/mongo/rpc/metadata/client_metadata.h +++ b/src/mongo/rpc/metadata/client_metadata.h @@ -90,9 +90,8 @@ public: /** * Get the ClientMetadata for the Client. * - * This function may return nullptr for either of two reasons: - * - The ClientMetadata hasn't been finalized yet via tryFinalize(). - * - The ClientMetadata wasn't provided at all. + * This function may return nullptr if there was no ClientMetadata provided for the + * Client. * * The pointer to ClientMetadata is valid to use if: * - You hold the Client lock. |