]>
Commit | Line | Data |
---|---|---|
7c673cae | 1 | // Copyright (c) 2011-present, Facebook, Inc. All rights reserved. |
11fdf7f2 TL |
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). | |
7c673cae FG |
5 | |
6 | #pragma once | |
7 | ||
8 | #include <stdint.h> | |
1e59de90 | 9 | |
7c673cae FG |
10 | #include <memory> |
11 | #include <string> | |
1e59de90 | 12 | |
7c673cae | 13 | #include "rocksdb/cache.h" |
11fdf7f2 | 14 | #include "rocksdb/env.h" |
7c673cae FG |
15 | #include "rocksdb/slice.h" |
16 | #include "rocksdb/statistics.h" | |
17 | #include "rocksdb/status.h" | |
18 | ||
f67539c2 | 19 | namespace ROCKSDB_NAMESPACE { |
7c673cae FG |
20 | |
21 | class SimCache; | |
22 | ||
23 | // For instrumentation purpose, use NewSimCache instead of NewLRUCache API | |
24 | // NewSimCache is a wrapper function returning a SimCache instance that can | |
25 | // have additional interface provided in Simcache class besides Cache interface | |
26 | // to predict block cache hit rate without actually allocating the memory. It | |
27 | // can help users tune their current block cache size, and determine how | |
28 | // efficient they are using the memory. | |
29 | // | |
1e59de90 | 30 | // Since GetSimCapacity() returns the capacity for simulation, it differs from |
7c673cae FG |
31 | // actual memory usage, which can be estimated as: |
32 | // sim_capacity * entry_size / (entry_size + block_size), | |
33 | // where 76 <= entry_size <= 104, | |
34 | // BlockBasedTableOptions.block_size = 4096 by default but is configurable, | |
35 | // Therefore, generally the actual memory overhead of SimCache is Less than | |
36 | // sim_capacity * 2% | |
37 | extern std::shared_ptr<SimCache> NewSimCache(std::shared_ptr<Cache> cache, | |
38 | size_t sim_capacity, | |
39 | int num_shard_bits); | |
40 | ||
f67539c2 TL |
41 | extern std::shared_ptr<SimCache> NewSimCache(std::shared_ptr<Cache> sim_cache, |
42 | std::shared_ptr<Cache> cache, | |
43 | int num_shard_bits); | |
44 | ||
7c673cae FG |
45 | class SimCache : public Cache { |
46 | public: | |
47 | SimCache() {} | |
48 | ||
11fdf7f2 | 49 | ~SimCache() override {} |
7c673cae | 50 | |
11fdf7f2 | 51 | const char* Name() const override { return "SimCache"; } |
7c673cae FG |
52 | |
53 | // returns the maximum configured capacity of the simcache for simulation | |
54 | virtual size_t GetSimCapacity() const = 0; | |
55 | ||
56 | // simcache doesn't provide internal handler reference to user, so always | |
57 | // PinnedUsage = 0 and the behavior will be not exactly consistent the | |
58 | // with real cache. | |
59 | // returns the memory size for the entries residing in the simcache. | |
60 | virtual size_t GetSimUsage() const = 0; | |
61 | ||
62 | // sets the maximum configured capacity of the simcache. When the new | |
63 | // capacity is less than the old capacity and the existing usage is | |
64 | // greater than new capacity, the implementation will purge old entries | |
1e59de90 | 65 | // to fit new capacity. |
7c673cae FG |
66 | virtual void SetSimCapacity(size_t capacity) = 0; |
67 | ||
68 | // returns the lookup times of simcache | |
69 | virtual uint64_t get_miss_counter() const = 0; | |
70 | // returns the hit times of simcache | |
71 | virtual uint64_t get_hit_counter() const = 0; | |
72 | // reset the lookup and hit counters | |
73 | virtual void reset_counter() = 0; | |
74 | // String representation of the statistics of the simcache | |
75 | virtual std::string ToString() const = 0; | |
76 | ||
11fdf7f2 TL |
77 | // Start storing logs of the cache activity (Add/Lookup) into |
78 | // a file located at activity_log_file, max_logging_size option can be used to | |
79 | // stop logging to the file automatically after reaching a specific size in | |
80 | // bytes, a values of 0 disable this feature | |
81 | virtual Status StartActivityLogging(const std::string& activity_log_file, | |
494da23a TL |
82 | Env* env, |
83 | uint64_t max_logging_size = 0) = 0; | |
11fdf7f2 TL |
84 | |
85 | // Stop cache activity logging if any | |
86 | virtual void StopActivityLogging() = 0; | |
87 | ||
88 | // Status of cache logging happening in background | |
89 | virtual Status GetActivityLoggingStatus() = 0; | |
90 | ||
7c673cae FG |
91 | private: |
92 | SimCache(const SimCache&); | |
93 | SimCache& operator=(const SimCache&); | |
94 | }; | |
95 | ||
f67539c2 | 96 | } // namespace ROCKSDB_NAMESPACE |