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