Skip to content

Commit

Permalink
Sanitize the secondary_cache option in TieredCacheOptions (#12137)
Browse files Browse the repository at this point in the history
Summary:
Sanitize the `secondary_cache` field in the `cache_opts` option of `TieredCacheOptions` to `nullptr` if set by the user. The nvm secondary cache should be directly set in `TieredCacheOptions`.

Pull Request resolved: #12137

Reviewed By: akankshamahajan15

Differential Revision: D52063817

Pulled By: anand1976

fbshipit-source-id: 255116c665a9b908c8f44109a2d331d4b73e7591
  • Loading branch information
anand1976 authored and facebook-github-bot committed Dec 12, 2023
1 parent c2ab4e7 commit ebb5242
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
2 changes: 2 additions & 0 deletions cache/secondary_cache_adapter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -683,12 +683,14 @@ std::shared_ptr<Cache> NewTieredCache(const TieredCacheOptions& _opts) {
*(static_cast_with_check<LRUCacheOptions, ShardedCacheOptions>(
opts.cache_opts));
cache_opts.capacity = opts.total_capacity;
cache_opts.secondary_cache = nullptr;
cache = cache_opts.MakeSharedCache();
} else if (opts.cache_type == PrimaryCacheType::kCacheTypeHCC) {
HyperClockCacheOptions cache_opts =
*(static_cast_with_check<HyperClockCacheOptions, ShardedCacheOptions>(
opts.cache_opts));
cache_opts.capacity = opts.total_capacity;
cache_opts.secondary_cache = nullptr;
cache = cache_opts.MakeSharedCache();
} else {
return nullptr;
Expand Down
4 changes: 4 additions & 0 deletions include/rocksdb/cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,10 @@ enum TieredAdmissionPolicy {
// allocations costed to the block cache, will be distributed
// proportionally across both the primary and secondary.
struct TieredCacheOptions {
// This should point to an instance of either LRUCacheOptions or
// HyperClockCacheOptions, depending on the cache_type. In either
// case, the capacity and secondary_cache fields in those options
// should not be set. If set, they will be ignored by NewTieredCache.
ShardedCacheOptions* cache_opts = nullptr;
PrimaryCacheType cache_type = PrimaryCacheType::kCacheTypeLRU;
TieredAdmissionPolicy adm_policy = TieredAdmissionPolicy::kAdmPolicyAuto;
Expand Down

0 comments on commit ebb5242

Please sign in to comment.