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 <stdint.h>
11 12 #include <string>
13 14 #include "db/dbformat.h"
15 #include "leveldb/cache.h"
16 #include "leveldb/table.h"
17 #include "port/port.h"
18 19 namespace leveldb {
20 21 class Env;
22 23 class TableCache {
24 public:
25 TableCache(const std::string& dbname, const Options& options, int entries);
26 ~TableCache();
27 28 // Return an iterator for the specified file number (the corresponding
29 // file length must be exactly "file_size" bytes). If "tableptr" is
30 // non-null, also sets "*tableptr" to point to the Table object
31 // underlying the returned iterator, or to nullptr if no Table object
32 // underlies the returned iterator. The returned "*tableptr" object is owned
33 // by the cache and should not be deleted, and is valid for as long as the
34 // returned iterator is live.
35 Iterator* NewIterator(const ReadOptions& options, uint64_t file_number,
36 uint64_t file_size, Table** tableptr = nullptr);
37 38 // If a seek to internal key "k" in specified file finds an entry,
39 // call (*handle_result)(arg, found_key, found_value).
40 Status Get(const ReadOptions& options, uint64_t file_number,
41 uint64_t file_size, const Slice& k, void* arg,
42 void (*handle_result)(void*, const Slice&, const Slice&));
43 44 // Evict any entry for the specified file number
45 void Evict(uint64_t file_number);
46 47 private:
48 Status FindTable(uint64_t file_number, uint64_t file_size, Cache::Handle**);
49 50 Env* const env_;
51 const std::string dbname_;
52 const Options& options_;
53 Cache* cache_;
54 };
55 56 } // namespace leveldb
57 58 #endif // STORAGE_LEVELDB_DB_TABLE_CACHE_H_
59