Make max_subcompactions dynamically changeable (#7159)

Summary:
Make `max-subcompactions` dynamically changeable by passing the `DBOption` to Compaction.

Pull Request resolved: https://github.com/facebook/rocksdb/pull/7159

Reviewed By: siying

Differential Revision: D22671238

Pulled By: jay-zhuang

fbshipit-source-id: 311ca9f6bb606965544d8708616d358cfed5be42
main
Jay Zhuang 4 years ago committed by Facebook GitHub Bot
parent 0d04a8434a
commit b0c5ecd6b3
  1. 1
      HISTORY.md
  2. 15
      db/column_family.cc
  3. 2
      db/column_family.h
  4. 3
      db/compaction/compaction.cc
  5. 1
      db/compaction/compaction.h
  6. 9
      db/compaction/compaction_job_test.cc
  7. 17
      db/compaction/compaction_picker.cc
  8. 9
      db/compaction/compaction_picker.h
  9. 37
      db/compaction/compaction_picker_fifo.cc
  10. 8
      db/compaction/compaction_picker_fifo.h
  11. 18
      db/compaction/compaction_picker_level.cc
  12. 3
      db/compaction/compaction_picker_level.h
  13. 167
      db/compaction/compaction_picker_test.cc
  14. 34
      db/compaction/compaction_picker_universal.cc
  15. 3
      db/compaction/compaction_picker_universal.h
  16. 102
      db/db_compaction_test.cc
  17. 11
      db/db_impl/db_impl_compaction_flush.cc
  18. 2
      include/rocksdb/options.h
  19. 1
      options/cf_options.cc
  20. 5
      options/cf_options.h
  21. 15
      options/db_options.cc
  22. 2
      options/db_options.h
  23. 2
      options/options_helper.cc

@ -28,6 +28,7 @@
* Added experimental option BlockBasedTableOptions::optimize_filters_for_memory for reducing allocated memory size of Bloom filters (~10% savings with Jemalloc) while preserving the same general accuracy. To have an effect, the option requires format_version=5 and malloc_usable_size. Enabling this option is forward and backward compatible with existing format_version=5. * Added experimental option BlockBasedTableOptions::optimize_filters_for_memory for reducing allocated memory size of Bloom filters (~10% savings with Jemalloc) while preserving the same general accuracy. To have an effect, the option requires format_version=5 and malloc_usable_size. Enabling this option is forward and backward compatible with existing format_version=5.
* `BackupTableNameOption BackupableDBOptions::share_files_with_checksum_naming` is added, where `BackupTableNameOption` is an `enum` type with two enumerators `kChecksumAndFileSize` and `kOptionalChecksumAndDbSessionId`. By default, `BackupableDBOptions::share_files_with_checksum_naming` is set to `kOptionalChecksumAndDbSessionId`. In the default case, backup table filenames generated by this version of RocksDB are of the form either `<file_number>_<crc32c>_<db_session_id>.sst` or `<file_number>_<db_session_id>.sst` as opposed to `<file_number>_<crc32c>_<file_size>.sst`. Specifically, table filenames are of the form `<file_number>_<crc32c>_<db_session_id>.sst` if `DBOptions::file_checksum_gen_factory` is set to `GetFileChecksumGenCrc32cFactory()`. Futhermore, the checksum value `<crc32c>` appeared in the filenames is hexadecimal-encoded, instead of being decimal-encoded `uint32_t` value. If `DBOptions::file_checksum_gen_factory` is `nullptr`, the table filenames are of the form `<file_number>_<db_session_id>.sst`. The new default behavior fixes the backup file name collision problem, which might be possible at large scale, but the option `kChecksumAndFileSize` is added to allow use of old naming in case it is needed. Moreover, for table files generated prior to this version of RocksDB, using `kOptionalChecksumAndDbSessionId` will fall back on `kChecksumAndFileSize`. In these cases, the checksum value `<crc32c>` in the filenames `<file_number>_<crc32c>_<file_size>.sst` is decimal-encoded `uint32_t` value as before. This default behavior change is not an upgrade issue, because previous versions of RocksDB can read, restore, and delete backups using new names, and it's OK for a backup directory to use a mixture of table file naming schemes. Note that `share_files_with_checksum_naming` comes into effect only when both `share_files_with_checksum` and `share_table_files` are true. * `BackupTableNameOption BackupableDBOptions::share_files_with_checksum_naming` is added, where `BackupTableNameOption` is an `enum` type with two enumerators `kChecksumAndFileSize` and `kOptionalChecksumAndDbSessionId`. By default, `BackupableDBOptions::share_files_with_checksum_naming` is set to `kOptionalChecksumAndDbSessionId`. In the default case, backup table filenames generated by this version of RocksDB are of the form either `<file_number>_<crc32c>_<db_session_id>.sst` or `<file_number>_<db_session_id>.sst` as opposed to `<file_number>_<crc32c>_<file_size>.sst`. Specifically, table filenames are of the form `<file_number>_<crc32c>_<db_session_id>.sst` if `DBOptions::file_checksum_gen_factory` is set to `GetFileChecksumGenCrc32cFactory()`. Futhermore, the checksum value `<crc32c>` appeared in the filenames is hexadecimal-encoded, instead of being decimal-encoded `uint32_t` value. If `DBOptions::file_checksum_gen_factory` is `nullptr`, the table filenames are of the form `<file_number>_<db_session_id>.sst`. The new default behavior fixes the backup file name collision problem, which might be possible at large scale, but the option `kChecksumAndFileSize` is added to allow use of old naming in case it is needed. Moreover, for table files generated prior to this version of RocksDB, using `kOptionalChecksumAndDbSessionId` will fall back on `kChecksumAndFileSize`. In these cases, the checksum value `<crc32c>` in the filenames `<file_number>_<crc32c>_<file_size>.sst` is decimal-encoded `uint32_t` value as before. This default behavior change is not an upgrade issue, because previous versions of RocksDB can read, restore, and delete backups using new names, and it's OK for a backup directory to use a mixture of table file naming schemes. Note that `share_files_with_checksum_naming` comes into effect only when both `share_files_with_checksum` and `share_table_files` are true.
* Added auto resume function to automatically recover the DB from background Retryable IO Error. When retryable IOError happens during flush and WAL write, the error is mapped to Hard Error and DB will be in read mode. When retryable IO Error happens during compaction, the error will be mapped to Soft Error. DB is still in write/read mode. Autoresume function will create a thread for a DB to call DB->ResumeImpl() to try the recover for Retryable IO Error during flush and WAL write. Compaction will be rescheduled by itself if retryable IO Error happens. Auto resume may also cause other Retryable IO Error during the recovery, so the recovery will fail. Retry the auto resume may solve the issue, so we use max_bgerror_resume_count to decide how many resume cycles will be tried in total. If it is <=0, auto resume retryable IO Error is disabled. Default is INT_MAX, which will lead to a infinit auto resume. bgerror_resume_retry_interval decides the time interval between two auto resumes. * Added auto resume function to automatically recover the DB from background Retryable IO Error. When retryable IOError happens during flush and WAL write, the error is mapped to Hard Error and DB will be in read mode. When retryable IO Error happens during compaction, the error will be mapped to Soft Error. DB is still in write/read mode. Autoresume function will create a thread for a DB to call DB->ResumeImpl() to try the recover for Retryable IO Error during flush and WAL write. Compaction will be rescheduled by itself if retryable IO Error happens. Auto resume may also cause other Retryable IO Error during the recovery, so the recovery will fail. Retry the auto resume may solve the issue, so we use max_bgerror_resume_count to decide how many resume cycles will be tried in total. If it is <=0, auto resume retryable IO Error is disabled. Default is INT_MAX, which will lead to a infinit auto resume. bgerror_resume_retry_interval decides the time interval between two auto resumes.
* Option `max_subcompactions` can be set dynamically using DB::SetDBOptions().
### Bug Fixes ### Bug Fixes
* Fail recovery and report once hitting a physical log record checksum mismatch, while reading MANIFEST. RocksDB should not continue processing the MANIFEST any further. * Fail recovery and report once hitting a physical log record checksum mismatch, while reading MANIFEST. RocksDB should not continue processing the MANIFEST any further.

@ -1047,13 +1047,14 @@ bool ColumnFamilyData::NeedsCompaction() const {
} }
Compaction* ColumnFamilyData::PickCompaction( Compaction* ColumnFamilyData::PickCompaction(
const MutableCFOptions& mutable_options, LogBuffer* log_buffer) { const MutableCFOptions& mutable_options,
const MutableDBOptions& mutable_db_options, LogBuffer* log_buffer) {
SequenceNumber earliest_mem_seqno = SequenceNumber earliest_mem_seqno =
std::min(mem_->GetEarliestSequenceNumber(), std::min(mem_->GetEarliestSequenceNumber(),
imm_.current()->GetEarliestSequenceNumber(false)); imm_.current()->GetEarliestSequenceNumber(false));
auto* result = compaction_picker_->PickCompaction( auto* result = compaction_picker_->PickCompaction(
GetName(), mutable_options, current_->storage_info(), log_buffer, GetName(), mutable_options, mutable_db_options, current_->storage_info(),
earliest_mem_seqno); log_buffer, earliest_mem_seqno);
if (result != nullptr) { if (result != nullptr) {
result->SetInputVersion(current_); result->SetInputVersion(current_);
} }
@ -1123,14 +1124,16 @@ const int ColumnFamilyData::kCompactAllLevels = -1;
const int ColumnFamilyData::kCompactToBaseLevel = -2; const int ColumnFamilyData::kCompactToBaseLevel = -2;
Compaction* ColumnFamilyData::CompactRange( Compaction* ColumnFamilyData::CompactRange(
const MutableCFOptions& mutable_cf_options, int input_level, const MutableCFOptions& mutable_cf_options,
const MutableDBOptions& mutable_db_options, int input_level,
int output_level, const CompactRangeOptions& compact_range_options, int output_level, const CompactRangeOptions& compact_range_options,
const InternalKey* begin, const InternalKey* end, const InternalKey* begin, const InternalKey* end,
InternalKey** compaction_end, bool* conflict, InternalKey** compaction_end, bool* conflict,
uint64_t max_file_num_to_ignore) { uint64_t max_file_num_to_ignore) {
auto* result = compaction_picker_->CompactRange( auto* result = compaction_picker_->CompactRange(
GetName(), mutable_cf_options, current_->storage_info(), input_level, GetName(), mutable_cf_options, mutable_db_options,
output_level, compact_range_options, begin, end, compaction_end, conflict, current_->storage_info(), input_level, output_level,
compact_range_options, begin, end, compaction_end, conflict,
max_file_num_to_ignore); max_file_num_to_ignore);
if (result != nullptr) { if (result != nullptr) {
result->SetInputVersion(current_); result->SetInputVersion(current_);

@ -387,6 +387,7 @@ class ColumnFamilyData {
bool NeedsCompaction() const; bool NeedsCompaction() const;
// REQUIRES: DB mutex held // REQUIRES: DB mutex held
Compaction* PickCompaction(const MutableCFOptions& mutable_options, Compaction* PickCompaction(const MutableCFOptions& mutable_options,
const MutableDBOptions& mutable_db_options,
LogBuffer* log_buffer); LogBuffer* log_buffer);
// Check if the passed range overlap with any running compactions. // Check if the passed range overlap with any running compactions.
@ -412,6 +413,7 @@ class ColumnFamilyData {
static const int kCompactToBaseLevel; static const int kCompactToBaseLevel;
// REQUIRES: DB mutex held // REQUIRES: DB mutex held
Compaction* CompactRange(const MutableCFOptions& mutable_cf_options, Compaction* CompactRange(const MutableCFOptions& mutable_cf_options,
const MutableDBOptions& mutable_db_options,
int input_level, int output_level, int input_level, int output_level,
const CompactRangeOptions& compact_range_options, const CompactRangeOptions& compact_range_options,
const InternalKey* begin, const InternalKey* end, const InternalKey* begin, const InternalKey* end,

@ -205,6 +205,7 @@ bool Compaction::IsFullCompaction(
Compaction::Compaction(VersionStorageInfo* vstorage, Compaction::Compaction(VersionStorageInfo* vstorage,
const ImmutableCFOptions& _immutable_cf_options, const ImmutableCFOptions& _immutable_cf_options,
const MutableCFOptions& _mutable_cf_options, const MutableCFOptions& _mutable_cf_options,
const MutableDBOptions& _mutable_db_options,
std::vector<CompactionInputFiles> _inputs, std::vector<CompactionInputFiles> _inputs,
int _output_level, uint64_t _target_file_size, int _output_level, uint64_t _target_file_size,
uint64_t _max_compaction_bytes, uint32_t _output_path_id, uint64_t _max_compaction_bytes, uint32_t _output_path_id,
@ -243,7 +244,7 @@ Compaction::Compaction(VersionStorageInfo* vstorage,
compaction_reason_ = CompactionReason::kManualCompaction; compaction_reason_ = CompactionReason::kManualCompaction;
} }
if (max_subcompactions_ == 0) { if (max_subcompactions_ == 0) {
max_subcompactions_ = immutable_cf_options_.max_subcompactions; max_subcompactions_ = _mutable_db_options.max_subcompactions;
} }
if (!bottommost_level_) { if (!bottommost_level_) {
// Currently we only enable dictionary compression during compaction to the // Currently we only enable dictionary compression during compaction to the

@ -71,6 +71,7 @@ class Compaction {
Compaction(VersionStorageInfo* input_version, Compaction(VersionStorageInfo* input_version,
const ImmutableCFOptions& immutable_cf_options, const ImmutableCFOptions& immutable_cf_options,
const MutableCFOptions& mutable_cf_options, const MutableCFOptions& mutable_cf_options,
const MutableDBOptions& mutable_db_options,
std::vector<CompactionInputFiles> inputs, int output_level, std::vector<CompactionInputFiles> inputs, int output_level,
uint64_t target_file_size, uint64_t max_compaction_bytes, uint64_t target_file_size, uint64_t max_compaction_bytes,
uint32_t output_path_id, CompressionType compression, uint32_t output_path_id, CompressionType compression,

@ -76,6 +76,7 @@ class CompactionJobTest : public testing::Test {
dbname_(test::PerThreadDBPath("compaction_job_test")), dbname_(test::PerThreadDBPath("compaction_job_test")),
db_options_(), db_options_(),
mutable_cf_options_(cf_options_), mutable_cf_options_(cf_options_),
mutable_db_options_(),
table_cache_(NewLRUCache(50000, 16)), table_cache_(NewLRUCache(50000, 16)),
write_buffer_manager_(db_options_.db_write_buffer_size), write_buffer_manager_(db_options_.db_write_buffer_size),
versions_(new VersionSet(dbname_, &db_options_, env_options_, versions_(new VersionSet(dbname_, &db_options_, env_options_,
@ -316,9 +317,10 @@ class CompactionJobTest : public testing::Test {
Compaction compaction( Compaction compaction(
cfd->current()->storage_info(), *cfd->ioptions(), cfd->current()->storage_info(), *cfd->ioptions(),
*cfd->GetLatestMutableCFOptions(), compaction_input_files, output_level, *cfd->GetLatestMutableCFOptions(), mutable_db_options_,
1024 * 1024, 10 * 1024 * 1024, 0, kNoCompression, compaction_input_files, output_level, 1024 * 1024, 10 * 1024 * 1024, 0,
cfd->GetLatestMutableCFOptions()->compression_opts, 0, {}, true); kNoCompression, cfd->GetLatestMutableCFOptions()->compression_opts, 0,
{}, true);
compaction.SetInputVersion(cfd->current()); compaction.SetInputVersion(cfd->current());
LogBuffer log_buffer(InfoLogLevel::INFO_LEVEL, db_options_.info_log.get()); LogBuffer log_buffer(InfoLogLevel::INFO_LEVEL, db_options_.info_log.get());
@ -370,6 +372,7 @@ class CompactionJobTest : public testing::Test {
ImmutableDBOptions db_options_; ImmutableDBOptions db_options_;
ColumnFamilyOptions cf_options_; ColumnFamilyOptions cf_options_;
MutableCFOptions mutable_cf_options_; MutableCFOptions mutable_cf_options_;
MutableDBOptions mutable_db_options_;
std::shared_ptr<Cache> table_cache_; std::shared_ptr<Cache> table_cache_;
WriteController write_controller_; WriteController write_controller_;
WriteBufferManager write_buffer_manager_; WriteBufferManager write_buffer_manager_;

@ -332,7 +332,7 @@ Compaction* CompactionPicker::CompactFiles(
const CompactionOptions& compact_options, const CompactionOptions& compact_options,
const std::vector<CompactionInputFiles>& input_files, int output_level, const std::vector<CompactionInputFiles>& input_files, int output_level,
VersionStorageInfo* vstorage, const MutableCFOptions& mutable_cf_options, VersionStorageInfo* vstorage, const MutableCFOptions& mutable_cf_options,
uint32_t output_path_id) { const MutableDBOptions& mutable_db_options, uint32_t output_path_id) {
assert(input_files.size()); assert(input_files.size());
// This compaction output should not overlap with a running compaction as // This compaction output should not overlap with a running compaction as
// `SanitizeCompactionInputFiles` should've checked earlier and db mutex // `SanitizeCompactionInputFiles` should've checked earlier and db mutex
@ -356,8 +356,8 @@ Compaction* CompactionPicker::CompactFiles(
compression_type = compact_options.compression; compression_type = compact_options.compression;
} }
auto c = new Compaction( auto c = new Compaction(
vstorage, ioptions_, mutable_cf_options, input_files, output_level, vstorage, ioptions_, mutable_cf_options, mutable_db_options, input_files,
compact_options.output_file_size_limit, output_level, compact_options.output_file_size_limit,
mutable_cf_options.max_compaction_bytes, output_path_id, compression_type, mutable_cf_options.max_compaction_bytes, output_path_id, compression_type,
GetCompressionOptions(mutable_cf_options, vstorage, output_level), GetCompressionOptions(mutable_cf_options, vstorage, output_level),
compact_options.max_subcompactions, compact_options.max_subcompactions,
@ -563,7 +563,8 @@ void CompactionPicker::GetGrandparents(
Compaction* CompactionPicker::CompactRange( Compaction* CompactionPicker::CompactRange(
const std::string& cf_name, const MutableCFOptions& mutable_cf_options, const std::string& cf_name, const MutableCFOptions& mutable_cf_options,
VersionStorageInfo* vstorage, int input_level, int output_level, const MutableDBOptions& mutable_db_options, VersionStorageInfo* vstorage,
int input_level, int output_level,
const CompactRangeOptions& compact_range_options, const InternalKey* begin, const CompactRangeOptions& compact_range_options, const InternalKey* begin,
const InternalKey* end, InternalKey** compaction_end, bool* manual_conflict, const InternalKey* end, InternalKey** compaction_end, bool* manual_conflict,
uint64_t max_file_num_to_ignore) { uint64_t max_file_num_to_ignore) {
@ -626,8 +627,8 @@ Compaction* CompactionPicker::CompactRange(
} }
Compaction* c = new Compaction( Compaction* c = new Compaction(
vstorage, ioptions_, mutable_cf_options, std::move(inputs), vstorage, ioptions_, mutable_cf_options, mutable_db_options,
output_level, std::move(inputs), output_level,
MaxFileSizeForLevel(mutable_cf_options, output_level, MaxFileSizeForLevel(mutable_cf_options, output_level,
ioptions_.compaction_style), ioptions_.compaction_style),
/* max_compaction_bytes */ LLONG_MAX, /* max_compaction_bytes */ LLONG_MAX,
@ -778,8 +779,8 @@ Compaction* CompactionPicker::CompactRange(
std::vector<FileMetaData*> grandparents; std::vector<FileMetaData*> grandparents;
GetGrandparents(vstorage, inputs, output_level_inputs, &grandparents); GetGrandparents(vstorage, inputs, output_level_inputs, &grandparents);
Compaction* compaction = new Compaction( Compaction* compaction = new Compaction(
vstorage, ioptions_, mutable_cf_options, std::move(compaction_inputs), vstorage, ioptions_, mutable_cf_options, mutable_db_options,
output_level, std::move(compaction_inputs), output_level,
MaxFileSizeForLevel(mutable_cf_options, output_level, MaxFileSizeForLevel(mutable_cf_options, output_level,
ioptions_.compaction_style, vstorage->base_level(), ioptions_.compaction_style, vstorage->base_level(),
ioptions_.level_compaction_dynamic_level_bytes), ioptions_.level_compaction_dynamic_level_bytes),

@ -56,7 +56,8 @@ class CompactionPicker {
// describes the compaction. Caller should delete the result. // describes the compaction. Caller should delete the result.
virtual Compaction* PickCompaction( virtual Compaction* PickCompaction(
const std::string& cf_name, const MutableCFOptions& mutable_cf_options, const std::string& cf_name, const MutableCFOptions& mutable_cf_options,
VersionStorageInfo* vstorage, LogBuffer* log_buffer, const MutableDBOptions& mutable_db_options, VersionStorageInfo* vstorage,
LogBuffer* log_buffer,
SequenceNumber earliest_memtable_seqno = kMaxSequenceNumber) = 0; SequenceNumber earliest_memtable_seqno = kMaxSequenceNumber) = 0;
// Return a compaction object for compacting the range [begin,end] in // Return a compaction object for compacting the range [begin,end] in
@ -72,7 +73,8 @@ class CompactionPicker {
// *compaction_end should point to valid InternalKey! // *compaction_end should point to valid InternalKey!
virtual Compaction* CompactRange( virtual Compaction* CompactRange(
const std::string& cf_name, const MutableCFOptions& mutable_cf_options, const std::string& cf_name, const MutableCFOptions& mutable_cf_options,
VersionStorageInfo* vstorage, int input_level, int output_level, const MutableDBOptions& mutable_db_options, VersionStorageInfo* vstorage,
int input_level, int output_level,
const CompactRangeOptions& compact_range_options, const CompactRangeOptions& compact_range_options,
const InternalKey* begin, const InternalKey* end, const InternalKey* begin, const InternalKey* end,
InternalKey** compaction_end, bool* manual_conflict, InternalKey** compaction_end, bool* manual_conflict,
@ -113,6 +115,7 @@ class CompactionPicker {
const std::vector<CompactionInputFiles>& input_files, const std::vector<CompactionInputFiles>& input_files,
int output_level, VersionStorageInfo* vstorage, int output_level, VersionStorageInfo* vstorage,
const MutableCFOptions& mutable_cf_options, const MutableCFOptions& mutable_cf_options,
const MutableDBOptions& mutable_db_options,
uint32_t output_path_id); uint32_t output_path_id);
// Converts a set of compaction input file numbers into // Converts a set of compaction input file numbers into
@ -250,6 +253,7 @@ class NullCompactionPicker : public CompactionPicker {
Compaction* PickCompaction( Compaction* PickCompaction(
const std::string& /*cf_name*/, const std::string& /*cf_name*/,
const MutableCFOptions& /*mutable_cf_options*/, const MutableCFOptions& /*mutable_cf_options*/,
const MutableDBOptions& /*mutable_db_options*/,
VersionStorageInfo* /*vstorage*/, LogBuffer* /* log_buffer */, VersionStorageInfo* /*vstorage*/, LogBuffer* /* log_buffer */,
SequenceNumber /* earliest_memtable_seqno */) override { SequenceNumber /* earliest_memtable_seqno */) override {
return nullptr; return nullptr;
@ -258,6 +262,7 @@ class NullCompactionPicker : public CompactionPicker {
// Always return "nullptr" // Always return "nullptr"
Compaction* CompactRange(const std::string& /*cf_name*/, Compaction* CompactRange(const std::string& /*cf_name*/,
const MutableCFOptions& /*mutable_cf_options*/, const MutableCFOptions& /*mutable_cf_options*/,
const MutableDBOptions& /*mutable_db_options*/,
VersionStorageInfo* /*vstorage*/, VersionStorageInfo* /*vstorage*/,
int /*input_level*/, int /*output_level*/, int /*input_level*/, int /*output_level*/,
const CompactRangeOptions& /*compact_range_options*/, const CompactRangeOptions& /*compact_range_options*/,

@ -36,7 +36,8 @@ bool FIFOCompactionPicker::NeedsCompaction(
Compaction* FIFOCompactionPicker::PickTTLCompaction( Compaction* FIFOCompactionPicker::PickTTLCompaction(
const std::string& cf_name, const MutableCFOptions& mutable_cf_options, const std::string& cf_name, const MutableCFOptions& mutable_cf_options,
VersionStorageInfo* vstorage, LogBuffer* log_buffer) { const MutableDBOptions& mutable_db_options, VersionStorageInfo* vstorage,
LogBuffer* log_buffer) {
assert(mutable_cf_options.ttl > 0); assert(mutable_cf_options.ttl > 0);
const int kLevel0 = 0; const int kLevel0 = 0;
@ -108,8 +109,9 @@ Compaction* FIFOCompactionPicker::PickTTLCompaction(
} }
Compaction* c = new Compaction( Compaction* c = new Compaction(
vstorage, ioptions_, mutable_cf_options, std::move(inputs), 0, 0, 0, 0, vstorage, ioptions_, mutable_cf_options, mutable_db_options,
kNoCompression, mutable_cf_options.compression_opts, std::move(inputs), 0, 0, 0, 0, kNoCompression,
mutable_cf_options.compression_opts,
/* max_subcompactions */ 0, {}, /* is manual */ false, /* max_subcompactions */ 0, {}, /* is manual */ false,
vstorage->CompactionScore(0), vstorage->CompactionScore(0),
/* is deletion compaction */ true, CompactionReason::kFIFOTtl); /* is deletion compaction */ true, CompactionReason::kFIFOTtl);
@ -118,7 +120,8 @@ Compaction* FIFOCompactionPicker::PickTTLCompaction(
Compaction* FIFOCompactionPicker::PickSizeCompaction( Compaction* FIFOCompactionPicker::PickSizeCompaction(
const std::string& cf_name, const MutableCFOptions& mutable_cf_options, const std::string& cf_name, const MutableCFOptions& mutable_cf_options,
VersionStorageInfo* vstorage, LogBuffer* log_buffer) { const MutableDBOptions& mutable_db_options, VersionStorageInfo* vstorage,
LogBuffer* log_buffer) {
const int kLevel0 = 0; const int kLevel0 = 0;
const std::vector<FileMetaData*>& level_files = vstorage->LevelFiles(kLevel0); const std::vector<FileMetaData*>& level_files = vstorage->LevelFiles(kLevel0);
uint64_t total_size = GetTotalFilesSize(level_files); uint64_t total_size = GetTotalFilesSize(level_files);
@ -147,8 +150,8 @@ Compaction* FIFOCompactionPicker::PickSizeCompaction(
max_compact_bytes_per_del_file, max_compact_bytes_per_del_file,
mutable_cf_options.max_compaction_bytes, &comp_inputs)) { mutable_cf_options.max_compaction_bytes, &comp_inputs)) {
Compaction* c = new Compaction( Compaction* c = new Compaction(
vstorage, ioptions_, mutable_cf_options, {comp_inputs}, 0, vstorage, ioptions_, mutable_cf_options, mutable_db_options,
16 * 1024 * 1024 /* output file size limit */, {comp_inputs}, 0, 16 * 1024 * 1024 /* output file size limit */,
0 /* max compaction bytes, not applicable */, 0 /* max compaction bytes, not applicable */,
0 /* output path ID */, mutable_cf_options.compression, 0 /* output path ID */, mutable_cf_options.compression,
mutable_cf_options.compression_opts, 0 /* max_subcompactions */, {}, mutable_cf_options.compression_opts, 0 /* max_subcompactions */, {},
@ -198,8 +201,9 @@ Compaction* FIFOCompactionPicker::PickSizeCompaction(
} }
Compaction* c = new Compaction( Compaction* c = new Compaction(
vstorage, ioptions_, mutable_cf_options, std::move(inputs), 0, 0, 0, 0, vstorage, ioptions_, mutable_cf_options, mutable_db_options,
kNoCompression, mutable_cf_options.compression_opts, std::move(inputs), 0, 0, 0, 0, kNoCompression,
mutable_cf_options.compression_opts,
/* max_subcompactions */ 0, {}, /* is manual */ false, /* max_subcompactions */ 0, {}, /* is manual */ false,
vstorage->CompactionScore(0), vstorage->CompactionScore(0),
/* is deletion compaction */ true, CompactionReason::kFIFOMaxSize); /* is deletion compaction */ true, CompactionReason::kFIFOMaxSize);
@ -208,16 +212,18 @@ Compaction* FIFOCompactionPicker::PickSizeCompaction(
Compaction* FIFOCompactionPicker::PickCompaction( Compaction* FIFOCompactionPicker::PickCompaction(
const std::string& cf_name, const MutableCFOptions& mutable_cf_options, const std::string& cf_name, const MutableCFOptions& mutable_cf_options,
VersionStorageInfo* vstorage, LogBuffer* log_buffer, const MutableDBOptions& mutable_db_options, VersionStorageInfo* vstorage,
SequenceNumber /*earliest_memtable_seqno*/) { LogBuffer* log_buffer, SequenceNumber /*earliest_memtable_seqno*/) {
assert(vstorage->num_levels() == 1); assert(vstorage->num_levels() == 1);
Compaction* c = nullptr; Compaction* c = nullptr;
if (mutable_cf_options.ttl > 0) { if (mutable_cf_options.ttl > 0) {
c = PickTTLCompaction(cf_name, mutable_cf_options, vstorage, log_buffer); c = PickTTLCompaction(cf_name, mutable_cf_options, mutable_db_options,
vstorage, log_buffer);
} }
if (c == nullptr) { if (c == nullptr) {
c = PickSizeCompaction(cf_name, mutable_cf_options, vstorage, log_buffer); c = PickSizeCompaction(cf_name, mutable_cf_options, mutable_db_options,
vstorage, log_buffer);
} }
RegisterCompaction(c); RegisterCompaction(c);
return c; return c;
@ -225,7 +231,8 @@ Compaction* FIFOCompactionPicker::PickCompaction(
Compaction* FIFOCompactionPicker::CompactRange( Compaction* FIFOCompactionPicker::CompactRange(
const std::string& cf_name, const MutableCFOptions& mutable_cf_options, const std::string& cf_name, const MutableCFOptions& mutable_cf_options,
VersionStorageInfo* vstorage, int input_level, int output_level, const MutableDBOptions& mutable_db_options, VersionStorageInfo* vstorage,
int input_level, int output_level,
const CompactRangeOptions& /*compact_range_options*/, const CompactRangeOptions& /*compact_range_options*/,
const InternalKey* /*begin*/, const InternalKey* /*end*/, const InternalKey* /*begin*/, const InternalKey* /*end*/,
InternalKey** compaction_end, bool* /*manual_conflict*/, InternalKey** compaction_end, bool* /*manual_conflict*/,
@ -238,8 +245,8 @@ Compaction* FIFOCompactionPicker::CompactRange(
assert(output_level == 0); assert(output_level == 0);
*compaction_end = nullptr; *compaction_end = nullptr;
LogBuffer log_buffer(InfoLogLevel::INFO_LEVEL, ioptions_.info_log); LogBuffer log_buffer(InfoLogLevel::INFO_LEVEL, ioptions_.info_log);
Compaction* c = Compaction* c = PickCompaction(cf_name, mutable_cf_options,
PickCompaction(cf_name, mutable_cf_options, vstorage, &log_buffer); mutable_db_options, vstorage, &log_buffer);
log_buffer.FlushBufferToLog(); log_buffer.FlushBufferToLog();
return c; return c;
} }

@ -21,12 +21,14 @@ class FIFOCompactionPicker : public CompactionPicker {
virtual Compaction* PickCompaction( virtual Compaction* PickCompaction(
const std::string& cf_name, const MutableCFOptions& mutable_cf_options, const std::string& cf_name, const MutableCFOptions& mutable_cf_options,
VersionStorageInfo* version, LogBuffer* log_buffer, const MutableDBOptions& mutable_db_options, VersionStorageInfo* version,
LogBuffer* log_buffer,
SequenceNumber earliest_memtable_seqno = kMaxSequenceNumber) override; SequenceNumber earliest_memtable_seqno = kMaxSequenceNumber) override;
virtual Compaction* CompactRange( virtual Compaction* CompactRange(
const std::string& cf_name, const MutableCFOptions& mutable_cf_options, const std::string& cf_name, const MutableCFOptions& mutable_cf_options,
VersionStorageInfo* vstorage, int input_level, int output_level, const MutableDBOptions& mutable_db_options, VersionStorageInfo* vstorage,
int input_level, int output_level,
const CompactRangeOptions& compact_range_options, const CompactRangeOptions& compact_range_options,
const InternalKey* begin, const InternalKey* end, const InternalKey* begin, const InternalKey* end,
InternalKey** compaction_end, bool* manual_conflict, InternalKey** compaction_end, bool* manual_conflict,
@ -41,11 +43,13 @@ class FIFOCompactionPicker : public CompactionPicker {
private: private:
Compaction* PickTTLCompaction(const std::string& cf_name, Compaction* PickTTLCompaction(const std::string& cf_name,
const MutableCFOptions& mutable_cf_options, const MutableCFOptions& mutable_cf_options,
const MutableDBOptions& mutable_db_options,
VersionStorageInfo* version, VersionStorageInfo* version,
LogBuffer* log_buffer); LogBuffer* log_buffer);
Compaction* PickSizeCompaction(const std::string& cf_name, Compaction* PickSizeCompaction(const std::string& cf_name,
const MutableCFOptions& mutable_cf_options, const MutableCFOptions& mutable_cf_options,
const MutableDBOptions& mutable_db_options,
VersionStorageInfo* version, VersionStorageInfo* version,
LogBuffer* log_buffer); LogBuffer* log_buffer);
}; };

@ -49,14 +49,16 @@ class LevelCompactionBuilder {
CompactionPicker* compaction_picker, CompactionPicker* compaction_picker,
LogBuffer* log_buffer, LogBuffer* log_buffer,
const MutableCFOptions& mutable_cf_options, const MutableCFOptions& mutable_cf_options,
const ImmutableCFOptions& ioptions) const ImmutableCFOptions& ioptions,
const MutableDBOptions& mutable_db_options)
: cf_name_(cf_name), : cf_name_(cf_name),
vstorage_(vstorage), vstorage_(vstorage),
earliest_mem_seqno_(earliest_mem_seqno), earliest_mem_seqno_(earliest_mem_seqno),
compaction_picker_(compaction_picker), compaction_picker_(compaction_picker),
log_buffer_(log_buffer), log_buffer_(log_buffer),
mutable_cf_options_(mutable_cf_options), mutable_cf_options_(mutable_cf_options),
ioptions_(ioptions) {} ioptions_(ioptions),
mutable_db_options_(mutable_db_options) {}
// Pick and return a compaction. // Pick and return a compaction.
Compaction* PickCompaction(); Compaction* PickCompaction();
@ -120,6 +122,7 @@ class LevelCompactionBuilder {
const MutableCFOptions& mutable_cf_options_; const MutableCFOptions& mutable_cf_options_;
const ImmutableCFOptions& ioptions_; const ImmutableCFOptions& ioptions_;
const MutableDBOptions& mutable_db_options_;
// Pick a path ID to place a newly generated file, with its level // Pick a path ID to place a newly generated file, with its level
static uint32_t GetPathId(const ImmutableCFOptions& ioptions, static uint32_t GetPathId(const ImmutableCFOptions& ioptions,
const MutableCFOptions& mutable_cf_options, const MutableCFOptions& mutable_cf_options,
@ -323,8 +326,8 @@ Compaction* LevelCompactionBuilder::PickCompaction() {
Compaction* LevelCompactionBuilder::GetCompaction() { Compaction* LevelCompactionBuilder::GetCompaction() {
auto c = new Compaction( auto c = new Compaction(
vstorage_, ioptions_, mutable_cf_options_, std::move(compaction_inputs_), vstorage_, ioptions_, mutable_cf_options_, mutable_db_options_,
output_level_, std::move(compaction_inputs_), output_level_,
MaxFileSizeForLevel(mutable_cf_options_, output_level_, MaxFileSizeForLevel(mutable_cf_options_, output_level_,
ioptions_.compaction_style, vstorage_->base_level(), ioptions_.compaction_style, vstorage_->base_level(),
ioptions_.level_compaction_dynamic_level_bytes), ioptions_.level_compaction_dynamic_level_bytes),
@ -497,10 +500,11 @@ bool LevelCompactionBuilder::PickIntraL0Compaction() {
Compaction* LevelCompactionPicker::PickCompaction( Compaction* LevelCompactionPicker::PickCompaction(
const std::string& cf_name, const MutableCFOptions& mutable_cf_options, const std::string& cf_name, const MutableCFOptions& mutable_cf_options,
VersionStorageInfo* vstorage, LogBuffer* log_buffer, const MutableDBOptions& mutable_db_options, VersionStorageInfo* vstorage,
SequenceNumber earliest_mem_seqno) { LogBuffer* log_buffer, SequenceNumber earliest_mem_seqno) {
LevelCompactionBuilder builder(cf_name, vstorage, earliest_mem_seqno, this, LevelCompactionBuilder builder(cf_name, vstorage, earliest_mem_seqno, this,
log_buffer, mutable_cf_options, ioptions_); log_buffer, mutable_cf_options, ioptions_,
mutable_db_options);
return builder.PickCompaction(); return builder.PickCompaction();
} }
} // namespace ROCKSDB_NAMESPACE } // namespace ROCKSDB_NAMESPACE

@ -22,7 +22,8 @@ class LevelCompactionPicker : public CompactionPicker {
: CompactionPicker(ioptions, icmp) {} : CompactionPicker(ioptions, icmp) {}
virtual Compaction* PickCompaction( virtual Compaction* PickCompaction(
const std::string& cf_name, const MutableCFOptions& mutable_cf_options, const std::string& cf_name, const MutableCFOptions& mutable_cf_options,
VersionStorageInfo* vstorage, LogBuffer* log_buffer, const MutableDBOptions& mutable_db_options, VersionStorageInfo* vstorage,
LogBuffer* log_buffer,
SequenceNumber earliest_memtable_seqno = kMaxSequenceNumber) override; SequenceNumber earliest_memtable_seqno = kMaxSequenceNumber) override;
virtual bool NeedsCompaction( virtual bool NeedsCompaction(

@ -33,6 +33,7 @@ class CompactionPickerTest : public testing::Test {
Options options_; Options options_;
ImmutableCFOptions ioptions_; ImmutableCFOptions ioptions_;
MutableCFOptions mutable_cf_options_; MutableCFOptions mutable_cf_options_;
MutableDBOptions mutable_db_options_;
LevelCompactionPicker level_compaction_picker; LevelCompactionPicker level_compaction_picker;
std::string cf_name_; std::string cf_name_;
CountingLogger logger_; CountingLogger logger_;
@ -52,6 +53,7 @@ class CompactionPickerTest : public testing::Test {
icmp_(ucmp_), icmp_(ucmp_),
ioptions_(options_), ioptions_(options_),
mutable_cf_options_(options_), mutable_cf_options_(options_),
mutable_db_options_(),
level_compaction_picker(ioptions_, &icmp_), level_compaction_picker(ioptions_, &icmp_),
cf_name_("dummy"), cf_name_("dummy"),
log_buffer_(InfoLogLevel::INFO_LEVEL, &logger_), log_buffer_(InfoLogLevel::INFO_LEVEL, &logger_),
@ -181,7 +183,8 @@ TEST_F(CompactionPickerTest, Empty) {
NewVersionStorage(6, kCompactionStyleLevel); NewVersionStorage(6, kCompactionStyleLevel);
UpdateVersionStorageInfo(); UpdateVersionStorageInfo();
std::unique_ptr<Compaction> compaction(level_compaction_picker.PickCompaction( std::unique_ptr<Compaction> compaction(level_compaction_picker.PickCompaction(
cf_name_, mutable_cf_options_, vstorage_.get(), &log_buffer_)); cf_name_, mutable_cf_options_, mutable_db_options_, vstorage_.get(),
&log_buffer_));
ASSERT_TRUE(compaction.get() == nullptr); ASSERT_TRUE(compaction.get() == nullptr);
} }
@ -192,7 +195,8 @@ TEST_F(CompactionPickerTest, Single) {
UpdateVersionStorageInfo(); UpdateVersionStorageInfo();
std::unique_ptr<Compaction> compaction(level_compaction_picker.PickCompaction( std::unique_ptr<Compaction> compaction(level_compaction_picker.PickCompaction(
cf_name_, mutable_cf_options_, vstorage_.get(), &log_buffer_)); cf_name_, mutable_cf_options_, mutable_db_options_, vstorage_.get(),
&log_buffer_));
ASSERT_TRUE(compaction.get() == nullptr); ASSERT_TRUE(compaction.get() == nullptr);
} }
@ -205,7 +209,8 @@ TEST_F(CompactionPickerTest, Level0Trigger) {
UpdateVersionStorageInfo(); UpdateVersionStorageInfo();
std::unique_ptr<Compaction> compaction(level_compaction_picker.PickCompaction( std::unique_ptr<Compaction> compaction(level_compaction_picker.PickCompaction(
cf_name_, mutable_cf_options_, vstorage_.get(), &log_buffer_)); cf_name_, mutable_cf_options_, mutable_db_options_, vstorage_.get(),
&log_buffer_));
ASSERT_TRUE(compaction.get() != nullptr); ASSERT_TRUE(compaction.get() != nullptr);
ASSERT_EQ(2U, compaction->num_input_files(0)); ASSERT_EQ(2U, compaction->num_input_files(0));
ASSERT_EQ(1U, compaction->input(0, 0)->fd.GetNumber()); ASSERT_EQ(1U, compaction->input(0, 0)->fd.GetNumber());
@ -218,7 +223,8 @@ TEST_F(CompactionPickerTest, Level1Trigger) {
UpdateVersionStorageInfo(); UpdateVersionStorageInfo();
std::unique_ptr<Compaction> compaction(level_compaction_picker.PickCompaction( std::unique_ptr<Compaction> compaction(level_compaction_picker.PickCompaction(
cf_name_, mutable_cf_options_, vstorage_.get(), &log_buffer_)); cf_name_, mutable_cf_options_, mutable_db_options_, vstorage_.get(),
&log_buffer_));
ASSERT_TRUE(compaction.get() != nullptr); ASSERT_TRUE(compaction.get() != nullptr);
ASSERT_EQ(1U, compaction->num_input_files(0)); ASSERT_EQ(1U, compaction->num_input_files(0));
ASSERT_EQ(66U, compaction->input(0, 0)->fd.GetNumber()); ASSERT_EQ(66U, compaction->input(0, 0)->fd.GetNumber());
@ -236,7 +242,8 @@ TEST_F(CompactionPickerTest, Level1Trigger2) {
UpdateVersionStorageInfo(); UpdateVersionStorageInfo();
std::unique_ptr<Compaction> compaction(level_compaction_picker.PickCompaction( std::unique_ptr<Compaction> compaction(level_compaction_picker.PickCompaction(
cf_name_, mutable_cf_options_, vstorage_.get(), &log_buffer_)); cf_name_, mutable_cf_options_, mutable_db_options_, vstorage_.get(),
&log_buffer_));
ASSERT_TRUE(compaction.get() != nullptr); ASSERT_TRUE(compaction.get() != nullptr);
ASSERT_EQ(1U, compaction->num_input_files(0)); ASSERT_EQ(1U, compaction->num_input_files(0));
ASSERT_EQ(2U, compaction->num_input_files(1)); ASSERT_EQ(2U, compaction->num_input_files(1));
@ -267,7 +274,8 @@ TEST_F(CompactionPickerTest, LevelMaxScore) {
UpdateVersionStorageInfo(); UpdateVersionStorageInfo();
std::unique_ptr<Compaction> compaction(level_compaction_picker.PickCompaction( std::unique_ptr<Compaction> compaction(level_compaction_picker.PickCompaction(
cf_name_, mutable_cf_options_, vstorage_.get(), &log_buffer_)); cf_name_, mutable_cf_options_, mutable_db_options_, vstorage_.get(),
&log_buffer_));
ASSERT_TRUE(compaction.get() != nullptr); ASSERT_TRUE(compaction.get() != nullptr);
ASSERT_EQ(1U, compaction->num_input_files(0)); ASSERT_EQ(1U, compaction->num_input_files(0));
ASSERT_EQ(7U, compaction->input(0, 0)->fd.GetNumber()); ASSERT_EQ(7U, compaction->input(0, 0)->fd.GetNumber());
@ -314,7 +322,8 @@ TEST_F(CompactionPickerTest, Level0TriggerDynamic) {
UpdateVersionStorageInfo(); UpdateVersionStorageInfo();
std::unique_ptr<Compaction> compaction(level_compaction_picker.PickCompaction( std::unique_ptr<Compaction> compaction(level_compaction_picker.PickCompaction(
cf_name_, mutable_cf_options_, vstorage_.get(), &log_buffer_)); cf_name_, mutable_cf_options_, mutable_db_options_, vstorage_.get(),
&log_buffer_));
ASSERT_TRUE(compaction.get() != nullptr); ASSERT_TRUE(compaction.get() != nullptr);
ASSERT_EQ(2U, compaction->num_input_files(0)); ASSERT_EQ(2U, compaction->num_input_files(0));
ASSERT_EQ(1U, compaction->input(0, 0)->fd.GetNumber()); ASSERT_EQ(1U, compaction->input(0, 0)->fd.GetNumber());
@ -338,7 +347,8 @@ TEST_F(CompactionPickerTest, Level0TriggerDynamic2) {
ASSERT_EQ(vstorage_->base_level(), num_levels - 2); ASSERT_EQ(vstorage_->base_level(), num_levels - 2);
std::unique_ptr<Compaction> compaction(level_compaction_picker.PickCompaction( std::unique_ptr<Compaction> compaction(level_compaction_picker.PickCompaction(
cf_name_, mutable_cf_options_, vstorage_.get(), &log_buffer_)); cf_name_, mutable_cf_options_, mutable_db_options_, vstorage_.get(),
&log_buffer_));
ASSERT_TRUE(compaction.get() != nullptr); ASSERT_TRUE(compaction.get() != nullptr);
ASSERT_EQ(2U, compaction->num_input_files(0)); ASSERT_EQ(2U, compaction->num_input_files(0));
ASSERT_EQ(1U, compaction->input(0, 0)->fd.GetNumber()); ASSERT_EQ(1U, compaction->input(0, 0)->fd.GetNumber());
@ -363,7 +373,8 @@ TEST_F(CompactionPickerTest, Level0TriggerDynamic3) {
ASSERT_EQ(vstorage_->base_level(), num_levels - 3); ASSERT_EQ(vstorage_->base_level(), num_levels - 3);
std::unique_ptr<Compaction> compaction(level_compaction_picker.PickCompaction( std::unique_ptr<Compaction> compaction(level_compaction_picker.PickCompaction(
cf_name_, mutable_cf_options_, vstorage_.get(), &log_buffer_)); cf_name_, mutable_cf_options_, mutable_db_options_, vstorage_.get(),
&log_buffer_));
ASSERT_TRUE(compaction.get() != nullptr); ASSERT_TRUE(compaction.get() != nullptr);
ASSERT_EQ(2U, compaction->num_input_files(0)); ASSERT_EQ(2U, compaction->num_input_files(0));
ASSERT_EQ(1U, compaction->input(0, 0)->fd.GetNumber()); ASSERT_EQ(1U, compaction->input(0, 0)->fd.GetNumber());
@ -392,7 +403,8 @@ TEST_F(CompactionPickerTest, Level0TriggerDynamic4) {
ASSERT_EQ(vstorage_->base_level(), num_levels - 3); ASSERT_EQ(vstorage_->base_level(), num_levels - 3);
std::unique_ptr<Compaction> compaction(level_compaction_picker.PickCompaction( std::unique_ptr<Compaction> compaction(level_compaction_picker.PickCompaction(
cf_name_, mutable_cf_options_, vstorage_.get(), &log_buffer_)); cf_name_, mutable_cf_options_, mutable_db_options_, vstorage_.get(),
&log_buffer_));
ASSERT_TRUE(compaction.get() != nullptr); ASSERT_TRUE(compaction.get() != nullptr);
ASSERT_EQ(2U, compaction->num_input_files(0)); ASSERT_EQ(2U, compaction->num_input_files(0));
ASSERT_EQ(1U, compaction->input(0, 0)->fd.GetNumber()); ASSERT_EQ(1U, compaction->input(0, 0)->fd.GetNumber());
@ -424,7 +436,8 @@ TEST_F(CompactionPickerTest, LevelTriggerDynamic4) {
UpdateVersionStorageInfo(); UpdateVersionStorageInfo();
std::unique_ptr<Compaction> compaction(level_compaction_picker.PickCompaction( std::unique_ptr<Compaction> compaction(level_compaction_picker.PickCompaction(
cf_name_, mutable_cf_options_, vstorage_.get(), &log_buffer_)); cf_name_, mutable_cf_options_, mutable_db_options_, vstorage_.get(),
&log_buffer_));
ASSERT_TRUE(compaction.get() != nullptr); ASSERT_TRUE(compaction.get() != nullptr);
ASSERT_EQ(1U, compaction->num_input_files(0)); ASSERT_EQ(1U, compaction->num_input_files(0));
ASSERT_EQ(5U, compaction->input(0, 0)->fd.GetNumber()); ASSERT_EQ(5U, compaction->input(0, 0)->fd.GetNumber());
@ -481,7 +494,8 @@ TEST_F(CompactionPickerTest, CompactionUniversalIngestBehindReservedLevel) {
std::unique_ptr<Compaction> compaction( std::unique_ptr<Compaction> compaction(
universal_compaction_picker.PickCompaction( universal_compaction_picker.PickCompaction(
cf_name_, mutable_cf_options_, vstorage_.get(), &log_buffer_)); cf_name_, mutable_cf_options_, mutable_db_options_, vstorage_.get(),
&log_buffer_));
// output level should be the one above the bottom-most // output level should be the one above the bottom-most
ASSERT_EQ(1, compaction->output_level()); ASSERT_EQ(1, compaction->output_level());
@ -515,7 +529,8 @@ TEST_F(CompactionPickerTest, CannotTrivialMoveUniversal) {
std::unique_ptr<Compaction> compaction( std::unique_ptr<Compaction> compaction(
universal_compaction_picker.PickCompaction( universal_compaction_picker.PickCompaction(
cf_name_, mutable_cf_options_, vstorage_.get(), &log_buffer_)); cf_name_, mutable_cf_options_, mutable_db_options_, vstorage_.get(),
&log_buffer_));
ASSERT_TRUE(!compaction->is_trivial_move()); ASSERT_TRUE(!compaction->is_trivial_move());
} }
@ -541,7 +556,8 @@ TEST_F(CompactionPickerTest, AllowsTrivialMoveUniversal) {
std::unique_ptr<Compaction> compaction( std::unique_ptr<Compaction> compaction(
universal_compaction_picker.PickCompaction( universal_compaction_picker.PickCompaction(
cf_name_, mutable_cf_options_, vstorage_.get(), &log_buffer_)); cf_name_, mutable_cf_options_, mutable_db_options_, vstorage_.get(),
&log_buffer_));
ASSERT_TRUE(compaction->is_trivial_move()); ASSERT_TRUE(compaction->is_trivial_move());
} }
@ -569,7 +585,8 @@ TEST_F(CompactionPickerTest, UniversalPeriodicCompaction1) {
std::unique_ptr<Compaction> compaction( std::unique_ptr<Compaction> compaction(
universal_compaction_picker.PickCompaction( universal_compaction_picker.PickCompaction(
cf_name_, mutable_cf_options_, vstorage_.get(), &log_buffer_)); cf_name_, mutable_cf_options_, mutable_db_options_, vstorage_.get(),
&log_buffer_));
ASSERT_TRUE(compaction); ASSERT_TRUE(compaction);
ASSERT_EQ(4, compaction->output_level()); ASSERT_EQ(4, compaction->output_level());
@ -599,7 +616,8 @@ TEST_F(CompactionPickerTest, UniversalPeriodicCompaction2) {
std::unique_ptr<Compaction> compaction( std::unique_ptr<Compaction> compaction(
universal_compaction_picker.PickCompaction( universal_compaction_picker.PickCompaction(
cf_name_, mutable_cf_options_, vstorage_.get(), &log_buffer_)); cf_name_, mutable_cf_options_, mutable_db_options_, vstorage_.get(),
&log_buffer_));
ASSERT_FALSE(compaction); ASSERT_FALSE(compaction);
} }
@ -625,7 +643,8 @@ TEST_F(CompactionPickerTest, UniversalPeriodicCompaction3) {
std::unique_ptr<Compaction> compaction( std::unique_ptr<Compaction> compaction(
universal_compaction_picker.PickCompaction( universal_compaction_picker.PickCompaction(
cf_name_, mutable_cf_options_, vstorage_.get(), &log_buffer_)); cf_name_, mutable_cf_options_, mutable_db_options_, vstorage_.get(),
&log_buffer_));
ASSERT_FALSE(compaction); ASSERT_FALSE(compaction);
} }
@ -655,7 +674,8 @@ TEST_F(CompactionPickerTest, UniversalPeriodicCompaction4) {
std::unique_ptr<Compaction> compaction( std::unique_ptr<Compaction> compaction(
universal_compaction_picker.PickCompaction( universal_compaction_picker.PickCompaction(
cf_name_, mutable_cf_options_, vstorage_.get(), &log_buffer_)); cf_name_, mutable_cf_options_, mutable_db_options_, vstorage_.get(),
&log_buffer_));
ASSERT_TRUE(!compaction || ASSERT_TRUE(!compaction ||
compaction->start_level() != compaction->output_level()); compaction->start_level() != compaction->output_level());
} }
@ -675,7 +695,8 @@ TEST_F(CompactionPickerTest, UniversalPeriodicCompaction5) {
std::unique_ptr<Compaction> compaction( std::unique_ptr<Compaction> compaction(
universal_compaction_picker.PickCompaction( universal_compaction_picker.PickCompaction(
cf_name_, mutable_cf_options_, vstorage_.get(), &log_buffer_)); cf_name_, mutable_cf_options_, mutable_db_options_, vstorage_.get(),
&log_buffer_));
ASSERT_TRUE(compaction); ASSERT_TRUE(compaction);
ASSERT_EQ(0, compaction->start_level()); ASSERT_EQ(0, compaction->start_level());
ASSERT_EQ(1U, compaction->num_input_files(0)); ASSERT_EQ(1U, compaction->num_input_files(0));
@ -699,7 +720,8 @@ TEST_F(CompactionPickerTest, UniversalPeriodicCompaction6) {
std::unique_ptr<Compaction> compaction( std::unique_ptr<Compaction> compaction(
universal_compaction_picker.PickCompaction( universal_compaction_picker.PickCompaction(
cf_name_, mutable_cf_options_, vstorage_.get(), &log_buffer_)); cf_name_, mutable_cf_options_, mutable_db_options_, vstorage_.get(),
&log_buffer_));
ASSERT_TRUE(compaction); ASSERT_TRUE(compaction);
ASSERT_EQ(4, compaction->start_level()); ASSERT_EQ(4, compaction->start_level());
ASSERT_EQ(2U, compaction->num_input_files(0)); ASSERT_EQ(2U, compaction->num_input_files(0));
@ -759,7 +781,8 @@ TEST_F(CompactionPickerTest, CompactionPriMinOverlapping1) {
UpdateVersionStorageInfo(); UpdateVersionStorageInfo();
std::unique_ptr<Compaction> compaction(level_compaction_picker.PickCompaction( std::unique_ptr<Compaction> compaction(level_compaction_picker.PickCompaction(
cf_name_, mutable_cf_options_, vstorage_.get(), &log_buffer_)); cf_name_, mutable_cf_options_, mutable_db_options_, vstorage_.get(),
&log_buffer_));
ASSERT_TRUE(compaction.get() != nullptr); ASSERT_TRUE(compaction.get() != nullptr);
ASSERT_EQ(1U, compaction->num_input_files(0)); ASSERT_EQ(1U, compaction->num_input_files(0));
// Pick file 8 because it overlaps with 0 files on level 3. // Pick file 8 because it overlaps with 0 files on level 3.
@ -791,7 +814,8 @@ TEST_F(CompactionPickerTest, CompactionPriMinOverlapping2) {
UpdateVersionStorageInfo(); UpdateVersionStorageInfo();
std::unique_ptr<Compaction> compaction(level_compaction_picker.PickCompaction( std::unique_ptr<Compaction> compaction(level_compaction_picker.PickCompaction(
cf_name_, mutable_cf_options_, vstorage_.get(), &log_buffer_)); cf_name_, mutable_cf_options_, mutable_db_options_, vstorage_.get(),
&log_buffer_));
ASSERT_TRUE(compaction.get() != nullptr); ASSERT_TRUE(compaction.get() != nullptr);
ASSERT_EQ(1U, compaction->num_input_files(0)); ASSERT_EQ(1U, compaction->num_input_files(0));
// Picking file 7 because overlapping ratio is the biggest. // Picking file 7 because overlapping ratio is the biggest.
@ -818,7 +842,8 @@ TEST_F(CompactionPickerTest, CompactionPriMinOverlapping3) {
UpdateVersionStorageInfo(); UpdateVersionStorageInfo();
std::unique_ptr<Compaction> compaction(level_compaction_picker.PickCompaction( std::unique_ptr<Compaction> compaction(level_compaction_picker.PickCompaction(
cf_name_, mutable_cf_options_, vstorage_.get(), &log_buffer_)); cf_name_, mutable_cf_options_, mutable_db_options_, vstorage_.get(),
&log_buffer_));
ASSERT_TRUE(compaction.get() != nullptr); ASSERT_TRUE(compaction.get() != nullptr);
ASSERT_EQ(1U, compaction->num_input_files(0)); ASSERT_EQ(1U, compaction->num_input_files(0));
// Picking file 8 because overlapping ratio is the biggest. // Picking file 8 because overlapping ratio is the biggest.
@ -847,7 +872,8 @@ TEST_F(CompactionPickerTest, CompactionPriMinOverlapping4) {
UpdateVersionStorageInfo(); UpdateVersionStorageInfo();
std::unique_ptr<Compaction> compaction(level_compaction_picker.PickCompaction( std::unique_ptr<Compaction> compaction(level_compaction_picker.PickCompaction(
cf_name_, mutable_cf_options_, vstorage_.get(), &log_buffer_)); cf_name_, mutable_cf_options_, mutable_db_options_, vstorage_.get(),
&log_buffer_));
ASSERT_TRUE(compaction.get() != nullptr); ASSERT_TRUE(compaction.get() != nullptr);
ASSERT_EQ(1U, compaction->num_input_files(0)); ASSERT_EQ(1U, compaction->num_input_files(0));
// Picking file 8 because overlapping ratio is the biggest. // Picking file 8 because overlapping ratio is the biggest.
@ -874,7 +900,8 @@ TEST_F(CompactionPickerTest, ParentIndexResetBug) {
UpdateVersionStorageInfo(); UpdateVersionStorageInfo();
std::unique_ptr<Compaction> compaction(level_compaction_picker.PickCompaction( std::unique_ptr<Compaction> compaction(level_compaction_picker.PickCompaction(
cf_name_, mutable_cf_options_, vstorage_.get(), &log_buffer_)); cf_name_, mutable_cf_options_, mutable_db_options_, vstorage_.get(),
&log_buffer_));
} }
// This test checks ExpandWhileOverlapping() by having overlapping user keys // This test checks ExpandWhileOverlapping() by having overlapping user keys
@ -891,7 +918,8 @@ TEST_F(CompactionPickerTest, OverlappingUserKeys) {
UpdateVersionStorageInfo(); UpdateVersionStorageInfo();
std::unique_ptr<Compaction> compaction(level_compaction_picker.PickCompaction( std::unique_ptr<Compaction> compaction(level_compaction_picker.PickCompaction(
cf_name_, mutable_cf_options_, vstorage_.get(), &log_buffer_)); cf_name_, mutable_cf_options_, mutable_db_options_, vstorage_.get(),
&log_buffer_));
ASSERT_TRUE(compaction.get() != nullptr); ASSERT_TRUE(compaction.get() != nullptr);
ASSERT_EQ(1U, compaction->num_input_levels()); ASSERT_EQ(1U, compaction->num_input_levels());
ASSERT_EQ(2U, compaction->num_input_files(0)); ASSERT_EQ(2U, compaction->num_input_files(0));
@ -910,7 +938,8 @@ TEST_F(CompactionPickerTest, OverlappingUserKeys2) {
UpdateVersionStorageInfo(); UpdateVersionStorageInfo();
std::unique_ptr<Compaction> compaction(level_compaction_picker.PickCompaction( std::unique_ptr<Compaction> compaction(level_compaction_picker.PickCompaction(
cf_name_, mutable_cf_options_, vstorage_.get(), &log_buffer_)); cf_name_, mutable_cf_options_, mutable_db_options_, vstorage_.get(),
&log_buffer_));
ASSERT_TRUE(compaction.get() != nullptr); ASSERT_TRUE(compaction.get() != nullptr);
ASSERT_EQ(2U, compaction->num_input_levels()); ASSERT_EQ(2U, compaction->num_input_levels());
ASSERT_EQ(2U, compaction->num_input_files(0)); ASSERT_EQ(2U, compaction->num_input_files(0));
@ -937,7 +966,8 @@ TEST_F(CompactionPickerTest, OverlappingUserKeys3) {
UpdateVersionStorageInfo(); UpdateVersionStorageInfo();
std::unique_ptr<Compaction> compaction(level_compaction_picker.PickCompaction( std::unique_ptr<Compaction> compaction(level_compaction_picker.PickCompaction(
cf_name_, mutable_cf_options_, vstorage_.get(), &log_buffer_)); cf_name_, mutable_cf_options_, mutable_db_options_, vstorage_.get(),
&log_buffer_));
ASSERT_TRUE(compaction.get() != nullptr); ASSERT_TRUE(compaction.get() != nullptr);
ASSERT_EQ(2U, compaction->num_input_levels()); ASSERT_EQ(2U, compaction->num_input_levels());
ASSERT_EQ(5U, compaction->num_input_files(0)); ASSERT_EQ(5U, compaction->num_input_files(0));
@ -967,7 +997,8 @@ TEST_F(CompactionPickerTest, OverlappingUserKeys4) {
UpdateVersionStorageInfo(); UpdateVersionStorageInfo();
std::unique_ptr<Compaction> compaction(level_compaction_picker.PickCompaction( std::unique_ptr<Compaction> compaction(level_compaction_picker.PickCompaction(
cf_name_, mutable_cf_options_, vstorage_.get(), &log_buffer_)); cf_name_, mutable_cf_options_, mutable_db_options_, vstorage_.get(),
&log_buffer_));
ASSERT_TRUE(compaction.get() != nullptr); ASSERT_TRUE(compaction.get() != nullptr);
ASSERT_EQ(2U, compaction->num_input_levels()); ASSERT_EQ(2U, compaction->num_input_levels());
ASSERT_EQ(1U, compaction->num_input_files(0)); ASSERT_EQ(1U, compaction->num_input_files(0));
@ -990,7 +1021,8 @@ TEST_F(CompactionPickerTest, OverlappingUserKeys5) {
UpdateVersionStorageInfo(); UpdateVersionStorageInfo();
std::unique_ptr<Compaction> compaction(level_compaction_picker.PickCompaction( std::unique_ptr<Compaction> compaction(level_compaction_picker.PickCompaction(
cf_name_, mutable_cf_options_, vstorage_.get(), &log_buffer_)); cf_name_, mutable_cf_options_, mutable_db_options_, vstorage_.get(),
&log_buffer_));
ASSERT_TRUE(compaction.get() == nullptr); ASSERT_TRUE(compaction.get() == nullptr);
} }
@ -1011,7 +1043,8 @@ TEST_F(CompactionPickerTest, OverlappingUserKeys6) {
UpdateVersionStorageInfo(); UpdateVersionStorageInfo();
std::unique_ptr<Compaction> compaction(level_compaction_picker.PickCompaction( std::unique_ptr<Compaction> compaction(level_compaction_picker.PickCompaction(
cf_name_, mutable_cf_options_, vstorage_.get(), &log_buffer_)); cf_name_, mutable_cf_options_, mutable_db_options_, vstorage_.get(),
&log_buffer_));
ASSERT_TRUE(compaction.get() != nullptr); ASSERT_TRUE(compaction.get() != nullptr);
ASSERT_EQ(2U, compaction->num_input_levels()); ASSERT_EQ(2U, compaction->num_input_levels());
ASSERT_EQ(1U, compaction->num_input_files(0)); ASSERT_EQ(1U, compaction->num_input_files(0));
@ -1031,7 +1064,8 @@ TEST_F(CompactionPickerTest, OverlappingUserKeys7) {
UpdateVersionStorageInfo(); UpdateVersionStorageInfo();
std::unique_ptr<Compaction> compaction(level_compaction_picker.PickCompaction( std::unique_ptr<Compaction> compaction(level_compaction_picker.PickCompaction(
cf_name_, mutable_cf_options_, vstorage_.get(), &log_buffer_)); cf_name_, mutable_cf_options_, mutable_db_options_, vstorage_.get(),
&log_buffer_));
ASSERT_TRUE(compaction.get() != nullptr); ASSERT_TRUE(compaction.get() != nullptr);
ASSERT_EQ(2U, compaction->num_input_levels()); ASSERT_EQ(2U, compaction->num_input_levels());
ASSERT_GE(1U, compaction->num_input_files(0)); ASSERT_GE(1U, compaction->num_input_files(0));
@ -1059,7 +1093,8 @@ TEST_F(CompactionPickerTest, OverlappingUserKeys8) {
UpdateVersionStorageInfo(); UpdateVersionStorageInfo();
std::unique_ptr<Compaction> compaction(level_compaction_picker.PickCompaction( std::unique_ptr<Compaction> compaction(level_compaction_picker.PickCompaction(
cf_name_, mutable_cf_options_, vstorage_.get(), &log_buffer_)); cf_name_, mutable_cf_options_, mutable_db_options_, vstorage_.get(),
&log_buffer_));
ASSERT_TRUE(compaction.get() != nullptr); ASSERT_TRUE(compaction.get() != nullptr);
ASSERT_EQ(2U, compaction->num_input_levels()); ASSERT_EQ(2U, compaction->num_input_levels());
ASSERT_EQ(3U, compaction->num_input_files(0)); ASSERT_EQ(3U, compaction->num_input_files(0));
@ -1091,7 +1126,8 @@ TEST_F(CompactionPickerTest, OverlappingUserKeys9) {
UpdateVersionStorageInfo(); UpdateVersionStorageInfo();
std::unique_ptr<Compaction> compaction(level_compaction_picker.PickCompaction( std::unique_ptr<Compaction> compaction(level_compaction_picker.PickCompaction(
cf_name_, mutable_cf_options_, vstorage_.get(), &log_buffer_)); cf_name_, mutable_cf_options_, mutable_db_options_, vstorage_.get(),
&log_buffer_));
ASSERT_TRUE(compaction.get() != nullptr); ASSERT_TRUE(compaction.get() != nullptr);
ASSERT_EQ(2U, compaction->num_input_levels()); ASSERT_EQ(2U, compaction->num_input_levels());
ASSERT_EQ(5U, compaction->num_input_files(0)); ASSERT_EQ(5U, compaction->num_input_files(0));
@ -1131,7 +1167,8 @@ TEST_F(CompactionPickerTest, OverlappingUserKeys10) {
UpdateVersionStorageInfo(); UpdateVersionStorageInfo();
std::unique_ptr<Compaction> compaction(level_compaction_picker.PickCompaction( std::unique_ptr<Compaction> compaction(level_compaction_picker.PickCompaction(
cf_name_, mutable_cf_options_, vstorage_.get(), &log_buffer_)); cf_name_, mutable_cf_options_, mutable_db_options_, vstorage_.get(),
&log_buffer_));
ASSERT_TRUE(compaction.get() != nullptr); ASSERT_TRUE(compaction.get() != nullptr);
ASSERT_EQ(2U, compaction->num_input_levels()); ASSERT_EQ(2U, compaction->num_input_levels());
ASSERT_EQ(1U, compaction->num_input_files(0)); ASSERT_EQ(1U, compaction->num_input_files(0));
@ -1169,7 +1206,8 @@ TEST_F(CompactionPickerTest, OverlappingUserKeys11) {
UpdateVersionStorageInfo(); UpdateVersionStorageInfo();
std::unique_ptr<Compaction> compaction(level_compaction_picker.PickCompaction( std::unique_ptr<Compaction> compaction(level_compaction_picker.PickCompaction(
cf_name_, mutable_cf_options_, vstorage_.get(), &log_buffer_)); cf_name_, mutable_cf_options_, mutable_db_options_, vstorage_.get(),
&log_buffer_));
ASSERT_TRUE(compaction.get() != nullptr); ASSERT_TRUE(compaction.get() != nullptr);
ASSERT_EQ(2U, compaction->num_input_levels()); ASSERT_EQ(2U, compaction->num_input_levels());
ASSERT_EQ(1U, compaction->num_input_files(0)); ASSERT_EQ(1U, compaction->num_input_files(0));
@ -1206,7 +1244,8 @@ TEST_F(CompactionPickerTest, NotScheduleL1IfL0WithHigherPri1) {
ASSERT_EQ(0, vstorage_->CompactionScoreLevel(0)); ASSERT_EQ(0, vstorage_->CompactionScoreLevel(0));
ASSERT_EQ(1, vstorage_->CompactionScoreLevel(1)); ASSERT_EQ(1, vstorage_->CompactionScoreLevel(1));
std::unique_ptr<Compaction> compaction(level_compaction_picker.PickCompaction( std::unique_ptr<Compaction> compaction(level_compaction_picker.PickCompaction(
cf_name_, mutable_cf_options_, vstorage_.get(), &log_buffer_)); cf_name_, mutable_cf_options_, mutable_db_options_, vstorage_.get(),
&log_buffer_));
ASSERT_TRUE(compaction.get() == nullptr); ASSERT_TRUE(compaction.get() == nullptr);
} }
@ -1236,7 +1275,8 @@ TEST_F(CompactionPickerTest, NotScheduleL1IfL0WithHigherPri2) {
ASSERT_EQ(0, vstorage_->CompactionScoreLevel(0)); ASSERT_EQ(0, vstorage_->CompactionScoreLevel(0));
ASSERT_EQ(1, vstorage_->CompactionScoreLevel(1)); ASSERT_EQ(1, vstorage_->CompactionScoreLevel(1));
std::unique_ptr<Compaction> compaction(level_compaction_picker.PickCompaction( std::unique_ptr<Compaction> compaction(level_compaction_picker.PickCompaction(
cf_name_, mutable_cf_options_, vstorage_.get(), &log_buffer_)); cf_name_, mutable_cf_options_, mutable_db_options_, vstorage_.get(),
&log_buffer_));
ASSERT_TRUE(compaction.get() != nullptr); ASSERT_TRUE(compaction.get() != nullptr);
} }
@ -1269,7 +1309,8 @@ TEST_F(CompactionPickerTest, NotScheduleL1IfL0WithHigherPri3) {
ASSERT_EQ(1, vstorage_->CompactionScoreLevel(0)); ASSERT_EQ(1, vstorage_->CompactionScoreLevel(0));
ASSERT_EQ(0, vstorage_->CompactionScoreLevel(1)); ASSERT_EQ(0, vstorage_->CompactionScoreLevel(1));
std::unique_ptr<Compaction> compaction(level_compaction_picker.PickCompaction( std::unique_ptr<Compaction> compaction(level_compaction_picker.PickCompaction(
cf_name_, mutable_cf_options_, vstorage_.get(), &log_buffer_)); cf_name_, mutable_cf_options_, mutable_db_options_, vstorage_.get(),
&log_buffer_));
ASSERT_TRUE(compaction.get() != nullptr); ASSERT_TRUE(compaction.get() != nullptr);
} }
@ -1563,7 +1604,8 @@ TEST_F(CompactionPickerTest, MaxCompactionBytesHit) {
UpdateVersionStorageInfo(); UpdateVersionStorageInfo();
std::unique_ptr<Compaction> compaction(level_compaction_picker.PickCompaction( std::unique_ptr<Compaction> compaction(level_compaction_picker.PickCompaction(
cf_name_, mutable_cf_options_, vstorage_.get(), &log_buffer_)); cf_name_, mutable_cf_options_, mutable_db_options_, vstorage_.get(),
&log_buffer_));
ASSERT_TRUE(compaction.get() != nullptr); ASSERT_TRUE(compaction.get() != nullptr);
ASSERT_EQ(2U, compaction->num_input_levels()); ASSERT_EQ(2U, compaction->num_input_levels());
ASSERT_EQ(1U, compaction->num_input_files(0)); ASSERT_EQ(1U, compaction->num_input_files(0));
@ -1587,7 +1629,8 @@ TEST_F(CompactionPickerTest, MaxCompactionBytesNotHit) {
UpdateVersionStorageInfo(); UpdateVersionStorageInfo();
std::unique_ptr<Compaction> compaction(level_compaction_picker.PickCompaction( std::unique_ptr<Compaction> compaction(level_compaction_picker.PickCompaction(
cf_name_, mutable_cf_options_, vstorage_.get(), &log_buffer_)); cf_name_, mutable_cf_options_, mutable_db_options_, vstorage_.get(),
&log_buffer_));
ASSERT_TRUE(compaction.get() != nullptr); ASSERT_TRUE(compaction.get() != nullptr);
ASSERT_EQ(2U, compaction->num_input_levels()); ASSERT_EQ(2U, compaction->num_input_levels());
ASSERT_EQ(3U, compaction->num_input_files(0)); ASSERT_EQ(3U, compaction->num_input_files(0));
@ -1616,7 +1659,8 @@ TEST_F(CompactionPickerTest, IsTrivialMoveOn) {
UpdateVersionStorageInfo(); UpdateVersionStorageInfo();
std::unique_ptr<Compaction> compaction(level_compaction_picker.PickCompaction( std::unique_ptr<Compaction> compaction(level_compaction_picker.PickCompaction(
cf_name_, mutable_cf_options_, vstorage_.get(), &log_buffer_)); cf_name_, mutable_cf_options_, mutable_db_options_, vstorage_.get(),
&log_buffer_));
ASSERT_TRUE(compaction.get() != nullptr); ASSERT_TRUE(compaction.get() != nullptr);
ASSERT_TRUE(compaction->IsTrivialMove()); ASSERT_TRUE(compaction->IsTrivialMove());
} }
@ -1637,7 +1681,8 @@ TEST_F(CompactionPickerTest, IsTrivialMoveOff) {
UpdateVersionStorageInfo(); UpdateVersionStorageInfo();
std::unique_ptr<Compaction> compaction(level_compaction_picker.PickCompaction( std::unique_ptr<Compaction> compaction(level_compaction_picker.PickCompaction(
cf_name_, mutable_cf_options_, vstorage_.get(), &log_buffer_)); cf_name_, mutable_cf_options_, mutable_db_options_, vstorage_.get(),
&log_buffer_));
ASSERT_TRUE(compaction.get() != nullptr); ASSERT_TRUE(compaction.get() != nullptr);
ASSERT_FALSE(compaction->IsTrivialMove()); ASSERT_FALSE(compaction->IsTrivialMove());
} }
@ -1662,7 +1707,8 @@ TEST_F(CompactionPickerTest, CacheNextCompactionIndex) {
UpdateVersionStorageInfo(); UpdateVersionStorageInfo();
std::unique_ptr<Compaction> compaction(level_compaction_picker.PickCompaction( std::unique_ptr<Compaction> compaction(level_compaction_picker.PickCompaction(
cf_name_, mutable_cf_options_, vstorage_.get(), &log_buffer_)); cf_name_, mutable_cf_options_, mutable_db_options_, vstorage_.get(),
&log_buffer_));
ASSERT_TRUE(compaction.get() != nullptr); ASSERT_TRUE(compaction.get() != nullptr);
ASSERT_EQ(1U, compaction->num_input_levels()); ASSERT_EQ(1U, compaction->num_input_levels());
ASSERT_EQ(1U, compaction->num_input_files(0)); ASSERT_EQ(1U, compaction->num_input_files(0));
@ -1671,7 +1717,8 @@ TEST_F(CompactionPickerTest, CacheNextCompactionIndex) {
ASSERT_EQ(2, vstorage_->NextCompactionIndex(1 /* level */)); ASSERT_EQ(2, vstorage_->NextCompactionIndex(1 /* level */));
compaction.reset(level_compaction_picker.PickCompaction( compaction.reset(level_compaction_picker.PickCompaction(
cf_name_, mutable_cf_options_, vstorage_.get(), &log_buffer_)); cf_name_, mutable_cf_options_, mutable_db_options_, vstorage_.get(),
&log_buffer_));
ASSERT_TRUE(compaction.get() != nullptr); ASSERT_TRUE(compaction.get() != nullptr);
ASSERT_EQ(1U, compaction->num_input_levels()); ASSERT_EQ(1U, compaction->num_input_levels());
ASSERT_EQ(1U, compaction->num_input_files(0)); ASSERT_EQ(1U, compaction->num_input_files(0));
@ -1680,7 +1727,8 @@ TEST_F(CompactionPickerTest, CacheNextCompactionIndex) {
ASSERT_EQ(3, vstorage_->NextCompactionIndex(1 /* level */)); ASSERT_EQ(3, vstorage_->NextCompactionIndex(1 /* level */));
compaction.reset(level_compaction_picker.PickCompaction( compaction.reset(level_compaction_picker.PickCompaction(
cf_name_, mutable_cf_options_, vstorage_.get(), &log_buffer_)); cf_name_, mutable_cf_options_, mutable_db_options_, vstorage_.get(),
&log_buffer_));
ASSERT_TRUE(compaction.get() == nullptr); ASSERT_TRUE(compaction.get() == nullptr);
ASSERT_EQ(4, vstorage_->NextCompactionIndex(1 /* level */)); ASSERT_EQ(4, vstorage_->NextCompactionIndex(1 /* level */));
} }
@ -1705,7 +1753,8 @@ TEST_F(CompactionPickerTest, IntraL0MaxCompactionBytesNotHit) {
UpdateVersionStorageInfo(); UpdateVersionStorageInfo();
std::unique_ptr<Compaction> compaction(level_compaction_picker.PickCompaction( std::unique_ptr<Compaction> compaction(level_compaction_picker.PickCompaction(
cf_name_, mutable_cf_options_, vstorage_.get(), &log_buffer_)); cf_name_, mutable_cf_options_, mutable_db_options_, vstorage_.get(),
&log_buffer_));
ASSERT_TRUE(compaction.get() != nullptr); ASSERT_TRUE(compaction.get() != nullptr);
ASSERT_EQ(1U, compaction->num_input_levels()); ASSERT_EQ(1U, compaction->num_input_levels());
ASSERT_EQ(5U, compaction->num_input_files(0)); ASSERT_EQ(5U, compaction->num_input_files(0));
@ -1735,7 +1784,8 @@ TEST_F(CompactionPickerTest, IntraL0MaxCompactionBytesHit) {
UpdateVersionStorageInfo(); UpdateVersionStorageInfo();
std::unique_ptr<Compaction> compaction(level_compaction_picker.PickCompaction( std::unique_ptr<Compaction> compaction(level_compaction_picker.PickCompaction(
cf_name_, mutable_cf_options_, vstorage_.get(), &log_buffer_)); cf_name_, mutable_cf_options_, mutable_db_options_, vstorage_.get(),
&log_buffer_));
ASSERT_TRUE(compaction.get() != nullptr); ASSERT_TRUE(compaction.get() != nullptr);
ASSERT_EQ(1U, compaction->num_input_levels()); ASSERT_EQ(1U, compaction->num_input_levels());
ASSERT_EQ(4U, compaction->num_input_files(0)); ASSERT_EQ(4U, compaction->num_input_files(0));
@ -1767,7 +1817,8 @@ TEST_F(CompactionPickerTest, IntraL0ForEarliestSeqno) {
UpdateVersionStorageInfo(); UpdateVersionStorageInfo();
std::unique_ptr<Compaction> compaction(level_compaction_picker.PickCompaction( std::unique_ptr<Compaction> compaction(level_compaction_picker.PickCompaction(
cf_name_, mutable_cf_options_, vstorage_.get(), &log_buffer_, 107)); cf_name_, mutable_cf_options_, mutable_db_options_, vstorage_.get(),
&log_buffer_, 107));
ASSERT_TRUE(compaction.get() != nullptr); ASSERT_TRUE(compaction.get() != nullptr);
ASSERT_EQ(1U, compaction->num_input_levels()); ASSERT_EQ(1U, compaction->num_input_levels());
ASSERT_EQ(4U, compaction->num_input_files(0)); ASSERT_EQ(4U, compaction->num_input_files(0));
@ -1799,7 +1850,8 @@ TEST_F(CompactionPickerTest, UniversalMarkedCompactionFullOverlap) {
std::unique_ptr<Compaction> compaction( std::unique_ptr<Compaction> compaction(
universal_compaction_picker.PickCompaction( universal_compaction_picker.PickCompaction(
cf_name_, mutable_cf_options_, vstorage_.get(), &log_buffer_)); cf_name_, mutable_cf_options_, mutable_db_options_, vstorage_.get(),
&log_buffer_));
ASSERT_TRUE(compaction); ASSERT_TRUE(compaction);
// Validate that its a compaction to reduce sorted runs // Validate that its a compaction to reduce sorted runs
@ -1816,7 +1868,8 @@ TEST_F(CompactionPickerTest, UniversalMarkedCompactionFullOverlap) {
std::unique_ptr<Compaction> compaction2( std::unique_ptr<Compaction> compaction2(
universal_compaction_picker.PickCompaction( universal_compaction_picker.PickCompaction(
cf_name_, mutable_cf_options_, vstorage_.get(), &log_buffer_)); cf_name_, mutable_cf_options_, mutable_db_options_, vstorage_.get(),
&log_buffer_));
ASSERT_FALSE(compaction2); ASSERT_FALSE(compaction2);
} }
@ -1840,7 +1893,8 @@ TEST_F(CompactionPickerTest, UniversalMarkedCompactionFullOverlap2) {
std::unique_ptr<Compaction> compaction( std::unique_ptr<Compaction> compaction(
universal_compaction_picker.PickCompaction( universal_compaction_picker.PickCompaction(
cf_name_, mutable_cf_options_, vstorage_.get(), &log_buffer_)); cf_name_, mutable_cf_options_, mutable_db_options_, vstorage_.get(),
&log_buffer_));
ASSERT_TRUE(compaction); ASSERT_TRUE(compaction);
// Validate that its a delete triggered compaction // Validate that its a delete triggered compaction
@ -1858,7 +1912,8 @@ TEST_F(CompactionPickerTest, UniversalMarkedCompactionFullOverlap2) {
std::unique_ptr<Compaction> compaction2( std::unique_ptr<Compaction> compaction2(
universal_compaction_picker.PickCompaction( universal_compaction_picker.PickCompaction(
cf_name_, mutable_cf_options_, vstorage_.get(), &log_buffer_)); cf_name_, mutable_cf_options_, mutable_db_options_, vstorage_.get(),
&log_buffer_));
ASSERT_FALSE(compaction2); ASSERT_FALSE(compaction2);
} }
@ -1898,7 +1953,8 @@ TEST_F(CompactionPickerTest, UniversalMarkedCompactionStartOutputOverlap) {
std::unique_ptr<Compaction> compaction( std::unique_ptr<Compaction> compaction(
universal_compaction_picker.PickCompaction( universal_compaction_picker.PickCompaction(
cf_name_, mutable_cf_options_, vstorage_.get(), &log_buffer_)); cf_name_, mutable_cf_options_, mutable_db_options_, vstorage_.get(),
&log_buffer_));
ASSERT_TRUE(compaction); ASSERT_TRUE(compaction);
// Validate that its a delete triggered compaction // Validate that its a delete triggered compaction
@ -1928,7 +1984,8 @@ TEST_F(CompactionPickerTest, UniversalMarkedCompactionStartOutputOverlap) {
random_index = 0; random_index = 0;
std::unique_ptr<Compaction> compaction2( std::unique_ptr<Compaction> compaction2(
universal_compaction_picker.PickCompaction( universal_compaction_picker.PickCompaction(
cf_name_, mutable_cf_options_, vstorage_.get(), &log_buffer_)); cf_name_, mutable_cf_options_, mutable_db_options_, vstorage_.get(),
&log_buffer_));
ASSERT_FALSE(compaction2); ASSERT_FALSE(compaction2);
DeleteVersionStorage(); DeleteVersionStorage();
} }

@ -31,17 +31,16 @@ namespace {
// PickCompaction(). // PickCompaction().
class UniversalCompactionBuilder { class UniversalCompactionBuilder {
public: public:
UniversalCompactionBuilder(const ImmutableCFOptions& ioptions, UniversalCompactionBuilder(
const InternalKeyComparator* icmp, const ImmutableCFOptions& ioptions, const InternalKeyComparator* icmp,
const std::string& cf_name, const std::string& cf_name, const MutableCFOptions& mutable_cf_options,
const MutableCFOptions& mutable_cf_options, const MutableDBOptions& mutable_db_options, VersionStorageInfo* vstorage,
VersionStorageInfo* vstorage, UniversalCompactionPicker* picker, LogBuffer* log_buffer)
UniversalCompactionPicker* picker,
LogBuffer* log_buffer)
: ioptions_(ioptions), : ioptions_(ioptions),
icmp_(icmp), icmp_(icmp),
cf_name_(cf_name), cf_name_(cf_name),
mutable_cf_options_(mutable_cf_options), mutable_cf_options_(mutable_cf_options),
mutable_db_options_(mutable_db_options),
vstorage_(vstorage), vstorage_(vstorage),
picker_(picker), picker_(picker),
log_buffer_(log_buffer) {} log_buffer_(log_buffer) {}
@ -115,6 +114,7 @@ class UniversalCompactionBuilder {
std::vector<SortedRun> sorted_runs_; std::vector<SortedRun> sorted_runs_;
const std::string& cf_name_; const std::string& cf_name_;
const MutableCFOptions& mutable_cf_options_; const MutableCFOptions& mutable_cf_options_;
const MutableDBOptions& mutable_db_options_;
VersionStorageInfo* vstorage_; VersionStorageInfo* vstorage_;
UniversalCompactionPicker* picker_; UniversalCompactionPicker* picker_;
LogBuffer* log_buffer_; LogBuffer* log_buffer_;
@ -277,11 +277,11 @@ bool UniversalCompactionPicker::NeedsCompaction(
Compaction* UniversalCompactionPicker::PickCompaction( Compaction* UniversalCompactionPicker::PickCompaction(
const std::string& cf_name, const MutableCFOptions& mutable_cf_options, const std::string& cf_name, const MutableCFOptions& mutable_cf_options,
VersionStorageInfo* vstorage, LogBuffer* log_buffer, const MutableDBOptions& mutable_db_options, VersionStorageInfo* vstorage,
SequenceNumber /* earliest_memtable_seqno */) { LogBuffer* log_buffer, SequenceNumber /* earliest_memtable_seqno */) {
UniversalCompactionBuilder builder(ioptions_, icmp_, cf_name, UniversalCompactionBuilder builder(ioptions_, icmp_, cf_name,
mutable_cf_options, vstorage, this, mutable_cf_options, mutable_db_options,
log_buffer); vstorage, this, log_buffer);
return builder.PickCompaction(); return builder.PickCompaction();
} }
@ -730,8 +730,8 @@ Compaction* UniversalCompactionBuilder::PickCompactionToReduceSortedRuns(
compaction_reason = CompactionReason::kUniversalSortedRunNum; compaction_reason = CompactionReason::kUniversalSortedRunNum;
} }
return new Compaction( return new Compaction(
vstorage_, ioptions_, mutable_cf_options_, std::move(inputs), vstorage_, ioptions_, mutable_cf_options_, mutable_db_options_,
output_level, std::move(inputs), output_level,
MaxFileSizeForLevel(mutable_cf_options_, output_level, MaxFileSizeForLevel(mutable_cf_options_, output_level,
kCompactionStyleUniversal), kCompactionStyleUniversal),
LLONG_MAX, path_id, LLONG_MAX, path_id,
@ -944,8 +944,8 @@ Compaction* UniversalCompactionBuilder::PickDeleteTriggeredCompaction() {
uint32_t path_id = uint32_t path_id =
GetPathId(ioptions_, mutable_cf_options_, estimated_total_size); GetPathId(ioptions_, mutable_cf_options_, estimated_total_size);
return new Compaction( return new Compaction(
vstorage_, ioptions_, mutable_cf_options_, std::move(inputs), vstorage_, ioptions_, mutable_cf_options_, mutable_db_options_,
output_level, std::move(inputs), output_level,
MaxFileSizeForLevel(mutable_cf_options_, output_level, MaxFileSizeForLevel(mutable_cf_options_, output_level,
kCompactionStyleUniversal), kCompactionStyleUniversal),
/* max_grandparent_overlap_bytes */ LLONG_MAX, path_id, /* max_grandparent_overlap_bytes */ LLONG_MAX, path_id,
@ -1014,8 +1014,8 @@ Compaction* UniversalCompactionBuilder::PickCompactionToOldest(
// compaction_options_universal.compression_size_percent, // compaction_options_universal.compression_size_percent,
// because we always compact all the files, so always compress. // because we always compact all the files, so always compress.
return new Compaction( return new Compaction(
vstorage_, ioptions_, mutable_cf_options_, std::move(inputs), vstorage_, ioptions_, mutable_cf_options_, mutable_db_options_,
output_level, std::move(inputs), output_level,
MaxFileSizeForLevel(mutable_cf_options_, output_level, MaxFileSizeForLevel(mutable_cf_options_, output_level,
kCompactionStyleUniversal), kCompactionStyleUniversal),
LLONG_MAX, path_id, LLONG_MAX, path_id,

@ -20,7 +20,8 @@ class UniversalCompactionPicker : public CompactionPicker {
: CompactionPicker(ioptions, icmp) {} : CompactionPicker(ioptions, icmp) {}
virtual Compaction* PickCompaction( virtual Compaction* PickCompaction(
const std::string& cf_name, const MutableCFOptions& mutable_cf_options, const std::string& cf_name, const MutableCFOptions& mutable_cf_options,
VersionStorageInfo* vstorage, LogBuffer* log_buffer, const MutableDBOptions& mutable_db_options, VersionStorageInfo* vstorage,
LogBuffer* log_buffer,
SequenceNumber earliest_memtable_seqno = kMaxSequenceNumber) override; SequenceNumber earliest_memtable_seqno = kMaxSequenceNumber) override;
virtual int MaxOutputLevel() const override { return NumberLevels() - 1; } virtual int MaxOutputLevel() const override { return NumberLevels() - 1; }

@ -5279,6 +5279,108 @@ TEST_P(DBCompactionTestWithParam,
} }
} }
TEST_F(DBCompactionTest, UpdateLevelSubCompactionTest) {
Options options = CurrentOptions();
options.max_subcompactions = 10;
options.target_file_size_base = 1 << 10; // 1KB
DestroyAndReopen(options);
bool has_compaction = false;
ROCKSDB_NAMESPACE::SyncPoint::GetInstance()->SetCallBack(
"LevelCompactionPicker::PickCompaction:Return", [&](void* arg) {
Compaction* compaction = reinterpret_cast<Compaction*>(arg);
ASSERT_TRUE(compaction->max_subcompactions() == 10);
has_compaction = true;
});
ROCKSDB_NAMESPACE::SyncPoint::GetInstance()->EnableProcessing();
ASSERT_TRUE(dbfull()->GetDBOptions().max_subcompactions == 10);
// Trigger compaction
for (int i = 0; i < 32; i++) {
for (int j = 0; j < 5000; j++) {
Put(std::to_string(j), std::string(1, 'A'));
}
ASSERT_OK(Flush());
ASSERT_OK(dbfull()->TEST_WaitForFlushMemTable());
}
dbfull()->TEST_WaitForCompact();
ASSERT_TRUE(has_compaction);
has_compaction = false;
ASSERT_OK(dbfull()->SetDBOptions({{"max_subcompactions", "2"}}));
ASSERT_TRUE(dbfull()->GetDBOptions().max_subcompactions == 2);
ROCKSDB_NAMESPACE::SyncPoint::GetInstance()->SetCallBack(
"LevelCompactionPicker::PickCompaction:Return", [&](void* arg) {
Compaction* compaction = reinterpret_cast<Compaction*>(arg);
ASSERT_TRUE(compaction->max_subcompactions() == 2);
has_compaction = true;
});
ROCKSDB_NAMESPACE::SyncPoint::GetInstance()->EnableProcessing();
// Trigger compaction
for (int i = 0; i < 32; i++) {
for (int j = 0; j < 5000; j++) {
Put(std::to_string(j), std::string(1, 'A'));
}
ASSERT_OK(Flush());
ASSERT_OK(dbfull()->TEST_WaitForFlushMemTable());
}
dbfull()->TEST_WaitForCompact();
ASSERT_TRUE(has_compaction);
}
TEST_F(DBCompactionTest, UpdateUniversalSubCompactionTest) {
Options options = CurrentOptions();
options.max_subcompactions = 10;
options.compaction_style = kCompactionStyleUniversal;
options.target_file_size_base = 1 << 10; // 1KB
DestroyAndReopen(options);
bool has_compaction = false;
ROCKSDB_NAMESPACE::SyncPoint::GetInstance()->SetCallBack(
"UniversalCompactionBuilder::PickCompaction:Return", [&](void* arg) {
Compaction* compaction = reinterpret_cast<Compaction*>(arg);
ASSERT_TRUE(compaction->max_subcompactions() == 10);
has_compaction = true;
});
ROCKSDB_NAMESPACE::SyncPoint::GetInstance()->EnableProcessing();
// Trigger compaction
for (int i = 0; i < 32; i++) {
for (int j = 0; j < 5000; j++) {
Put(std::to_string(j), std::string(1, 'A'));
}
ASSERT_OK(Flush());
ASSERT_OK(dbfull()->TEST_WaitForFlushMemTable());
}
dbfull()->TEST_WaitForCompact();
ASSERT_TRUE(has_compaction);
has_compaction = false;
ASSERT_OK(dbfull()->SetDBOptions({{"max_subcompactions", "2"}}));
ASSERT_TRUE(dbfull()->GetDBOptions().max_subcompactions == 2);
ROCKSDB_NAMESPACE::SyncPoint::GetInstance()->SetCallBack(
"UniversalCompactionBuilder::PickCompaction:Return", [&](void* arg) {
Compaction* compaction = reinterpret_cast<Compaction*>(arg);
ASSERT_TRUE(compaction->max_subcompactions() == 2);
has_compaction = true;
});
ROCKSDB_NAMESPACE::SyncPoint::GetInstance()->EnableProcessing();
// Trigger compaction
for (int i = 0; i < 32; i++) {
for (int j = 0; j < 5000; j++) {
Put(std::to_string(j), std::string(1, 'A'));
}
ASSERT_OK(Flush());
ASSERT_OK(dbfull()->TEST_WaitForFlushMemTable());
}
dbfull()->TEST_WaitForCompact();
ASSERT_TRUE(has_compaction);
}
#endif // !defined(ROCKSDB_LITE) #endif // !defined(ROCKSDB_LITE)
} // namespace ROCKSDB_NAMESPACE } // namespace ROCKSDB_NAMESPACE

@ -1021,7 +1021,7 @@ Status DBImpl::CompactFilesImpl(
assert(cfd->compaction_picker()); assert(cfd->compaction_picker());
c.reset(cfd->compaction_picker()->CompactFiles( c.reset(cfd->compaction_picker()->CompactFiles(
compact_options, input_files, output_level, version->storage_info(), compact_options, input_files, output_level, version->storage_info(),
*cfd->GetLatestMutableCFOptions(), output_path_id)); *cfd->GetLatestMutableCFOptions(), mutable_db_options_, output_path_id));
// we already sanitized the set of input files and checked for conflicts // we already sanitized the set of input files and checked for conflicts
// without releasing the lock, so we're guaranteed a compaction can be formed. // without releasing the lock, so we're guaranteed a compaction can be formed.
assert(c != nullptr); assert(c != nullptr);
@ -1536,9 +1536,9 @@ Status DBImpl::RunManualCompaction(
scheduled || scheduled ||
(((manual.manual_end = &manual.tmp_storage1) != nullptr) && (((manual.manual_end = &manual.tmp_storage1) != nullptr) &&
((compaction = manual.cfd->CompactRange( ((compaction = manual.cfd->CompactRange(
*manual.cfd->GetLatestMutableCFOptions(), manual.input_level, *manual.cfd->GetLatestMutableCFOptions(), mutable_db_options_,
manual.output_level, compact_range_options, manual.begin, manual.input_level, manual.output_level, compact_range_options,
manual.end, &manual.manual_end, &manual_conflict, manual.begin, manual.end, &manual.manual_end, &manual_conflict,
max_file_num_to_ignore)) == nullptr && max_file_num_to_ignore)) == nullptr &&
manual_conflict))) { manual_conflict))) {
// exclusive manual compactions should not see a conflict during // exclusive manual compactions should not see a conflict during
@ -2642,7 +2642,8 @@ Status DBImpl::BackgroundCompaction(bool* made_progress,
// compaction is not necessary. Need to make sure mutex is held // compaction is not necessary. Need to make sure mutex is held
// until we make a copy in the following code // until we make a copy in the following code
TEST_SYNC_POINT("DBImpl::BackgroundCompaction():BeforePickCompaction"); TEST_SYNC_POINT("DBImpl::BackgroundCompaction():BeforePickCompaction");
c.reset(cfd->PickCompaction(*mutable_cf_options, log_buffer)); c.reset(cfd->PickCompaction(*mutable_cf_options, mutable_db_options_,
log_buffer));
TEST_SYNC_POINT("DBImpl::BackgroundCompaction():AfterPickCompaction"); TEST_SYNC_POINT("DBImpl::BackgroundCompaction():AfterPickCompaction");
if (c != nullptr) { if (c != nullptr) {

@ -558,6 +558,8 @@ struct DBOptions {
// concurrently perform a compaction job by breaking it into multiple, // concurrently perform a compaction job by breaking it into multiple,
// smaller ones that are run simultaneously. // smaller ones that are run simultaneously.
// Default: 1 (i.e. no subcompactions) // Default: 1 (i.e. no subcompactions)
//
// Dynamically changeable through SetDBOptions() API.
uint32_t max_subcompactions = 1; uint32_t max_subcompactions = 1;
// NOT SUPPORTED ANYMORE: RocksDB automatically decides this based on the // NOT SUPPORTED ANYMORE: RocksDB automatically decides this based on the

@ -759,7 +759,6 @@ ImmutableCFOptions::ImmutableCFOptions(const ImmutableDBOptions& db_options,
preserve_deletes(db_options.preserve_deletes), preserve_deletes(db_options.preserve_deletes),
listeners(db_options.listeners), listeners(db_options.listeners),
row_cache(db_options.row_cache), row_cache(db_options.row_cache),
max_subcompactions(db_options.max_subcompactions),
memtable_insert_with_hint_prefix_extractor( memtable_insert_with_hint_prefix_extractor(
cf_options.memtable_insert_with_hint_prefix_extractor.get()), cf_options.memtable_insert_with_hint_prefix_extractor.get()),
cf_paths(cf_options.cf_paths), cf_paths(cf_options.cf_paths),

@ -112,8 +112,6 @@ struct ImmutableCFOptions {
std::shared_ptr<Cache> row_cache; std::shared_ptr<Cache> row_cache;
uint32_t max_subcompactions;
const SliceTransform* memtable_insert_with_hint_prefix_extractor; const SliceTransform* memtable_insert_with_hint_prefix_extractor;
std::vector<DbPath> cf_paths; std::vector<DbPath> cf_paths;
@ -163,7 +161,8 @@ struct MutableCFOptions {
bottommost_compression(options.bottommost_compression), bottommost_compression(options.bottommost_compression),
compression_opts(options.compression_opts), compression_opts(options.compression_opts),
bottommost_compression_opts(options.bottommost_compression_opts), bottommost_compression_opts(options.bottommost_compression_opts),
sample_for_compression(options.sample_for_compression) { sample_for_compression(
options.sample_for_compression) { // TODO: is 0 fine here?
RefreshDerivedOptions(options.num_levels, options.compaction_style); RefreshDerivedOptions(options.num_levels, options.compaction_style);
} }

@ -149,6 +149,10 @@ std::unordered_map<std::string, OptionTypeInfo>
OptionType::kInt, OptionVerificationType::kNormal, OptionType::kInt, OptionVerificationType::kNormal,
OptionTypeFlags::kMutable, OptionTypeFlags::kMutable,
offsetof(struct MutableDBOptions, max_background_compactions)}}, offsetof(struct MutableDBOptions, max_background_compactions)}},
{"max_subcompactions",
{offsetof(struct DBOptions, max_subcompactions), OptionType::kUInt32T,
OptionVerificationType::kNormal, OptionTypeFlags::kMutable,
offsetof(struct MutableDBOptions, max_subcompactions)}},
{"base_background_compactions", {"base_background_compactions",
{offsetof(struct DBOptions, base_background_compactions), {offsetof(struct DBOptions, base_background_compactions),
OptionType::kInt, OptionVerificationType::kNormal, OptionType::kInt, OptionVerificationType::kNormal,
@ -195,9 +199,6 @@ std::unordered_map<std::string, OptionTypeInfo>
{"wal_dir", {"wal_dir",
{offsetof(struct DBOptions, wal_dir), OptionType::kString, {offsetof(struct DBOptions, wal_dir), OptionType::kString,
OptionVerificationType::kNormal, OptionTypeFlags::kNone, 0}}, OptionVerificationType::kNormal, OptionTypeFlags::kNone, 0}},
{"max_subcompactions",
{offsetof(struct DBOptions, max_subcompactions), OptionType::kUInt32T,
OptionVerificationType::kNormal, OptionTypeFlags::kNone, 0}},
{"WAL_size_limit_MB", {"WAL_size_limit_MB",
{offsetof(struct DBOptions, WAL_size_limit_MB), OptionType::kUInt64T, {offsetof(struct DBOptions, WAL_size_limit_MB), OptionType::kUInt64T,
OptionVerificationType::kNormal, OptionTypeFlags::kNone, 0}}, OptionVerificationType::kNormal, OptionTypeFlags::kNone, 0}},
@ -415,7 +416,6 @@ ImmutableDBOptions::ImmutableDBOptions(const DBOptions& options)
db_paths(options.db_paths), db_paths(options.db_paths),
db_log_dir(options.db_log_dir), db_log_dir(options.db_log_dir),
wal_dir(options.wal_dir), wal_dir(options.wal_dir),
max_subcompactions(options.max_subcompactions),
max_log_file_size(options.max_log_file_size), max_log_file_size(options.max_log_file_size),
log_file_time_to_roll(options.log_file_time_to_roll), log_file_time_to_roll(options.log_file_time_to_roll),
keep_log_file_num(options.keep_log_file_num), keep_log_file_num(options.keep_log_file_num),
@ -532,9 +532,6 @@ void ImmutableDBOptions::Dump(Logger* log) const {
wal_dir.c_str()); wal_dir.c_str());
ROCKS_LOG_HEADER(log, " Options.table_cache_numshardbits: %d", ROCKS_LOG_HEADER(log, " Options.table_cache_numshardbits: %d",
table_cache_numshardbits); table_cache_numshardbits);
ROCKS_LOG_HEADER(log,
" Options.max_subcompactions: %" PRIu32,
max_subcompactions);
ROCKS_LOG_HEADER(log, ROCKS_LOG_HEADER(log,
" Options.WAL_ttl_seconds: %" PRIu64, " Options.WAL_ttl_seconds: %" PRIu64,
wal_ttl_seconds); wal_ttl_seconds);
@ -640,6 +637,7 @@ MutableDBOptions::MutableDBOptions()
: max_background_jobs(2), : max_background_jobs(2),
base_background_compactions(-1), base_background_compactions(-1),
max_background_compactions(-1), max_background_compactions(-1),
max_subcompactions(0),
avoid_flush_during_shutdown(false), avoid_flush_during_shutdown(false),
writable_file_max_buffer_size(1024 * 1024), writable_file_max_buffer_size(1024 * 1024),
delayed_write_rate(2 * 1024U * 1024U), delayed_write_rate(2 * 1024U * 1024U),
@ -659,6 +657,7 @@ MutableDBOptions::MutableDBOptions(const DBOptions& options)
: max_background_jobs(options.max_background_jobs), : max_background_jobs(options.max_background_jobs),
base_background_compactions(options.base_background_compactions), base_background_compactions(options.base_background_compactions),
max_background_compactions(options.max_background_compactions), max_background_compactions(options.max_background_compactions),
max_subcompactions(options.max_subcompactions),
avoid_flush_during_shutdown(options.avoid_flush_during_shutdown), avoid_flush_during_shutdown(options.avoid_flush_during_shutdown),
writable_file_max_buffer_size(options.writable_file_max_buffer_size), writable_file_max_buffer_size(options.writable_file_max_buffer_size),
delayed_write_rate(options.delayed_write_rate), delayed_write_rate(options.delayed_write_rate),
@ -680,6 +679,8 @@ void MutableDBOptions::Dump(Logger* log) const {
max_background_jobs); max_background_jobs);
ROCKS_LOG_HEADER(log, " Options.max_background_compactions: %d", ROCKS_LOG_HEADER(log, " Options.max_background_compactions: %d",
max_background_compactions); max_background_compactions);
ROCKS_LOG_HEADER(log, " Options.max_subcompactions: %" PRIu32,
max_subcompactions);
ROCKS_LOG_HEADER(log, " Options.avoid_flush_during_shutdown: %d", ROCKS_LOG_HEADER(log, " Options.avoid_flush_during_shutdown: %d",
avoid_flush_during_shutdown); avoid_flush_during_shutdown);
ROCKS_LOG_HEADER( ROCKS_LOG_HEADER(

@ -34,7 +34,6 @@ struct ImmutableDBOptions {
std::vector<DbPath> db_paths; std::vector<DbPath> db_paths;
std::string db_log_dir; std::string db_log_dir;
std::string wal_dir; std::string wal_dir;
uint32_t max_subcompactions;
size_t max_log_file_size; size_t max_log_file_size;
size_t log_file_time_to_roll; size_t log_file_time_to_roll;
size_t keep_log_file_num; size_t keep_log_file_num;
@ -102,6 +101,7 @@ struct MutableDBOptions {
int max_background_jobs; int max_background_jobs;
int base_background_compactions; int base_background_compactions;
int max_background_compactions; int max_background_compactions;
uint32_t max_subcompactions;
bool avoid_flush_during_shutdown; bool avoid_flush_during_shutdown;
size_t writable_file_max_buffer_size; size_t writable_file_max_buffer_size;
uint64_t delayed_write_rate; uint64_t delayed_write_rate;

@ -61,7 +61,7 @@ DBOptions BuildDBOptions(const ImmutableDBOptions& immutable_db_options,
options.bytes_per_sync = mutable_db_options.bytes_per_sync; options.bytes_per_sync = mutable_db_options.bytes_per_sync;
options.wal_bytes_per_sync = mutable_db_options.wal_bytes_per_sync; options.wal_bytes_per_sync = mutable_db_options.wal_bytes_per_sync;
options.strict_bytes_per_sync = mutable_db_options.strict_bytes_per_sync; options.strict_bytes_per_sync = mutable_db_options.strict_bytes_per_sync;
options.max_subcompactions = immutable_db_options.max_subcompactions; options.max_subcompactions = mutable_db_options.max_subcompactions;
options.max_background_flushes = mutable_db_options.max_background_flushes; options.max_background_flushes = mutable_db_options.max_background_flushes;
options.max_log_file_size = immutable_db_options.max_log_file_size; options.max_log_file_size = immutable_db_options.max_log_file_size;
options.log_file_time_to_roll = immutable_db_options.log_file_time_to_roll; options.log_file_time_to_roll = immutable_db_options.log_file_time_to_roll;

Loading…
Cancel
Save