Skip to content

Commit

Permalink
Ensure bucket index counters non-zero in serialize bucket index test
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomasBrady committed Sep 5, 2024
1 parent d58635b commit b18d407
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 6 deletions.
13 changes: 13 additions & 0 deletions src/bucket/Bucket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -875,4 +875,17 @@ BucketEntryCounters::operator+=(BucketEntryCounters const& other)
}
return *this;
}

bool
BucketEntryCounters::operator==(BucketEntryCounters const& other) const
{
return this->entryTypeCounts == other.entryTypeCounts &&
this->entryTypeSizes == other.entryTypeSizes;
}

bool
BucketEntryCounters::operator!=(BucketEntryCounters const& other) const
{
return !(*this == other);
}
}
2 changes: 2 additions & 0 deletions src/bucket/Bucket.h
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,8 @@ struct BucketEntryCounters
std::map<LedgerEntryTypeAndDurability, size_t> entryTypeSizes;

BucketEntryCounters& operator+=(BucketEntryCounters const& other);
bool operator==(BucketEntryCounters const& other) const;
bool operator!=(BucketEntryCounters const& other) const;

template <class Archive>
void
Expand Down
7 changes: 1 addition & 6 deletions src/bucket/BucketIndexImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -564,12 +564,7 @@ BucketIndexImpl<IndexT>::operator==(BucketIndex const& inRaw) const
}
}

if (mData.counters.entryTypeCounts != in.mData.counters.entryTypeCounts)
{
return false;
}

if (mData.counters.entryTypeSizes != in.mData.counters.entryTypeSizes)
if (mData.counters != in.mData.counters)
{
return false;
}
Expand Down
11 changes: 11 additions & 0 deletions src/bucket/test/BucketIndexTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -663,6 +663,17 @@ TEST_CASE("serialize bucket indexes", "[bucket][bucketindex]")

auto& inMemoryIndex = b->getIndexForTesting();
REQUIRE(inMemoryIndex.getPageSize() == (1UL << 10));
auto inMemoryCoutners = inMemoryIndex.getBucketEntryCounters();
// Ensure the inMemoryIndex has some non-zero counters.
REQUIRE(!inMemoryCoutners.entryTypeCounts.empty());
REQUIRE(!inMemoryCoutners.entryTypeSizes.empty());
bool allZero = true;
for (auto const& [k, v] : inMemoryCoutners.entryTypeCounts)
{
allZero = allZero && (v == 0);
allZero = allZero && (inMemoryCoutners.entryTypeSizes.at(k) == 0);
}
REQUIRE(!allZero);

// Check if on-disk index rewritten with correct config params
auto indexFilename = test.getBM().bucketIndexFilename(bucketHash);
Expand Down

0 comments on commit b18d407

Please sign in to comment.