1 // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 // 5 // Thread-safe (provides internal synchronization) 6 7 #ifndef STORAGE_LEVELDB_DB_TABLE_CACHE_H_ 8 #define STORAGE_LEVELDB_DB_TABLE_CACHE_H_ 9 10 #include <cstdint> 11 #include <string> 12 13 #include "db/dbformat.h" 14 #include "leveldb/cache.h" 15 #include "leveldb/table.h" 16 #include "port/port.h" 17 18 namespace leveldb { 19 20 class Env; 21 22 class TableCache { 23 public: 24 TableCache(const std::string& dbname, const Options& options, int entries); 25 ~TableCache(); 26 27 // Return an iterator for the specified file number (the corresponding 28 // file length must be exactly "file_size" bytes). If "tableptr" is 29 // non-null, also sets "*tableptr" to point to the Table object 30 // underlying the returned iterator, or to nullptr if no Table object 31 // underlies the returned iterator. The returned "*tableptr" object is owned 32 // by the cache and should not be deleted, and is valid for as long as the 33 // returned iterator is live. 34 Iterator* NewIterator(const ReadOptions& options, uint64_t file_number, 35 uint64_t file_size, Table** tableptr = nullptr); 36 37 // If a seek to internal key "k" in specified file finds an entry, 38 // call (*handle_result)(arg, found_key, found_value). 39 Status Get(const ReadOptions& options, uint64_t file_number, 40 uint64_t file_size, const Slice& k, void* arg, 41 void (*handle_result)(void*, const Slice&, const Slice&)); 42 43 // Evict any entry for the specified file number 44 void Evict(uint64_t file_number); 45 46 private: 47 Status FindTable(uint64_t file_number, uint64_t file_size, Cache::Handle**); 48 49 Env* const env_; 50 const std::string dbname_; 51 const Options& options_; 52 Cache* cache_; 53 }; 54 55 } // namespace leveldb 56 57 #endif // STORAGE_LEVELDB_DB_TABLE_CACHE_H_ 58