Skip to content

Commit

Permalink
show waiting status when a keyspace task has not been scheduled for e…
Browse files Browse the repository at this point in the history
  • Loading branch information
Axlgrep committed May 15, 2019
1 parent fe1a3c6 commit 5595d44
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
2 changes: 1 addition & 1 deletion include/pika_table.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ struct KeyScanInfo {
KeyScanInfo() :
start_time(0),
s_start_time("1970-01-01 08:00:00"),
duration(-2),
duration(-3),
key_infos({{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}),
key_scaning_(false) {
}
Expand Down
9 changes: 7 additions & 2 deletions src/pika_admin.cc
Original file line number Diff line number Diff line change
Expand Up @@ -674,9 +674,14 @@ void InfoCmd::InfoKeyspace(std::string& info) {
return;
}
tmp_stream << "# Time:" << key_scan_info.s_start_time << "\r\n";
if (duration != -2) {
tmp_stream << "# Duration: " << (duration == -1 ? "In Processing" : std::to_string(duration) + "s" )<< "\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";
Expand Down
9 changes: 6 additions & 3 deletions src/pika_table.cc
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,8 @@ void Table::KeyScan() {
}

key_scan_info_.key_scaning_ = true;
InitKeyScan();
key_scan_info_.duration = -2; // duration -2 mean the task in waiting status,
// has not been scheduled for exec
BgTaskArg* bg_task_arg = new BgTaskArg();
bg_task_arg->table = shared_from_this();
g_pika_server->KeyScanTaskSchedule(&DoKeyScan, reinterpret_cast<void*>(bg_task_arg));
Expand All @@ -123,6 +124,8 @@ bool Table::IsKeyScaning() {
void Table::RunKeyScan() {
rocksdb::Status s;
std::vector<blackwidow::KeyInfo> new_key_infos(5);

InitKeyScan();
slash::RWLock rwl(&partitions_rw_, false);
for (const auto& item : partitions_) {
std::vector<blackwidow::KeyInfo> tmp_key_infos;
Expand All @@ -134,11 +137,11 @@ void Table::RunKeyScan() {
new_key_infos[idx].avg_ttl += tmp_key_infos[idx].avg_ttl;
new_key_infos[idx].invaild_keys += tmp_key_infos[idx].invaild_keys;
}
key_scan_info_.duration = time(NULL) - key_scan_info_.start_time;
} else {
break;
}
}
key_scan_info_.duration = time(NULL) - key_scan_info_.start_time;

slash::MutexLock lm(&key_scan_protector_);
if (s.ok()) {
Expand Down Expand Up @@ -187,7 +190,7 @@ void Table::InitKeyScan() {
char s_time[32];
int len = strftime(s_time, sizeof(s_time), "%Y-%m-%d %H:%M:%S", localtime(&key_scan_info_.start_time));
key_scan_info_.s_start_time.assign(s_time, len);
key_scan_info_.duration = -1;
key_scan_info_.duration = -1; // duration -1 mean the task in processing
}

void Table::LeaveAllPartition() {
Expand Down

0 comments on commit 5595d44

Please sign in to comment.