2022-02-05 05:46:44 +08:00
|
|
|
/*
|
|
|
|
* TCInfo.actor.cpp
|
|
|
|
*
|
|
|
|
* This source file is part of the FoundationDB open source project
|
|
|
|
*
|
2022-02-10 05:28:40 +08:00
|
|
|
* Copyright 2013-2022 Apple Inc. and the FoundationDB project authors
|
2022-02-05 05:46:44 +08:00
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2022-02-05 02:20:11 +08:00
|
|
|
#include "fdbclient/ServerKnobs.h"
|
|
|
|
#include "fdbserver/DDTeamCollection.h"
|
2022-02-05 02:59:01 +08:00
|
|
|
#include "fdbserver/TCInfo.h"
|
2022-02-05 02:20:11 +08:00
|
|
|
#include "flow/actorcompiler.h" // This must be the last #include.
|
|
|
|
|
|
|
|
class TCServerInfoImpl {
|
|
|
|
public:
|
|
|
|
ACTOR static Future<Void> updateServerMetrics(TCServerInfo* server) {
|
|
|
|
state StorageServerInterface ssi = server->lastKnownInterface;
|
|
|
|
state Future<ErrorOr<GetStorageMetricsReply>> metricsRequest =
|
|
|
|
ssi.getStorageMetrics.tryGetReply(GetStorageMetricsRequest(), TaskPriority::DataDistributionLaunch);
|
|
|
|
state Future<Void> resetRequest = Never();
|
|
|
|
state Future<std::pair<StorageServerInterface, ProcessClass>> interfaceChanged(server->onInterfaceChanged);
|
|
|
|
state Future<Void> serverRemoved(server->onRemoved);
|
|
|
|
|
|
|
|
loop {
|
|
|
|
choose {
|
|
|
|
when(ErrorOr<GetStorageMetricsReply> rep = wait(metricsRequest)) {
|
|
|
|
if (rep.present()) {
|
2022-03-03 07:14:29 +08:00
|
|
|
server->metrics = rep;
|
2022-02-05 02:20:11 +08:00
|
|
|
if (server->updated.canBeSet()) {
|
|
|
|
server->updated.send(Void());
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
metricsRequest = Never();
|
|
|
|
resetRequest = delay(SERVER_KNOBS->METRIC_DELAY, TaskPriority::DataDistributionLaunch);
|
|
|
|
}
|
|
|
|
when(std::pair<StorageServerInterface, ProcessClass> _ssi = wait(interfaceChanged)) {
|
|
|
|
ssi = _ssi.first;
|
|
|
|
interfaceChanged = server->onInterfaceChanged;
|
|
|
|
resetRequest = Void();
|
|
|
|
}
|
|
|
|
when(wait(serverRemoved)) { return Void(); }
|
|
|
|
when(wait(resetRequest)) { // To prevent a tight spin loop
|
|
|
|
if (IFailureMonitor::failureMonitor().getState(ssi.getStorageMetrics.getEndpoint()).isFailed()) {
|
|
|
|
resetRequest = IFailureMonitor::failureMonitor().onStateEqual(
|
|
|
|
ssi.getStorageMetrics.getEndpoint(), FailureStatus(false));
|
|
|
|
} else {
|
|
|
|
resetRequest = Never();
|
|
|
|
metricsRequest = ssi.getStorageMetrics.tryGetReply(GetStorageMetricsRequest(),
|
|
|
|
TaskPriority::DataDistributionLaunch);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-03 07:14:29 +08:00
|
|
|
if (server->metrics.get().lastUpdate < now() - SERVER_KNOBS->DD_SS_STUCK_TIME_LIMIT) {
|
2022-02-05 02:20:11 +08:00
|
|
|
if (server->ssVersionTooFarBehind.get() == false) {
|
2022-02-11 10:26:06 +08:00
|
|
|
TraceEvent("StorageServerStuck", server->collection->getDistributorId())
|
2022-02-05 02:20:11 +08:00
|
|
|
.detail("ServerId", server->id.toString())
|
2022-03-03 07:14:29 +08:00
|
|
|
.detail("LastUpdate", server->metrics.get().lastUpdate);
|
2022-02-05 02:20:11 +08:00
|
|
|
server->ssVersionTooFarBehind.set(true);
|
|
|
|
server->collection->addLaggingStorageServer(server->lastKnownInterface.locality.zoneId().get());
|
|
|
|
}
|
2022-03-03 07:14:29 +08:00
|
|
|
} else if (server->metrics.get().versionLag > SERVER_KNOBS->DD_SS_FAILURE_VERSIONLAG) {
|
2022-02-05 02:20:11 +08:00
|
|
|
if (server->ssVersionTooFarBehind.get() == false) {
|
2022-02-11 10:26:06 +08:00
|
|
|
TraceEvent(SevWarn, "SSVersionDiffLarge", server->collection->getDistributorId())
|
2022-02-05 02:20:11 +08:00
|
|
|
.detail("ServerId", server->id.toString())
|
2022-03-03 07:14:29 +08:00
|
|
|
.detail("VersionLag", server->metrics.get().versionLag);
|
2022-02-05 02:20:11 +08:00
|
|
|
server->ssVersionTooFarBehind.set(true);
|
|
|
|
server->collection->addLaggingStorageServer(server->lastKnownInterface.locality.zoneId().get());
|
|
|
|
}
|
2022-03-03 07:14:29 +08:00
|
|
|
} else if (server->metrics.get().versionLag < SERVER_KNOBS->DD_SS_ALLOWED_VERSIONLAG) {
|
2022-02-05 02:20:11 +08:00
|
|
|
if (server->ssVersionTooFarBehind.get() == true) {
|
2022-02-11 10:26:06 +08:00
|
|
|
TraceEvent("SSVersionDiffNormal", server->collection->getDistributorId())
|
2022-02-05 02:20:11 +08:00
|
|
|
.detail("ServerId", server->id.toString())
|
2022-03-03 07:14:29 +08:00
|
|
|
.detail("VersionLag", server->metrics.get().versionLag);
|
2022-02-05 02:20:11 +08:00
|
|
|
server->ssVersionTooFarBehind.set(false);
|
|
|
|
server->collection->removeLaggingStorageServer(server->lastKnownInterface.locality.zoneId().get());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return Void();
|
|
|
|
}
|
|
|
|
|
|
|
|
ACTOR static Future<Void> updateServerMetrics(Reference<TCServerInfo> server) {
|
|
|
|
wait(updateServerMetrics(server.getPtr()));
|
|
|
|
return Void();
|
|
|
|
}
|
|
|
|
|
|
|
|
ACTOR static Future<Void> serverMetricsPolling(TCServerInfo* server) {
|
|
|
|
state double lastUpdate = now();
|
|
|
|
loop {
|
2022-02-05 05:46:44 +08:00
|
|
|
wait(server->updateServerMetrics());
|
2022-02-05 02:20:11 +08:00
|
|
|
wait(delayUntil(lastUpdate + SERVER_KNOBS->STORAGE_METRICS_POLLING_DELAY +
|
|
|
|
SERVER_KNOBS->STORAGE_METRICS_RANDOM_DELAY * deterministicRandom()->random01(),
|
|
|
|
TaskPriority::DataDistributionLaunch));
|
|
|
|
lastUpdate = now();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2022-02-05 02:59:01 +08:00
|
|
|
class TCTeamInfoImpl {
|
|
|
|
public:
|
|
|
|
ACTOR static Future<Void> updateStorageMetrics(TCTeamInfo* self) {
|
|
|
|
std::vector<Future<Void>> updates;
|
|
|
|
updates.reserve(self->servers.size());
|
|
|
|
for (int i = 0; i < self->servers.size(); i++)
|
|
|
|
updates.push_back(TCServerInfo::updateServerMetrics(self->servers[i]));
|
|
|
|
wait(waitForAll(updates));
|
|
|
|
return Void();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2022-02-11 11:19:50 +08:00
|
|
|
TCServerInfo::TCServerInfo(StorageServerInterface ssi,
|
|
|
|
DDTeamCollection* collection,
|
|
|
|
ProcessClass processClass,
|
|
|
|
bool inDesiredDC,
|
|
|
|
Reference<LocalitySet> storageServerSet,
|
|
|
|
Version addedVersion)
|
2022-02-12 04:52:09 +08:00
|
|
|
: id(ssi.id()), inDesiredDC(inDesiredDC), collection(collection), addedVersion(addedVersion), lastKnownInterface(ssi),
|
2022-02-12 05:49:16 +08:00
|
|
|
lastKnownClass(processClass), storeType(KeyValueStoreType::END), dataInFlightToServer(0),
|
|
|
|
onInterfaceChanged(interfaceChanged.getFuture()), onRemoved(removed.getFuture()), onTSSPairRemoved(Never()) {
|
2022-02-11 11:19:50 +08:00
|
|
|
|
|
|
|
if (!ssi.isTss()) {
|
|
|
|
localityEntry = ((LocalityMap<UID>*)storageServerSet.getPtr())->add(ssi.locality, &id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-16 14:43:06 +08:00
|
|
|
bool TCServerInfo::hasHealthyAvailableSpace(double minAvailableSpaceRatio) const {
|
2022-03-03 07:14:29 +08:00
|
|
|
ASSERT(metricsPresent());
|
2022-02-16 14:43:06 +08:00
|
|
|
|
2022-03-03 07:14:29 +08:00
|
|
|
auto& metrics = getMetrics();
|
2022-02-16 14:43:06 +08:00
|
|
|
ASSERT(metrics.available.bytes >= 0);
|
|
|
|
ASSERT(metrics.capacity.bytes >= 0);
|
|
|
|
|
|
|
|
double availableSpaceRatio;
|
|
|
|
if (metrics.capacity.bytes == 0) {
|
|
|
|
availableSpaceRatio = 0;
|
|
|
|
} else {
|
|
|
|
availableSpaceRatio = (((double)metrics.available.bytes) / metrics.capacity.bytes);
|
|
|
|
}
|
|
|
|
|
|
|
|
return availableSpaceRatio >= minAvailableSpaceRatio;
|
|
|
|
}
|
|
|
|
|
2022-03-15 07:02:42 +08:00
|
|
|
bool TCServerInfo::isWigglePausedServer() const {
|
|
|
|
return collection && collection->isWigglePausedServer(id);
|
|
|
|
}
|
|
|
|
|
2022-02-05 02:20:11 +08:00
|
|
|
Future<Void> TCServerInfo::updateServerMetrics() {
|
|
|
|
return TCServerInfoImpl::updateServerMetrics(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
Future<Void> TCServerInfo::updateServerMetrics(Reference<TCServerInfo> server) {
|
|
|
|
return TCServerInfoImpl::updateServerMetrics(server);
|
|
|
|
}
|
|
|
|
|
|
|
|
Future<Void> TCServerInfo::serverMetricsPolling() {
|
|
|
|
return TCServerInfoImpl::serverMetricsPolling(this);
|
|
|
|
}
|
|
|
|
|
2022-02-12 02:29:10 +08:00
|
|
|
void TCServerInfo::updateInDesiredDC(std::vector<Optional<Key>> const& includedDCs) {
|
|
|
|
inDesiredDC =
|
|
|
|
(includedDCs.empty() ||
|
|
|
|
std::find(includedDCs.begin(), includedDCs.end(), lastKnownInterface.locality.dcId()) != includedDCs.end());
|
|
|
|
}
|
|
|
|
|
2022-02-12 04:52:09 +08:00
|
|
|
void TCServerInfo::cancel() {
|
|
|
|
tracker.cancel();
|
|
|
|
collection = nullptr;
|
|
|
|
}
|
|
|
|
|
2022-02-12 05:49:16 +08:00
|
|
|
void TCServerInfo::updateLastKnown(StorageServerInterface const& ssi, ProcessClass processClass) {
|
|
|
|
lastKnownInterface = ssi;
|
|
|
|
lastKnownClass = processClass;
|
|
|
|
}
|
|
|
|
|
|
|
|
Future<Void> TCServerInfo::updateStoreType() {
|
|
|
|
return store(storeType,
|
|
|
|
brokenPromiseToNever(lastKnownInterface.getKeyValueStoreType.getReplyWithTaskID<KeyValueStoreType>(
|
|
|
|
TaskPriority::DataDistribution)));
|
|
|
|
}
|
|
|
|
|
2022-02-12 13:29:52 +08:00
|
|
|
void TCServerInfo::removeTeamsContainingServer(UID removedServer) {
|
|
|
|
for (int t = 0; t < teams.size(); t++) {
|
|
|
|
auto const& serverIds = teams[t]->getServerIDs();
|
|
|
|
if (std::count(serverIds.begin(), serverIds.end(), removedServer)) {
|
|
|
|
teams[t--] = teams.back();
|
|
|
|
teams.pop_back();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-03 06:29:43 +08:00
|
|
|
std::pair<int64_t, int64_t> TCServerInfo::spaceBytes(bool includeInFlight) const {
|
2022-03-03 07:14:29 +08:00
|
|
|
auto& metrics = getMetrics();
|
2022-03-03 05:42:56 +08:00
|
|
|
ASSERT(metrics.capacity.bytes >= 0);
|
|
|
|
ASSERT(metrics.available.bytes >= 0);
|
|
|
|
|
|
|
|
int64_t bytesAvailable = metrics.available.bytes;
|
|
|
|
if (includeInFlight) {
|
|
|
|
bytesAvailable -= getDataInFlightToServer();
|
|
|
|
}
|
|
|
|
|
|
|
|
return std::make_pair(bytesAvailable, metrics.capacity.bytes); // bytesAvailable could be negative
|
|
|
|
}
|
|
|
|
|
2022-03-03 06:29:43 +08:00
|
|
|
int64_t TCServerInfo::loadBytes() const {
|
2022-03-03 07:14:29 +08:00
|
|
|
return getMetrics().load.bytes;
|
2022-03-03 06:29:43 +08:00
|
|
|
}
|
|
|
|
|
2022-02-12 13:05:45 +08:00
|
|
|
void TCServerInfo::removeTeam(Reference<TCTeamInfo> team) {
|
|
|
|
for (int t = 0; t < teams.size(); t++) {
|
|
|
|
if (teams[t] == team) {
|
|
|
|
teams[t--] = teams.back();
|
|
|
|
teams.pop_back();
|
|
|
|
return; // The teams on a server should never duplicate
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-16 06:11:30 +08:00
|
|
|
void TCServerInfo::markTeamUnhealthy(int teamIndex) {
|
|
|
|
teams[teamIndex]->setHealthy(false);
|
|
|
|
}
|
|
|
|
|
2022-02-05 02:20:11 +08:00
|
|
|
TCServerInfo::~TCServerInfo() {
|
|
|
|
if (collection && ssVersionTooFarBehind.get() && !lastKnownInterface.isTss()) {
|
|
|
|
collection->removeLaggingStorageServer(lastKnownInterface.locality.zoneId().get());
|
|
|
|
}
|
|
|
|
}
|
2022-02-05 02:59:01 +08:00
|
|
|
|
2022-02-13 07:50:51 +08:00
|
|
|
bool TCMachineTeamInfo::matches(std::vector<Standalone<StringRef>> const& sortedMachineIDs) {
|
|
|
|
std::sort(machineIDs.begin(), machineIDs.end());
|
|
|
|
return sortedMachineIDs == machineIDs;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool TCMachineTeamInfo::removeServerTeam(Reference<TCTeamInfo> team) {
|
|
|
|
for (int t = 0; t < serverTeams.size(); ++t) {
|
|
|
|
if (serverTeams[t] == team) {
|
|
|
|
serverTeams[t--] = serverTeams.back();
|
|
|
|
serverTeams.pop_back();
|
|
|
|
return true; // The same team is added to the serverTeams only once
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2022-02-11 11:19:50 +08:00
|
|
|
Reference<TCMachineInfo> TCMachineInfo::clone() const {
|
|
|
|
auto result = Reference<TCMachineInfo>(new TCMachineInfo);
|
|
|
|
result->serversOnMachine = serversOnMachine;
|
|
|
|
result->machineID = machineID;
|
|
|
|
result->machineTeams = machineTeams;
|
|
|
|
result->localityEntry = localityEntry;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
TCMachineInfo::TCMachineInfo(Reference<TCServerInfo> server, const LocalityEntry& entry) : localityEntry(entry) {
|
|
|
|
ASSERT(serversOnMachine.empty());
|
|
|
|
serversOnMachine.push_back(server);
|
|
|
|
|
2022-02-12 05:49:16 +08:00
|
|
|
LocalityData const& locality = server->getLastKnownInterface().locality;
|
2022-02-11 11:19:50 +08:00
|
|
|
ASSERT(locality.zoneId().present());
|
|
|
|
machineID = locality.zoneId().get();
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string TCMachineInfo::getServersIDStr() const {
|
|
|
|
std::stringstream ss;
|
|
|
|
if (serversOnMachine.empty())
|
|
|
|
return "[unset]";
|
|
|
|
|
|
|
|
for (const auto& server : serversOnMachine) {
|
2022-02-11 15:04:25 +08:00
|
|
|
ss << server->getId().toString() << " ";
|
2022-02-11 11:19:50 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return std::move(ss).str();
|
|
|
|
}
|
|
|
|
|
|
|
|
TCMachineTeamInfo::TCMachineTeamInfo(std::vector<Reference<TCMachineInfo>> const& machines)
|
2022-02-12 14:56:16 +08:00
|
|
|
: _id(deterministicRandom()->randomUniqueID()), machines(machines) {
|
2022-02-11 11:19:50 +08:00
|
|
|
machineIDs.reserve(machines.size());
|
|
|
|
for (int i = 0; i < machines.size(); i++) {
|
|
|
|
machineIDs.push_back(machines[i]->machineID);
|
|
|
|
}
|
|
|
|
sort(machineIDs.begin(), machineIDs.end());
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string TCMachineTeamInfo::getMachineIDsStr() const {
|
|
|
|
std::stringstream ss;
|
|
|
|
|
|
|
|
if (machineIDs.empty())
|
|
|
|
return "[unset]";
|
|
|
|
|
|
|
|
for (const auto& id : machineIDs) {
|
|
|
|
ss << id.contents().toString() << " ";
|
|
|
|
}
|
|
|
|
|
|
|
|
return std::move(ss).str();
|
|
|
|
}
|
|
|
|
|
2022-06-22 07:29:30 +08:00
|
|
|
TCTeamInfo::TCTeamInfo(std::vector<Reference<TCServerInfo>> const& servers, Optional<Reference<TCTenantInfo>> tenant)
|
|
|
|
: servers(servers), tenant(tenant), healthy(true), wrongConfiguration(false),
|
|
|
|
priority(SERVER_KNOBS->PRIORITY_TEAM_HEALTHY), id(deterministicRandom()->randomUniqueID()) {
|
2022-02-11 11:19:50 +08:00
|
|
|
if (servers.empty()) {
|
|
|
|
TraceEvent(SevInfo, "ConstructTCTeamFromEmptyServers").log();
|
|
|
|
}
|
|
|
|
serverIDs.reserve(servers.size());
|
|
|
|
for (int i = 0; i < servers.size(); i++) {
|
2022-02-11 15:04:25 +08:00
|
|
|
serverIDs.push_back(servers[i]->getId());
|
2022-02-11 11:19:50 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-08 11:49:16 +08:00
|
|
|
// static
|
|
|
|
std::string TCTeamInfo::serversToString(std::vector<UID> servers) {
|
|
|
|
if (servers.empty()) {
|
|
|
|
return "[unset]";
|
|
|
|
}
|
|
|
|
|
|
|
|
std::sort(servers.begin(), servers.end());
|
|
|
|
std::stringstream ss;
|
|
|
|
for (const auto& id : servers) {
|
|
|
|
ss << id.toString() << " ";
|
|
|
|
}
|
|
|
|
|
|
|
|
return ss.str();
|
|
|
|
}
|
|
|
|
|
2022-02-11 11:19:50 +08:00
|
|
|
std::vector<StorageServerInterface> TCTeamInfo::getLastKnownServerInterfaces() const {
|
|
|
|
std::vector<StorageServerInterface> v;
|
|
|
|
v.reserve(servers.size());
|
|
|
|
for (const auto& server : servers) {
|
2022-02-12 05:49:16 +08:00
|
|
|
v.push_back(server->getLastKnownInterface());
|
2022-02-11 11:19:50 +08:00
|
|
|
}
|
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string TCTeamInfo::getServerIDsStr() const {
|
2022-07-08 11:49:16 +08:00
|
|
|
return serversToString(this->serverIDs);
|
2022-02-11 11:19:50 +08:00
|
|
|
}
|
|
|
|
|
2022-04-01 00:57:00 +08:00
|
|
|
void TCTeamInfo::addDataInFlightToTeam(int64_t delta) {
|
2022-02-11 11:19:50 +08:00
|
|
|
for (int i = 0; i < servers.size(); i++)
|
2022-04-01 00:57:00 +08:00
|
|
|
servers[i]->incrementDataInFlightToServer(delta);
|
|
|
|
}
|
|
|
|
|
|
|
|
void TCTeamInfo::addReadInFlightToTeam(int64_t delta) {
|
|
|
|
for (int i = 0; i < servers.size(); i++)
|
|
|
|
servers[i]->incrementReadInFlightToServer(delta);
|
2022-02-11 11:19:50 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int64_t TCTeamInfo::getDataInFlightToTeam() const {
|
|
|
|
int64_t dataInFlight = 0.0;
|
2022-02-12 05:55:07 +08:00
|
|
|
for (auto const& server : servers) {
|
|
|
|
dataInFlight += server->getDataInFlightToServer();
|
|
|
|
}
|
2022-02-11 11:19:50 +08:00
|
|
|
return dataInFlight;
|
|
|
|
}
|
|
|
|
|
2022-03-29 05:20:07 +08:00
|
|
|
int64_t TCTeamInfo::getReadInFlightToTeam() const {
|
|
|
|
int64_t inFlight = 0.0;
|
|
|
|
for (auto const& server : servers) {
|
|
|
|
inFlight += server->getReadInFlightToServer();
|
|
|
|
}
|
|
|
|
return inFlight;
|
|
|
|
}
|
|
|
|
|
2022-02-11 11:19:50 +08:00
|
|
|
int64_t TCTeamInfo::getLoadBytes(bool includeInFlight, double inflightPenalty) const {
|
|
|
|
int64_t physicalBytes = getLoadAverage();
|
|
|
|
double minAvailableSpaceRatio = getMinAvailableSpaceRatio(includeInFlight);
|
|
|
|
int64_t inFlightBytes = includeInFlight ? getDataInFlightToTeam() / servers.size() : 0;
|
|
|
|
double availableSpaceMultiplier =
|
|
|
|
SERVER_KNOBS->AVAILABLE_SPACE_RATIO_CUTOFF /
|
|
|
|
(std::max(std::min(SERVER_KNOBS->AVAILABLE_SPACE_RATIO_CUTOFF, minAvailableSpaceRatio), 0.000001));
|
|
|
|
if (servers.size() > 2) {
|
|
|
|
// make sure in triple replication the penalty is high enough that you will always avoid a team with a
|
|
|
|
// member at 20% free space
|
|
|
|
availableSpaceMultiplier = availableSpaceMultiplier * availableSpaceMultiplier;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (minAvailableSpaceRatio < SERVER_KNOBS->TARGET_AVAILABLE_SPACE_RATIO) {
|
|
|
|
TraceEvent(SevWarn, "DiskNearCapacity").suppressFor(1.0).detail("AvailableSpaceRatio", minAvailableSpaceRatio);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (physicalBytes + (inflightPenalty * inFlightBytes)) * availableSpaceMultiplier;
|
|
|
|
}
|
|
|
|
|
2022-04-21 03:15:40 +08:00
|
|
|
// average read bandwidth within a team
|
2022-04-01 00:57:00 +08:00
|
|
|
double TCTeamInfo::getLoadReadBandwidth(bool includeInFlight, double inflightPenalty) const {
|
|
|
|
// FIXME: consider team load variance
|
2022-03-01 02:22:32 +08:00
|
|
|
double sum = 0;
|
|
|
|
int size = 0;
|
|
|
|
for (const auto& server : servers) {
|
2022-03-25 09:38:50 +08:00
|
|
|
if (server->metricsPresent()) {
|
|
|
|
auto& replyValue = server->getMetrics();
|
2022-03-01 02:22:32 +08:00
|
|
|
ASSERT(replyValue.load.bytesReadPerKSecond >= 0);
|
|
|
|
sum += replyValue.load.bytesReadPerKSecond;
|
|
|
|
size += 1;
|
|
|
|
}
|
|
|
|
}
|
2022-03-29 05:20:07 +08:00
|
|
|
return (size == 0 ? 0 : sum / size) +
|
2022-05-04 08:21:08 +08:00
|
|
|
(includeInFlight ? inflightPenalty * getReadInFlightToTeam() / servers.size() : 0);
|
2022-03-01 02:22:32 +08:00
|
|
|
}
|
|
|
|
|
2022-02-11 11:19:50 +08:00
|
|
|
int64_t TCTeamInfo::getMinAvailableSpace(bool includeInFlight) const {
|
|
|
|
int64_t minAvailableSpace = std::numeric_limits<int64_t>::max();
|
|
|
|
for (const auto& server : servers) {
|
2022-03-03 07:14:29 +08:00
|
|
|
if (server->metricsPresent()) {
|
2022-03-03 06:29:43 +08:00
|
|
|
const auto [bytesAvailable, bytesCapacity] = server->spaceBytes(includeInFlight);
|
2022-02-11 11:19:50 +08:00
|
|
|
minAvailableSpace = std::min(bytesAvailable, minAvailableSpace);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return minAvailableSpace; // Could be negative
|
|
|
|
}
|
|
|
|
|
2022-02-25 08:41:01 +08:00
|
|
|
// return the min ratio of servers in this team
|
2022-02-11 11:19:50 +08:00
|
|
|
double TCTeamInfo::getMinAvailableSpaceRatio(bool includeInFlight) const {
|
|
|
|
double minRatio = 1.0;
|
|
|
|
for (const auto& server : servers) {
|
2022-03-03 07:14:29 +08:00
|
|
|
if (server->metricsPresent()) {
|
2022-03-03 06:29:43 +08:00
|
|
|
auto [bytesAvailable, bytesCapacity] = server->spaceBytes(includeInFlight);
|
2022-03-03 05:42:56 +08:00
|
|
|
bytesAvailable = std::max((int64_t)0, bytesAvailable);
|
2022-02-11 11:19:50 +08:00
|
|
|
|
2022-03-03 05:42:56 +08:00
|
|
|
if (bytesCapacity == 0)
|
2022-02-11 11:19:50 +08:00
|
|
|
minRatio = 0;
|
|
|
|
else
|
2022-03-03 05:42:56 +08:00
|
|
|
minRatio = std::min(minRatio, ((double)bytesAvailable) / bytesCapacity);
|
2022-02-11 11:19:50 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return minRatio;
|
|
|
|
}
|
|
|
|
|
2022-02-16 14:43:06 +08:00
|
|
|
bool TCTeamInfo::allServersHaveHealthyAvailableSpace() const {
|
|
|
|
bool result = true;
|
|
|
|
double minAvailableSpaceRatio =
|
2022-02-17 03:33:07 +08:00
|
|
|
SERVER_KNOBS->MIN_AVAILABLE_SPACE_RATIO + SERVER_KNOBS->MIN_AVAILABLE_SPACE_RATIO_SAFETY_BUFFER;
|
2022-02-16 14:43:06 +08:00
|
|
|
for (const auto& server : servers) {
|
2022-03-03 07:14:29 +08:00
|
|
|
if (!server->metricsPresent() || !server->hasHealthyAvailableSpace(minAvailableSpaceRatio)) {
|
2022-02-16 14:43:06 +08:00
|
|
|
result = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2022-02-11 11:19:50 +08:00
|
|
|
bool TCTeamInfo::hasHealthyAvailableSpace(double minRatio) const {
|
2022-02-16 14:43:06 +08:00
|
|
|
return getMinAvailableSpaceRatio() >= minRatio && getMinAvailableSpace() > SERVER_KNOBS->MIN_AVAILABLE_SPACE &&
|
|
|
|
allServersHaveHealthyAvailableSpace();
|
2022-02-11 11:19:50 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool TCTeamInfo::isOptimal() const {
|
|
|
|
for (const auto& server : servers) {
|
2022-02-12 05:49:16 +08:00
|
|
|
if (server->getLastKnownClass().machineClassFitness(ProcessClass::Storage) > ProcessClass::UnsetFit) {
|
2022-02-11 11:19:50 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool TCTeamInfo::hasServer(const UID& server) const {
|
|
|
|
return std::find(serverIDs.begin(), serverIDs.end(), server) != serverIDs.end();
|
|
|
|
}
|
|
|
|
|
2022-03-15 07:02:42 +08:00
|
|
|
bool TCTeamInfo::hasWigglePausedServer() const {
|
|
|
|
for (const auto& server : servers) {
|
|
|
|
if (server->isWigglePausedServer())
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2022-02-11 11:19:50 +08:00
|
|
|
void TCTeamInfo::addServers(const std::vector<UID>& servers) {
|
|
|
|
serverIDs.reserve(servers.size());
|
|
|
|
for (int i = 0; i < servers.size(); i++) {
|
|
|
|
serverIDs.push_back(servers[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int64_t TCTeamInfo::getLoadAverage() const {
|
|
|
|
int64_t bytesSum = 0;
|
|
|
|
int added = 0;
|
2022-03-03 06:29:43 +08:00
|
|
|
for (const auto& server : servers) {
|
2022-03-03 07:14:29 +08:00
|
|
|
if (server->metricsPresent()) {
|
2022-02-11 11:19:50 +08:00
|
|
|
added++;
|
2022-03-03 06:29:43 +08:00
|
|
|
bytesSum += server->loadBytes();
|
2022-02-11 11:19:50 +08:00
|
|
|
}
|
2022-03-03 06:29:43 +08:00
|
|
|
}
|
2022-02-11 11:19:50 +08:00
|
|
|
|
|
|
|
if (added < servers.size())
|
|
|
|
bytesSum *= 2;
|
|
|
|
|
|
|
|
return added == 0 ? 0 : bytesSum / added;
|
|
|
|
}
|
|
|
|
|
2022-02-05 02:59:01 +08:00
|
|
|
Future<Void> TCTeamInfo::updateStorageMetrics() {
|
|
|
|
return TCTeamInfoImpl::updateStorageMetrics(this);
|
|
|
|
}
|