Skip to content

Commit

Permalink
fix some minor issues (OpenAtomFoundation#629)
Browse files Browse the repository at this point in the history
  • Loading branch information
Axlgrep authored May 15, 2019
1 parent d474ba8 commit 652eea2
Show file tree
Hide file tree
Showing 9 changed files with 64 additions and 73 deletions.
2 changes: 0 additions & 2 deletions conf/pika.conf
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions include/pika_admin.h
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ class InfoCmd : public Cmd {
InfoSection info_section_;
bool rescan_; //whether to rescan the keyspace
bool off_;
std::set<std::string> keyspace_scan_tables;
std::set<std::string> keyspace_scan_tables_;

const static std::string kInfoSection;
const static std::string kAllSection;
Expand All @@ -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);
Expand Down
1 change: 0 additions & 1 deletion include/pika_server.h
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,6 @@ class PikaServer {
*/
void SyncError();
void RemoveMaster();
bool ShouldStartPingMaster();
bool SetMaster(std::string& master_ip, int master_port);

/*
Expand Down
94 changes: 48 additions & 46 deletions src/pika_admin.cc
Original file line number Diff line number Diff line change
Expand Up @@ -436,29 +436,32 @@ 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<std::string> 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") {
off_ = true;
} else if (argv_[2] != "0") {
res_.SetRes(CmdRes::kSyntaxErr);
}

if (argc == 4) {
std::vector<std::string> 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())) {
Expand Down Expand Up @@ -535,10 +538,6 @@ void InfoCmd::Do(std::shared_ptr<Partition> partition) {
break;
case kInfoKeyspace:
InfoKeyspace(info);
// off_ should return +OK
if (off_) {
res_.SetRes(CmdRes::kOk);
}
break;
case kInfoLog:
InfoLog(info);
Expand Down Expand Up @@ -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;
}

Expand All @@ -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;
}
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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");
Expand Down
13 changes: 7 additions & 6 deletions src/pika_conf.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

#include "include/pika_conf.h"

#include <glog/logging.h>

#include <algorithm>
#include <strings.h>

Expand Down Expand Up @@ -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});
}
Expand Down Expand Up @@ -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;
Expand Down
8 changes: 4 additions & 4 deletions src/pika_repl_client_conn.cc
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,10 @@ void PikaReplClientConn::HandleMetaSyncResponse(void* arg) {

bool force_full_sync = g_pika_server->force_full_sync();
std::vector<TableStruct> 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;
Expand Down
9 changes: 0 additions & 9 deletions src/pika_server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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_;
Expand Down
4 changes: 2 additions & 2 deletions src/pika_table.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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_);
Expand Down
2 changes: 1 addition & 1 deletion third/blackwidow
Submodule blackwidow updated 1 files
+0 −1 src/blackwidow.cc

0 comments on commit 652eea2

Please sign in to comment.