]>
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 | ||
12 | #include <stdint.h> | |
13 | #include <string> | |
14 | #include <utility> | |
15 | #include <vector> | |
16 | #include "db/table_properties_collector.h" | |
17 | #include "options/cf_options.h" | |
18 | #include "rocksdb/options.h" | |
19 | #include "rocksdb/table_properties.h" | |
20 | #include "util/file_reader_writer.h" | |
21 | ||
22 | namespace rocksdb { | |
23 | ||
24 | class Slice; | |
25 | class Status; | |
26 | ||
27 | struct TableReaderOptions { | |
28 | // @param skip_filters Disables loading/accessing the filter block | |
29 | TableReaderOptions(const ImmutableCFOptions& _ioptions, | |
30 | const EnvOptions& _env_options, | |
31 | const InternalKeyComparator& _internal_comparator, | |
32 | bool _skip_filters = false, int _level = -1) | |
33 | : ioptions(_ioptions), | |
34 | env_options(_env_options), | |
35 | internal_comparator(_internal_comparator), | |
36 | skip_filters(_skip_filters), | |
37 | level(_level) {} | |
38 | ||
39 | const ImmutableCFOptions& ioptions; | |
40 | const EnvOptions& env_options; | |
41 | const InternalKeyComparator& internal_comparator; | |
42 | // This is only used for BlockBasedTable (reader) | |
43 | bool skip_filters; | |
44 | // what level this table/file is on, -1 for "not set, don't know" | |
45 | int level; | |
46 | }; | |
47 | ||
48 | struct TableBuilderOptions { | |
49 | TableBuilderOptions( | |
50 | const ImmutableCFOptions& _ioptions, | |
51 | const InternalKeyComparator& _internal_comparator, | |
52 | const std::vector<std::unique_ptr<IntTblPropCollectorFactory>>* | |
53 | _int_tbl_prop_collector_factories, | |
54 | CompressionType _compression_type, | |
55 | const CompressionOptions& _compression_opts, | |
56 | const std::string* _compression_dict, bool _skip_filters, | |
57 | const std::string& _column_family_name, int _level) | |
58 | : ioptions(_ioptions), | |
59 | internal_comparator(_internal_comparator), | |
60 | int_tbl_prop_collector_factories(_int_tbl_prop_collector_factories), | |
61 | compression_type(_compression_type), | |
62 | compression_opts(_compression_opts), | |
63 | compression_dict(_compression_dict), | |
64 | skip_filters(_skip_filters), | |
65 | column_family_name(_column_family_name), | |
66 | level(_level) {} | |
67 | const ImmutableCFOptions& ioptions; | |
68 | const InternalKeyComparator& internal_comparator; | |
69 | const std::vector<std::unique_ptr<IntTblPropCollectorFactory>>* | |
70 | int_tbl_prop_collector_factories; | |
71 | CompressionType compression_type; | |
72 | const CompressionOptions& compression_opts; | |
73 | // Data for presetting the compression library's dictionary, or nullptr. | |
74 | const std::string* compression_dict; | |
75 | bool skip_filters; // only used by BlockBasedTableBuilder | |
76 | const std::string& column_family_name; | |
77 | int level; // what level this table/file is on, -1 for "not set, don't know" | |
78 | }; | |
79 | ||
80 | // TableBuilder provides the interface used to build a Table | |
81 | // (an immutable and sorted map from keys to values). | |
82 | // | |
83 | // Multiple threads can invoke const methods on a TableBuilder without | |
84 | // external synchronization, but if any of the threads may call a | |
85 | // non-const method, all threads accessing the same TableBuilder must use | |
86 | // external synchronization. | |
87 | class TableBuilder { | |
88 | public: | |
89 | // REQUIRES: Either Finish() or Abandon() has been called. | |
90 | virtual ~TableBuilder() {} | |
91 | ||
92 | // Add key,value to the table being constructed. | |
93 | // REQUIRES: key is after any previously added key according to comparator. | |
94 | // REQUIRES: Finish(), Abandon() have not been called | |
95 | virtual void Add(const Slice& key, const Slice& value) = 0; | |
96 | ||
97 | // Return non-ok iff some error has been detected. | |
98 | virtual Status status() const = 0; | |
99 | ||
100 | // Finish building the table. | |
101 | // REQUIRES: Finish(), Abandon() have not been called | |
102 | virtual Status Finish() = 0; | |
103 | ||
104 | // Indicate that the contents of this builder should be abandoned. | |
105 | // If the caller is not going to call Finish(), it must call Abandon() | |
106 | // before destroying this builder. | |
107 | // REQUIRES: Finish(), Abandon() have not been called | |
108 | virtual void Abandon() = 0; | |
109 | ||
110 | // Number of calls to Add() so far. | |
111 | virtual uint64_t NumEntries() const = 0; | |
112 | ||
113 | // Size of the file generated so far. If invoked after a successful | |
114 | // Finish() call, returns the size of the final generated file. | |
115 | virtual uint64_t FileSize() const = 0; | |
116 | ||
117 | // If the user defined table properties collector suggest the file to | |
118 | // be further compacted. | |
119 | virtual bool NeedCompact() const { return false; } | |
120 | ||
121 | // Returns table properties | |
122 | virtual TableProperties GetTableProperties() const = 0; | |
123 | }; | |
124 | ||
125 | } // namespace rocksdb |