/Users/deen/code/yugabyte-db/src/yb/rocksdb/table/table_builder.h
Line | Count | Source |
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 | | // The following only applies to changes made to this file as part of YugaByte development. |
7 | | // |
8 | | // Portions Copyright (c) YugaByte, Inc. |
9 | | // |
10 | | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except |
11 | | // in compliance with the License. You may obtain a copy of the License at |
12 | | // |
13 | | // http://www.apache.org/licenses/LICENSE-2.0 |
14 | | // |
15 | | // Unless required by applicable law or agreed to in writing, software distributed under the License |
16 | | // is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express |
17 | | // or implied. See the License for the specific language governing permissions and limitations |
18 | | // under the License. |
19 | | // |
20 | | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. |
21 | | // Use of this source code is governed by a BSD-style license that can be |
22 | | // found in the LICENSE file. See the AUTHORS file for names of contributors. |
23 | | |
24 | | #ifndef YB_ROCKSDB_TABLE_TABLE_BUILDER_H |
25 | | #define YB_ROCKSDB_TABLE_TABLE_BUILDER_H |
26 | | |
27 | | #include <stdint.h> |
28 | | |
29 | | #include <string> |
30 | | #include <utility> |
31 | | #include <vector> |
32 | | |
33 | | #include "yb/rocksdb/db/table_properties_collector.h" |
34 | | #include "yb/rocksdb/env.h" |
35 | | #include "yb/rocksdb/immutable_options.h" |
36 | | #include "yb/rocksdb/options.h" |
37 | | #include "yb/rocksdb/table_properties.h" |
38 | | #include "yb/rocksdb/util/statistics.h" |
39 | | |
40 | | #include "yb/util/status_fwd.h" |
41 | | #include "yb/util/slice.h" |
42 | | |
43 | | namespace rocksdb { |
44 | | |
45 | | struct TableReaderOptions { |
46 | | // @param skip_filters Disables loading/accessing the filter block |
47 | | TableReaderOptions(const ImmutableCFOptions& _ioptions, |
48 | | const EnvOptions& _env_options, |
49 | | const InternalKeyComparatorPtr& _internal_comparator, |
50 | | bool _skip_filters = false) |
51 | | : ioptions(_ioptions), |
52 | | env_options(_env_options), |
53 | | internal_comparator(_internal_comparator), |
54 | 75.9k | skip_filters(_skip_filters) {} |
55 | | |
56 | | const ImmutableCFOptions& ioptions; |
57 | | const EnvOptions& env_options; |
58 | | const InternalKeyComparatorPtr internal_comparator; |
59 | | // This is only used for BlockBasedTable (reader) |
60 | | bool skip_filters; |
61 | | }; |
62 | | |
63 | | struct TableBuilderOptions { |
64 | | TableBuilderOptions( |
65 | | const ImmutableCFOptions& _ioptions, |
66 | | const InternalKeyComparatorPtr& _internal_comparator, |
67 | | const IntTblPropCollectorFactories& _int_tbl_prop_collector_factories, |
68 | | CompressionType _compression_type, |
69 | | const CompressionOptions& _compression_opts, |
70 | | bool _skip_filters) |
71 | | : ioptions(_ioptions), |
72 | | internal_comparator(_internal_comparator), |
73 | | int_tbl_prop_collector_factories(&_int_tbl_prop_collector_factories), |
74 | | compression_type(_compression_type), |
75 | | compression_opts(_compression_opts), |
76 | 63.6k | skip_filters(_skip_filters) {} |
77 | | |
78 | | const ImmutableCFOptions& ioptions; |
79 | | InternalKeyComparatorPtr internal_comparator; |
80 | | const IntTblPropCollectorFactories* int_tbl_prop_collector_factories; |
81 | | CompressionType compression_type; |
82 | | const CompressionOptions& compression_opts; |
83 | | // This is only used for BlockBasedTableBuilder |
84 | | bool skip_filters = false; |
85 | | }; |
86 | | |
87 | | // TableBuilder provides the interface used to build a Table |
88 | | // (an immutable and sorted map from keys to values). |
89 | | // |
90 | | // Multiple threads can invoke const methods on a TableBuilder without |
91 | | // external synchronization, but if any of the threads may call a |
92 | | // non-const method, all threads accessing the same TableBuilder must use |
93 | | // external synchronization. |
94 | | class TableBuilder { |
95 | | public: |
96 | | // REQUIRES: Either Finish() or Abandon() has been called. |
97 | 63.5k | virtual ~TableBuilder() {} |
98 | | |
99 | | // Add key,value to the table being constructed. |
100 | | // REQUIRES: key is after any previously added key according to comparator. |
101 | | // REQUIRES: Finish(), Abandon() have not been called |
102 | | virtual void Add(const Slice& key, const Slice& value) = 0; |
103 | | |
104 | | // Return non-ok iff some error has been detected. |
105 | | virtual Status status() const = 0; |
106 | | |
107 | | // Finish building the table. |
108 | | // REQUIRES: Finish(), Abandon() have not been called |
109 | | virtual Status Finish() = 0; |
110 | | |
111 | | // Indicate that the contents of this builder should be abandoned. |
112 | | // If the caller is not going to call Finish(), it must call Abandon() |
113 | | // before destroying this builder. |
114 | | // REQUIRES: Finish(), Abandon() have not been called |
115 | | virtual void Abandon() = 0; |
116 | | |
117 | | // Number of calls to Add() so far. |
118 | | virtual uint64_t NumEntries() const = 0; |
119 | | |
120 | | // Total size of the file(s) generated so far. If invoked after a successful |
121 | | // Finish() call, returns the total size of the final generated file(s). |
122 | | virtual uint64_t TotalFileSize() const = 0; |
123 | | |
124 | | // Size of the base file generated so far. If invoked after a successful Finish() call, returns |
125 | | // the size of the final generated base file. SST is either stored in single base file, or |
126 | | // metadata is stored in base file while data is split among data files (S-Blocks). |
127 | | virtual uint64_t BaseFileSize() const = 0; |
128 | | |
129 | | // If the user defined table properties collector suggest the file to |
130 | | // be further compacted. |
131 | 1.36k | virtual bool NeedCompact() const { return false; } |
132 | | |
133 | | // Returns table properties |
134 | | virtual TableProperties GetTableProperties() const = 0; |
135 | | }; |
136 | | |
137 | | } // namespace rocksdb |
138 | | |
139 | | #endif // YB_ROCKSDB_TABLE_TABLE_BUILDER_H |