Make server API for load metrics

This commit is contained in:
Bharadwaj V.R 2022-03-02 14:29:43 -08:00 committed by Trevor Clinkenbeard
parent 2d2f7ed2c6
commit 7bad6c5093
2 changed files with 13 additions and 7 deletions

View File

@ -198,7 +198,7 @@ void TCServerInfo::removeTeamsContainingServer(UID removedServer) {
}
}
std::pair<int64_t, int64_t> TCServerInfo::spaceInBytes(bool includeInFlight) const {
std::pair<int64_t, int64_t> TCServerInfo::spaceBytes(bool includeInFlight) const {
auto& metrics = getServerMetrics();
ASSERT(metrics.capacity.bytes >= 0);
ASSERT(metrics.available.bytes >= 0);
@ -211,6 +211,10 @@ std::pair<int64_t, int64_t> TCServerInfo::spaceInBytes(bool includeInFlight) con
return std::make_pair(bytesAvailable, metrics.capacity.bytes); // bytesAvailable could be negative
}
int64_t TCServerInfo::loadBytes() const {
return getServerMetrics().load.bytes;
}
void TCServerInfo::removeTeam(Reference<TCTeamInfo> team) {
for (int t = 0; t < teams.size(); t++) {
if (teams[t] == team) {
@ -370,7 +374,7 @@ int64_t TCTeamInfo::getMinAvailableSpace(bool includeInFlight) const {
int64_t minAvailableSpace = std::numeric_limits<int64_t>::max();
for (const auto& server : servers) {
if (server->serverMetricsPresent()) {
const auto [bytesAvailable, bytesCapacity] = server->spaceInBytes(includeInFlight);
const auto [bytesAvailable, bytesCapacity] = server->spaceBytes(includeInFlight);
minAvailableSpace = std::min(bytesAvailable, minAvailableSpace);
}
}
@ -382,7 +386,7 @@ double TCTeamInfo::getMinAvailableSpaceRatio(bool includeInFlight) const {
double minRatio = 1.0;
for (const auto& server : servers) {
if (server->serverMetricsPresent()) {
auto [bytesAvailable, bytesCapacity] = server->spaceInBytes(includeInFlight);
auto [bytesAvailable, bytesCapacity] = server->spaceBytes(includeInFlight);
bytesAvailable = std::max((int64_t)0, bytesAvailable);
if (bytesCapacity == 0)
@ -437,11 +441,12 @@ void TCTeamInfo::addServers(const std::vector<UID>& servers) {
int64_t TCTeamInfo::getLoadAverage() const {
int64_t bytesSum = 0;
int added = 0;
for (int i = 0; i < servers.size(); i++)
if (servers[i]->serverMetricsPresent()) {
for (const auto& server : servers) {
if (server->serverMetricsPresent()) {
added++;
bytesSum += servers[i]->getServerMetrics().load.bytes;
bytesSum += server->loadBytes();
}
}
if (added < servers.size())
bytesSum *= 2;

View File

@ -97,7 +97,8 @@ public:
return (storeType == configStoreType || storeType == KeyValueStoreType::END);
}
std::pair<int64_t, int64_t> spaceInBytes(bool includeInFlight = true) const;
std::pair<int64_t, int64_t> spaceBytes(bool includeInFlight = true) const;
int64_t loadBytes() const;
bool hasHealthyAvailableSpace(double minAvailableSpaceRatio) const;
Future<Void> updateServerMetrics();