]>
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> | |
11fdf7f2 | 12 | #include "rocksdb/slice_transform.h" |
7c673cae FG |
13 | #include "table/internal_iterator.h" |
14 | ||
15 | namespace rocksdb { | |
16 | ||
17 | class Iterator; | |
18 | struct ParsedInternalKey; | |
19 | class Slice; | |
20 | class Arena; | |
21 | struct ReadOptions; | |
22 | struct TableProperties; | |
23 | class GetContext; | |
7c673cae FG |
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&, | |
11fdf7f2 | 42 | const SliceTransform* prefix_extractor, |
7c673cae | 43 | Arena* arena = nullptr, |
11fdf7f2 TL |
44 | bool skip_filters = false, |
45 | bool for_compaction = false) = 0; | |
7c673cae FG |
46 | |
47 | virtual InternalIterator* NewRangeTombstoneIterator( | |
11fdf7f2 | 48 | const ReadOptions& /*read_options*/) { |
7c673cae FG |
49 | return nullptr; |
50 | } | |
51 | ||
52 | // Given a key, return an approximate byte offset in the file where | |
53 | // the data for that key begins (or would begin if the key were | |
54 | // present in the file). The returned value is in terms of file | |
55 | // bytes, and so includes effects like compression of the underlying data. | |
56 | // E.g., the approximate offset of the last key in the table will | |
57 | // be close to the file length. | |
58 | virtual uint64_t ApproximateOffsetOf(const Slice& key) = 0; | |
59 | ||
60 | // Set up the table for Compaction. Might change some parameters with | |
61 | // posix_fadvise | |
62 | virtual void SetupForCompaction() = 0; | |
63 | ||
64 | virtual std::shared_ptr<const TableProperties> GetTableProperties() const = 0; | |
65 | ||
66 | // Prepare work that can be done before the real Get() | |
11fdf7f2 | 67 | virtual void Prepare(const Slice& /*target*/) {} |
7c673cae FG |
68 | |
69 | // Report an approximation of how much memory has been used. | |
70 | virtual size_t ApproximateMemoryUsage() const = 0; | |
71 | ||
72 | // Calls get_context->SaveValue() repeatedly, starting with | |
73 | // the entry found after a call to Seek(key), until it returns false. | |
74 | // May not make such a call if filter policy says that key is not present. | |
75 | // | |
76 | // get_context->MarkKeyMayExist needs to be called when it is configured to be | |
77 | // memory only and the key is not found in the block cache. | |
78 | // | |
79 | // readOptions is the options for the read | |
80 | // key is the key to search for | |
81 | // skip_filters: disables checking the bloom filters even if they exist. This | |
82 | // option is effective only for block-based table format. | |
83 | virtual Status Get(const ReadOptions& readOptions, const Slice& key, | |
11fdf7f2 TL |
84 | GetContext* get_context, |
85 | const SliceTransform* prefix_extractor, | |
86 | bool skip_filters = false) = 0; | |
7c673cae FG |
87 | |
88 | // Prefetch data corresponding to a give range of keys | |
89 | // Typically this functionality is required for table implementations that | |
90 | // persists the data on a non volatile storage medium like disk/SSD | |
91 | virtual Status Prefetch(const Slice* begin = nullptr, | |
92 | const Slice* end = nullptr) { | |
93 | (void) begin; | |
94 | (void) end; | |
95 | // Default implementation is NOOP. | |
96 | // The child class should implement functionality when applicable | |
97 | return Status::OK(); | |
98 | } | |
99 | ||
100 | // convert db file to a human readable form | |
11fdf7f2 TL |
101 | virtual Status DumpTable(WritableFile* /*out_file*/, |
102 | const SliceTransform* /*prefix_extractor*/) { | |
7c673cae FG |
103 | return Status::NotSupported("DumpTable() not supported"); |
104 | } | |
105 | ||
11fdf7f2 TL |
106 | // check whether there is corruption in this db file |
107 | virtual Status VerifyChecksum() { | |
108 | return Status::NotSupported("VerifyChecksum() not supported"); | |
109 | } | |
110 | ||
7c673cae FG |
111 | virtual void Close() {} |
112 | }; | |
113 | ||
114 | } // namespace rocksdb |