Skip to content

Commit 30cd958

Browse files
committed
Add unsafe_add option to SstFileWriter (reapply D8914)
See https://rockset.phacility.com/D8914
1 parent 1590a1c commit 30cd958

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

include/rocksdb/sst_file_writer.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,21 +86,24 @@ class SstFileWriter {
8686
// hint that this file pages is not needed every time we write 1MB to the
8787
// file. To use the rate limiter an io_priority smaller than IO_TOTAL can be
8888
// passed.
89+
// If unsafe_add is true, SstFileWriter doesn't check that keys are written in
90+
// ascending order.
8991
SstFileWriter(const EnvOptions& env_options, const Options& options,
9092
ColumnFamilyHandle* column_family = nullptr,
9193
bool invalidate_page_cache = true,
9294
Env::IOPriority io_priority = Env::IOPriority::IO_TOTAL,
93-
bool skip_filters = false)
95+
bool skip_filters = false, bool unsafe_add = false)
9496
: SstFileWriter(env_options, options, options.comparator, column_family,
95-
invalidate_page_cache, io_priority, skip_filters) {}
97+
invalidate_page_cache, io_priority, skip_filters,
98+
unsafe_add) {}
9699

97100
// Deprecated API
98101
SstFileWriter(const EnvOptions& env_options, const Options& options,
99102
const Comparator* user_comparator,
100103
ColumnFamilyHandle* column_family = nullptr,
101104
bool invalidate_page_cache = true,
102105
Env::IOPriority io_priority = Env::IOPriority::IO_TOTAL,
103-
bool skip_filters = false);
106+
bool skip_filters = false, bool unsafe_add = false);
104107

105108
~SstFileWriter();
106109

table/sst_file_writer.cc

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ const size_t kFadviseTrigger = 1024 * 1024; // 1MB
2929
struct SstFileWriter::Rep {
3030
Rep(const EnvOptions& _env_options, const Options& options,
3131
Env::IOPriority _io_priority, const Comparator* _user_comparator,
32-
ColumnFamilyHandle* _cfh, bool _invalidate_page_cache, bool _skip_filters)
32+
ColumnFamilyHandle* _cfh, bool _invalidate_page_cache, bool _skip_filters,
33+
bool _unsafe_add)
3334
: env_options(_env_options),
3435
ioptions(options),
3536
mutable_cf_options(options),
@@ -38,7 +39,8 @@ struct SstFileWriter::Rep {
3839
cfh(_cfh),
3940
invalidate_page_cache(_invalidate_page_cache),
4041
last_fadvise_size(0),
41-
skip_filters(_skip_filters) {}
42+
skip_filters(_skip_filters),
43+
unsafe_add(_unsafe_add) {}
4244

4345
std::unique_ptr<WritableFileWriter> file_writer;
4446
std::unique_ptr<TableBuilder> builder;
@@ -58,6 +60,7 @@ struct SstFileWriter::Rep {
5860
// cached pages from page cache.
5961
uint64_t last_fadvise_size;
6062
bool skip_filters;
63+
bool unsafe_add;
6164
Status Add(const Slice& user_key, const Slice& value,
6265
const ValueType value_type) {
6366
if (!builder) {
@@ -66,7 +69,7 @@ struct SstFileWriter::Rep {
6669

6770
if (file_info.num_entries == 0) {
6871
file_info.smallest_key.assign(user_key.data(), user_key.size());
69-
} else {
72+
} else if (!unsafe_add) {
7073
if (internal_comparator.user_comparator()->Compare(
7174
user_key, file_info.largest_key) <= 0) {
7275
// Make sure that keys are added in order
@@ -165,9 +168,11 @@ SstFileWriter::SstFileWriter(const EnvOptions& env_options,
165168
const Comparator* user_comparator,
166169
ColumnFamilyHandle* column_family,
167170
bool invalidate_page_cache,
168-
Env::IOPriority io_priority, bool skip_filters)
171+
Env::IOPriority io_priority, bool skip_filters,
172+
bool unsafe_add)
169173
: rep_(new Rep(env_options, options, io_priority, user_comparator,
170-
column_family, invalidate_page_cache, skip_filters)) {
174+
column_family, invalidate_page_cache, skip_filters,
175+
unsafe_add)) {
171176
rep_->file_info.file_size = 0;
172177
}
173178

0 commit comments

Comments
 (0)