Encapsulate TCServerInfo::serverMetrics

This commit is contained in:
sfc-gh-tclinkenbeard 2022-02-11 22:05:57 -08:00
parent 62dbd29ddc
commit a958fd2fbc
2 changed files with 9 additions and 7 deletions

View File

@ -319,8 +319,8 @@ int64_t TCTeamInfo::getLoadBytes(bool includeInFlight, double inflightPenalty) c
int64_t TCTeamInfo::getMinAvailableSpace(bool includeInFlight) const {
int64_t minAvailableSpace = std::numeric_limits<int64_t>::max();
for (const auto& server : servers) {
if (server->serverMetrics.present()) {
auto& replyValue = server->serverMetrics.get();
if (server->serverMetricsPresent()) {
auto& replyValue = server->getServerMetrics();
ASSERT(replyValue.available.bytes >= 0);
ASSERT(replyValue.capacity.bytes >= 0);
@ -340,8 +340,8 @@ int64_t TCTeamInfo::getMinAvailableSpace(bool includeInFlight) const {
double TCTeamInfo::getMinAvailableSpaceRatio(bool includeInFlight) const {
double minRatio = 1.0;
for (const auto& server : servers) {
if (server->serverMetrics.present()) {
auto& replyValue = server->serverMetrics.get();
if (server->serverMetricsPresent()) {
auto const& replyValue = server->getServerMetrics();
ASSERT(replyValue.available.bytes >= 0);
ASSERT(replyValue.capacity.bytes >= 0);
@ -389,9 +389,9 @@ int64_t TCTeamInfo::getLoadAverage() const {
int64_t bytesSum = 0;
int added = 0;
for (int i = 0; i < servers.size(); i++)
if (servers[i]->serverMetrics.present()) {
if (servers[i]->serverMetricsPresent()) {
added++;
bytesSum += servers[i]->serverMetrics.get().load.bytes;
bytesSum += servers[i]->getServerMetrics().load.bytes;
}
if (added < servers.size())

View File

@ -45,10 +45,10 @@ class TCServerInfo : public ReferenceCounted<TCServerInfo> {
int64_t dataInFlightToServer;
std::vector<Reference<TCTeamInfo>> teams;
ErrorOr<GetStorageMetricsReply> serverMetrics;
public:
Reference<TCMachineInfo> machine;
ErrorOr<GetStorageMetricsReply> serverMetrics;
Promise<std::pair<StorageServerInterface, ProcessClass>> interfaceChanged;
Future<std::pair<StorageServerInterface, ProcessClass>> onInterfaceChanged;
Promise<Void> removed;
@ -84,6 +84,8 @@ public:
void addTeam(Reference<TCTeamInfo> team) { teams.push_back(team); }
void removeTeamsContainingServer(UID removedServer);
void removeTeam(Reference<TCTeamInfo>);
GetStorageMetricsReply const& getServerMetrics() const { return serverMetrics.get(); }
bool serverMetricsPresent() const { return serverMetrics.present(); }
bool isCorrectStoreType(KeyValueStoreType configStoreType) const {
// A new storage server's store type may not be set immediately.