]>
Commit | Line | Data |
---|---|---|
7c673cae | 1 | // Copyright (c) 2011-present, Facebook, Inc. All rights reserved. |
11fdf7f2 TL |
2 | // This source code is licensed under both the GPLv2 (found in the |
3 | // COPYING file in the root directory) and Apache 2.0 License | |
4 | // (found in the LICENSE.Apache file in the root directory). | |
7c673cae FG |
5 | // |
6 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. | |
7 | // Use of this source code is governed by a BSD-style license that can be | |
8 | // found in the LICENSE file. See the AUTHORS file for names of contributors. | |
9 | ||
10 | #pragma once | |
11 | #include <memory> | |
494da23a | 12 | #include "db/range_tombstone_fragmenter.h" |
11fdf7f2 | 13 | #include "rocksdb/slice_transform.h" |
7c673cae FG |
14 | #include "table/internal_iterator.h" |
15 | ||
16 | namespace rocksdb { | |
17 | ||
18 | class Iterator; | |
19 | struct ParsedInternalKey; | |
20 | class Slice; | |
21 | class Arena; | |
22 | struct ReadOptions; | |
23 | struct TableProperties; | |
24 | class GetContext; | |
7c673cae FG |
25 | |
26 | // A Table is a sorted map from strings to strings. Tables are | |
27 | // immutable and persistent. A Table may be safely accessed from | |
28 | // multiple threads without external synchronization. | |
29 | class TableReader { | |
30 | public: | |
31 | virtual ~TableReader() {} | |
32 | ||
33 | // Returns a new iterator over the table contents. | |
34 | // The result of NewIterator() is initially invalid (caller must | |
35 | // call one of the Seek methods on the iterator before using it). | |
36 | // arena: If not null, the arena needs to be used to allocate the Iterator. | |
37 | // When destroying the iterator, the caller will not call "delete" | |
38 | // but Iterator::~Iterator() directly. The destructor needs to destroy | |
39 | // all the states but those allocated in arena. | |
40 | // skip_filters: disables checking the bloom filters even if they exist. This | |
41 | // option is effective only for block-based table format. | |
42 | virtual InternalIterator* NewIterator(const ReadOptions&, | |
11fdf7f2 | 43 | const SliceTransform* prefix_extractor, |
7c673cae | 44 | Arena* arena = nullptr, |
11fdf7f2 TL |
45 | bool skip_filters = false, |
46 | bool for_compaction = false) = 0; | |
7c673cae | 47 | |
494da23a | 48 | virtual FragmentedRangeTombstoneIterator* NewRangeTombstoneIterator( |
11fdf7f2 | 49 | const ReadOptions& /*read_options*/) { |
7c673cae FG |
50 | return nullptr; |
51 | } | |
52 | ||
53 | // Given a key, return an approximate byte offset in the file where | |
54 | // the data for that key begins (or would begin if the key were | |
55 | // present in the file). The returned value is in terms of file | |
56 | // bytes, and so includes effects like compression of the underlying data. | |
57 | // E.g., the approximate offset of the last key in the table will | |
58 | // be close to the file length. | |
59 | virtual uint64_t ApproximateOffsetOf(const Slice& key) = 0; | |
60 | ||
61 | // Set up the table for Compaction. Might change some parameters with | |
62 | // posix_fadvise | |
63 | virtual void SetupForCompaction() = 0; | |
64 | ||
65 | virtual std::shared_ptr<const TableProperties> GetTableProperties() const = 0; | |
66 | ||
67 | // Prepare work that can be done before the real Get() | |
11fdf7f2 | 68 | virtual void Prepare(const Slice& /*target*/) {} |
7c673cae FG |
69 | |
70 | // Report an approximation of how much memory has been used. | |
71 | virtual size_t ApproximateMemoryUsage() const = 0; | |
72 | ||
73 | // Calls get_context->SaveValue() repeatedly, starting with | |
74 | // the entry found after a call to Seek(key), until it returns false. | |
75 | // May not make such a call if filter policy says that key is not present. | |
76 | // | |
77 | // get_context->MarkKeyMayExist needs to be called when it is configured to be | |
78 | // memory only and the key is not found in the block cache. | |
79 | // | |
80 | // readOptions is the options for the read | |
81 | // key is the key to search for | |
82 | // skip_filters: disables checking the bloom filters even if they exist. This | |
83 | // option is effective only for block-based table format. | |
84 | virtual Status Get(const ReadOptions& readOptions, const Slice& key, | |
11fdf7f2 TL |
85 | GetContext* get_context, |
86 | const SliceTransform* prefix_extractor, | |
87 | bool skip_filters = false) = 0; | |
7c673cae FG |
88 | |
89 | // Prefetch data corresponding to a give range of keys | |
90 | // Typically this functionality is required for table implementations that | |
91 | // persists the data on a non volatile storage medium like disk/SSD | |
92 | virtual Status Prefetch(const Slice* begin = nullptr, | |
93 | const Slice* end = nullptr) { | |
94 | (void) begin; | |
95 | (void) end; | |
96 | // Default implementation is NOOP. | |
97 | // The child class should implement functionality when applicable | |
98 | return Status::OK(); | |
99 | } | |
100 | ||
101 | // convert db file to a human readable form | |
11fdf7f2 TL |
102 | virtual Status DumpTable(WritableFile* /*out_file*/, |
103 | const SliceTransform* /*prefix_extractor*/) { | |
7c673cae FG |
104 | return Status::NotSupported("DumpTable() not supported"); |
105 | } | |
106 | ||
11fdf7f2 TL |
107 | // check whether there is corruption in this db file |
108 | virtual Status VerifyChecksum() { | |
109 | return Status::NotSupported("VerifyChecksum() not supported"); | |
110 | } | |
111 | ||
7c673cae FG |
112 | virtual void Close() {} |
113 | }; | |
114 | ||
115 | } // namespace rocksdb |