| 36 | }; |
| 37 | |
| 38 | Status Table::Open(const Options& options, RandomAccessFile* file, |
| 39 | uint64_t size, Table** table) { |
| 40 | *table = nullptr; |
| 41 | if (size < Footer::kEncodedLength) { |
| 42 | return Status::Corruption("file is too short to be an sstable"); |
| 43 | } |
| 44 | |
| 45 | char footer_space[Footer::kEncodedLength]; |
| 46 | Slice footer_input; |
| 47 | Status s = file->Read(size - Footer::kEncodedLength, Footer::kEncodedLength, |
| 48 | &footer_input, footer_space); |
| 49 | if (!s.ok()) return s; |
| 50 | |
| 51 | Footer footer; |
| 52 | s = footer.DecodeFrom(&footer_input); |
| 53 | if (!s.ok()) return s; |
| 54 | |
| 55 | // Read the index block |
| 56 | BlockContents index_block_contents; |
| 57 | if (s.ok()) { |
| 58 | ReadOptions opt; |
| 59 | if (options.paranoid_checks) { |
| 60 | opt.verify_checksums = true; |
| 61 | } |
| 62 | s = ReadBlock(file, opt, footer.index_handle(), &index_block_contents); |
| 63 | } |
| 64 | |
| 65 | if (s.ok()) { |
| 66 | // We've successfully read the footer and the index block: we're |
| 67 | // ready to serve requests. |
| 68 | Block* index_block = new Block(index_block_contents); |
| 69 | Rep* rep = new Table::Rep; |
| 70 | rep->options = options; |
| 71 | rep->file = file; |
| 72 | rep->metaindex_handle = footer.metaindex_handle(); |
| 73 | rep->index_block = index_block; |
| 74 | rep->cache_id = (options.block_cache ? options.block_cache->NewId() : 0); |
| 75 | rep->filter_data = nullptr; |
| 76 | rep->filter = nullptr; |
| 77 | *table = new Table(rep); |
| 78 | (*table)->ReadMeta(footer); |
| 79 | } |
| 80 | |
| 81 | return s; |
| 82 | } |
| 83 | |
| 84 | void Table::ReadMeta(const Footer& footer) { |
| 85 | if (rep_->options.filter_policy == nullptr) { |
nothing calls this directly
no test coverage detected