mirror of https://github.com/mongodb/mongo
SERVER-112081 Label causal consistency module (#44128)
GitOrigin-RevId: 4b02ad8ef04cc4788ab40242694782197c72b038
This commit is contained in:
parent
f4e88b9c67
commit
d8496c0a18
|
|
@ -93,6 +93,7 @@ core.service:
|
|||
- src/mongo/db/commands/test_deprecation_command.cpp
|
||||
- src/mongo/db/s/forwardable_operation_metadata*
|
||||
- src/mongo/embedded
|
||||
- src/mongo/db/logical_time.*
|
||||
|
||||
# stuff that is part of a *specific* mongo server (eg mongos, mongod)
|
||||
core.servers:
|
||||
|
|
@ -490,15 +491,16 @@ field_level_encryption.crypt_shared:
|
|||
files:
|
||||
- src/mongo/db/modules/enterprise/src/fle/lib
|
||||
|
||||
causal_consistency:
|
||||
catalog_and_routing.topology.causal_consistency:
|
||||
meta:
|
||||
slack: server-sharding
|
||||
jira: Cluster Scalability
|
||||
files:
|
||||
- src/mongo/db/keys_collection*
|
||||
- src/mongo/db/key_generator*
|
||||
- src/mongo/db/*logical_time*
|
||||
- src/mongo/db/logical_time_*
|
||||
- src/mongo/db/time_proof_service*
|
||||
- src/mongo/db/signed_logical_time*
|
||||
|
||||
data_movement:
|
||||
meta:
|
||||
|
|
|
|||
|
|
@ -31,6 +31,7 @@
|
|||
|
||||
#include "mongo/base/status.h"
|
||||
#include "mongo/util/duration.h"
|
||||
#include "mongo/util/modules.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
|
|
|
|||
|
|
@ -35,6 +35,7 @@
|
|||
#include "mongo/db/logical_time.h"
|
||||
#include "mongo/db/operation_context.h"
|
||||
#include "mongo/stdx/mutex.h"
|
||||
#include "mongo/util/modules.h"
|
||||
|
||||
#include <map>
|
||||
#include <string>
|
||||
|
|
|
|||
|
|
@ -32,6 +32,7 @@
|
|||
#include "mongo/base/status_with.h"
|
||||
#include "mongo/base/string_data.h"
|
||||
#include "mongo/db/keys_collection_document_gen.h"
|
||||
#include "mongo/util/modules.h"
|
||||
|
||||
#include <vector>
|
||||
|
||||
|
|
@ -41,7 +42,7 @@ class BSONObj;
|
|||
class LogicalTime;
|
||||
class OperationContext;
|
||||
|
||||
class KeysCollectionClient {
|
||||
class MONGO_MOD_NEEDS_REPLACEMENT KeysCollectionClient {
|
||||
public:
|
||||
virtual ~KeysCollectionClient() = default;
|
||||
|
||||
|
|
@ -50,7 +51,7 @@ public:
|
|||
* clusters that this node is in) that match the given purpose and have an expiresAt value
|
||||
* greater than newerThanThis. Uses readConcern level majority if possible.
|
||||
*/
|
||||
virtual StatusWith<std::vector<KeysCollectionDocument>> getNewInternalKeys(
|
||||
MONGO_MOD_PRIVATE virtual StatusWith<std::vector<KeysCollectionDocument>> getNewInternalKeys(
|
||||
OperationContext* opCtx,
|
||||
StringData purpose,
|
||||
const LogicalTime& newerThanThis,
|
||||
|
|
@ -60,19 +61,19 @@ public:
|
|||
* Returns all external keys (validation-only keys copied from other clusters) that match the
|
||||
* given purpose.
|
||||
*/
|
||||
virtual StatusWith<std::vector<ExternalKeysCollectionDocument>> getAllExternalKeys(
|
||||
OperationContext* opCtx, StringData purpose) = 0;
|
||||
MONGO_MOD_PRIVATE virtual StatusWith<std::vector<ExternalKeysCollectionDocument>>
|
||||
getAllExternalKeys(OperationContext* opCtx, StringData purpose) = 0;
|
||||
|
||||
/**
|
||||
* Directly inserts a key document to the storage
|
||||
*/
|
||||
virtual Status insertNewKey(OperationContext* opCtx, const BSONObj& doc) = 0;
|
||||
MONGO_MOD_PRIVATE virtual Status insertNewKey(OperationContext* opCtx, const BSONObj& doc) = 0;
|
||||
|
||||
/**
|
||||
* Returns true if the client can only read with local read concern, which means keys read by a
|
||||
* refresh may be rolled back.
|
||||
*/
|
||||
virtual bool mustUseLocalReads() const = 0;
|
||||
MONGO_MOD_PRIVATE virtual bool mustUseLocalReads() const = 0;
|
||||
};
|
||||
|
||||
} // namespace mongo
|
||||
|
|
|
|||
|
|
@ -44,6 +44,7 @@
|
|||
#include "mongo/db/rs_local_client.h"
|
||||
#include "mongo/db/sharding_environment/client/shard.h"
|
||||
#include "mongo/db/write_concern_options.h"
|
||||
#include "mongo/util/modules.h"
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
|
@ -57,7 +58,7 @@ class OperationContext;
|
|||
class LogicalTime;
|
||||
class BSONObj;
|
||||
|
||||
class KeysCollectionClientDirect : public KeysCollectionClient {
|
||||
class MONGO_MOD_NEEDS_REPLACEMENT KeysCollectionClientDirect : public KeysCollectionClient {
|
||||
public:
|
||||
KeysCollectionClientDirect(bool mustUseLocalReads);
|
||||
|
||||
|
|
@ -65,7 +66,7 @@ public:
|
|||
* Returns internal keys for the given purpose and have an expiresAt value greater than
|
||||
* newerThanThis. Uses readConcern level majority if possible.
|
||||
*/
|
||||
StatusWith<std::vector<KeysCollectionDocument>> getNewInternalKeys(
|
||||
MONGO_MOD_PRIVATE StatusWith<std::vector<KeysCollectionDocument>> getNewInternalKeys(
|
||||
OperationContext* opCtx,
|
||||
StringData purpose,
|
||||
const LogicalTime& newerThanThis,
|
||||
|
|
@ -74,19 +75,19 @@ public:
|
|||
/**
|
||||
* Returns all external (i.e. validation-only) keys for the given purpose.
|
||||
*/
|
||||
StatusWith<std::vector<ExternalKeysCollectionDocument>> getAllExternalKeys(
|
||||
MONGO_MOD_PRIVATE StatusWith<std::vector<ExternalKeysCollectionDocument>> getAllExternalKeys(
|
||||
OperationContext* opCtx, StringData purpose) override;
|
||||
|
||||
/**
|
||||
* Directly inserts a key document to the storage
|
||||
*/
|
||||
Status insertNewKey(OperationContext* opCtx, const BSONObj& doc) override;
|
||||
MONGO_MOD_PRIVATE Status insertNewKey(OperationContext* opCtx, const BSONObj& doc) override;
|
||||
|
||||
/**
|
||||
* Returns true if getNewKeys always uses readConcern level:local, so the documents returned can
|
||||
* be rolled back.
|
||||
*/
|
||||
bool mustUseLocalReads() const final {
|
||||
MONGO_MOD_PRIVATE bool mustUseLocalReads() const final {
|
||||
return _mustUseLocalReads;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -36,6 +36,7 @@
|
|||
#include "mongo/db/keys_collection_client.h"
|
||||
#include "mongo/db/keys_collection_document_gen.h"
|
||||
#include "mongo/db/logical_time.h"
|
||||
#include "mongo/util/modules.h"
|
||||
|
||||
#include <vector>
|
||||
|
||||
|
|
@ -43,7 +44,7 @@ namespace mongo {
|
|||
|
||||
class ShardingCatalogClient;
|
||||
|
||||
class KeysCollectionClientSharded : public KeysCollectionClient {
|
||||
class MONGO_MOD_NEEDS_REPLACEMENT KeysCollectionClientSharded : public KeysCollectionClient {
|
||||
public:
|
||||
KeysCollectionClientSharded(ShardingCatalogClient*);
|
||||
|
||||
|
|
@ -51,7 +52,7 @@ public:
|
|||
* Returns internal keys for the given purpose and have an expiresAt value greater than
|
||||
* newerThanThis on the config server. Uses readConcern level majority if possible.
|
||||
*/
|
||||
StatusWith<std::vector<KeysCollectionDocument>> getNewInternalKeys(
|
||||
MONGO_MOD_PRIVATE StatusWith<std::vector<KeysCollectionDocument>> getNewInternalKeys(
|
||||
OperationContext* opCtx,
|
||||
StringData purpose,
|
||||
const LogicalTime& newerThanThis,
|
||||
|
|
@ -60,15 +61,15 @@ public:
|
|||
/**
|
||||
* Returns all external (i.e. validation-only) keys for the given purpose on the config server.
|
||||
*/
|
||||
StatusWith<std::vector<ExternalKeysCollectionDocument>> getAllExternalKeys(
|
||||
MONGO_MOD_PRIVATE StatusWith<std::vector<ExternalKeysCollectionDocument>> getAllExternalKeys(
|
||||
OperationContext* opCtx, StringData purpose) override;
|
||||
|
||||
/**
|
||||
* Directly inserts a key document to the storage
|
||||
*/
|
||||
Status insertNewKey(OperationContext* opCtx, const BSONObj& doc) override;
|
||||
MONGO_MOD_PRIVATE Status insertNewKey(OperationContext* opCtx, const BSONObj& doc) override;
|
||||
|
||||
bool mustUseLocalReads() const final {
|
||||
MONGO_MOD_PRIVATE bool mustUseLocalReads() const final {
|
||||
// Reads are always made against the config server with majority read concern.
|
||||
return false;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -37,6 +37,7 @@ structs:
|
|||
description: >-
|
||||
Contains the fields shared by key documents stored in admin.system.keys and
|
||||
config.external_validation_keys.
|
||||
mod_visibility: needs_replacement
|
||||
strict: true
|
||||
fields:
|
||||
purpose:
|
||||
|
|
@ -52,6 +53,7 @@ structs:
|
|||
keysCollectionDocument:
|
||||
description: >-
|
||||
Represents a key document stored in admin.system.keys.
|
||||
mod_visibility: needs_replacement
|
||||
strict: true
|
||||
inline_chained_structs: true
|
||||
chained_structs:
|
||||
|
|
@ -66,6 +68,7 @@ structs:
|
|||
externalKeysCollectionDocument:
|
||||
description: >-
|
||||
Represents a key document stored in config.external_validation_keys.
|
||||
mod_visibility: needs_replacement
|
||||
strict: true
|
||||
inline_chained_structs: true
|
||||
chained_structs:
|
||||
|
|
|
|||
|
|
@ -43,6 +43,7 @@
|
|||
#include "mongo/stdx/thread.h"
|
||||
#include "mongo/util/concurrency/notification.h"
|
||||
#include "mongo/util/duration.h"
|
||||
#include "mongo/util/modules.h"
|
||||
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
|
|
@ -74,7 +75,8 @@ Milliseconds howMuchSleepNeedFor(const LogicalTime& currentTime,
|
|||
* HMAC computation. It maintains an internal background thread that is used to periodically
|
||||
* refresh the local key cache against the keys collection stored on the config servers.
|
||||
*/
|
||||
class KeysCollectionManager {
|
||||
// TODO This class should be parent_private ideally
|
||||
class MONGO_MOD_NEEDS_REPLACEMENT KeysCollectionManager {
|
||||
public:
|
||||
static const unsigned kReadConcernMajorityNotAvailableYetMaxTries;
|
||||
static const Milliseconds kRefreshIntervalIfErrored;
|
||||
|
|
|
|||
|
|
@ -35,6 +35,7 @@ server_parameters:
|
|||
Specifies the number of seconds for which an HMAC signing key is valid before
|
||||
rotating to the next one. This parameter is intended primarily to facilitate
|
||||
authentication testing.
|
||||
mod_visibility: needs_replacement
|
||||
set_at: [startup]
|
||||
cpp_vartype: int
|
||||
cpp_varname: KeysRotationIntervalSec
|
||||
|
|
|
|||
|
|
@ -33,6 +33,7 @@
|
|||
#include "mongo/db/keys_collection_document_gen.h"
|
||||
#include "mongo/db/operation_context.h"
|
||||
#include "mongo/db/repl/optime.h"
|
||||
#include "mongo/util/modules.h"
|
||||
#include "mongo/util/time_support.h"
|
||||
#include "mongo/util/uuid.h"
|
||||
|
||||
|
|
@ -47,15 +48,15 @@ namespace keys_collection_util {
|
|||
* Creates an ExternalKeysCollectionDocument representing an config.external_validation_keys
|
||||
* document created based on the given the admin.system.keys document BSONObj.
|
||||
*/
|
||||
ExternalKeysCollectionDocument makeExternalClusterTimeKeyDoc(BSONObj keyDoc,
|
||||
boost::optional<Date_t> expireAt);
|
||||
MONGO_MOD_PARENT_PRIVATE ExternalKeysCollectionDocument
|
||||
makeExternalClusterTimeKeyDoc(BSONObj keyDoc, boost::optional<Date_t> expireAt);
|
||||
|
||||
/*
|
||||
* Upserts the given ExternalKeysCollectionDocuments into the
|
||||
* config.external_validation_keys collection, and returns the optime for the upserts.
|
||||
*/
|
||||
repl::OpTime storeExternalClusterTimeKeyDocs(OperationContext* opCtx,
|
||||
std::vector<ExternalKeysCollectionDocument> keyDocs);
|
||||
MONGO_MOD_PARENT_PRIVATE repl::OpTime storeExternalClusterTimeKeyDocs(
|
||||
OperationContext* opCtx, std::vector<ExternalKeysCollectionDocument> keyDocs);
|
||||
|
||||
} // namespace keys_collection_util
|
||||
} // namespace mongo
|
||||
|
|
|
|||
|
|
@ -39,6 +39,7 @@
|
|||
#include "mongo/db/time_proof_service.h"
|
||||
#include "mongo/unittest/unittest.h"
|
||||
#include "mongo/util/assert_util.h"
|
||||
#include "mongo/util/modules.h"
|
||||
|
||||
#include <cstddef>
|
||||
|
||||
|
|
|
|||
|
|
@ -37,6 +37,7 @@
|
|||
#include "mongo/db/signed_logical_time.h"
|
||||
#include "mongo/db/time_proof_service.h"
|
||||
#include "mongo/stdx/mutex.h"
|
||||
#include "mongo/util/modules.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
|
|
@ -51,7 +52,7 @@ class KeysCollectionManager;
|
|||
* This is responsible for signing cluster times that can be used to sent to other servers and
|
||||
* verifying signatures of signed cluster times.
|
||||
*/
|
||||
class LogicalTimeValidator {
|
||||
class MONGO_MOD_NEEDS_REPLACEMENT LogicalTimeValidator {
|
||||
public:
|
||||
// Decorate ServiceContext with LogicalTimeValidator instance.
|
||||
static std::shared_ptr<LogicalTimeValidator> get(ServiceContext* service);
|
||||
|
|
|
|||
|
|
@ -31,6 +31,7 @@
|
|||
|
||||
#include "mongo/db/logical_time.h"
|
||||
#include "mongo/db/time_proof_service.h"
|
||||
#include "mongo/util/modules.h"
|
||||
|
||||
#include <string>
|
||||
#include <utility>
|
||||
|
|
@ -44,7 +45,8 @@ namespace mongo {
|
|||
* The SignedLogicalTime class is a pair of value i.e. time and a signature i.e. _proof
|
||||
* The class is immutable and is used to hold the cryptographically protected LogicalTime.
|
||||
*/
|
||||
class SignedLogicalTime {
|
||||
// TODO This class should be parent_private ideally
|
||||
class MONGO_MOD_NEEDS_REPLACEMENT SignedLogicalTime {
|
||||
public:
|
||||
using TimeProof = TimeProofService::TimeProof;
|
||||
|
||||
|
|
|
|||
|
|
@ -34,6 +34,7 @@
|
|||
#include "mongo/crypto/sha1_block.h"
|
||||
#include "mongo/db/logical_time.h"
|
||||
#include "mongo/stdx/mutex.h"
|
||||
#include "mongo/util/modules.h"
|
||||
|
||||
#include <utility>
|
||||
|
||||
|
|
@ -47,7 +48,7 @@ namespace mongo {
|
|||
* and contains the logic to generate this key. As a performance optimization to avoid expensive
|
||||
* signature generation the class also holds the cache.
|
||||
*/
|
||||
class TimeProofService {
|
||||
class MONGO_MOD_NEEDS_REPLACEMENT TimeProofService {
|
||||
public:
|
||||
// This type must be synchronized with the library that generates SHA1 or other proof.
|
||||
using TimeProof = SHA1Block;
|
||||
|
|
@ -58,22 +59,22 @@ public:
|
|||
/**
|
||||
* Generates a pseudorandom key to be used for HMAC authentication.
|
||||
*/
|
||||
static Key generateRandomKey();
|
||||
MONGO_MOD_NEEDS_REPLACEMENT static Key generateRandomKey();
|
||||
|
||||
/**
|
||||
* Returns the proof matching the time argument.
|
||||
*/
|
||||
TimeProof getProof(LogicalTime time, const Key& key);
|
||||
MONGO_MOD_PRIVATE TimeProof getProof(LogicalTime time, const Key& key);
|
||||
|
||||
/**
|
||||
* Verifies that the proof matches the time argument.
|
||||
*/
|
||||
Status checkProof(LogicalTime time, const TimeProof& proof, const Key& key);
|
||||
MONGO_MOD_PRIVATE Status checkProof(LogicalTime time, const TimeProof& proof, const Key& key);
|
||||
|
||||
/**
|
||||
* Resets the cache.
|
||||
*/
|
||||
void resetCache();
|
||||
MONGO_MOD_PRIVATE void resetCache();
|
||||
|
||||
private:
|
||||
/**
|
||||
|
|
|
|||
Loading…
Reference in New Issue