]>
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 | ||
12 | #include <stdint.h> | |
13 | #include <string> | |
14 | #include <utility> | |
15 | #include <vector> | |
11fdf7f2 | 16 | #include "db/dbformat.h" |
7c673cae | 17 | #include "db/table_properties_collector.h" |
f67539c2 | 18 | #include "file/writable_file_writer.h" |
7c673cae FG |
19 | #include "options/cf_options.h" |
20 | #include "rocksdb/options.h" | |
21 | #include "rocksdb/table_properties.h" | |
f67539c2 | 22 | #include "trace_replay/block_cache_tracer.h" |
7c673cae | 23 | |
f67539c2 | 24 | namespace ROCKSDB_NAMESPACE { |
7c673cae FG |
25 | |
26 | class Slice; | |
27 | class Status; | |
28 | ||
29 | struct TableReaderOptions { | |
30 | // @param skip_filters Disables loading/accessing the filter block | |
31 | TableReaderOptions(const ImmutableCFOptions& _ioptions, | |
11fdf7f2 | 32 | const SliceTransform* _prefix_extractor, |
7c673cae FG |
33 | const EnvOptions& _env_options, |
34 | const InternalKeyComparator& _internal_comparator, | |
11fdf7f2 | 35 | bool _skip_filters = false, bool _immortal = false, |
f67539c2 TL |
36 | int _level = -1, |
37 | BlockCacheTracer* const _block_cache_tracer = nullptr) | |
11fdf7f2 TL |
38 | : TableReaderOptions(_ioptions, _prefix_extractor, _env_options, |
39 | _internal_comparator, _skip_filters, _immortal, | |
f67539c2 TL |
40 | _level, 0 /* _largest_seqno */, |
41 | _block_cache_tracer) {} | |
11fdf7f2 TL |
42 | |
43 | // @param skip_filters Disables loading/accessing the filter block | |
44 | TableReaderOptions(const ImmutableCFOptions& _ioptions, | |
45 | const SliceTransform* _prefix_extractor, | |
46 | const EnvOptions& _env_options, | |
47 | const InternalKeyComparator& _internal_comparator, | |
48 | bool _skip_filters, bool _immortal, int _level, | |
f67539c2 TL |
49 | SequenceNumber _largest_seqno, |
50 | BlockCacheTracer* const _block_cache_tracer) | |
7c673cae | 51 | : ioptions(_ioptions), |
11fdf7f2 | 52 | prefix_extractor(_prefix_extractor), |
7c673cae FG |
53 | env_options(_env_options), |
54 | internal_comparator(_internal_comparator), | |
55 | skip_filters(_skip_filters), | |
11fdf7f2 TL |
56 | immortal(_immortal), |
57 | level(_level), | |
f67539c2 TL |
58 | largest_seqno(_largest_seqno), |
59 | block_cache_tracer(_block_cache_tracer) {} | |
7c673cae FG |
60 | |
61 | const ImmutableCFOptions& ioptions; | |
11fdf7f2 | 62 | const SliceTransform* prefix_extractor; |
7c673cae FG |
63 | const EnvOptions& env_options; |
64 | const InternalKeyComparator& internal_comparator; | |
65 | // This is only used for BlockBasedTable (reader) | |
66 | bool skip_filters; | |
11fdf7f2 TL |
67 | // Whether the table will be valid as long as the DB is open |
68 | bool immortal; | |
7c673cae FG |
69 | // what level this table/file is on, -1 for "not set, don't know" |
70 | int level; | |
11fdf7f2 TL |
71 | // largest seqno in the table |
72 | SequenceNumber largest_seqno; | |
f67539c2 | 73 | BlockCacheTracer* const block_cache_tracer; |
7c673cae FG |
74 | }; |
75 | ||
76 | struct TableBuilderOptions { | |
77 | TableBuilderOptions( | |
11fdf7f2 | 78 | const ImmutableCFOptions& _ioptions, const MutableCFOptions& _moptions, |
7c673cae FG |
79 | const InternalKeyComparator& _internal_comparator, |
80 | const std::vector<std::unique_ptr<IntTblPropCollectorFactory>>* | |
81 | _int_tbl_prop_collector_factories, | |
494da23a TL |
82 | CompressionType _compression_type, uint64_t _sample_for_compression, |
83 | const CompressionOptions& _compression_opts, bool _skip_filters, | |
11fdf7f2 | 84 | const std::string& _column_family_name, int _level, |
494da23a | 85 | const uint64_t _creation_time = 0, const int64_t _oldest_key_time = 0, |
f67539c2 TL |
86 | const uint64_t _target_file_size = 0, |
87 | const uint64_t _file_creation_time = 0) | |
7c673cae | 88 | : ioptions(_ioptions), |
11fdf7f2 | 89 | moptions(_moptions), |
7c673cae FG |
90 | internal_comparator(_internal_comparator), |
91 | int_tbl_prop_collector_factories(_int_tbl_prop_collector_factories), | |
92 | compression_type(_compression_type), | |
494da23a | 93 | sample_for_compression(_sample_for_compression), |
7c673cae | 94 | compression_opts(_compression_opts), |
7c673cae FG |
95 | skip_filters(_skip_filters), |
96 | column_family_name(_column_family_name), | |
11fdf7f2 TL |
97 | level(_level), |
98 | creation_time(_creation_time), | |
494da23a | 99 | oldest_key_time(_oldest_key_time), |
f67539c2 TL |
100 | target_file_size(_target_file_size), |
101 | file_creation_time(_file_creation_time) {} | |
7c673cae | 102 | const ImmutableCFOptions& ioptions; |
11fdf7f2 | 103 | const MutableCFOptions& moptions; |
7c673cae FG |
104 | const InternalKeyComparator& internal_comparator; |
105 | const std::vector<std::unique_ptr<IntTblPropCollectorFactory>>* | |
106 | int_tbl_prop_collector_factories; | |
107 | CompressionType compression_type; | |
494da23a | 108 | uint64_t sample_for_compression; |
7c673cae | 109 | const CompressionOptions& compression_opts; |
7c673cae FG |
110 | bool skip_filters; // only used by BlockBasedTableBuilder |
111 | const std::string& column_family_name; | |
112 | int level; // what level this table/file is on, -1 for "not set, don't know" | |
11fdf7f2 TL |
113 | const uint64_t creation_time; |
114 | const int64_t oldest_key_time; | |
494da23a | 115 | const uint64_t target_file_size; |
f67539c2 | 116 | const uint64_t file_creation_time; |
7c673cae FG |
117 | }; |
118 | ||
119 | // TableBuilder provides the interface used to build a Table | |
120 | // (an immutable and sorted map from keys to values). | |
121 | // | |
122 | // Multiple threads can invoke const methods on a TableBuilder without | |
123 | // external synchronization, but if any of the threads may call a | |
124 | // non-const method, all threads accessing the same TableBuilder must use | |
125 | // external synchronization. | |
126 | class TableBuilder { | |
127 | public: | |
128 | // REQUIRES: Either Finish() or Abandon() has been called. | |
129 | virtual ~TableBuilder() {} | |
130 | ||
131 | // Add key,value to the table being constructed. | |
132 | // REQUIRES: key is after any previously added key according to comparator. | |
133 | // REQUIRES: Finish(), Abandon() have not been called | |
134 | virtual void Add(const Slice& key, const Slice& value) = 0; | |
135 | ||
136 | // Return non-ok iff some error has been detected. | |
137 | virtual Status status() const = 0; | |
138 | ||
139 | // Finish building the table. | |
140 | // REQUIRES: Finish(), Abandon() have not been called | |
141 | virtual Status Finish() = 0; | |
142 | ||
143 | // Indicate that the contents of this builder should be abandoned. | |
144 | // If the caller is not going to call Finish(), it must call Abandon() | |
145 | // before destroying this builder. | |
146 | // REQUIRES: Finish(), Abandon() have not been called | |
147 | virtual void Abandon() = 0; | |
148 | ||
149 | // Number of calls to Add() so far. | |
150 | virtual uint64_t NumEntries() const = 0; | |
151 | ||
152 | // Size of the file generated so far. If invoked after a successful | |
153 | // Finish() call, returns the size of the final generated file. | |
154 | virtual uint64_t FileSize() const = 0; | |
155 | ||
156 | // If the user defined table properties collector suggest the file to | |
157 | // be further compacted. | |
158 | virtual bool NeedCompact() const { return false; } | |
159 | ||
160 | // Returns table properties | |
161 | virtual TableProperties GetTableProperties() const = 0; | |
f67539c2 TL |
162 | |
163 | // Return file checksum | |
164 | virtual const std::string& GetFileChecksum() const = 0; | |
165 | ||
166 | // Return file checksum function name | |
167 | virtual const char* GetFileChecksumFuncName() const = 0; | |
7c673cae FG |
168 | }; |
169 | ||
f67539c2 | 170 | } // namespace ROCKSDB_NAMESPACE |