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

Minor refactoring of stc/storage/storage.cc #1321

Merged
merged 1 commit into from
Mar 16, 2023
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
4 changes: 2 additions & 2 deletions src/cluster/replication.cc
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ void FeedSlaveThread::loop() {
// batches strategy, we still send batches if current batch sequence is less
// kMaxDelayUpdates than latest sequence.
if (is_first_repl_batch || batches_bulk.size() >= kMaxDelayBytes || updates_in_batches >= kMaxDelayUpdates ||
srv_->storage_->LatestSeq() - batch.sequence <= kMaxDelayUpdates) {
srv_->storage_->LatestSeqNumber() - batch.sequence <= kMaxDelayUpdates) {
// Send entire bulk which contain multiple batches
auto s = Util::SockSend(conn_->GetFD(), batches_bulk);
if (!s.IsOK()) {
Expand Down Expand Up @@ -469,7 +469,7 @@ ReplicationThread::CBState ReplicationThread::replConfReadCB(bufferevent *bev, v

ReplicationThread::CBState ReplicationThread::tryPSyncWriteCB(bufferevent *bev, void *ctx) {
auto self = static_cast<ReplicationThread *>(ctx);
auto cur_seq = self->storage_->LatestSeq();
auto cur_seq = self->storage_->LatestSeqNumber();
auto next_seq = cur_seq + 1;
std::string replid;

Expand Down
6 changes: 3 additions & 3 deletions src/commands/cmd_replication.cc
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class CommandPSync : public Commander {
<< ", announce ip: " << conn->GetAnnounceIP() << " asks for synchronization"
<< " with next sequence: " << next_repl_seq
<< " replication id: " << (replica_replid.length() ? replica_replid : "not supported")
<< ", and local sequence: " << svr->storage_->LatestSeq();
<< ", and local sequence: " << svr->storage_->LatestSeqNumber();

bool need_full_sync = false;

Expand Down Expand Up @@ -121,12 +121,12 @@ class CommandPSync : public Commander {

// Return OK if the seq is in the range of the current WAL
Status checkWALBoundary(Engine::Storage *storage, rocksdb::SequenceNumber seq) {
if (seq == storage->LatestSeq() + 1) {
if (seq == storage->LatestSeqNumber() + 1) {
return Status::OK();
}

// Upper bound
if (seq > storage->LatestSeq() + 1) {
if (seq > storage->LatestSeqNumber() + 1) {
return {Status::NotOK};
}

Expand Down
29 changes: 15 additions & 14 deletions src/config/config.cc
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ void Config::initFieldCallback() {
};
auto set_cf_option_cb = [](Server *srv, const std::string &k, const std::string &v) -> Status {
if (!srv) return Status::OK(); // srv is nullptr when load config from file
return srv->storage_->SetColumnFamilyOption(trimRocksDBPrefix(k), v);
return srv->storage_->SetOptionForAllColumnFamilies(trimRocksDBPrefix(k), v);
};
#ifdef ENABLE_OPENSSL
auto set_tls_option = [](Server *srv, const std::string &k, const std::string &v) {
Expand Down Expand Up @@ -488,20 +488,20 @@ void Config::initFieldCallback() {
{"rocksdb.target_file_size_base",
[this](Server *srv, const std::string &k, const std::string &v) -> Status {
if (!srv) return Status::OK();
return srv->storage_->SetColumnFamilyOption(trimRocksDBPrefix(k),
std::to_string(RocksDB.target_file_size_base * MiB));
return srv->storage_->SetOptionForAllColumnFamilies(trimRocksDBPrefix(k),
std::to_string(RocksDB.target_file_size_base * MiB));
}},
{"rocksdb.write_buffer_size",
[this](Server *srv, const std::string &k, const std::string &v) -> Status {
if (!srv) return Status::OK();
return srv->storage_->SetColumnFamilyOption(trimRocksDBPrefix(k),
std::to_string(RocksDB.write_buffer_size * MiB));
return srv->storage_->SetOptionForAllColumnFamilies(trimRocksDBPrefix(k),
std::to_string(RocksDB.write_buffer_size * MiB));
}},
{"rocksdb.disable_auto_compactions",
[](Server *srv, const std::string &k, const std::string &v) -> Status {
if (!srv) return Status::OK();
std::string disable_auto_compactions = v == "yes" ? "true" : "false";
return srv->storage_->SetColumnFamilyOption(trimRocksDBPrefix(k), disable_auto_compactions);
return srv->storage_->SetOptionForAllColumnFamilies(trimRocksDBPrefix(k), disable_auto_compactions);
}},
{"rocksdb.max_total_wal_size",
[this](Server *srv, const std::string &k, const std::string &v) -> Status {
Expand All @@ -512,23 +512,24 @@ void Config::initFieldCallback() {
[this](Server *srv, const std::string &k, const std::string &v) -> Status {
if (!srv) return Status::OK();
std::string enable_blob_files = RocksDB.enable_blob_files ? "true" : "false";
return srv->storage_->SetColumnFamilyOption(trimRocksDBPrefix(k), enable_blob_files);
return srv->storage_->SetOptionForAllColumnFamilies(trimRocksDBPrefix(k), enable_blob_files);
}},
{"rocksdb.min_blob_size",
[this](Server *srv, const std::string &k, const std::string &v) -> Status {
if (!srv) return Status::OK();
if (!RocksDB.enable_blob_files) {
return {Status::NotOK, errBlobDbNotEnabled};
}
return srv->storage_->SetColumnFamilyOption(trimRocksDBPrefix(k), v);
return srv->storage_->SetOptionForAllColumnFamilies(trimRocksDBPrefix(k), v);
}},
{"rocksdb.blob_file_size",
[this](Server *srv, const std::string &k, const std::string &v) -> Status {
if (!srv) return Status::OK();
if (!RocksDB.enable_blob_files) {
return {Status::NotOK, errBlobDbNotEnabled};
}
return srv->storage_->SetColumnFamilyOption(trimRocksDBPrefix(k), std::to_string(RocksDB.blob_file_size));
return srv->storage_->SetOptionForAllColumnFamilies(trimRocksDBPrefix(k),
std::to_string(RocksDB.blob_file_size));
}},
{"rocksdb.enable_blob_garbage_collection",
[this](Server *srv, const std::string &k, const std::string &v) -> Status {
Expand All @@ -537,7 +538,7 @@ void Config::initFieldCallback() {
return {Status::NotOK, errBlobDbNotEnabled};
}
std::string enable_blob_garbage_collection = v == "yes" ? "true" : "false";
return srv->storage_->SetColumnFamilyOption(trimRocksDBPrefix(k), enable_blob_garbage_collection);
return srv->storage_->SetOptionForAllColumnFamilies(trimRocksDBPrefix(k), enable_blob_garbage_collection);
}},
{"rocksdb.blob_garbage_collection_age_cutoff",
[this](Server *srv, const std::string &k, const std::string &v) -> Status {
Expand All @@ -556,7 +557,7 @@ void Config::initFieldCallback() {
}

double cutoff = val / 100.0;
return srv->storage_->SetColumnFamilyOption(trimRocksDBPrefix(k), std::to_string(cutoff));
return srv->storage_->SetOptionForAllColumnFamilies(trimRocksDBPrefix(k), std::to_string(cutoff));
}},
{"rocksdb.level_compaction_dynamic_level_bytes",
[](Server *srv, const std::string &k, const std::string &v) -> Status {
Expand All @@ -570,16 +571,16 @@ void Config::initFieldCallback() {
if (!RocksDB.level_compaction_dynamic_level_bytes) {
return {Status::NotOK, errLevelCompactionDynamicLevelBytesNotSet};
}
return srv->storage_->SetColumnFamilyOption(trimRocksDBPrefix(k),
std::to_string(RocksDB.max_bytes_for_level_base));
return srv->storage_->SetOptionForAllColumnFamilies(trimRocksDBPrefix(k),
std::to_string(RocksDB.max_bytes_for_level_base));
}},
{"rocksdb.max_bytes_for_level_multiplier",
[this](Server *srv, const std::string &k, const std::string &v) -> Status {
if (!srv) return Status::OK();
if (!RocksDB.level_compaction_dynamic_level_bytes) {
return {Status::NotOK, errLevelCompactionDynamicLevelBytesNotSet};
}
return srv->storage_->SetColumnFamilyOption(trimRocksDBPrefix(k), v);
return srv->storage_->SetOptionForAllColumnFamilies(trimRocksDBPrefix(k), v);
}},
{"rocksdb.max_open_files", set_db_option_cb},
{"rocksdb.stats_dump_period_sec", set_db_option_cb},
Expand Down
10 changes: 5 additions & 5 deletions src/server/server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -905,12 +905,12 @@ void Server::GetReplicationInfo(std::string *info) {
string_stream << "master_sync_unrecoverable_error:" << (state == kReplError ? "yes" : "no") << "\r\n";
string_stream << "master_sync_in_progress:" << (state == kReplFetchMeta || state == kReplFetchSST) << "\r\n";
string_stream << "master_last_io_seconds_ago:" << now - replication_thread_->LastIOTime() << "\r\n";
string_stream << "slave_repl_offset:" << storage_->LatestSeq() << "\r\n";
string_stream << "slave_repl_offset:" << storage_->LatestSeqNumber() << "\r\n";
string_stream << "slave_priority:" << config_->slave_priority << "\r\n";
}

int idx = 0;
rocksdb::SequenceNumber latest_seq = storage_->LatestSeq();
rocksdb::SequenceNumber latest_seq = storage_->LatestSeqNumber();

slave_threads_mu_.lock();
string_stream << "connected_slaves:" << slave_threads_.size() << "\r\n";
Expand Down Expand Up @@ -945,7 +945,7 @@ void Server::GetRoleInfo(std::string *info) {
} else {
roles.emplace_back("connecting");
}
roles.emplace_back(std::to_string(storage_->LatestSeq()));
roles.emplace_back(std::to_string(storage_->LatestSeqNumber()));
*info = Redis::MultiBulkString(roles);
} else {
std::vector<std::string> list;
Expand All @@ -968,7 +968,7 @@ void Server::GetRoleInfo(std::string *info) {
}
info->append(Redis::MultiLen(multi_len));
info->append(Redis::BulkString("master"));
info->append(Redis::BulkString(std::to_string(storage_->LatestSeq())));
info->append(Redis::BulkString(std::to_string(storage_->LatestSeqNumber())));
if (list.size() > 0) {
info->append(Redis::Array(list));
}
Expand Down Expand Up @@ -1375,7 +1375,7 @@ Status Server::autoResizeBlockAndSST() {
}

if (block_size != config_->RocksDB.block_size) {
auto s = storage_->SetColumnFamilyOption("table_factory.block_size", std::to_string(block_size));
auto s = storage_->SetOptionForAllColumnFamilies("table_factory.block_size", std::to_string(block_size));
LOG(INFO) << "[server] Resize rocksdb.block_size from " << config_->RocksDB.block_size << " to " << block_size
<< ", average_kv_size: " << average_kv_size << ", total_size: " << total_size
<< ", total_keys: " << total_keys << ", result: " << s.Msg();
Expand Down
Loading