Skip to content

Commit

Permalink
Prepare tests for new HCC naming (facebook#11676)
Browse files Browse the repository at this point in the history
Summary:
I'm anticipating using the public name HyperClockCache for both the current version with a fixed-size table and the upcoming version with an automatically growing table. However, for simplicity of testing them as substantially distinct implementations, I want to give them distinct internal names, like FixedHyperClockCache and AutoHyperClockCache.

This change anticipates that by renaming to FixedHyperClockCache and assuming for now that all the unit tests run on HCC will run and behave similarly for the automatic HCC. Obviously updates will need to be made, but I'm trying to avoid uninteresting find & replace updates in what will be a large and engineering-heavy PR for AutoHCC

Pull Request resolved: facebook#11676

Test Plan: no behavior change intended, except logging will now use the name FixedHyperClockCache

Reviewed By: ajkr

Differential Revision: D48103165

Pulled By: pdillinger

fbshipit-source-id: a33f1901488fea102164c2318e2f2b156aaba736
  • Loading branch information
pdillinger authored and facebook-github-bot committed Aug 8, 2023
1 parent 6d1effa commit 99daea3
Show file tree
Hide file tree
Showing 9 changed files with 109 additions and 105 deletions.
3 changes: 2 additions & 1 deletion cache/cache_bench_tool.cc
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,8 @@ class CacheBench {
if (FLAGS_cache_type == "clock_cache") {
fprintf(stderr, "Old clock cache implementation has been removed.\n");
exit(1);
} else if (FLAGS_cache_type == "hyper_clock_cache") {
} else if (FLAGS_cache_type == "hyper_clock_cache" ||
FLAGS_cache_type == "fixed_hyper_clock_cache") {
HyperClockCacheOptions opts(FLAGS_cache_size, FLAGS_value_bytes,
FLAGS_num_shard_bits);
opts.hash_seed = BitwiseAnd(FLAGS_seed, INT32_MAX);
Expand Down
31 changes: 14 additions & 17 deletions cache/cache_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -120,17 +120,15 @@ class CacheTest : public testing::Test,
// Currently, HyperClockCache requires keys to be 16B long, whereas
// LRUCache doesn't, so the encoding depends on the cache type.
std::string EncodeKey(int k) {
auto type = GetParam();
if (type == kHyperClock) {
if (IsHyperClock()) {
return EncodeKey16Bytes(k);
} else {
return EncodeKey32Bits(k);
}
}

int DecodeKey(const Slice& k) {
auto type = GetParam();
if (type == kHyperClock) {
if (IsHyperClock()) {
return DecodeKey16Bytes(k);
} else {
return DecodeKey32Bits(k);
Expand Down Expand Up @@ -190,7 +188,7 @@ TEST_P(CacheTest, UsageTest) {
auto precise_cache = NewCache(kCapacity, 0, false, kFullChargeCacheMetadata);
ASSERT_EQ(0, cache->GetUsage());
size_t baseline_meta_usage = precise_cache->GetUsage();
if (type != kHyperClock) {
if (!IsHyperClock()) {
ASSERT_EQ(0, baseline_meta_usage);
}

Expand All @@ -209,7 +207,7 @@ TEST_P(CacheTest, UsageTest) {
ASSERT_OK(precise_cache->Insert(key, value, &kDumbHelper, kv_size));
usage += kv_size;
ASSERT_EQ(usage, cache->GetUsage());
if (type == kHyperClock) {
if (IsHyperClock()) {
ASSERT_EQ(baseline_meta_usage + usage, precise_cache->GetUsage());
} else {
ASSERT_LT(usage, precise_cache->GetUsage());
Expand Down Expand Up @@ -237,7 +235,7 @@ TEST_P(CacheTest, UsageTest) {
ASSERT_GT(kCapacity, cache->GetUsage());
ASSERT_GT(kCapacity, precise_cache->GetUsage());
ASSERT_LT(kCapacity * 0.95, cache->GetUsage());
if (type != kHyperClock) {
if (!IsHyperClock()) {
ASSERT_LT(kCapacity * 0.95, precise_cache->GetUsage());
} else {
// estimated value size of 1 is weird for clock cache, because
Expand All @@ -263,7 +261,7 @@ TEST_P(CacheTest, PinnedUsageTest) {
auto cache = NewCache(kCapacity, 8, false, kDontChargeCacheMetadata);
auto precise_cache = NewCache(kCapacity, 8, false, kFullChargeCacheMetadata);
size_t baseline_meta_usage = precise_cache->GetUsage();
if (type != kHyperClock) {
if (!IsHyperClock()) {
ASSERT_EQ(0, baseline_meta_usage);
}

Expand Down Expand Up @@ -368,7 +366,7 @@ TEST_P(CacheTest, HitAndMiss) {
ASSERT_EQ(-1, Lookup(300));

Insert(100, 102);
if (GetParam() == kHyperClock) {
if (IsHyperClock()) {
// ClockCache usually doesn't overwrite on Insert
ASSERT_EQ(101, Lookup(100));
} else {
Expand All @@ -378,15 +376,15 @@ TEST_P(CacheTest, HitAndMiss) {
ASSERT_EQ(-1, Lookup(300));

ASSERT_EQ(1U, deleted_values_.size());
if (GetParam() == kHyperClock) {
if (IsHyperClock()) {
ASSERT_EQ(102, deleted_values_[0]);
} else {
ASSERT_EQ(101, deleted_values_[0]);
}
}

TEST_P(CacheTest, InsertSameKey) {
if (GetParam() == kHyperClock) {
if (IsHyperClock()) {
ROCKSDB_GTEST_BYPASS(
"ClockCache doesn't guarantee Insert overwrite same key.");
return;
Expand Down Expand Up @@ -415,7 +413,7 @@ TEST_P(CacheTest, Erase) {
}

TEST_P(CacheTest, EntriesArePinned) {
if (GetParam() == kHyperClock) {
if (IsHyperClock()) {
ROCKSDB_GTEST_BYPASS(
"ClockCache doesn't guarantee Insert overwrite same key.");
return;
Expand Down Expand Up @@ -479,7 +477,7 @@ TEST_P(CacheTest, ExternalRefPinsEntries) {
Insert(1000 + j, 2000 + j);
}
// Clock cache is even more stateful and needs more churn to evict
if (GetParam() == kHyperClock) {
if (IsHyperClock()) {
for (int j = 0; j < kCacheSize; j++) {
Insert(11000 + j, 11000 + j);
}
Expand Down Expand Up @@ -679,7 +677,7 @@ using TypedHandle = SharedCache::TypedHandle;

TEST_P(CacheTest, SetCapacity) {
auto type = GetParam();
if (type == kHyperClock) {
if (IsHyperClock()) {
ROCKSDB_GTEST_BYPASS(
"FastLRUCache and HyperClockCache don't support arbitrary capacity "
"adjustments.");
Expand Down Expand Up @@ -811,7 +809,7 @@ TEST_P(CacheTest, OverCapacity) {
cache.Release(handles[i]);
}

if (GetParam() == kHyperClock) {
if (IsHyperClock()) {
// Make sure eviction is triggered.
ASSERT_OK(cache.Insert(EncodeKey(-1), nullptr, 1, &handles[0]));

Expand Down Expand Up @@ -923,8 +921,7 @@ TEST_P(CacheTest, DefaultShardBits) {
// Prevent excessive allocation (to save time & space)
estimated_value_size_ = 100000;
// Implementations use different minimum shard sizes
size_t min_shard_size =
(GetParam() == kHyperClock ? 32U * 1024U : 512U) * 1024U;
size_t min_shard_size = (IsHyperClock() ? 32U * 1024U : 512U) * 1024U;

std::shared_ptr<Cache> cache = NewCache(32U * min_shard_size);
ShardedCacheBase* sc = dynamic_cast<ShardedCacheBase*>(cache.get());
Expand Down
Loading

0 comments on commit 99daea3

Please sign in to comment.