Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

restore the default behavior to 8M Block Cache per CF #361

Merged
merged 1 commit into from
Sep 21, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions conf/pika.conf
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ write-binlog : yes
binlog-file-size : 104857600
# When it becomes slave, the type of binlog it receives from the master
# if this option is set to 'new', that means I will be a slave to Pika who's version 3.0
# if this opsion is set to 'old', that means I will be a slave to Pika who's version 2.3.3 ~ 2.3.5
# if this opsion is set to 'old', that means I will be a slave to Pika who's version 2.3.3 ~ 2.3.6
# identify-binlog-type [new | old]
identify-binlog-type : new
# Compression
Expand All @@ -105,8 +105,10 @@ max-cache-files : 5000
max-bytes-for-level-multiplier : 10
# BlockBasedTable block_size, default 4k
# block-size: 4096
# block LRU cache, default 8M
# block LRU cache, default 8M, 0 to disable
# block-cache: 8388608
# whether the block cache is shared among the RocksDB instances, default is per CF
# share-block-cache: no
# whether or not index and filter blocks is stored in block cache
# cache-index-and-filter-blocks: no
# when set to yes, bloomfilter of the last level will not be built
Expand Down
2 changes: 2 additions & 0 deletions include/pika_conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ class PikaConf : public slash::BaseConf {
int max_bytes_for_level_multiplier() {RWLock l(&rwlock_, false); return max_bytes_for_level_multiplier_; }
int block_size() {RWLock l(&rwlock_, false); return block_size_; }
int block_cache() {RWLock l(&rwlock_, false); return block_cache_; }
bool share_block_cache() {RWLock l(&rwlock_, false); return share_block_cache_; }
bool cache_index_and_filter_blocks() {RWLock l(&rwlock_, false); return cache_index_and_filter_blocks_; }
bool optimize_filters_for_hits() {RWLock l(&rwlock_, false); return optimize_filters_for_hits_; }
bool level_compaction_dynamic_level_bytes() {RWLock l(&rwlock_, false); return level_compaction_dynamic_level_bytes_; }
Expand Down Expand Up @@ -239,6 +240,7 @@ class PikaConf : public slash::BaseConf {
int max_bytes_for_level_multiplier_;
int block_size_;
int block_cache_;
bool share_block_cache_;
bool cache_index_and_filter_blocks_;
bool optimize_filters_for_hits_;
bool level_compaction_dynamic_level_bytes_;
Expand Down
3 changes: 1 addition & 2 deletions include/pika_server.h
Original file line number Diff line number Diff line change
Expand Up @@ -197,8 +197,7 @@ class PikaServer {
/*
* Blackwidow options init
*/
void RocksdbOptionInit(rocksdb::Options* option);
void RocksdbTableOptionInit(rocksdb::BlockBasedTableOptions* table_option);
void RocksdbOptionInit(blackwidow::BlackwidowOptions* bw_option);

/*
* Binlog
Expand Down
8 changes: 7 additions & 1 deletion src/pika_admin.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1084,6 +1084,10 @@ void ConfigCmd::ConfigGet(std::string &ret) {
ret = "*2\r\n";
EncodeString(&ret, "block-cache");
EncodeInt32(&ret, g_pika_conf->block_cache());
} else if (get_item == "share-block-cache") {
ret = "*2\r\n";
EncodeString(&ret, "share-block-cache");
EncodeString(&ret, g_pika_conf->share_block_cache() ? "yes" : "no");
} else if (get_item == "cache-index-and-filter-blocks") {
ret = "*2\r\n";
EncodeString(&ret, "cache-index-and-filter-blocks");
Expand Down Expand Up @@ -1153,7 +1157,7 @@ void ConfigCmd::ConfigGet(std::string &ret) {
EncodeString(&ret, "slave-priority");
EncodeInt32(&ret, g_pika_conf->slave_priority());
} else if (get_item == "*") {
ret = "*102\r\n";
ret = "*104\r\n";
EncodeString(&ret, "port");
EncodeInt32(&ret, g_pika_conf->port());
EncodeString(&ret, "double-master-ip");
Expand Down Expand Up @@ -1214,6 +1218,8 @@ void ConfigCmd::ConfigGet(std::string &ret) {
EncodeInt32(&ret, g_pika_conf->block_size());
EncodeString(&ret, "block-cache");
EncodeInt32(&ret, g_pika_conf->block_cache());
EncodeString(&ret, "share-block-cache");
EncodeString(&ret, g_pika_conf->share_block_cache() ? "yes" : "no");
EncodeString(&ret, "cache-index-and-filter-blocks");
EncodeString(&ret, g_pika_conf->cache_index_and_filter_blocks() ? "yes" : "no");
EncodeString(&ret, "optimize-filters-for-hits");
Expand Down
7 changes: 6 additions & 1 deletion src/pika_conf.cc
Original file line number Diff line number Diff line change
Expand Up @@ -211,10 +211,14 @@ int PikaConf::Load()

block_cache_ = 8 * 1024 * 1024;
GetConfInt("block-cache", &block_cache_);
if (block_cache_ <= 0) {
if (block_cache_ < 0) {
block_cache_ = 8 * 1024 * 1024;
}

std::string sbc;
GetConfStr("share-block-cache", &sbc);
share_block_cache_ = (sbc == "yes") ? true : false;

std::string ciafb;
GetConfStr("cache-index-and-filter-blocks", &ciafb);
cache_index_and_filter_blocks_ = (ciafb == "yes") ? true : false;
Expand Down Expand Up @@ -318,6 +322,7 @@ int PikaConf::ConfigRewrite() {
SetConfInt("max-bytes-for-level-multiplier", max_bytes_for_level_multiplier_);
SetConfInt("block-size", block_size_);
SetConfInt("block-cache", block_cache_);
SetConfStr("share-block-cache", share_block_cache_ ? "yes" : "no");
SetConfStr("cache-index-and-filter-blocks", cache_index_and_filter_blocks_ ? "yes" : "no");
SetConfStr("optimize-filters-for-hits", optimize_filters_for_hits_ ? "yes" : "no");
SetConfStr("level-compaction-dynamic-level-bytes", level_compaction_dynamic_level_bytes_ ? "yes" : "no");
Expand Down
76 changes: 33 additions & 43 deletions src/pika_server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,13 @@ PikaServer::PikaServer() :
}

//Create blackwidow handle
rocksdb::Options rocksdb_option;
rocksdb::BlockBasedTableOptions rocksdb_table_option;
RocksdbOptionInit(&rocksdb_option);
RocksdbTableOptionInit(&rocksdb_table_option);
blackwidow::BlackwidowOptions bw_option;
RocksdbOptionInit(&bw_option);

std::string db_path = g_pika_conf->db_path();
LOG(INFO) << "Prepare Blackwidow DB...";
db_ = std::shared_ptr<blackwidow::BlackWidow>(new blackwidow::BlackWidow());
rocksdb::Status s = db_->Open(rocksdb_option, rocksdb_table_option, db_path);
rocksdb::Status s = db_->Open(bw_option, db_path);
assert(db_);
assert(s.ok());
LOG(INFO) << "DB Success";
Expand Down Expand Up @@ -239,35 +237,33 @@ bool PikaServer::ServerInit() {

}

void PikaServer::RocksdbTableOptionInit(rocksdb::BlockBasedTableOptions* table_option) {
table_option->block_size = g_pika_conf->block_size();
table_option->block_cache = rocksdb::NewLRUCache(g_pika_conf->block_cache());
table_option->cache_index_and_filter_blocks = g_pika_conf->cache_index_and_filter_blocks();
}

void PikaServer::RocksdbOptionInit(blackwidow::BlackwidowOptions* bw_option) {
bw_option->options.create_if_missing = true;
bw_option->options.keep_log_file_num = 10;
bw_option->options.max_manifest_file_size = 64 * 1024 * 1024;
bw_option->options.max_log_file_size = 512 * 1024 * 1024;

void PikaServer::RocksdbOptionInit(rocksdb::Options* option) {
option->create_if_missing = true;
option->keep_log_file_num = 10;
option->max_manifest_file_size = 64 * 1024 * 1024;
option->max_log_file_size = 512 * 1024 * 1024;

option->write_buffer_size = g_pika_conf->write_buffer_size();
option->target_file_size_base = g_pika_conf->target_file_size_base();
option->max_background_flushes = g_pika_conf->max_background_flushes();
option->max_background_compactions = g_pika_conf->max_background_compactions();
option->max_open_files = g_pika_conf->max_cache_files();
option->max_bytes_for_level_multiplier = g_pika_conf->max_bytes_for_level_multiplier();
option->optimize_filters_for_hits = g_pika_conf->optimize_filters_for_hits();
option->level_compaction_dynamic_level_bytes = g_pika_conf->level_compaction_dynamic_level_bytes();
bw_option->options.write_buffer_size = g_pika_conf->write_buffer_size();
bw_option->options.target_file_size_base = g_pika_conf->target_file_size_base();
bw_option->options.max_background_flushes = g_pika_conf->max_background_flushes();
bw_option->options.max_background_compactions = g_pika_conf->max_background_compactions();
bw_option->options.max_open_files = g_pika_conf->max_cache_files();
bw_option->options.max_bytes_for_level_multiplier = g_pika_conf->max_bytes_for_level_multiplier();
bw_option->options.optimize_filters_for_hits = g_pika_conf->optimize_filters_for_hits();
bw_option->options.level_compaction_dynamic_level_bytes = g_pika_conf->level_compaction_dynamic_level_bytes();

if (g_pika_conf->compression() == "none") {
option->compression = rocksdb::CompressionType::kNoCompression;
bw_option->options.compression = rocksdb::CompressionType::kNoCompression;
} else if (g_pika_conf->compression() == "snappy") {
option->compression = rocksdb::CompressionType::kSnappyCompression;
bw_option->options.compression = rocksdb::CompressionType::kSnappyCompression;
} else if (g_pika_conf->compression() == "zlib") {
option->compression = rocksdb::CompressionType::kZlibCompression;
bw_option->options.compression = rocksdb::CompressionType::kZlibCompression;
}

bw_option->table_options.block_size = g_pika_conf->block_size();
bw_option->table_options.cache_index_and_filter_blocks = g_pika_conf->cache_index_and_filter_blocks();
bw_option->block_cache_size = g_pika_conf->block_cache();
bw_option->share_block_cache = g_pika_conf->share_block_cache();
}

void PikaServer::Start() {
Expand Down Expand Up @@ -413,10 +409,8 @@ void PikaServer::DeleteSlave(int fd) {
*/
bool PikaServer::ChangeDb(const std::string& new_path) {

rocksdb::Options rocksdb_option;
rocksdb::BlockBasedTableOptions rocksdb_table_option;
RocksdbOptionInit(&rocksdb_option);
RocksdbTableOptionInit(&rocksdb_table_option);
blackwidow::BlackwidowOptions bw_option;
RocksdbOptionInit(&bw_option);

std::string db_path = g_pika_conf->db_path();
std::string tmp_path(db_path);
Expand All @@ -440,7 +434,7 @@ bool PikaServer::ChangeDb(const std::string& new_path) {
}

db_.reset(new blackwidow::BlackWidow());
rocksdb::Status s = db_->Open(rocksdb_option, rocksdb_table_option, db_path);
rocksdb::Status s = db_->Open(bw_option, db_path);
assert(db_);
assert(s.ok());
slash::DeleteDirIfExist(tmp_path);
Expand Down Expand Up @@ -1404,14 +1398,12 @@ bool PikaServer::FlushAll() {
slash::RenameFile(g_pika_conf->db_path(), dbpath.c_str());

//Create blackwidow handle
rocksdb::Options rocksdb_option;
rocksdb::BlockBasedTableOptions rocksdb_table_option;
RocksdbOptionInit(&rocksdb_option);
RocksdbTableOptionInit(&rocksdb_table_option);
blackwidow::BlackwidowOptions bw_option;
RocksdbOptionInit(&bw_option);

LOG(INFO) << "Prepare open new db...";
db_ = std::shared_ptr<blackwidow::BlackWidow>(new blackwidow::BlackWidow());
rocksdb::Status s = db_->Open(rocksdb_option, rocksdb_table_option, g_pika_conf->db_path());
rocksdb::Status s = db_->Open(bw_option, g_pika_conf->db_path());
assert(db_);
assert(s.ok());
LOG(INFO) << "open new db success";
Expand Down Expand Up @@ -1444,14 +1436,12 @@ bool PikaServer::FlushDb(const std::string& db_name) {
std::string del_dbpath = dbpath + db_name + "_deleting";
slash::RenameFile(sub_dbpath, del_dbpath);

rocksdb::Options rocksdb_option;
rocksdb::BlockBasedTableOptions rocksdb_table_option;
RocksdbOptionInit(&rocksdb_option);
RocksdbTableOptionInit(&rocksdb_table_option);
blackwidow::BlackwidowOptions bw_option;
RocksdbOptionInit(&bw_option);

LOG(INFO) << "Prepare open new " + db_name + " db...";
db_ = std::shared_ptr<blackwidow::BlackWidow>(new blackwidow::BlackWidow());
rocksdb::Status s = db_->Open(rocksdb_option, rocksdb_table_option, g_pika_conf->db_path());
rocksdb::Status s = db_->Open(bw_option, g_pika_conf->db_path());
assert(db_);
assert(s.ok());
LOG(INFO) << "open new " + db_name + " db success";
Expand Down