2011-03-18 22:37:00 +00:00
|
|
|
// Copyright (c) 2011 The LevelDB Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file. See the AUTHORS file for names of contributors.
|
|
|
|
|
2011-03-30 18:35:40 +00:00
|
|
|
#include "leveldb/options.h"
|
2011-03-18 22:37:00 +00:00
|
|
|
|
2013-01-11 01:18:50 +00:00
|
|
|
#include <limits>
|
|
|
|
|
2013-03-21 22:59:47 +00:00
|
|
|
#include "leveldb/cache.h"
|
2013-05-12 09:36:59 +00:00
|
|
|
#include "leveldb/compaction_filter.h"
|
2011-03-30 18:35:40 +00:00
|
|
|
#include "leveldb/comparator.h"
|
|
|
|
#include "leveldb/env.h"
|
2012-08-22 18:43:53 +00:00
|
|
|
#include "leveldb/filter_policy.h"
|
2013-03-21 22:59:47 +00:00
|
|
|
#include "leveldb/merge_operator.h"
|
2011-03-18 22:37:00 +00:00
|
|
|
|
|
|
|
namespace leveldb {
|
|
|
|
|
|
|
|
Options::Options()
|
|
|
|
: comparator(BytewiseComparator()),
|
2013-03-21 22:59:47 +00:00
|
|
|
merge_operator(nullptr),
|
2013-05-12 09:36:59 +00:00
|
|
|
compaction_filter(nullptr),
|
2011-03-18 22:37:00 +00:00
|
|
|
create_if_missing(false),
|
|
|
|
error_if_exists(false),
|
|
|
|
paranoid_checks(false),
|
|
|
|
env(Env::Default()),
|
2013-03-01 02:04:58 +00:00
|
|
|
info_log(nullptr),
|
2011-04-12 19:38:58 +00:00
|
|
|
write_buffer_size(4<<20),
|
2012-10-19 21:00:53 +00:00
|
|
|
max_write_buffer_number(2),
|
2011-03-18 22:37:00 +00:00
|
|
|
max_open_files(1000),
|
2011-04-12 19:38:58 +00:00
|
|
|
block_size(4096),
|
2011-03-18 22:37:00 +00:00
|
|
|
block_restart_interval(16),
|
2012-04-17 15:36:46 +00:00
|
|
|
compression(kSnappyCompression),
|
2013-03-01 02:04:58 +00:00
|
|
|
filter_policy(nullptr),
|
2012-06-23 02:30:03 +00:00
|
|
|
num_levels(7),
|
|
|
|
level0_file_num_compaction_trigger(4),
|
|
|
|
level0_slowdown_writes_trigger(8),
|
|
|
|
level0_stop_writes_trigger(12),
|
|
|
|
max_mem_compaction_level(2),
|
|
|
|
target_file_size_base(2 * 1048576),
|
2012-08-22 00:33:46 +00:00
|
|
|
target_file_size_multiplier(1),
|
2012-07-03 00:30:32 +00:00
|
|
|
max_bytes_for_level_base(10 * 1048576),
|
2012-06-23 02:30:03 +00:00
|
|
|
max_bytes_for_level_multiplier(10),
|
2013-05-21 18:37:06 +00:00
|
|
|
max_bytes_for_level_multiplier_additional(num_levels, 1),
|
2012-06-23 02:30:03 +00:00
|
|
|
expanded_compaction_factor(25),
|
2012-11-21 07:07:41 +00:00
|
|
|
source_compaction_factor(1),
|
2012-06-23 02:30:03 +00:00
|
|
|
max_grandparent_overlap_factor(10),
|
2012-08-14 22:20:36 +00:00
|
|
|
disableDataSync(false),
|
2012-08-27 19:10:26 +00:00
|
|
|
use_fsync(false),
|
2012-09-06 00:44:13 +00:00
|
|
|
db_stats_log_interval(1800),
|
2012-09-17 20:35:57 +00:00
|
|
|
db_log_dir(""),
|
2012-10-16 15:53:46 +00:00
|
|
|
disable_seek_compaction(false),
|
2012-10-26 20:37:21 +00:00
|
|
|
delete_obsolete_files_period_micros(0),
|
2012-11-06 00:51:55 +00:00
|
|
|
max_background_compactions(1),
|
2012-10-29 21:18:00 +00:00
|
|
|
max_log_file_size(0),
|
2013-02-05 03:42:40 +00:00
|
|
|
log_file_time_to_roll(0),
|
|
|
|
keep_log_file_num(1000),
|
2012-11-12 06:33:22 +00:00
|
|
|
rate_limit(0.0),
|
2013-03-02 20:56:04 +00:00
|
|
|
rate_limit_delay_milliseconds(1000),
|
2013-01-11 01:18:50 +00:00
|
|
|
max_manifest_file_size(std::numeric_limits<uint64_t>::max()),
|
2012-11-06 20:02:18 +00:00
|
|
|
no_block_cache(false),
|
|
|
|
table_cache_numshardbits(4),
|
2012-11-26 21:56:45 +00:00
|
|
|
disable_auto_compactions(false),
|
2013-01-15 22:05:42 +00:00
|
|
|
WAL_ttl_seconds(0),
|
2013-02-28 22:09:30 +00:00
|
|
|
manifest_preallocation_size(4 * 1024 * 1024),
|
2013-03-15 00:00:04 +00:00
|
|
|
purge_redundant_kvs_while_flush(true),
|
|
|
|
allow_os_buffer(true),
|
|
|
|
allow_readahead(true),
|
|
|
|
allow_readahead_compactions(true),
|
|
|
|
allow_mmap_reads(false),
|
2013-04-10 02:42:07 +00:00
|
|
|
allow_mmap_writes(true),
|
2013-05-21 18:53:33 +00:00
|
|
|
is_fd_close_on_exec(true),
|
|
|
|
skip_log_error_on_recovery(false) {
|
2011-03-18 22:37:00 +00:00
|
|
|
}
|
|
|
|
|
2012-08-22 18:43:53 +00:00
|
|
|
void
|
2013-01-20 10:07:13 +00:00
|
|
|
Options::Dump(Logger* log) const
|
2012-08-22 18:43:53 +00:00
|
|
|
{
|
2012-10-19 21:00:53 +00:00
|
|
|
Log(log," Options.comparator: %s", comparator->Name());
|
2013-03-21 22:59:47 +00:00
|
|
|
Log(log," Options.merge_operator: %s",
|
|
|
|
merge_operator? merge_operator->Name() : "None");
|
2013-05-12 09:36:59 +00:00
|
|
|
Log(log," Options.compaction_filter: %s",
|
|
|
|
compaction_filter? compaction_filter->Name() : "None");
|
2012-10-19 21:00:53 +00:00
|
|
|
Log(log," Options.error_if_exists: %d", error_if_exists);
|
|
|
|
Log(log," Options.paranoid_checks: %d", paranoid_checks);
|
|
|
|
Log(log," Options.env: %p", env);
|
2013-01-20 10:07:13 +00:00
|
|
|
Log(log," Options.info_log: %p", info_log.get());
|
2012-10-19 21:00:53 +00:00
|
|
|
Log(log," Options.write_buffer_size: %zd", write_buffer_size);
|
2012-11-07 23:11:37 +00:00
|
|
|
Log(log," Options.max_write_buffer_number: %d", max_write_buffer_number);
|
2012-10-19 21:00:53 +00:00
|
|
|
Log(log," Options.max_open_files: %d", max_open_files);
|
2013-01-20 10:07:13 +00:00
|
|
|
Log(log," Options.block_cache: %p", block_cache.get());
|
2012-11-01 00:02:24 +00:00
|
|
|
if (block_cache) {
|
|
|
|
Log(log," Options.block_cache_size: %zd",
|
|
|
|
block_cache->GetCapacity());
|
|
|
|
}
|
2012-10-19 21:00:53 +00:00
|
|
|
Log(log," Options.block_size: %zd", block_size);
|
|
|
|
Log(log," Options.block_restart_interval: %d", block_restart_interval);
|
2013-01-24 18:54:26 +00:00
|
|
|
if (!compression_per_level.empty()) {
|
2013-03-15 01:32:01 +00:00
|
|
|
for (unsigned int i = 0; i < compression_per_level.size(); i++) {
|
2012-11-01 17:50:08 +00:00
|
|
|
Log(log," Options.compression[%d]: %d",
|
2012-10-28 06:13:17 +00:00
|
|
|
i, compression_per_level[i]);
|
|
|
|
}
|
|
|
|
} else {
|
2012-10-29 21:18:00 +00:00
|
|
|
Log(log," Options.compression: %d", compression);
|
2012-10-28 06:13:17 +00:00
|
|
|
}
|
2012-08-27 19:10:26 +00:00
|
|
|
Log(log," Options.filter_policy: %s",
|
2013-03-01 02:04:58 +00:00
|
|
|
filter_policy == nullptr ? "nullptr" : filter_policy->Name());
|
2012-08-27 19:10:26 +00:00
|
|
|
Log(log," Options.num_levels: %d", num_levels);
|
|
|
|
Log(log," Options.disableDataSync: %d", disableDataSync);
|
|
|
|
Log(log," Options.use_fsync: %d", use_fsync);
|
2012-11-06 20:02:18 +00:00
|
|
|
Log(log," Options.max_log_file_size: %ld", max_log_file_size);
|
2013-01-11 01:18:50 +00:00
|
|
|
Log(log,"Options.max_manifest_file_size: %ld",
|
|
|
|
max_manifest_file_size);
|
2013-02-05 03:42:40 +00:00
|
|
|
Log(log," Options.log_file_time_to_roll: %ld", log_file_time_to_roll);
|
|
|
|
Log(log," Options.keep_log_file_num: %ld", keep_log_file_num);
|
2012-10-26 21:55:02 +00:00
|
|
|
Log(log," Options.db_stats_log_interval: %d",
|
2012-08-27 19:10:26 +00:00
|
|
|
db_stats_log_interval);
|
2013-03-15 00:00:04 +00:00
|
|
|
Log(log," Options.allow_os_buffer: %d", allow_os_buffer);
|
|
|
|
Log(log," Options.allow_readahead: %d", allow_readahead);
|
|
|
|
Log(log," Options.allow_mmap_reads: %d", allow_mmap_reads);
|
|
|
|
Log(log," Options.allow_mmap_writes: %d", allow_mmap_writes);
|
|
|
|
Log(log," Options.allow_readahead_compactions: %d",
|
|
|
|
allow_readahead_compactions);
|
2013-02-28 22:09:30 +00:00
|
|
|
Log(log," Options.purge_redundant_kvs_while_flush: %d",
|
|
|
|
purge_redundant_kvs_while_flush);
|
2012-11-01 17:50:08 +00:00
|
|
|
Log(log," Options.compression_opts.window_bits: %d",
|
|
|
|
compression_opts.window_bits);
|
|
|
|
Log(log," Options.compression_opts.level: %d",
|
|
|
|
compression_opts.level);
|
|
|
|
Log(log," Options.compression_opts.strategy: %d",
|
|
|
|
compression_opts.strategy);
|
2012-08-27 19:10:26 +00:00
|
|
|
Log(log," Options.level0_file_num_compaction_trigger: %d",
|
|
|
|
level0_file_num_compaction_trigger);
|
|
|
|
Log(log," Options.level0_slowdown_writes_trigger: %d",
|
|
|
|
level0_slowdown_writes_trigger);
|
|
|
|
Log(log," Options.level0_stop_writes_trigger: %d",
|
|
|
|
level0_stop_writes_trigger);
|
|
|
|
Log(log," Options.max_mem_compaction_level: %d",
|
|
|
|
max_mem_compaction_level);
|
|
|
|
Log(log," Options.target_file_size_base: %d",
|
|
|
|
target_file_size_base);
|
|
|
|
Log(log," Options.target_file_size_multiplier: %d",
|
|
|
|
target_file_size_multiplier);
|
2012-11-09 02:45:19 +00:00
|
|
|
Log(log," Options.max_bytes_for_level_base: %ld",
|
2012-08-27 19:10:26 +00:00
|
|
|
max_bytes_for_level_base);
|
|
|
|
Log(log," Options.max_bytes_for_level_multiplier: %d",
|
|
|
|
max_bytes_for_level_multiplier);
|
2013-05-21 18:37:06 +00:00
|
|
|
for (int i = 0; i < num_levels; i++) {
|
|
|
|
Log(log,"Options.max_bytes_for_level_multiplier_addtl[%d]: %d",
|
|
|
|
i, max_bytes_for_level_multiplier_additional[i]);
|
|
|
|
}
|
2012-08-27 19:10:26 +00:00
|
|
|
Log(log," Options.expanded_compaction_factor: %d",
|
|
|
|
expanded_compaction_factor);
|
2012-11-21 07:07:41 +00:00
|
|
|
Log(log," Options.source_compaction_factor: %d",
|
|
|
|
source_compaction_factor);
|
2012-08-27 19:10:26 +00:00
|
|
|
Log(log," Options.max_grandparent_overlap_factor: %d",
|
|
|
|
max_grandparent_overlap_factor);
|
2012-10-19 21:00:53 +00:00
|
|
|
Log(log," Options.db_log_dir: %s",
|
2012-09-06 00:44:13 +00:00
|
|
|
db_log_dir.c_str());
|
2012-10-19 21:00:53 +00:00
|
|
|
Log(log," Options.disable_seek_compaction: %d",
|
2012-09-17 20:35:57 +00:00
|
|
|
disable_seek_compaction);
|
2012-11-01 00:02:24 +00:00
|
|
|
Log(log," Options.no_block_cache: %d",
|
|
|
|
no_block_cache);
|
|
|
|
Log(log," Options.table_cache_numshardbits: %d",
|
2012-11-29 00:42:36 +00:00
|
|
|
table_cache_numshardbits);
|
2012-10-19 19:16:18 +00:00
|
|
|
Log(log," Options.delete_obsolete_files_period_micros: %ld",
|
|
|
|
delete_obsolete_files_period_micros);
|
2012-10-19 21:00:53 +00:00
|
|
|
Log(log," Options.max_background_compactions: %d",
|
|
|
|
max_background_compactions);
|
2012-10-26 20:37:21 +00:00
|
|
|
Log(log," Options.rate_limit: %.2f",
|
|
|
|
rate_limit);
|
2013-03-02 20:56:04 +00:00
|
|
|
Log(log," Options.rate_limit_delay_milliseconds: %d",
|
|
|
|
rate_limit_delay_milliseconds);
|
2012-11-20 23:45:41 +00:00
|
|
|
Log(log," Options.disable_auto_compactions: %d",
|
|
|
|
disable_auto_compactions);
|
2013-01-15 22:05:42 +00:00
|
|
|
Log(log," Options.WAL_ttl_seconds: %ld",
|
2012-11-26 21:56:45 +00:00
|
|
|
WAL_ttl_seconds);
|
2013-01-15 22:05:42 +00:00
|
|
|
Log(log," Options.manifest_preallocation_size: %ld",
|
|
|
|
manifest_preallocation_size);
|
2013-04-10 02:42:07 +00:00
|
|
|
Log(log," Options.purge_redundant_kvs_while_flush: %d",
|
|
|
|
purge_redundant_kvs_while_flush);
|
|
|
|
Log(log," Options.allow_os_buffer: %d",
|
|
|
|
allow_os_buffer);
|
|
|
|
Log(log," Options.allow_readahead: %d",
|
|
|
|
allow_readahead);
|
|
|
|
Log(log," Options.allow_readahead_compactions: %d",
|
|
|
|
allow_readahead_compactions);
|
|
|
|
Log(log," Options.allow_mmap_reads: %d",
|
|
|
|
allow_mmap_reads);
|
|
|
|
Log(log," Options.allow_mmap_writes: %d",
|
|
|
|
allow_mmap_writes);
|
|
|
|
Log(log," Options.is_fd_close_on_exec: %d",
|
|
|
|
is_fd_close_on_exec);
|
2013-05-21 18:53:33 +00:00
|
|
|
Log(log," Options.skip_log_error_on_recovery: %d",
|
|
|
|
skip_log_error_on_recovery);
|
2012-08-22 18:43:53 +00:00
|
|
|
} // Options::Dump
|
|
|
|
|
2013-03-08 17:19:24 +00:00
|
|
|
//
|
|
|
|
// The goal of this method is to create a configuration that
|
|
|
|
// allows an application to write all files into L0 and
|
|
|
|
// then do a single compaction to output all files into L1.
|
2013-02-26 06:57:37 +00:00
|
|
|
Options*
|
|
|
|
Options::PrepareForBulkLoad()
|
|
|
|
{
|
2013-03-08 17:19:24 +00:00
|
|
|
// never slowdown ingest.
|
2013-02-26 06:57:37 +00:00
|
|
|
level0_file_num_compaction_trigger = (1<<30);
|
|
|
|
level0_slowdown_writes_trigger = (1<<30);
|
|
|
|
level0_stop_writes_trigger = (1<<30);
|
2013-03-08 17:19:24 +00:00
|
|
|
|
|
|
|
// no auto compactions please. The application should issue a
|
|
|
|
// manual compaction after all data is loaded into L0.
|
2013-02-26 06:57:37 +00:00
|
|
|
disable_auto_compactions = true;
|
|
|
|
disable_seek_compaction = true;
|
|
|
|
disableDataSync = true;
|
2013-03-08 17:19:24 +00:00
|
|
|
|
|
|
|
// A manual compaction run should pick all files in L0 in
|
|
|
|
// a single compaction run.
|
2013-02-26 06:57:37 +00:00
|
|
|
source_compaction_factor = (1<<30);
|
|
|
|
|
2013-03-08 17:19:24 +00:00
|
|
|
// It is better to have only 2 levels, otherwise a manual
|
|
|
|
// compaction would compact at every possible level, thereby
|
|
|
|
// increasing the total time needed for compactions.
|
|
|
|
num_levels = 2;
|
|
|
|
|
|
|
|
// Prevent a memtable flush to automatically promote files
|
|
|
|
// to L1. This is helpful so that all files that are
|
|
|
|
// input to the manual compaction are all at L0.
|
|
|
|
max_background_compactions = 2;
|
|
|
|
|
|
|
|
// The compaction would create large files in L1.
|
|
|
|
target_file_size_base = 256 * 1024 * 1024;
|
2013-02-26 06:57:37 +00:00
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
2011-10-31 17:22:06 +00:00
|
|
|
} // namespace leveldb
|