Skip to content

Commit

Permalink
curvefs/tool: fix copyset health check error
Browse files Browse the repository at this point in the history
when get all coysetinfo (in curvefs_copyset_status) has error,
tools would not to check copyset status,
so get health instaed of unhealthy
  • Loading branch information
Cyber-SiKu committed Jan 19, 2022
1 parent 361cf81 commit ddc8e9b
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 35 deletions.
5 changes: 2 additions & 3 deletions curvefs/src/tools/copyset/curvefs_copyset_base_tool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ bool CopysetInfo2CopysetStatus(
uint64_t key = (static_cast<uint64_t>(copysets[m].poolid()) << 32) |
copysets[m].copysetid();
(*key2Status)[key].push_back(copysetsStatus[n]);
// TODO(chengyi01): check copysetsStatus[n].status()
}
}
return ret;
Expand Down Expand Up @@ -135,7 +134,8 @@ bool CopysetInfo2CopysetStatus(
getCopysetStatusTool.SetRequestQueue(i.second);
auto checkRet = getCopysetStatusTool.RunCommand();
if (checkRet < 0) {
std::cerr << "send request to mds get error." << std::endl;
std::cerr << "send request to metaserver (" << FLAGS_metaserverAddr
<< ") get error." << std::endl;
ret = false;
}
const auto& copysetsStatus =
Expand All @@ -146,7 +146,6 @@ bool CopysetInfo2CopysetStatus(
uint64_t key = (static_cast<uint64_t>(copysets[m].poolid()) << 32) |
copysets[m].copysetid();
(*key2Status)[key].push_back(copysetsStatus[n]);
// TODO(chengyi01): check copysetsStatus[n].status()
}
}
return ret;
Expand Down
65 changes: 33 additions & 32 deletions curvefs/src/tools/status/curvefs_copyset_status.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,46 +41,47 @@ void CopysetStatusTool::PrintHelp() {
}

int CopysetStatusTool::RunCommand() {
if (copyInfoListTool_->RunCommand() == 0) {
auto response = copyInfoListTool_->GetResponse();
std::map<
uint64_t,
std::vector<curvefs::metaserver::copyset::CopysetStatusResponse>>
key2Status;
copyset::CopysetInfo2CopysetStatus(*response.get(), &key2Status);
copyInfoListTool_->RunCommand();
auto response = copyInfoListTool_->GetResponse();
std::map<uint64_t,
std::vector<curvefs::metaserver::copyset::CopysetStatusResponse>>
key2Status;
copyset::CopysetInfo2CopysetStatus(*response.get(), &key2Status);

std::map<uint64_t, std::vector<curvefs::mds::topology::CopysetValue>>
key2Info;
std::map<uint64_t, std::vector<curvefs::mds::topology::CopysetValue>>
key2Info;

copyset::Response2CopysetInfo(*response.get(), &key2Info);
copyset::Response2CopysetInfo(*response.get(), &key2Info);

bool isHealth = true;
for (auto const& i : key2Info) {
if (copyset::checkCopysetHelthy(i.second, key2Status[i.first]) !=
copyset::CheckResult::kHealthy) {
isHealth = false;
break;
}
bool isHealth = true;
for (auto const& i : key2Info) {
if (copyset::checkCopysetHelthy(i.second, key2Status[i.first]) !=
copyset::CheckResult::kHealthy) {
isHealth = false;
break;
}
}
int ret = 0;
if (show_) {
if (isHealth) {
std::cout << "all copyset is healthy." << std::endl;
} else {
std::cout << "copysets is unhealthy." << std::endl;
ret = -1;
}
if (show_) {
if (isHealth) {
std::cout << "all copyset is health." << std::endl;
} else {
std::cout << "copysets is unhealth." << std::endl;
for (auto const& i : key2Info) {
std::cout << "copyset[" << i.first << "]:\n-info:\n";
for (auto const& j : i.second) {
std::cout << j.ShortDebugString() << std::endl;
}
for (auto const& i : key2Info) {
std::cout << "copyset[" << i.first << "]:\n-info:\n";
for (auto const& j : i.second) {
std::cout << j.ShortDebugString() << std::endl;
}
std::cout << "-status:\n";
for (auto const& j : key2Status[i.first]) {
std::cout << j.ShortDebugString() << std::endl;
}
std::cout << "-status:\n";
for (auto const& j : key2Status[i.first]) {
std::cout << j.ShortDebugString() << std::endl;
}
}
}
return 0;

return ret;
}

} // namespace status
Expand Down

0 comments on commit ddc8e9b

Please sign in to comment.