SERVER-120856 Clean up the replicated size and count document field names (#48945)
GitOrigin-RevId: 90669097497e00e07d419c283888ce69d677cde7
This commit is contained in:
committed by
MongoDB Bot
parent
c2419a02e7
commit
b55cead1b7
@@ -84,8 +84,8 @@ public:
|
||||
static constexpr StringData kSystemDotProfileCollectionName = "system.profile"_sd;
|
||||
|
||||
// Name for fastcount - replicated collection size and count - collections.
|
||||
static constexpr StringData kSystemReplicatedFastCountStore = "fast_count_metadata_store"_sd;
|
||||
static constexpr StringData kSystemReplicatedFastCountStoreTimestamps =
|
||||
static constexpr StringData kReplicatedFastCountStore = "fast_count_metadata_store"_sd;
|
||||
static constexpr StringData kReplicatedFastCountStoreTimestamps =
|
||||
"fast_count_metadata_store_timestamps"_sd;
|
||||
|
||||
// Names of privilege document collections
|
||||
|
||||
@@ -45,14 +45,13 @@ Status createFastcountCollection(OperationContext* opCtx) {
|
||||
WriteUnitOfWork wuow(opCtx);
|
||||
Status createCollectionStatus = createCollection(
|
||||
opCtx,
|
||||
NamespaceString::makeGlobalConfigCollection(
|
||||
NamespaceString::kSystemReplicatedFastCountStore),
|
||||
NamespaceString::makeGlobalConfigCollection(NamespaceString::kReplicatedFastCountStore),
|
||||
CollectionOptions{.clusteredIndex = clustered_util::makeDefaultClusteredIdIndex()},
|
||||
BSONObj{});
|
||||
uassert(11757500,
|
||||
str::stream() << "Failed to create the replicated fast count collection: "
|
||||
<< NamespaceString::makeGlobalConfigCollection(
|
||||
NamespaceString::kSystemReplicatedFastCountStore)
|
||||
NamespaceString::kReplicatedFastCountStore)
|
||||
.toStringForErrorMsg()
|
||||
<< causedBy(createCollectionStatus.reason()) << "code"
|
||||
<< createCollectionStatus.code(),
|
||||
@@ -63,13 +62,13 @@ Status createFastcountCollection(OperationContext* opCtx) {
|
||||
LOGV2(11718601,
|
||||
"Created internal fastcount collection.",
|
||||
"ns"_attr = NamespaceString::makeGlobalConfigCollection(
|
||||
NamespaceString::kSystemReplicatedFastCountStore)
|
||||
NamespaceString::kReplicatedFastCountStore)
|
||||
.toStringForErrorMsg());
|
||||
} else if (createCollectionStatus.code() == ErrorCodes::NamespaceExists) {
|
||||
LOGV2(11886900,
|
||||
"Internal fastcount collection already exists.",
|
||||
"ns"_attr = NamespaceString::makeGlobalConfigCollection(
|
||||
NamespaceString::kSystemReplicatedFastCountStore)
|
||||
NamespaceString::kReplicatedFastCountStore)
|
||||
.toStringForErrorMsg());
|
||||
}
|
||||
|
||||
|
||||
@@ -105,8 +105,8 @@ int ReplicatedFastCountManager::_hydrateMetadataFromDisk(
|
||||
++numRecordsScanned;
|
||||
|
||||
auto& meta = _metadata[uuid];
|
||||
meta.sizeCount.count = data.getField(kCountKey).Long();
|
||||
meta.sizeCount.size = data.getField(kSizeKey).Long();
|
||||
meta.sizeCount.count = data.getField(kMetaDataKey).Obj().getField(kCountKey).Long();
|
||||
meta.sizeCount.size = data.getField(kMetaDataKey).Obj().getField(kSizeKey).Long();
|
||||
}
|
||||
return numRecordsScanned;
|
||||
}
|
||||
@@ -346,14 +346,13 @@ void ReplicatedFastCountManager::_insertOneMetadata(OperationContext* opCtx,
|
||||
|
||||
boost::optional<CollectionOrViewAcquisition>
|
||||
ReplicatedFastCountManager::_acquireFastCountCollectionForWrite(OperationContext* opCtx) {
|
||||
CollectionOrViewAcquisition acquisition =
|
||||
acquireCollectionOrView(opCtx,
|
||||
CollectionOrViewAcquisitionRequest::fromOpCtx(
|
||||
opCtx,
|
||||
NamespaceString::makeGlobalConfigCollection(
|
||||
NamespaceString::kSystemReplicatedFastCountStore),
|
||||
AcquisitionPrerequisites::OperationType::kWrite),
|
||||
LockMode::MODE_IX);
|
||||
CollectionOrViewAcquisition acquisition = acquireCollectionOrView(
|
||||
opCtx,
|
||||
CollectionOrViewAcquisitionRequest::fromOpCtx(
|
||||
opCtx,
|
||||
NamespaceString::makeGlobalConfigCollection(NamespaceString::kReplicatedFastCountStore),
|
||||
AcquisitionPrerequisites::OperationType::kWrite),
|
||||
LockMode::MODE_IX);
|
||||
|
||||
if (acquisition.getCollectionPtr()) {
|
||||
return acquisition;
|
||||
@@ -364,14 +363,13 @@ ReplicatedFastCountManager::_acquireFastCountCollectionForWrite(OperationContext
|
||||
|
||||
boost::optional<CollectionOrViewAcquisition>
|
||||
ReplicatedFastCountManager::_acquireFastCountCollectionForRead(OperationContext* opCtx) {
|
||||
CollectionOrViewAcquisition acquisition =
|
||||
acquireCollectionOrView(opCtx,
|
||||
CollectionOrViewAcquisitionRequest::fromOpCtx(
|
||||
opCtx,
|
||||
NamespaceString::makeGlobalConfigCollection(
|
||||
NamespaceString::kSystemReplicatedFastCountStore),
|
||||
AcquisitionPrerequisites::OperationType::kRead),
|
||||
LockMode::MODE_IS);
|
||||
CollectionOrViewAcquisition acquisition = acquireCollectionOrView(
|
||||
opCtx,
|
||||
CollectionOrViewAcquisitionRequest::fromOpCtx(
|
||||
opCtx,
|
||||
NamespaceString::makeGlobalConfigCollection(NamespaceString::kReplicatedFastCountStore),
|
||||
AcquisitionPrerequisites::OperationType::kRead),
|
||||
LockMode::MODE_IS);
|
||||
|
||||
if (acquisition.getCollectionPtr()) {
|
||||
return acquisition;
|
||||
@@ -382,7 +380,8 @@ ReplicatedFastCountManager::_acquireFastCountCollectionForRead(OperationContext*
|
||||
|
||||
BSONObj ReplicatedFastCountManager::_getDocForWrite(const UUID& uuid,
|
||||
const CollectionSizeCount& sizeCount) const {
|
||||
return BSON("_id" << uuid << kCountKey << sizeCount.count << kSizeKey << sizeCount.size);
|
||||
return BSON("_id" << uuid << kMetaDataKey
|
||||
<< BSON(kCountKey << sizeCount.count << kSizeKey << sizeCount.size));
|
||||
}
|
||||
|
||||
RecordId ReplicatedFastCountManager::_keyForUUID(const UUID& uuid) const {
|
||||
|
||||
@@ -104,8 +104,9 @@ public:
|
||||
*/
|
||||
void initializeFastCountCommitFn();
|
||||
|
||||
inline static StringData kSizeKey = "s"_sd;
|
||||
inline static StringData kCountKey = "c"_sd;
|
||||
inline static StringData kMetaDataKey = "meta"_sd;
|
||||
inline static StringData kSizeKey = "sz"_sd;
|
||||
inline static StringData kCountKey = "ct"_sd;
|
||||
|
||||
/**
|
||||
* Spawns fastcount thread.
|
||||
|
||||
@@ -113,7 +113,7 @@ protected:
|
||||
};
|
||||
|
||||
const NamespaceString replicatedFastCountStoreNss =
|
||||
NamespaceString::makeGlobalConfigCollection(NamespaceString::kSystemReplicatedFastCountStore);
|
||||
NamespaceString::makeGlobalConfigCollection(NamespaceString::kReplicatedFastCountStore);
|
||||
|
||||
const std::function<BSONObj(int)> docGeneratorForInsert = [](int i) {
|
||||
return BSON("_id" << i << "x" << i);
|
||||
@@ -461,10 +461,10 @@ TEST_F(ReplicatedFastCountTest, StartupFailsIfFastCountCollectionNotPresent) {
|
||||
|
||||
{
|
||||
repl::UnreplicatedWritesBlock uwb(_opCtx);
|
||||
ASSERT_OK(storageInterface()->dropCollection(
|
||||
_opCtx,
|
||||
NamespaceString::makeGlobalConfigCollection(
|
||||
NamespaceString::kSystemReplicatedFastCountStore)));
|
||||
ASSERT_OK(
|
||||
storageInterface()->dropCollection(_opCtx,
|
||||
NamespaceString::makeGlobalConfigCollection(
|
||||
NamespaceString::kReplicatedFastCountStore)));
|
||||
}
|
||||
|
||||
ASSERT_THROWS_CODE(_fastCountManager->startup(_opCtx), DBException, 11718600);
|
||||
@@ -484,10 +484,10 @@ TEST_F(ReplicatedFastCountTest, InitializePopulatesMetadataFromExistingInternalC
|
||||
const int64_t expectedSize2 = 250;
|
||||
|
||||
{
|
||||
AutoGetCollection fastCountColl(_opCtx,
|
||||
NamespaceString::makeGlobalConfigCollection(
|
||||
NamespaceString::kSystemReplicatedFastCountStore),
|
||||
LockMode::MODE_IX);
|
||||
AutoGetCollection fastCountColl(
|
||||
_opCtx,
|
||||
NamespaceString::makeGlobalConfigCollection(NamespaceString::kReplicatedFastCountStore),
|
||||
LockMode::MODE_IX);
|
||||
ASSERT(fastCountColl);
|
||||
|
||||
WriteUnitOfWork wuow{_opCtx, WriteUnitOfWork::kGroupForPossiblyRetryableOperations};
|
||||
@@ -495,14 +495,18 @@ TEST_F(ReplicatedFastCountTest, InitializePopulatesMetadataFromExistingInternalC
|
||||
ASSERT_OK(Helpers::insert(
|
||||
_opCtx,
|
||||
*fastCountColl,
|
||||
BSON("_id" << uuid1 << ReplicatedFastCountManager::kCountKey << expectedCount1
|
||||
<< ReplicatedFastCountManager::kSizeKey << expectedSize1)));
|
||||
BSON("_id" << uuid1 << ReplicatedFastCountManager::kMetaDataKey
|
||||
<< BSON(ReplicatedFastCountManager::kCountKey
|
||||
<< expectedCount1 << ReplicatedFastCountManager::kSizeKey
|
||||
<< expectedSize1))));
|
||||
|
||||
ASSERT_OK(Helpers::insert(
|
||||
_opCtx,
|
||||
*fastCountColl,
|
||||
BSON("_id" << uuid2 << ReplicatedFastCountManager::kCountKey << expectedCount2
|
||||
<< ReplicatedFastCountManager::kSizeKey << expectedSize2)));
|
||||
BSON("_id" << uuid2 << ReplicatedFastCountManager::kMetaDataKey
|
||||
<< BSON(ReplicatedFastCountManager::kCountKey
|
||||
<< expectedCount2 << ReplicatedFastCountManager::kSizeKey
|
||||
<< expectedSize2))));
|
||||
|
||||
wuow.commit();
|
||||
}
|
||||
|
||||
@@ -49,10 +49,10 @@ void checkFastCountMetadataInInternalCollection(OperationContext* opCtx,
|
||||
int64_t expectedCount,
|
||||
int64_t expectedSize) {
|
||||
{
|
||||
AutoGetCollection fastCountColl(opCtx,
|
||||
NamespaceString::makeGlobalConfigCollection(
|
||||
NamespaceString::kSystemReplicatedFastCountStore),
|
||||
LockMode::MODE_IS);
|
||||
AutoGetCollection fastCountColl(
|
||||
opCtx,
|
||||
NamespaceString::makeGlobalConfigCollection(NamespaceString::kReplicatedFastCountStore),
|
||||
LockMode::MODE_IS);
|
||||
|
||||
BSONObj persisted;
|
||||
bool found = Helpers::findById(opCtx, fastCountColl->ns(), BSON("_id" << uuid), persisted);
|
||||
@@ -61,8 +61,14 @@ void checkFastCountMetadataInInternalCollection(OperationContext* opCtx,
|
||||
if (!expectPersisted) {
|
||||
return;
|
||||
}
|
||||
int64_t persistedCount = persisted.getField(ReplicatedFastCountManager::kCountKey).Long();
|
||||
int64_t persistedSize = persisted.getField(ReplicatedFastCountManager::kSizeKey).Long();
|
||||
int64_t persistedCount = persisted.getField(ReplicatedFastCountManager::kMetaDataKey)
|
||||
.Obj()
|
||||
.getField(ReplicatedFastCountManager::kCountKey)
|
||||
.Long();
|
||||
int64_t persistedSize = persisted.getField(ReplicatedFastCountManager::kMetaDataKey)
|
||||
.Obj()
|
||||
.getField(ReplicatedFastCountManager::kSizeKey)
|
||||
.Long();
|
||||
EXPECT_EQ(persistedCount, expectedCount);
|
||||
EXPECT_EQ(persistedSize, expectedSize);
|
||||
}
|
||||
@@ -324,8 +330,13 @@ void assertFastCountApplyOpsMatches(const repl::OplogEntry& applyOpsEntry,
|
||||
case FastCountOpType::kInsert: {
|
||||
const auto& obj = innerEntry.getObject();
|
||||
|
||||
auto countElem = obj[ReplicatedFastCountManager::kCountKey];
|
||||
auto sizeElem = obj[ReplicatedFastCountManager::kSizeKey];
|
||||
auto metaElem = obj[ReplicatedFastCountManager::kMetaDataKey];
|
||||
EXPECT_TRUE(metaElem.isABSONObj())
|
||||
<< "Meta field not numeric for UUID " << uuid << ": " << metaElem;
|
||||
|
||||
auto metaObj = metaElem.Obj();
|
||||
auto countElem = metaObj[ReplicatedFastCountManager::kCountKey];
|
||||
auto sizeElem = metaObj[ReplicatedFastCountManager::kSizeKey];
|
||||
|
||||
EXPECT_TRUE(countElem.isNumber())
|
||||
<< "Count field not numeric for UUID " << uuid << ": " << countElem;
|
||||
@@ -348,7 +359,11 @@ void assertFastCountApplyOpsMatches(const repl::OplogEntry& applyOpsEntry,
|
||||
case FastCountOpType::kUpdate: {
|
||||
const auto& obj = innerEntry.getObject();
|
||||
|
||||
auto sizeElem = obj["diff"]["u"][ReplicatedFastCountManager::kSizeKey];
|
||||
std::string kSubDiffSectionFieldPrefix = "s";
|
||||
auto sizeElem =
|
||||
obj["diff"]
|
||||
[kSubDiffSectionFieldPrefix + ReplicatedFastCountManager::kMetaDataKey]["u"]
|
||||
[ReplicatedFastCountManager::kSizeKey];
|
||||
EXPECT_TRUE(sizeElem.isNumber())
|
||||
<< "Size field not numeric for UUID " << uuid << ": " << sizeElem;
|
||||
|
||||
|
||||
@@ -134,8 +134,8 @@ ValidateState::ValidateState(OperationContext* opCtx,
|
||||
}
|
||||
|
||||
Status ValidateState::_checkReplicatedFastCountCollectionExists(OperationContext* opCtx) const {
|
||||
const NamespaceString fastCountNss = NamespaceString::makeGlobalConfigCollection(
|
||||
NamespaceString::kSystemReplicatedFastCountStore);
|
||||
const NamespaceString fastCountNss =
|
||||
NamespaceString::makeGlobalConfigCollection(NamespaceString::kReplicatedFastCountStore);
|
||||
const auto catalog = CollectionCatalog::get(opCtx);
|
||||
if (!catalog->lookupCollectionByNamespace(opCtx, fastCountNss)) {
|
||||
return Status(ErrorCodes::NamespaceNotFound,
|
||||
|
||||
@@ -32,6 +32,7 @@
|
||||
#include "mongo/db/repl/storage_interface.h"
|
||||
#include "mongo/db/replicated_fast_count/replicated_fast_count_test_helpers.h"
|
||||
#include "mongo/db/shard_role/shard_catalog/catalog_test_fixture.h"
|
||||
#include "mongo/db/shard_role/shard_catalog/clustered_collection_util.h"
|
||||
#include "mongo/db/shard_role/shard_catalog/collection_options.h"
|
||||
#include "mongo/db/storage/kv/kv_engine.h"
|
||||
#include "mongo/unittest/death_test.h"
|
||||
@@ -61,15 +62,14 @@ public:
|
||||
|
||||
/**
|
||||
* Creates a replicated fast count collection using the global namespace string
|
||||
* kSystemReplicatedFastCountStore.
|
||||
* kReplicatedFastCountStore.
|
||||
*/
|
||||
void createReplicatedFastCountCollection(repl::StorageInterface* storageInterface,
|
||||
OperationContext* opCtx) {
|
||||
ASSERT_OK(
|
||||
storageInterface->createCollection(opCtx,
|
||||
NamespaceString::makeGlobalConfigCollection(
|
||||
NamespaceString::kSystemReplicatedFastCountStore),
|
||||
CollectionOptions()));
|
||||
ASSERT_OK(storageInterface->createCollection(
|
||||
opCtx,
|
||||
NamespaceString::makeGlobalConfigCollection(NamespaceString::kReplicatedFastCountStore),
|
||||
CollectionOptions{.clusteredIndex = clustered_util::makeDefaultClusteredIdIndex()}));
|
||||
}
|
||||
} // namespace
|
||||
|
||||
|
||||
Reference in New Issue
Block a user