// Copyright (c) 2013, Facebook, Inc. All rights reserved.
-// This source code is licensed under the BSD-style license found in the
-// LICENSE file in the root directory of this source tree. An additional grant
-// of patent rights can be found in the PATENTS file in the same directory.
+// This source code is licensed under both the GPLv2 (found in the
+// COPYING file in the root directory) and Apache 2.0 License
+// (found in the LICENSE.Apache file in the root directory).
#pragma once
#ifndef ROCKSDB_LITE
-#ifndef OS_WIN
+#ifndef OS_WIN
#include <unistd.h>
-#endif // ! OS_WIN
+#endif // ! OS_WIN
+#include <atomic>
#include <list>
#include <memory>
#include <set>
#include <string>
#include <thread>
-#include "rocksdb/cache.h"
-#include "rocksdb/comparator.h"
-#include "rocksdb/persistent_cache.h"
-
-#include "utilities/persistent_cache/block_cache_tier_file.h"
-#include "utilities/persistent_cache/block_cache_tier_metadata.h"
-#include "utilities/persistent_cache/persistent_cache_util.h"
-
+#include "memory/arena.h"
#include "memtable/skiplist.h"
#include "monitoring/histogram.h"
#include "port/port.h"
-#include "util/arena.h"
+#include "rocksdb/cache.h"
+#include "rocksdb/comparator.h"
+#include "rocksdb/persistent_cache.h"
+#include "rocksdb/system_clock.h"
#include "util/coding.h"
#include "util/crc32c.h"
#include "util/mutexlock.h"
+#include "utilities/persistent_cache/block_cache_tier_file.h"
+#include "utilities/persistent_cache/block_cache_tier_metadata.h"
+#include "utilities/persistent_cache/persistent_cache_util.h"
-namespace rocksdb {
+namespace ROCKSDB_NAMESPACE {
//
// Block cache tier implementation
public:
explicit BlockCacheTier(const PersistentCacheConfig& opt)
: opt_(opt),
- insert_ops_(opt_.max_write_pipeline_backlog_size),
+ insert_ops_(static_cast<size_t>(opt_.max_write_pipeline_backlog_size)),
buffer_allocator_(opt.write_buffer_size, opt.write_buffer_count()),
- writer_(this, opt_.writer_qdepth, opt_.writer_dispatch_size) {
- Info(opt_.log, "Initializing allocator. size=%d B count=%d",
+ writer_(this, opt_.writer_qdepth,
+ static_cast<size_t>(opt_.writer_dispatch_size)) {
+ Info(opt_.log, "Initializing allocator. size=%d B count=%" ROCKSDB_PRIszt,
opt_.write_buffer_size, opt_.write_buffer_count());
}
virtual ~BlockCacheTier() {
// Close is re-entrant so we can call close even if it is already closed
- Close();
+ Close().PermitUncheckedError();
assert(!insert_th_.joinable());
}
void TEST_Flush() override {
while (insert_ops_.Size()) {
/* sleep override */
- Env::Default()->SleepForMicroseconds(1000000);
+ SystemClock::Default()->SleepForMicroseconds(1000000);
}
}
~InsertOp() {}
InsertOp() = delete;
- InsertOp(InsertOp&& rhs) = default;
+ InsertOp(InsertOp&& /*rhs*/) = default;
InsertOp& operator=(InsertOp&& rhs) = default;
// used for estimating size by bounded queue
std::string key_;
std::string data_;
- const bool signal_ = false; // signal to request processing thread to exit
+ bool signal_ = false; // signal to request processing thread to exit
};
// entry point for insert thread
HistogramImpl read_hit_latency_;
HistogramImpl read_miss_latency_;
HistogramImpl write_latency_;
- uint64_t cache_hits_ = 0;
- uint64_t cache_misses_ = 0;
- uint64_t cache_errors_ = 0;
- uint64_t insert_dropped_ = 0;
+ std::atomic<uint64_t> cache_hits_{0};
+ std::atomic<uint64_t> cache_misses_{0};
+ std::atomic<uint64_t> cache_errors_{0};
+ std::atomic<uint64_t> insert_dropped_{0};
double CacheHitPct() const {
const auto lookups = cache_hits_ + cache_misses_;
port::RWMutex lock_; // Synchronization
const PersistentCacheConfig opt_; // BlockCache options
BoundedQueue<InsertOp> insert_ops_; // Ops waiting for insert
- rocksdb::port::Thread insert_th_; // Insert thread
+ ROCKSDB_NAMESPACE::port::Thread insert_th_; // Insert thread
uint32_t writer_cache_id_ = 0; // Current cache file identifier
WriteableCacheFile* cache_file_ = nullptr; // Current cache file reference
CacheWriteBufferAllocator buffer_allocator_; // Buffer provider
ThreadedWriter writer_; // Writer threads
BlockCacheTierMetadata metadata_; // Cache meta data manager
std::atomic<uint64_t> size_{0}; // Size of the cache
- Statistics stats_; // Statistics
+ Statistics stats_; // Statistics
};
-} // namespace rocksdb
+} // namespace ROCKSDB_NAMESPACE
#endif