| 39 | TableCache::~TableCache() { delete cache_; } |
| 40 | |
| 41 | Status 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 | |
| 78 | Iterator* TableCache::NewIterator(const ReadOptions& options, |
| 79 | uint64_t file_number, uint64_t file_size, |
nothing calls this directly
no test coverage detected