From 652eea207dba65e18edc86cdfbe984e20d6809e9 Mon Sep 17 00:00:00 2001 From: Axlgrep Date: Wed, 15 May 2019 23:49:16 +0800 Subject: [PATCH] fix some minor issues (#629) --- conf/pika.conf | 2 - include/pika_admin.h | 4 +- include/pika_server.h | 1 - src/pika_admin.cc | 94 ++++++++++++++++++------------------ src/pika_conf.cc | 13 ++--- src/pika_repl_client_conn.cc | 8 +-- src/pika_server.cc | 9 ---- src/pika_table.cc | 4 +- third/blackwidow | 2 +- 9 files changed, 64 insertions(+), 73 deletions(-) diff --git a/conf/pika.conf b/conf/pika.conf index 6201879267..64164134d9 100644 --- a/conf/pika.conf +++ b/conf/pika.conf @@ -10,8 +10,6 @@ sync-thread-num : 6 log-path : ./log/ # Pika db path db-path : ./db/ -# Pika Trash path -trash-path: ./trash/ # Pika write-buffer-size write-buffer-size : 268435456 # Pika timeout diff --git a/include/pika_admin.h b/include/pika_admin.h index 81241f4d90..158d9a4c44 100644 --- a/include/pika_admin.h +++ b/include/pika_admin.h @@ -178,7 +178,7 @@ class InfoCmd : public Cmd { InfoSection info_section_; bool rescan_; //whether to rescan the keyspace bool off_; - std::set keyspace_scan_tables; + std::set keyspace_scan_tables_; const static std::string kInfoSection; const static std::string kAllSection; @@ -197,7 +197,7 @@ class InfoCmd : public Cmd { virtual void Clear() { rescan_ = false; off_ = false; - keyspace_scan_tables.clear(); + keyspace_scan_tables_.clear(); } void InfoServer(std::string& info); diff --git a/include/pika_server.h b/include/pika_server.h index 0bc4a4797e..909a328822 100644 --- a/include/pika_server.h +++ b/include/pika_server.h @@ -155,7 +155,6 @@ class PikaServer { */ void SyncError(); void RemoveMaster(); - bool ShouldStartPingMaster(); bool SetMaster(std::string& master_ip, int master_port); /* diff --git a/src/pika_admin.cc b/src/pika_admin.cc index 42e7ddc095..f5b2fe6a3e 100644 --- a/src/pika_admin.cc +++ b/src/pika_admin.cc @@ -436,22 +436,12 @@ void InfoCmd::DoInitial() { } // info keyspace [ 0 | 1 | off ] // info keyspace 1 db0,db1 + // info keyspace 0 db0,db1 + // info keyspace off db0,db1 if (argv_[2] == "1") { if (g_pika_server->IsCompacting()) { res_.SetRes(CmdRes::kErrOther, "The compact operation is executing, Try again later"); } else { - if (argc == 4) { - std::vector tables; - slash::StringSplit(argv_[3], COMMA, tables); - for (const auto& table : tables) { - if (!g_pika_server->IsTableExist(table)) { - res_.SetRes(CmdRes::kInvalidTable, table); - return; - } else { - keyspace_scan_tables.insert(table); - } - } - } rescan_ = true; } } else if (argv_[2] == "off") { @@ -459,6 +449,19 @@ void InfoCmd::DoInitial() { } else if (argv_[2] != "0") { res_.SetRes(CmdRes::kSyntaxErr); } + + if (argc == 4) { + std::vector tables; + slash::StringSplit(argv_[3], COMMA, tables); + for (const auto& table : tables) { + if (!g_pika_server->IsTableExist(table)) { + res_.SetRes(CmdRes::kInvalidTable, table); + return; + } else { + keyspace_scan_tables_.insert(table); + } + } + } LogCommand(); return; } else if (!strcasecmp(argv_[1].data(), kLogSection.data())) { @@ -535,10 +538,6 @@ void InfoCmd::Do(std::shared_ptr partition) { break; case kInfoKeyspace: InfoKeyspace(info); - // off_ should return +OK - if (off_) { - res_.SetRes(CmdRes::kOk); - } break; case kInfoLog: InfoLog(info); @@ -689,8 +688,8 @@ void InfoCmd::InfoReplication(std::string& info) { void InfoCmd::InfoKeyspace(std::string& info) { if (off_) { - g_pika_server->DoSameThingSpecificTable(TaskType::kStopKeyScan); - off_ = false; + g_pika_server->DoSameThingSpecificTable(TaskType::kStopKeyScan, keyspace_scan_tables_); + info.append("OK\r\n"); return; } @@ -702,33 +701,36 @@ void InfoCmd::InfoKeyspace(std::string& info) { tmp_stream << "# Keyspace\r\n"; slash::RWLock rwl(&g_pika_server->tables_rw_, false); for (const auto& table_item : g_pika_server->tables_) { - table_name = table_item.second->GetTableName(); - key_scan_info = table_item.second->GetKeyScanInfo(); - key_infos = key_scan_info.key_infos; - duration = key_scan_info.duration; - if (key_infos.size() != 5) { - info.append("info keyspace error\r\n"); - return; - } - tmp_stream << "# Time:" << key_scan_info.s_start_time << "\r\n"; - if (duration == -2) { - tmp_stream << "# Duration: " << "In Waiting\r\n"; - } else if (duration == -1) { - tmp_stream << "# Duration: " << "In Processing\r\n"; - } else if (duration >= 0) { - tmp_stream << "# Duration: " << std::to_string(duration) + "s" << "\r\n"; - } + if (keyspace_scan_tables_.empty() + || keyspace_scan_tables_.find(table_item.first) != keyspace_scan_tables_.end()) { + table_name = table_item.second->GetTableName(); + key_scan_info = table_item.second->GetKeyScanInfo(); + key_infos = key_scan_info.key_infos; + duration = key_scan_info.duration; + if (key_infos.size() != 5) { + info.append("info keyspace error\r\n"); + return; + } + tmp_stream << "# Time:" << key_scan_info.s_start_time << "\r\n"; + if (duration == -2) { + tmp_stream << "# Duration: " << "In Waiting\r\n"; + } else if (duration == -1) { + tmp_stream << "# Duration: " << "In Processing\r\n"; + } else if (duration >= 0) { + tmp_stream << "# Duration: " << std::to_string(duration) + "s" << "\r\n"; + } - tmp_stream << table_name << "_Strings: keys=" << key_infos[0].keys << ", expires=" << key_infos[0].expires << ", invaild_keys=" << key_infos[0].invaild_keys << "\r\n"; - tmp_stream << table_name << "_Hashes: keys=" << key_infos[1].keys << ", expires=" << key_infos[1].expires << ", invaild_keys=" << key_infos[1].invaild_keys << "\r\n"; - tmp_stream << table_name << "_Lists: keys=" << key_infos[2].keys << ", expires=" << key_infos[2].expires << ", invaild_keys=" << key_infos[2].invaild_keys << "\r\n"; - tmp_stream << table_name << "_Zsets: keys=" << key_infos[3].keys << ", expires=" << key_infos[3].expires << ", invaild_keys=" << key_infos[3].invaild_keys << "\r\n"; - tmp_stream << table_name << "_Sets: keys=" << key_infos[4].keys << ", expires=" << key_infos[4].expires << ", invaild_keys=" << key_infos[4].invaild_keys << "\r\n\r\n"; + tmp_stream << table_name << "_Strings: keys=" << key_infos[0].keys << ", expires=" << key_infos[0].expires << ", invaild_keys=" << key_infos[0].invaild_keys << "\r\n"; + tmp_stream << table_name << "_Hashes: keys=" << key_infos[1].keys << ", expires=" << key_infos[1].expires << ", invaild_keys=" << key_infos[1].invaild_keys << "\r\n"; + tmp_stream << table_name << "_Lists: keys=" << key_infos[2].keys << ", expires=" << key_infos[2].expires << ", invaild_keys=" << key_infos[2].invaild_keys << "\r\n"; + tmp_stream << table_name << "_Zsets: keys=" << key_infos[3].keys << ", expires=" << key_infos[3].expires << ", invaild_keys=" << key_infos[3].invaild_keys << "\r\n"; + tmp_stream << table_name << "_Sets: keys=" << key_infos[4].keys << ", expires=" << key_infos[4].expires << ", invaild_keys=" << key_infos[4].invaild_keys << "\r\n\r\n"; + } } info.append(tmp_stream.str()); if (rescan_) { - g_pika_server->DoSameThingSpecificTable(TaskType::kStartKeyScan, keyspace_scan_tables); + g_pika_server->DoSameThingSpecificTable(TaskType::kStartKeyScan, keyspace_scan_tables_); } return; } @@ -947,12 +949,6 @@ void ConfigCmd::ConfigGet(std::string &ret) { EncodeString(&config_body, g_pika_conf->db_path()); } - if (slash::stringmatch(pattern.data(), "trash-path", 1)) { - elements += 2; - EncodeString(&config_body, "trash-path"); - EncodeString(&config_body, g_pika_conf->trash_path()); - } - if (slash::stringmatch(pattern.data(), "maxmemory", 1)) { elements += 2; EncodeString(&config_body, "maxmemory"); @@ -1001,6 +997,12 @@ void ConfigCmd::ConfigGet(std::string &ret) { EncodeString(&config_body, (g_pika_conf->classic_mode() ? "classic" : "sharding")); } + if (slash::stringmatch(pattern.data(), "databases", 1)) { + elements += 2; + EncodeString(&config_body, "databases"); + EncodeInt32(&config_body, g_pika_conf->databases()); + } + if (slash::stringmatch(pattern.data(), "daemonize", 1)) { elements += 2; EncodeString(&config_body, "daemonize"); diff --git a/src/pika_conf.cc b/src/pika_conf.cc index cffed77ab9..0209be21d6 100644 --- a/src/pika_conf.cc +++ b/src/pika_conf.cc @@ -5,6 +5,8 @@ #include "include/pika_conf.h" +#include + #include #include @@ -63,7 +65,9 @@ int PikaConf::Load() if (classic_mode_) { GetConfInt("databases", &databases_); - databases_ = (databases_ < 1 || databases_ > 8) ? 1 : databases_; + if (databases_ < 1 || databases_ > 8) { + LOG(FATAL) << "config databases error, limit [1 ~ 8], the actual is: " << databases_; + } for (int idx = 0; idx < databases_; ++idx) { table_structs_.push_back({"db" + std::to_string(idx), 1}); } @@ -126,11 +130,8 @@ int PikaConf::Load() if (db_path_[db_path_.length() - 1] != '/') { db_path_ += "/"; } - GetConfStr("trash-path", &trash_path_); - trash_path_ = trash_path_.empty() ? "./trash/" : trash_path_; - if (trash_path_[trash_path_.length() - 1] != '/') { - trash_path_ += "/"; - } + trash_path_ = db_path_ + "trash/"; + GetConfInt("thread-num", &thread_num_); if (thread_num_ <= 0) { thread_num_ = 12; diff --git a/src/pika_repl_client_conn.cc b/src/pika_repl_client_conn.cc index 499fa95038..2e8e08ce25 100644 --- a/src/pika_repl_client_conn.cc +++ b/src/pika_repl_client_conn.cc @@ -108,10 +108,10 @@ void PikaReplClientConn::HandleMetaSyncResponse(void* arg) { bool force_full_sync = g_pika_server->force_full_sync(); std::vector self_table_structs = g_pika_conf->table_structs(); - if (!force_full_sync - && !PikaReplClientConn::IsTableStructConsistent(self_table_structs, master_table_structs)) { - LOG(WARNING) << "Self table structs inconsistent with master" - << ", failed to establish master-slave relationship"; + if (!PikaReplClientConn::IsTableStructConsistent(self_table_structs, master_table_structs)) { + LOG(WARNING) << "Self table structs(db size: " << self_table_structs.size() + << ") inconsistent with master(db size: " << master_table_structs.size() + << ", failed to establish master-slave relationship"; g_pika_server->SyncError(); conn->NotifyClose(); delete task_arg; diff --git a/src/pika_server.cc b/src/pika_server.cc index ab4b5c31b7..3ad2524ba3 100644 --- a/src/pika_server.cc +++ b/src/pika_server.cc @@ -754,15 +754,6 @@ void PikaServer::RemoveMaster() { } } -bool PikaServer::ShouldStartPingMaster() { - slash::RWLock l(&state_protector_, false); - if ((repl_state_ == PIKA_REPL_SHOULD_MARK_TRY_CONNECT - || repl_state_ == PIKA_REPL_CONNECTING)) { - return true; - } - return false; -} - bool PikaServer::SetMaster(std::string& master_ip, int master_port) { if (master_ip == "127.0.0.1") { master_ip = host_; diff --git a/src/pika_table.cc b/src/pika_table.cc index 29f88d4344..f36d8d4da1 100644 --- a/src/pika_table.cc +++ b/src/pika_table.cc @@ -25,8 +25,8 @@ Table::Table(const std::string& table_name, partition_num_(partition_num) { db_path_ = TablePath(db_path, table_name_); - log_path_ = TablePath(log_path, table_name_); - trash_path_ = TablePath(trash_path, table_name_); + log_path_ = TablePath(log_path, "log_" + table_name_); + trash_path_ = TablePath(trash_path, "trash_" + table_name_); slash::CreatePath(db_path_); slash::CreatePath(log_path_); diff --git a/third/blackwidow b/third/blackwidow index fea74a76d8..d76490bb18 160000 --- a/third/blackwidow +++ b/third/blackwidow @@ -1 +1 @@ -Subproject commit fea74a76d8e42cee53febd8080be1d0b474f0fc9 +Subproject commit d76490bb18431e3c67a4b3756187e8561fb828ad