]> git.proxmox.com Git - ceph.git/blame - ceph/src/rocksdb/table/table_builder.h
import quincy beta 17.1.0
[ceph.git] / ceph / src / rocksdb / table / table_builder.h
CommitLineData
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 24namespace ROCKSDB_NAMESPACE {
7c673cae
FG
25
26class Slice;
27class Status;
28
29struct 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,
20effc67
TL
36 bool _force_direct_prefetch = false, int _level = -1,
37 BlockCacheTracer* const _block_cache_tracer = nullptr,
38 size_t _max_file_size_for_l0_meta_pin = 0)
11fdf7f2
TL
39 : TableReaderOptions(_ioptions, _prefix_extractor, _env_options,
40 _internal_comparator, _skip_filters, _immortal,
20effc67
TL
41 _force_direct_prefetch, _level,
42 0 /* _largest_seqno */, _block_cache_tracer,
43 _max_file_size_for_l0_meta_pin) {}
11fdf7f2
TL
44
45 // @param skip_filters Disables loading/accessing the filter block
46 TableReaderOptions(const ImmutableCFOptions& _ioptions,
47 const SliceTransform* _prefix_extractor,
48 const EnvOptions& _env_options,
49 const InternalKeyComparator& _internal_comparator,
20effc67
TL
50 bool _skip_filters, bool _immortal,
51 bool _force_direct_prefetch, int _level,
f67539c2 52 SequenceNumber _largest_seqno,
20effc67
TL
53 BlockCacheTracer* const _block_cache_tracer,
54 size_t _max_file_size_for_l0_meta_pin)
7c673cae 55 : ioptions(_ioptions),
11fdf7f2 56 prefix_extractor(_prefix_extractor),
7c673cae
FG
57 env_options(_env_options),
58 internal_comparator(_internal_comparator),
59 skip_filters(_skip_filters),
11fdf7f2 60 immortal(_immortal),
20effc67 61 force_direct_prefetch(_force_direct_prefetch),
11fdf7f2 62 level(_level),
f67539c2 63 largest_seqno(_largest_seqno),
20effc67
TL
64 block_cache_tracer(_block_cache_tracer),
65 max_file_size_for_l0_meta_pin(_max_file_size_for_l0_meta_pin) {}
7c673cae
FG
66
67 const ImmutableCFOptions& ioptions;
11fdf7f2 68 const SliceTransform* prefix_extractor;
7c673cae
FG
69 const EnvOptions& env_options;
70 const InternalKeyComparator& internal_comparator;
71 // This is only used for BlockBasedTable (reader)
72 bool skip_filters;
11fdf7f2
TL
73 // Whether the table will be valid as long as the DB is open
74 bool immortal;
20effc67
TL
75 // When data prefetching is needed, even if direct I/O is off, read data to
76 // fetch into RocksDB's buffer, rather than relying
77 // RandomAccessFile::Prefetch().
78 bool force_direct_prefetch;
7c673cae
FG
79 // what level this table/file is on, -1 for "not set, don't know"
80 int level;
11fdf7f2
TL
81 // largest seqno in the table
82 SequenceNumber largest_seqno;
f67539c2 83 BlockCacheTracer* const block_cache_tracer;
20effc67
TL
84 // Largest L0 file size whose meta-blocks may be pinned (can be zero when
85 // unknown).
86 const size_t max_file_size_for_l0_meta_pin;
7c673cae
FG
87};
88
89struct TableBuilderOptions {
90 TableBuilderOptions(
11fdf7f2 91 const ImmutableCFOptions& _ioptions, const MutableCFOptions& _moptions,
7c673cae
FG
92 const InternalKeyComparator& _internal_comparator,
93 const std::vector<std::unique_ptr<IntTblPropCollectorFactory>>*
94 _int_tbl_prop_collector_factories,
494da23a
TL
95 CompressionType _compression_type, uint64_t _sample_for_compression,
96 const CompressionOptions& _compression_opts, bool _skip_filters,
11fdf7f2 97 const std::string& _column_family_name, int _level,
494da23a 98 const uint64_t _creation_time = 0, const int64_t _oldest_key_time = 0,
f67539c2 99 const uint64_t _target_file_size = 0,
20effc67
TL
100 const uint64_t _file_creation_time = 0, const std::string& _db_id = "",
101 const std::string& _db_session_id = "")
7c673cae 102 : ioptions(_ioptions),
11fdf7f2 103 moptions(_moptions),
7c673cae
FG
104 internal_comparator(_internal_comparator),
105 int_tbl_prop_collector_factories(_int_tbl_prop_collector_factories),
106 compression_type(_compression_type),
494da23a 107 sample_for_compression(_sample_for_compression),
7c673cae 108 compression_opts(_compression_opts),
7c673cae
FG
109 skip_filters(_skip_filters),
110 column_family_name(_column_family_name),
11fdf7f2
TL
111 level(_level),
112 creation_time(_creation_time),
494da23a 113 oldest_key_time(_oldest_key_time),
f67539c2 114 target_file_size(_target_file_size),
20effc67
TL
115 file_creation_time(_file_creation_time),
116 db_id(_db_id),
117 db_session_id(_db_session_id) {}
118
7c673cae 119 const ImmutableCFOptions& ioptions;
11fdf7f2 120 const MutableCFOptions& moptions;
7c673cae
FG
121 const InternalKeyComparator& internal_comparator;
122 const std::vector<std::unique_ptr<IntTblPropCollectorFactory>>*
123 int_tbl_prop_collector_factories;
124 CompressionType compression_type;
494da23a 125 uint64_t sample_for_compression;
7c673cae 126 const CompressionOptions& compression_opts;
7c673cae
FG
127 bool skip_filters; // only used by BlockBasedTableBuilder
128 const std::string& column_family_name;
129 int level; // what level this table/file is on, -1 for "not set, don't know"
11fdf7f2
TL
130 const uint64_t creation_time;
131 const int64_t oldest_key_time;
494da23a 132 const uint64_t target_file_size;
f67539c2 133 const uint64_t file_creation_time;
20effc67
TL
134 const std::string db_id;
135 const std::string db_session_id;
7c673cae
FG
136};
137
138// TableBuilder provides the interface used to build a Table
139// (an immutable and sorted map from keys to values).
140//
141// Multiple threads can invoke const methods on a TableBuilder without
142// external synchronization, but if any of the threads may call a
143// non-const method, all threads accessing the same TableBuilder must use
144// external synchronization.
145class TableBuilder {
146 public:
147 // REQUIRES: Either Finish() or Abandon() has been called.
148 virtual ~TableBuilder() {}
149
150 // Add key,value to the table being constructed.
151 // REQUIRES: key is after any previously added key according to comparator.
152 // REQUIRES: Finish(), Abandon() have not been called
153 virtual void Add(const Slice& key, const Slice& value) = 0;
154
155 // Return non-ok iff some error has been detected.
156 virtual Status status() const = 0;
157
20effc67
TL
158 // Return non-ok iff some error happens during IO.
159 virtual IOStatus io_status() const = 0;
160
7c673cae
FG
161 // Finish building the table.
162 // REQUIRES: Finish(), Abandon() have not been called
163 virtual Status Finish() = 0;
164
165 // Indicate that the contents of this builder should be abandoned.
166 // If the caller is not going to call Finish(), it must call Abandon()
167 // before destroying this builder.
168 // REQUIRES: Finish(), Abandon() have not been called
169 virtual void Abandon() = 0;
170
171 // Number of calls to Add() so far.
172 virtual uint64_t NumEntries() const = 0;
173
20effc67
TL
174 // Whether the output file is completely empty. It has neither entries
175 // or tombstones.
176 virtual bool IsEmpty() const {
177 return NumEntries() == 0 && GetTableProperties().num_range_deletions == 0;
178 }
179
7c673cae
FG
180 // Size of the file generated so far. If invoked after a successful
181 // Finish() call, returns the size of the final generated file.
182 virtual uint64_t FileSize() const = 0;
183
20effc67
TL
184 // Estimated size of the file generated so far. This is used when
185 // FileSize() cannot estimate final SST size, e.g. parallel compression
186 // is enabled.
187 virtual uint64_t EstimatedFileSize() const { return FileSize(); }
188
7c673cae
FG
189 // If the user defined table properties collector suggest the file to
190 // be further compacted.
191 virtual bool NeedCompact() const { return false; }
192
193 // Returns table properties
194 virtual TableProperties GetTableProperties() const = 0;
f67539c2
TL
195
196 // Return file checksum
20effc67 197 virtual std::string GetFileChecksum() const = 0;
f67539c2
TL
198
199 // Return file checksum function name
200 virtual const char* GetFileChecksumFuncName() const = 0;
7c673cae
FG
201};
202
f67539c2 203} // namespace ROCKSDB_NAMESPACE