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