Skip to content

Commit aecf955

Browse files
committed
Add unsafe_add option to SstFileWriter
Summary: We observed that key compare in SstFileWriter::Add() adds significant overhead to our ingest. This diff adds an option to avoid this check. Test Plan: make check Reviewers: hieu, dhruba Differential Revision: https://rockset.phacility.com/D8914
1 parent 2ab8bd0 commit aecf955

File tree

2 files changed

+15
-8
lines changed

2 files changed

+15
-8
lines changed

include/rocksdb/sst_file_writer.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,21 +80,23 @@ class SstFileWriter {
8080
// hint that this file pages is not needed every time we write 1MB to the
8181
// file. To use the rate limiter an io_priority smaller than IO_TOTAL can be
8282
// passed.
83+
// If unsafe_add is true, SstFileWriter doesn't check that keys are written in
84+
// ascending order.
8385
SstFileWriter(const EnvOptions& env_options, const Options& options,
8486
ColumnFamilyHandle* column_family = nullptr,
8587
bool invalidate_page_cache = true,
8688
Env::IOPriority io_priority = Env::IOPriority::IO_TOTAL,
87-
bool skip_filters = false)
89+
bool skip_filters = false, bool unsafe_add = false)
8890
: SstFileWriter(env_options, options, options.comparator, column_family,
89-
invalidate_page_cache, io_priority, skip_filters) {}
91+
invalidate_page_cache, io_priority, skip_filters, unsafe_add) {}
9092

9193
// Deprecated API
9294
SstFileWriter(const EnvOptions& env_options, const Options& options,
9395
const Comparator* user_comparator,
9496
ColumnFamilyHandle* column_family = nullptr,
9597
bool invalidate_page_cache = true,
9698
Env::IOPriority io_priority = Env::IOPriority::IO_TOTAL,
97-
bool skip_filters = false);
99+
bool skip_filters = false, bool unsafe_add = false);
98100

99101
~SstFileWriter();
100102

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
@@ -163,9 +166,11 @@ SstFileWriter::SstFileWriter(const EnvOptions& env_options,
163166
const Comparator* user_comparator,
164167
ColumnFamilyHandle* column_family,
165168
bool invalidate_page_cache,
166-
Env::IOPriority io_priority, bool skip_filters)
169+
Env::IOPriority io_priority, bool skip_filters,
170+
bool unsafe_add)
167171
: rep_(new Rep(env_options, options, io_priority, user_comparator,
168-
column_family, invalidate_page_cache, skip_filters)) {
172+
column_family, invalidate_page_cache, skip_filters,
173+
unsafe_add)) {
169174
rep_->file_info.file_size = 0;
170175
}
171176

0 commit comments

Comments
 (0)