| 241 | class ShardedCache : public Cache { |
| 242 | public: |
| 243 | explicit ShardedCache(Cache::EvictionPolicy policy, size_t capacity, const string& id) |
| 244 | : shard_bits_(DetermineShardBits()) { |
| 245 | // A cache is often a singleton, so: |
| 246 | // 1. We reuse its MemTracker if one already exists, and |
| 247 | // 2. It is directly parented to the root MemTracker. |
| 248 | // TODO: Change this to an Impala MemTracker, and only track the memory usage for the |
| 249 | // metadata. This currently does not hook up to Impala's MemTracker hierarchy |
| 250 | mem_tracker_ = kudu::MemTracker::FindOrCreateGlobalTracker( |
| 251 | -1, strings::Substitute("$0-sharded_$1_cache", id, ToString(policy))); |
| 252 | |
| 253 | int num_shards = 1 << shard_bits_; |
| 254 | const size_t per_shard = (capacity + (num_shards - 1)) / num_shards; |
| 255 | for (int s = 0; s < num_shards; ++s) { |
| 256 | shards_.push_back(NewCacheShard(policy, mem_tracker_.get(), per_shard)); |
| 257 | } |
| 258 | |
| 259 | if (per_shard < shard_charge_limit_) { |
| 260 | shard_charge_limit_ = static_cast<int>(per_shard); |
| 261 | } |
| 262 | } |
| 263 | |
| 264 | virtual ~ShardedCache() { |
| 265 | STLDeleteElements(&shards_); |
nothing calls this directly
no test coverage detected