1 // Copyright (c) 2013, Facebook, Inc. All rights reserved. 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 // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 6 // Use of this source code is governed by a BSD-style license that can be 7 // found in the LICENSE file. See the AUTHORS file for names of contributors. 8 #pragma once 9 10 #include <stdint.h> 11 #include <memory> 12 #include <string> 13 14 #include "rocksdb/env.h" 15 #include "rocksdb/slice.h" 16 #include "rocksdb/statistics.h" 17 #include "rocksdb/status.h" 18 19 namespace ROCKSDB_NAMESPACE { 20 21 // PersistentCache 22 // 23 // Persistent cache interface for caching IO pages on a persistent medium. The 24 // cache interface is specifically designed for persistent read cache. 25 class PersistentCache { 26 public: 27 typedef std::vector<std::map<std::string, double>> StatsType; 28 ~PersistentCache()29 virtual ~PersistentCache() {} 30 31 // Insert to page cache 32 // 33 // page_key Identifier to identify a page uniquely across restarts 34 // data Page data 35 // size Size of the page 36 virtual Status Insert(const Slice& key, const char* data, 37 const size_t size) = 0; 38 39 // Lookup page cache by page identifier 40 // 41 // page_key Page identifier 42 // buf Buffer where the data should be copied 43 // size Size of the page 44 virtual Status Lookup(const Slice& key, std::unique_ptr<char[]>* data, 45 size_t* size) = 0; 46 47 // Is cache storing uncompressed data ? 48 // 49 // True if the cache is configured to store uncompressed data else false 50 virtual bool IsCompressed() = 0; 51 52 // Return stats as map of {string, double} per-tier 53 // 54 // Persistent cache can be initialized as a tier of caches. The stats are per 55 // tire top-down 56 virtual StatsType Stats() = 0; 57 58 virtual std::string GetPrintableOptions() const = 0; 59 }; 60 61 // Factor method to create a new persistent cache 62 Status NewPersistentCache(Env* const env, const std::string& path, 63 const uint64_t size, 64 const std::shared_ptr<Logger>& log, 65 const bool optimized_for_nvm, 66 std::shared_ptr<PersistentCache>* cache); 67 } // namespace ROCKSDB_NAMESPACE 68