Coverage Report

Created: 2024-07-27 06:53

/src/rocksdb/cache/charged_cache.h
Line
Count
Source (jump to first uncovered line)
1
//  Copyright (c) Meta Platforms, Inc. and affiliates.
2
//  This source code is licensed under both the GPLv2 (found in the
3
//  COPYING file in the root directory) and Apache 2.0 License
4
//  (found in the LICENSE.Apache file in the root directory).
5
6
#pragma once
7
8
#include <string>
9
10
#include "port/port.h"
11
#include "rocksdb/advanced_cache.h"
12
13
namespace ROCKSDB_NAMESPACE {
14
15
class ConcurrentCacheReservationManager;
16
17
// A cache interface which wraps around another cache and takes care of
18
// reserving space in block cache towards a single global memory limit, and
19
// forwards all the calls to the underlying cache.
20
class ChargedCache : public CacheWrapper {
21
 public:
22
  ChargedCache(std::shared_ptr<Cache> cache,
23
               std::shared_ptr<Cache> block_cache);
24
25
  Status Insert(
26
      const Slice& key, ObjectPtr obj, const CacheItemHelper* helper,
27
      size_t charge, Handle** handle = nullptr,
28
      Priority priority = Priority::LOW, const Slice& compressed_val = Slice(),
29
      CompressionType type = CompressionType::kNoCompression) override;
30
31
  Cache::Handle* Lookup(const Slice& key, const CacheItemHelper* helper,
32
                        CreateContext* create_context,
33
                        Priority priority = Priority::LOW,
34
                        Statistics* stats = nullptr) override;
35
36
  void WaitAll(AsyncLookupHandle* async_handles, size_t count) override;
37
38
  bool Release(Cache::Handle* handle, bool useful,
39
               bool erase_if_last_ref = false) override;
40
  bool Release(Cache::Handle* handle, bool erase_if_last_ref = false) override;
41
42
  void Erase(const Slice& key) override;
43
  void EraseUnRefEntries() override;
44
45
0
  static const char* kClassName() { return "ChargedCache"; }
46
0
  const char* Name() const override { return kClassName(); }
47
48
  void SetCapacity(size_t capacity) override;
49
50
0
  inline Cache* GetCache() const { return target_.get(); }
51
52
  inline ConcurrentCacheReservationManager* TEST_GetCacheReservationManager()
53
0
      const {
54
0
    return cache_res_mgr_.get();
55
0
  }
56
57
 private:
58
  std::shared_ptr<ConcurrentCacheReservationManager> cache_res_mgr_;
59
};
60
61
}  // namespace ROCKSDB_NAMESPACE