diff options
author | Billy Donahue <billy.donahue@mongodb.com> | 2021-04-13 20:52:44 -0400 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2021-04-22 00:00:27 +0000 |
commit | 8f4dbd6889eb9534da7af27729aa0c2edea532f0 (patch) | |
tree | 9849d0d59ba36bb78f8bed91d9ee23512ea116a7 /src/mongo/util | |
parent | ccca20406141099cf6f778cd01e633ecd1fd8f11 (diff) | |
download | mongo-8f4dbd6889eb9534da7af27729aa0c2edea532f0.tar.gz |
SERVER-43964 UUID etc need not befriend IDL types
Diffstat (limited to 'src/mongo/util')
-rw-r--r-- | src/mongo/util/uuid.h | 84 |
1 files changed, 10 insertions, 74 deletions
diff --git a/src/mongo/util/uuid.h b/src/mongo/util/uuid.h index a5e259a3c9a..eade27480d6 100644 --- a/src/mongo/util/uuid.h +++ b/src/mongo/util/uuid.h @@ -40,83 +40,20 @@ #include "mongo/bson/bsonmisc.h" #include "mongo/bson/bsonobj.h" #include "mongo/logv2/log_attr.h" +#include "mongo/stdx/type_traits.h" namespace mongo { -namespace repl { -class CollectionInfo; -class OplogEntryBase; -class DurableReplOperation; -class InitialSyncIdDocument; -} // namespace repl - -namespace idl { -namespace import { -class One_UUID; -} // namespace import -} // namespace idl - /** * A UUID is a 128-bit unique identifier, per RFC 4122, v4, using * a secure random number generator. */ class UUID { - using UUIDStorage = std::array<unsigned char, 16>; - - // Make the IDL generated parser a friend - friend class ConfigsvrShardCollectionResponse; - friend class CommonReshardingMetadata; - friend class DonorAbortMigration; - friend class DonorStartMigration; - friend class DonorWaitForMigrationToCommit; - friend class DonorForgetMigration; - friend class DonorStateMachine; - friend class DatabaseVersion; - friend class DbCheckOplogCollection; - friend class EncryptionPlaceholder; - friend class ExternalKeysCollectionDocument; - friend class idl::import::One_UUID; - friend class IndexBuildEntry; - friend class KeyStoreRecord; - friend class ListCollectionsReplyInfo; - friend class LogicalSessionId; - friend class LogicalSessionToClient; - friend class LogicalSessionIdToClient; - friend class LogicalSessionFromClient; - friend class MigrationCoordinatorDocument; - friend class MigrationDestinationManager; - friend class MigrationRecipientCommonData; - friend class RangeDeletionTask; - friend class ResolvedKeyId; - friend class repl::CollectionInfo; - friend class repl::OplogEntryBase; - friend class repl::DurableReplOperation; - friend class repl::InitialSyncIdDocument; - friend class RecipientForgetMigration; - friend class RecipientSyncData; - friend class ReshardingDonorDocument; - friend class ReshardingSourceId; - friend class ResumeIndexInfo; - friend class ResumeTokenInternal; - friend class ShardCollectionTypeBase; - friend class ShardsvrCleanupReshardCollection; - friend class ShardsvrShardCollectionResponse; - friend class ShardsvrRenameCollection; - friend class TenantMigrationDonorDocument; - friend class TenantMigrationRecipientDocument; - friend class TestReshardCloneCollection; - friend class TypeCollectionRecipientFields; - friend class TypeCollectionReshardingFields; - friend class VoteCommitIndexBuild; - friend class ImportCollectionOplogEntry; - friend class VoteCommitImportCollection; - - public: /** * The number of bytes contained in a UUID. */ - static constexpr int kNumBytes = sizeof(UUIDStorage); + static constexpr int kNumBytes = 16; /** * Generate a new random v4 UUID per RFC 4122. @@ -143,7 +80,7 @@ public: static UUID parse(const BSONObj& obj); static UUID fromCDR(ConstDataRange cdr) { - UUID uuid; + UUID uuid{UUIDStorage{}}; invariant(cdr.length() == uuid._uuid.size()); memcpy(uuid._uuid.data(), cdr.data(), uuid._uuid.size()); return uuid; @@ -242,19 +179,18 @@ public: } private: - UUID(const UUIDStorage& uuid) : _uuid(uuid) {} + using UUIDStorage = std::array<unsigned char, kNumBytes>; - /** - * Should never be used, as the resulting UUID will not be unique. - * The exception is in code generated by the IDL compiler, which itself ensures - * such an invalid value cannot propagate. - */ - friend class LogicalSessionId; - UUID() = default; + UUID(const UUIDStorage& uuid) : _uuid(uuid) {} UUIDStorage _uuid{}; // UUID in network byte order }; +/** Allow IDL-generated parsers to define uninitialized UUID objects. */ +inline auto idlPreparsedValue(stdx::type_identity<UUID>) { + return UUID::fromCDR(std::array<unsigned char, 16>{}); +} + inline std::ostream& operator<<(std::ostream& s, const UUID& uuid) { return (s << uuid.toString()); } |