提交 4c240f70 编写于 作者: K KernelMaker

1) change some log; 2) compact-cron: free/total >? 3) config set compact-cron

上级 4a24bd2a
......@@ -56,8 +56,8 @@ db-sync-speed : -1
# network-interface : eth1
# replication
# slaveof : master-ip:master-port
# CronTask, format: start:end-ratio, like 02:04-60, pika will check to schedule compaction between 2 to 4 o'clock everyday
# if the dbsize/disksize > 60%
# CronTask, format: start:end-ratio, like 02-04/60, pika will check to schedule compaction between 2 to 4 o'clock everyday
# if the freesize/disksize > 60%
# compact-cron :
###################
......
......@@ -138,6 +138,11 @@ public:
RWLock l(&rwlock_, true);
db_sync_speed_ = value;
}
void SetCompactCron(const std::string &value) {
RWLock l(&rwlock_, true);
compact_cron_ = value;
}
int Load();
int ConfigRewrite();
......
......@@ -1077,6 +1077,30 @@ void ConfigCmd::ConfigSet(std::string& ret) {
}
g_pika_conf->SetDbSyncSpeed(ival);
ret = "+OK\r\n";
} else if (set_item == "compact-cron") {
bool invalid = false;
std::string::size_type len = value.length();
std::string::size_type colon = value.find("-");
std::string::size_type underline = value.find("/");
if (colon == std::string::npos || underline == std::string::npos ||
colon >= underline || colon + 1 >= len ||
colon + 1 == underline || underline + 1 >= len) {
invalid = true;
} else {
int start = std::atoi(value.substr(0, colon).c_str());
int end = std::atoi(value.substr(colon+1, underline).c_str());
int usage = std::atoi(value.substr(underline+1).c_str());
if (start < 0 || start > 23 || end < 0 || end > 23 || usage < 0 || usage > 100) {
invalid = true;
}
}
if (invalid) {
ret = "-ERR invalid compact-cron\r\n";
return;
} else {
g_pika_conf->SetCompactCron(value);
ret = "+OK\r\n";
}
} else {
ret = "-ERR No such configure item\r\n";
}
......
......@@ -46,7 +46,7 @@ std::string PikaClientConn::DoCmd(const std::string& opt) {
// Check authed
if (!auth_stat_.IsAuthed(cinfo_ptr)) {
LOG(WARNING) << "(" << ip_port() << ")Authentication required";
// LOG(WARNING) << "(" << ip_port() << ")Authentication required";
return "-ERR NOAUTH Authentication required.\r\n";
}
......@@ -140,7 +140,7 @@ std::string PikaClientConn::DoCmd(const std::string& opt) {
if (opt == kCmdNameAuth) {
if(!auth_stat_.ChecknUpdate(c_ptr->res().raw_message())) {
LOG(WARNING) << "(" << ip_port() << ")Wrong Password";
// LOG(WARNING) << "(" << ip_port() << ")Wrong Password";
}
}
return c_ptr->res().message();
......
......@@ -107,8 +107,8 @@ int PikaConf::Load()
GetConfStr("compact-cron", &compact_cron_);
if (compact_cron_ != "") {
std::string::size_type len = compact_cron_.length();
std::string::size_type colon = compact_cron_.find(":");
std::string::size_type underline = compact_cron_.find("-");
std::string::size_type colon = compact_cron_.find("-");
std::string::size_type underline = compact_cron_.find("/");
if (colon == std::string::npos || underline == std::string::npos ||
colon >= underline || colon + 1 >= len ||
colon + 1 == underline || underline + 1 >= len) {
......
......@@ -1105,8 +1105,8 @@ void PikaServer::AutoCompactRange() {
if (cc == "") {
return;
} else {
std::string::size_type colon = cc.find(":");
std::string::size_type underline = cc.find("-");
std::string::size_type colon = cc.find("-");
std::string::size_type underline = cc.find("/");
int start = std::atoi(cc.substr(0, colon).c_str());
int end = std::atoi(cc.substr(colon+1, underline).c_str());
int usage = std::atoi(cc.substr(underline+1).c_str());
......@@ -1121,7 +1121,8 @@ void PikaServer::AutoCompactRange() {
} else {
have_scheduled_crontask_ = false;
}
// LOG(INFO) << "start: " << start << " end: " << end << " usage " << usage <<
// " have_scheduled: " << have_scheduled_crontask_ << " in_window: " << in_window;
if (!have_scheduled_crontask_ && in_window) {
struct statfs disk_info;
int ret = statfs(g_pika_conf->db_path().c_str(), &disk_info);
......@@ -1131,14 +1132,16 @@ void PikaServer::AutoCompactRange() {
}
uint64_t total_size = disk_info.f_bsize * disk_info.f_blocks;
uint64_t free_size = disk_info.f_bsize * disk_info.f_blocks;
uint64_t db_size = slash::Du(g_pika_conf->db_path());
if ((db_size / total_size) * 100 >= usage) {
// LOG(INFO) << "free_size: " << free_size << " disk_size: " << total_size <<
// " cal: " << ((double)free_size / total_size) * 100;
if (((double)free_size / total_size) * 100 >= usage) {
nemo::Status s = db_->Compact(nemo::kALL);
if (s.ok()) {
LOG(INFO) << "schedule compactRange, dbsize: " << db_size << " disksize: " << total_size;
LOG(INFO) << "schedule compactRange, freesize: " << free_size << " disksize: " << total_size;
} else {
LOG(INFO) << "schedule compactRange Failed, dbsize: " << db_size << " disksize: " << total_size
LOG(INFO) << "schedule compactRange Failed, freesize: " << free_size << " disksize: " << total_size
<< " error: " << s.ToString();
}
have_scheduled_crontask_ = true;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册