MCPcopy Create free account
hub / github.com/ElementsProject/elements / FindTable

Method FindTable

src/leveldb/db/table_cache.cc:41–76  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

39TableCache::~TableCache() { delete cache_; }
40
41Status TableCache::FindTable(uint64_t file_number, uint64_t file_size,
42 Cache::Handle** handle) {
43 Status s;
44 char buf[sizeof(file_number)];
45 EncodeFixed64(buf, file_number);
46 Slice key(buf, sizeof(buf));
47 *handle = cache_->Lookup(key);
48 if (*handle == nullptr) {
49 std::string fname = TableFileName(dbname_, file_number);
50 RandomAccessFile* file = nullptr;
51 Table* table = nullptr;
52 s = env_->NewRandomAccessFile(fname, &file);
53 if (!s.ok()) {
54 std::string old_fname = SSTTableFileName(dbname_, file_number);
55 if (env_->NewRandomAccessFile(old_fname, &file).ok()) {
56 s = Status::OK();
57 }
58 }
59 if (s.ok()) {
60 s = Table::Open(options_, file, file_size, &table);
61 }
62
63 if (!s.ok()) {
64 assert(table == nullptr);
65 delete file;
66 // We do not cache error results so that if the error is transient,
67 // or somebody repairs the file, we recover automatically.
68 } else {
69 TableAndFile* tf = new TableAndFile;
70 tf->file = file;
71 tf->table = table;
72 *handle = cache_->Insert(key, tf, 1, &DeleteEntry);
73 }
74 }
75 return s;
76}
77
78Iterator* TableCache::NewIterator(const ReadOptions& options,
79 uint64_t file_number, uint64_t file_size,

Callers

nothing calls this directly

Calls 7

EncodeFixed64Function · 0.85
TableFileNameFunction · 0.85
SSTTableFileNameFunction · 0.85
OKFunction · 0.85
LookupMethod · 0.45
NewRandomAccessFileMethod · 0.45
InsertMethod · 0.45

Tested by

no test coverage detected