2017-05-26 04:48:44 +08:00
|
|
|
/*
|
2019-03-06 02:29:37 +08:00
|
|
|
* DataDistribution.actor.h
|
2017-05-26 04:48:44 +08:00
|
|
|
*
|
|
|
|
* This source file is part of the FoundationDB open source project
|
|
|
|
*
|
|
|
|
* Copyright 2013-2018 Apple Inc. and the FoundationDB project authors
|
2018-02-22 02:25:11 +08:00
|
|
|
*
|
2017-05-26 04:48: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
|
2018-02-22 02:25:11 +08:00
|
|
|
*
|
2017-05-26 04:48:44 +08:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2018-02-22 02:25:11 +08:00
|
|
|
*
|
2017-05-26 04:48:44 +08:00
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2019-03-06 02:29:37 +08:00
|
|
|
#if defined(NO_INTELLISENSE) && !defined(FDBSERVER_DATA_DISTRIBUTION_ACTOR_G_H)
|
|
|
|
#define FDBSERVER_DATA_DISTRIBUTION_ACTOR_G_H
|
|
|
|
#include "fdbserver/DataDistribution.actor.g.h"
|
|
|
|
#elif !defined(FDBSERVER_DATA_DISTRIBUTION_ACTOR_H)
|
|
|
|
#define FDBSERVER_DATA_DISTRIBUTION_ACTOR_H
|
|
|
|
|
2022-02-05 07:04:30 +08:00
|
|
|
#include <boost/heap/skew_heap.hpp>
|
|
|
|
#include <boost/heap/policies.hpp>
|
2019-02-18 07:41:16 +08:00
|
|
|
#include "fdbclient/NativeAPI.actor.h"
|
2019-02-18 10:55:52 +08:00
|
|
|
#include "fdbserver/MoveKeys.actor.h"
|
2018-10-20 01:30:13 +08:00
|
|
|
#include "fdbserver/LogSystem.h"
|
2022-02-05 07:04:30 +08:00
|
|
|
#include "fdbclient/RunTransaction.actor.h"
|
2019-03-06 02:29:37 +08:00
|
|
|
#include "flow/actorcompiler.h" // This must be the last #include.
|
2017-05-26 04:48:44 +08:00
|
|
|
|
|
|
|
struct RelocateShard {
|
|
|
|
KeyRange keys;
|
|
|
|
int priority;
|
|
|
|
|
2018-04-09 12:24:05 +08:00
|
|
|
RelocateShard() : priority(0) {}
|
2021-03-11 02:06:03 +08:00
|
|
|
RelocateShard(KeyRange const& keys, int priority) : keys(keys), priority(priority) {}
|
2017-05-26 04:48:44 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
struct IDataDistributionTeam {
|
2021-09-17 08:42:34 +08:00
|
|
|
virtual std::vector<StorageServerInterface> getLastKnownServerInterfaces() const = 0;
|
2020-07-21 15:08:01 +08:00
|
|
|
virtual int size() const = 0;
|
2021-09-17 08:42:34 +08:00
|
|
|
virtual std::vector<UID> const& getServerIDs() const = 0;
|
2021-03-11 02:06:03 +08:00
|
|
|
virtual void addDataInFlightToTeam(int64_t delta) = 0;
|
2020-07-21 15:08:01 +08:00
|
|
|
virtual int64_t getDataInFlightToTeam() const = 0;
|
|
|
|
virtual int64_t getLoadBytes(bool includeInFlight = true, double inflightPenalty = 1.0) const = 0;
|
|
|
|
virtual int64_t getMinAvailableSpace(bool includeInFlight = true) const = 0;
|
|
|
|
virtual double getMinAvailableSpaceRatio(bool includeInFlight = true) const = 0;
|
|
|
|
virtual bool hasHealthyAvailableSpace(double minRatio) const = 0;
|
2019-07-26 07:27:32 +08:00
|
|
|
virtual Future<Void> updateStorageMetrics() = 0;
|
2017-05-26 04:48:44 +08:00
|
|
|
virtual void addref() = 0;
|
|
|
|
virtual void delref() = 0;
|
2020-07-21 15:08:01 +08:00
|
|
|
virtual bool isHealthy() const = 0;
|
2017-05-26 04:48:44 +08:00
|
|
|
virtual void setHealthy(bool) = 0;
|
2020-07-21 15:08:01 +08:00
|
|
|
virtual int getPriority() const = 0;
|
2017-05-26 04:48:44 +08:00
|
|
|
virtual void setPriority(int) = 0;
|
2020-07-21 15:08:01 +08:00
|
|
|
virtual bool isOptimal() const = 0;
|
|
|
|
virtual bool isWrongConfiguration() const = 0;
|
2017-05-26 04:48:44 +08:00
|
|
|
virtual void setWrongConfiguration(bool) = 0;
|
2021-09-17 08:42:34 +08:00
|
|
|
virtual void addServers(const std::vector<UID>& servers) = 0;
|
2020-11-17 06:46:36 +08:00
|
|
|
virtual std::string getTeamID() const = 0;
|
2017-05-26 04:48:44 +08:00
|
|
|
|
2020-07-21 15:08:01 +08:00
|
|
|
std::string getDesc() const {
|
2017-05-26 04:48:44 +08:00
|
|
|
const auto& servers = getLastKnownServerInterfaces();
|
2020-10-24 01:06:22 +08:00
|
|
|
std::string s = format("TeamID:%s", getTeamID().c_str());
|
2020-10-22 02:10:14 +08:00
|
|
|
s += format("Size %d; ", servers.size());
|
2021-03-11 02:06:03 +08:00
|
|
|
for (int i = 0; i < servers.size(); i++) {
|
|
|
|
if (i)
|
|
|
|
s += ", ";
|
2017-05-26 04:48:44 +08:00
|
|
|
s += servers[i].address().toString() + " " + servers[i].id().shortString();
|
|
|
|
}
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct GetTeamRequest {
|
|
|
|
bool wantsNewServers;
|
|
|
|
bool wantsTrueBest;
|
|
|
|
bool preferLowerUtilization;
|
2020-02-21 02:59:52 +08:00
|
|
|
bool teamMustHaveShards;
|
2017-05-26 04:48:44 +08:00
|
|
|
double inflightPenalty;
|
2018-02-03 03:46:04 +08:00
|
|
|
std::vector<UID> completeSources;
|
2020-06-30 01:02:27 +08:00
|
|
|
std::vector<UID> src;
|
2021-03-11 02:06:03 +08:00
|
|
|
Promise<std::pair<Optional<Reference<IDataDistributionTeam>>, bool>> reply;
|
2017-05-26 04:48:44 +08:00
|
|
|
|
|
|
|
GetTeamRequest() {}
|
2021-03-11 02:06:03 +08:00
|
|
|
GetTeamRequest(bool wantsNewServers,
|
|
|
|
bool wantsTrueBest,
|
|
|
|
bool preferLowerUtilization,
|
|
|
|
bool teamMustHaveShards,
|
|
|
|
double inflightPenalty = 1.0)
|
|
|
|
: wantsNewServers(wantsNewServers), wantsTrueBest(wantsTrueBest), preferLowerUtilization(preferLowerUtilization),
|
|
|
|
teamMustHaveShards(teamMustHaveShards), inflightPenalty(inflightPenalty) {}
|
2020-12-27 07:37:54 +08:00
|
|
|
|
|
|
|
std::string getDesc() const {
|
2019-09-08 11:05:59 +08:00
|
|
|
std::stringstream ss;
|
|
|
|
|
2019-09-12 02:16:29 +08:00
|
|
|
ss << "WantsNewServers:" << wantsNewServers << " WantsTrueBest:" << wantsTrueBest
|
2021-03-11 02:06:03 +08:00
|
|
|
<< " PreferLowerUtilization:" << preferLowerUtilization << " teamMustHaveShards:" << teamMustHaveShards
|
2020-02-22 11:09:16 +08:00
|
|
|
<< " inflightPenalty:" << inflightPenalty << ";";
|
2019-09-08 11:05:59 +08:00
|
|
|
ss << "CompleteSources:";
|
2020-12-27 07:37:54 +08:00
|
|
|
for (const auto& cs : completeSources) {
|
2019-09-08 11:05:59 +08:00
|
|
|
ss << cs.toString() << ",";
|
|
|
|
}
|
|
|
|
|
2020-12-27 07:37:54 +08:00
|
|
|
return std::move(ss).str();
|
2019-09-08 11:05:59 +08:00
|
|
|
}
|
2017-05-26 04:48:44 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
struct GetMetricsRequest {
|
|
|
|
KeyRange keys;
|
2021-03-11 02:06:03 +08:00
|
|
|
Promise<StorageMetrics> reply;
|
2017-05-26 04:48:44 +08:00
|
|
|
|
|
|
|
GetMetricsRequest() {}
|
2021-03-11 02:06:03 +08:00
|
|
|
GetMetricsRequest(KeyRange const& keys) : keys(keys) {}
|
2017-05-26 04:48:44 +08:00
|
|
|
};
|
|
|
|
|
2019-05-17 07:46:33 +08:00
|
|
|
struct GetMetricsListRequest {
|
|
|
|
KeyRange keys;
|
2019-05-18 07:11:50 +08:00
|
|
|
int shardLimit;
|
2020-05-09 08:17:27 +08:00
|
|
|
Promise<Standalone<VectorRef<DDMetricsRef>>> reply;
|
2019-05-17 07:46:33 +08:00
|
|
|
|
|
|
|
GetMetricsListRequest() {}
|
2021-03-11 02:06:03 +08:00
|
|
|
GetMetricsListRequest(KeyRange const& keys, const int shardLimit) : keys(keys), shardLimit(shardLimit) {}
|
2019-05-17 07:46:33 +08:00
|
|
|
};
|
|
|
|
|
2017-05-26 04:48:44 +08:00
|
|
|
struct TeamCollectionInterface {
|
2021-03-11 02:06:03 +08:00
|
|
|
PromiseStream<GetTeamRequest> getTeam;
|
2017-05-26 04:48:44 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
class ShardsAffectedByTeamFailure : public ReferenceCounted<ShardsAffectedByTeamFailure> {
|
|
|
|
public:
|
|
|
|
ShardsAffectedByTeamFailure() {}
|
2019-07-10 07:09:51 +08:00
|
|
|
|
2018-03-09 02:50:05 +08:00
|
|
|
struct Team {
|
2021-09-17 08:42:34 +08:00
|
|
|
std::vector<UID> servers; // sorted
|
2018-03-09 02:50:05 +08:00
|
|
|
bool primary;
|
|
|
|
|
|
|
|
Team() : primary(true) {}
|
2021-09-17 08:42:34 +08:00
|
|
|
Team(std::vector<UID> const& servers, bool primary) : servers(servers), primary(primary) {}
|
2018-03-09 02:50:05 +08:00
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
bool operator<(const Team& r) const {
|
|
|
|
if (servers == r.servers)
|
|
|
|
return primary < r.primary;
|
2019-07-10 07:09:51 +08:00
|
|
|
return servers < r.servers;
|
2018-03-09 02:50:05 +08:00
|
|
|
}
|
2020-07-11 05:37:47 +08:00
|
|
|
bool operator>(const Team& r) const { return r < *this; }
|
|
|
|
bool operator<=(const Team& r) const { return !(*this > r); }
|
|
|
|
bool operator>=(const Team& r) const { return !(*this < r); }
|
2021-03-11 02:06:03 +08:00
|
|
|
bool operator==(const Team& r) const { return servers == r.servers && primary == r.primary; }
|
2020-07-11 05:37:47 +08:00
|
|
|
bool operator!=(const Team& r) const { return !(*this == r); }
|
2018-03-09 02:50:05 +08:00
|
|
|
};
|
|
|
|
|
2017-05-26 04:48:44 +08:00
|
|
|
// This tracks the data distribution on the data distribution server so that teamTrackers can
|
|
|
|
// relocate the right shards when a team is degraded.
|
|
|
|
|
|
|
|
// The following are important to make sure that failure responses don't revert splits or merges:
|
|
|
|
// - The shards boundaries in the two data structures reflect "queued" RelocateShard requests
|
|
|
|
// (i.e. reflects the desired set of shards being tracked by dataDistributionTracker,
|
|
|
|
// rather than the status quo). These boundaries are modified in defineShard and the content
|
|
|
|
// of what servers correspond to each shard is a copy or union of the shards already there
|
|
|
|
// - The teams associated with each shard reflect either the sources for non-moving shards
|
|
|
|
// or the destination team for in-flight shards (the change is atomic with respect to team selection).
|
|
|
|
// moveShard() changes the servers associated with a shard and will never adjust the shard
|
|
|
|
// boundaries. If a move is received for a shard that has been redefined (the exact shard is
|
|
|
|
// no longer in the map), the servers will be set for all contained shards and added to all
|
|
|
|
// intersecting shards.
|
|
|
|
|
2020-12-27 07:37:54 +08:00
|
|
|
int getNumberOfShards(UID ssID) const;
|
2021-09-17 08:42:34 +08:00
|
|
|
std::vector<KeyRange> getShardsFor(Team team);
|
2020-12-27 07:37:54 +08:00
|
|
|
bool hasShards(Team team) const;
|
2018-11-13 10:42:29 +08:00
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
// The first element of the pair is either the source for non-moving shards or the destination team for in-flight
|
|
|
|
// shards The second element of the pair is all previous sources for in-flight shards
|
2021-09-17 08:42:34 +08:00
|
|
|
std::pair<std::vector<Team>, std::vector<Team>> getTeamsFor(KeyRangeRef keys);
|
2018-11-13 10:42:29 +08:00
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
void defineShard(KeyRangeRef keys);
|
|
|
|
void moveShard(KeyRangeRef keys, std::vector<Team> destinationTeam);
|
|
|
|
void finishMove(KeyRangeRef keys);
|
2017-05-26 04:48:44 +08:00
|
|
|
void check();
|
2021-03-11 02:06:03 +08:00
|
|
|
|
2017-05-26 04:48:44 +08:00
|
|
|
private:
|
|
|
|
struct OrderByTeamKey {
|
2021-03-11 02:06:03 +08:00
|
|
|
bool operator()(const std::pair<Team, KeyRange>& lhs, const std::pair<Team, KeyRange>& rhs) const {
|
|
|
|
if (lhs.first < rhs.first)
|
|
|
|
return true;
|
|
|
|
if (lhs.first > rhs.first)
|
|
|
|
return false;
|
2017-05-26 04:48:44 +08:00
|
|
|
return lhs.second.begin < rhs.second.begin;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-09-17 08:42:34 +08:00
|
|
|
KeyRangeMap<std::pair<std::vector<Team>, std::vector<Team>>>
|
2021-03-11 02:06:03 +08:00
|
|
|
shard_teams; // A shard can be affected by the failure of multiple teams if it is a queued merge, or when
|
|
|
|
// usable_regions > 1
|
|
|
|
std::set<std::pair<Team, KeyRange>, OrderByTeamKey> team_shards;
|
|
|
|
std::map<UID, int> storageServerShards;
|
2017-05-26 04:48:44 +08:00
|
|
|
|
|
|
|
void erase(Team team, KeyRange const& range);
|
|
|
|
void insert(Team team, KeyRange const& range);
|
|
|
|
};
|
|
|
|
|
2018-07-01 09:44:46 +08:00
|
|
|
// DDShardInfo is so named to avoid link-time name collision with ShardInfo within the StorageServer
|
|
|
|
struct DDShardInfo {
|
2018-03-09 02:50:05 +08:00
|
|
|
Key key;
|
2021-09-17 08:42:34 +08:00
|
|
|
std::vector<UID> primarySrc;
|
|
|
|
std::vector<UID> remoteSrc;
|
|
|
|
std::vector<UID> primaryDest;
|
|
|
|
std::vector<UID> remoteDest;
|
2018-03-09 02:50:05 +08:00
|
|
|
bool hasDest;
|
|
|
|
|
2018-07-01 09:44:46 +08:00
|
|
|
explicit DDShardInfo(Key key) : key(key), hasDest(false) {}
|
2018-03-09 02:50:05 +08:00
|
|
|
};
|
|
|
|
|
2017-05-26 04:48:44 +08:00
|
|
|
struct InitialDataDistribution : ReferenceCounted<InitialDataDistribution> {
|
|
|
|
int mode;
|
2021-09-17 08:42:34 +08:00
|
|
|
std::vector<std::pair<StorageServerInterface, ProcessClass>> allServers;
|
|
|
|
std::set<std::vector<UID>> primaryTeams;
|
|
|
|
std::set<std::vector<UID>> remoteTeams;
|
|
|
|
std::vector<DDShardInfo> shards;
|
2019-07-10 07:09:51 +08:00
|
|
|
Optional<Key> initHealthyZoneValue;
|
2017-05-26 04:48:44 +08:00
|
|
|
};
|
|
|
|
|
2020-10-01 03:22:23 +08:00
|
|
|
struct ShardMetrics {
|
|
|
|
StorageMetrics metrics;
|
|
|
|
double lastLowBandwidthStartTime;
|
2020-10-28 00:11:56 +08:00
|
|
|
int shardCount; // number of smaller shards whose metrics are aggregated in the ShardMetrics
|
2020-10-01 03:22:23 +08:00
|
|
|
|
|
|
|
bool operator==(ShardMetrics const& rhs) const {
|
|
|
|
return metrics == rhs.metrics && lastLowBandwidthStartTime == rhs.lastLowBandwidthStartTime &&
|
|
|
|
shardCount == rhs.shardCount;
|
|
|
|
}
|
|
|
|
|
|
|
|
ShardMetrics(StorageMetrics const& metrics, double lastLowBandwidthStartTime, int shardCount)
|
|
|
|
: metrics(metrics), lastLowBandwidthStartTime(lastLowBandwidthStartTime), shardCount(shardCount) {}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct ShardTrackedData {
|
|
|
|
Future<Void> trackShard;
|
|
|
|
Future<Void> trackBytes;
|
|
|
|
Reference<AsyncVar<Optional<ShardMetrics>>> stats;
|
|
|
|
};
|
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
ACTOR Future<Void> dataDistributionTracker(Reference<InitialDataDistribution> initData,
|
|
|
|
Database cx,
|
2020-12-05 07:58:42 +08:00
|
|
|
PromiseStream<RelocateShard> output,
|
|
|
|
Reference<ShardsAffectedByTeamFailure> shardsAffectedByTeamFailure,
|
|
|
|
PromiseStream<GetMetricsRequest> getShardMetrics,
|
|
|
|
PromiseStream<GetMetricsListRequest> getShardMetricsList,
|
|
|
|
FutureStream<Promise<int64_t>> getAverageShardBytes,
|
2021-03-11 02:06:03 +08:00
|
|
|
Promise<Void> readyToStart,
|
|
|
|
Reference<AsyncVar<bool>> zeroHealthyTeams,
|
|
|
|
UID distributorId,
|
|
|
|
KeyRangeMap<ShardTrackedData>* shards,
|
2021-02-11 09:13:19 +08:00
|
|
|
bool* trackerCancelled);
|
2020-09-28 06:26:50 +08:00
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
ACTOR Future<Void> dataDistributionQueue(Database cx,
|
|
|
|
PromiseStream<RelocateShard> output,
|
|
|
|
FutureStream<RelocateShard> input,
|
|
|
|
PromiseStream<GetMetricsRequest> getShardMetrics,
|
|
|
|
Reference<AsyncVar<bool>> processingUnhealthy,
|
2021-10-15 07:22:47 +08:00
|
|
|
Reference<AsyncVar<bool>> processingWiggle,
|
2021-09-17 08:42:34 +08:00
|
|
|
std::vector<TeamCollectionInterface> teamCollection,
|
2021-03-11 02:06:03 +08:00
|
|
|
Reference<ShardsAffectedByTeamFailure> shardsAffectedByTeamFailure,
|
|
|
|
MoveKeysLock lock,
|
|
|
|
PromiseStream<Promise<int64_t>> getAverageShardBytes,
|
2021-05-21 07:31:08 +08:00
|
|
|
PromiseStream<Promise<int>> getUnhealthyRelocationCount,
|
2021-03-11 02:06:03 +08:00
|
|
|
UID distributorId,
|
|
|
|
int teamSize,
|
|
|
|
int singleRegionTeamSize,
|
|
|
|
double* lastLimited,
|
|
|
|
const DDEnabledState* ddEnabledState);
|
|
|
|
|
|
|
|
// Holds the permitted size and IO Bounds for a shard
|
2017-05-26 04:48:44 +08:00
|
|
|
struct ShardSizeBounds {
|
|
|
|
StorageMetrics max;
|
|
|
|
StorageMetrics min;
|
|
|
|
StorageMetrics permittedError;
|
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
bool operator==(ShardSizeBounds const& rhs) const {
|
2017-05-26 04:48:44 +08:00
|
|
|
return max == rhs.max && min == rhs.min && permittedError == rhs.permittedError;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
// Gets the permitted size and IO bounds for a shard
|
2017-05-26 04:48:44 +08:00
|
|
|
ShardSizeBounds getShardSizeBounds(KeyRangeRef shard, int64_t maxShardSize);
|
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
// Determines the maximum shard size based on the size of the database
|
|
|
|
int64_t getMaxShardSize(double dbSizeEstimate);
|
2019-02-07 15:34:56 +08:00
|
|
|
|
2022-02-04 16:39:42 +08:00
|
|
|
class DDTeamCollection;
|
2022-02-08 16:33:27 +08:00
|
|
|
|
2022-02-05 07:04:30 +08:00
|
|
|
struct StorageWiggleMetrics {
|
|
|
|
constexpr static FileIdentifier file_identifier = 4728961;
|
|
|
|
|
|
|
|
// round statistics
|
|
|
|
// One StorageServer wiggle round is considered 'complete', when all StorageServers with creationTime < T are
|
|
|
|
// wiggled
|
|
|
|
uint64_t last_round_start = 0; // wall timer: timer_int()
|
|
|
|
uint64_t last_round_finish = 0;
|
|
|
|
TimerSmoother smoothed_round_duration;
|
|
|
|
int finished_round = 0; // finished round since storage wiggle is open
|
|
|
|
|
|
|
|
// step statistics
|
|
|
|
// 1 wiggle step as 1 storage server is wiggled in the current round
|
|
|
|
uint64_t last_wiggle_start = 0; // wall timer: timer_int()
|
|
|
|
uint64_t last_wiggle_finish = 0;
|
|
|
|
TimerSmoother smoothed_wiggle_duration;
|
|
|
|
int finished_wiggle = 0; // finished step since storage wiggle is open
|
|
|
|
|
|
|
|
StorageWiggleMetrics() : smoothed_round_duration(20.0 * 60), smoothed_wiggle_duration(10.0 * 60) {}
|
|
|
|
|
|
|
|
template <class Ar>
|
|
|
|
void serialize(Ar& ar) {
|
|
|
|
if (ar.isDeserializing) {
|
|
|
|
double step_total, round_total;
|
|
|
|
serializer(ar,
|
|
|
|
last_wiggle_start,
|
|
|
|
last_wiggle_finish,
|
|
|
|
step_total,
|
|
|
|
finished_wiggle,
|
|
|
|
last_round_start,
|
|
|
|
last_round_finish,
|
|
|
|
round_total,
|
|
|
|
finished_round);
|
|
|
|
smoothed_round_duration.reset(round_total);
|
|
|
|
smoothed_wiggle_duration.reset(step_total);
|
|
|
|
} else {
|
|
|
|
serializer(ar,
|
|
|
|
last_wiggle_start,
|
|
|
|
last_wiggle_finish,
|
|
|
|
smoothed_wiggle_duration.total,
|
|
|
|
finished_wiggle,
|
|
|
|
last_round_start,
|
|
|
|
last_round_finish,
|
|
|
|
smoothed_round_duration.total,
|
|
|
|
finished_round);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static Future<Void> runSetTransaction(Reference<ReadYourWritesTransaction> tr,
|
|
|
|
bool primary,
|
|
|
|
StorageWiggleMetrics metrics) {
|
|
|
|
tr->setOption(FDBTransactionOptions::ACCESS_SYSTEM_KEYS);
|
|
|
|
tr->setOption(FDBTransactionOptions::LOCK_AWARE);
|
|
|
|
tr->set(perpetualStorageWiggleStatsPrefix.withSuffix(primary ? "primary"_sr : "remote"_sr),
|
|
|
|
ObjectWriter::toValue(metrics, IncludeVersion()));
|
|
|
|
return Void();
|
|
|
|
}
|
|
|
|
|
|
|
|
static Future<Void> runSetTransaction(Database cx, bool primary, StorageWiggleMetrics metrics) {
|
|
|
|
return runRYWTransaction(cx, [=](Reference<ReadYourWritesTransaction> tr) -> Future<Void> {
|
|
|
|
return runSetTransaction(tr, primary, metrics);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
static Future<Optional<Value>> runGetTransaction(Reference<ReadYourWritesTransaction> tr, bool primary) {
|
|
|
|
tr->setOption(FDBTransactionOptions::READ_SYSTEM_KEYS);
|
|
|
|
tr->setOption(FDBTransactionOptions::READ_LOCK_AWARE);
|
|
|
|
return tr->get(perpetualStorageWiggleStatsPrefix.withSuffix(primary ? "primary"_sr : "remote"_sr));
|
|
|
|
}
|
|
|
|
|
|
|
|
static Future<Optional<Value>> runGetTransaction(Database cx, bool primary) {
|
|
|
|
return runRYWTransaction(cx, [=](Reference<ReadYourWritesTransaction> tr) -> Future<Optional<Value>> {
|
|
|
|
return runGetTransaction(tr, primary);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
StatusObject toJSON() {
|
|
|
|
StatusObject result;
|
|
|
|
result["last_round_start_datetime"] = timerIntToGmt(last_round_start);
|
|
|
|
result["last_round_finish_datetime"] = timerIntToGmt(last_round_finish);
|
|
|
|
result["last_round_start_timestamp"] = last_round_start;
|
|
|
|
result["last_round_finish_timestamp"] = last_round_finish;
|
|
|
|
result["smoothed_round_seconds"] = smoothed_round_duration.estimate;
|
|
|
|
result["finished_round"] = finished_round;
|
|
|
|
|
|
|
|
result["last_wiggle_start_datetime"] = timerIntToGmt(last_wiggle_start);
|
|
|
|
result["last_wiggle_finish_datetime"] = timerIntToGmt(last_wiggle_finish);
|
|
|
|
result["last_wiggle_start_timestamp"] = last_wiggle_start;
|
|
|
|
result["last_wiggle_finish_timestamp"] = last_wiggle_finish;
|
|
|
|
result["smoothed_wiggle_seconds"] = smoothed_wiggle_duration.estimate;
|
|
|
|
result["finished_wiggle"] = finished_wiggle;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct StorageWiggler : ReferenceCounted<StorageWiggler> {
|
|
|
|
DDTeamCollection* teamCollection;
|
|
|
|
StorageWiggleMetrics metrics;
|
|
|
|
|
|
|
|
// data structures
|
|
|
|
typedef std::pair<StorageMetadataType, UID> MetadataUIDP;
|
|
|
|
// sorted by (createdTime, UID), the least comes first
|
|
|
|
struct CompPair {
|
|
|
|
bool operator()(MetadataUIDP const& a, MetadataUIDP const& b) const {
|
|
|
|
if (a.first.createdTime == b.first.createdTime) {
|
|
|
|
return a.second > b.second;
|
|
|
|
}
|
|
|
|
// larger createdTime means the age is younger
|
|
|
|
return a.first.createdTime > b.first.createdTime;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
boost::heap::skew_heap<MetadataUIDP, boost::heap::mutable_<true>, boost::heap::compare<CompPair>> wiggle_pq;
|
|
|
|
std::unordered_map<UID, decltype(wiggle_pq)::handle_type> pq_handles;
|
|
|
|
|
|
|
|
AsyncVar<bool> nonEmpty;
|
|
|
|
|
|
|
|
explicit StorageWiggler(DDTeamCollection* collection) : teamCollection(collection), nonEmpty(false){};
|
|
|
|
// add server to wiggling queue
|
|
|
|
void addServer(const UID& serverId, const StorageMetadataType& metadata);
|
|
|
|
// remove server from wiggling queue
|
|
|
|
void removeServer(const UID& serverId);
|
|
|
|
// update metadata and adjust priority_queue
|
|
|
|
void updateMetadata(const UID& serverId, const StorageMetadataType& metadata);
|
|
|
|
bool contains(const UID& serverId) { return pq_handles.count(serverId) > 0; }
|
|
|
|
bool empty() { return wiggle_pq.empty(); }
|
|
|
|
Optional<UID> getNextServerId();
|
|
|
|
|
|
|
|
// -- statistic update
|
|
|
|
|
|
|
|
// reset Statistic in database when perpetual wiggle is closed by user
|
|
|
|
Future<Void> resetStats();
|
|
|
|
// restore Statistic from database when the perpetual wiggle is opened
|
|
|
|
Future<Void> restoreStats();
|
|
|
|
// called when start wiggling a SS
|
|
|
|
Future<Void> startWiggle();
|
|
|
|
Future<Void> finishWiggle();
|
|
|
|
bool shouldStartNewRound() { return metrics.last_round_finish >= metrics.last_round_start; }
|
|
|
|
bool shouldFinishRound() {
|
|
|
|
if (wiggle_pq.empty())
|
|
|
|
return true;
|
|
|
|
return (wiggle_pq.top().first.createdTime >= metrics.last_round_start);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-09-17 08:42:34 +08:00
|
|
|
ACTOR Future<std::vector<std::pair<StorageServerInterface, ProcessClass>>> getServerListAndProcessClasses(
|
|
|
|
Transaction* tr);
|
2019-03-06 02:29:37 +08:00
|
|
|
|
2019-04-06 01:36:38 +08:00
|
|
|
#include "flow/unactorcompiler.h"
|
2019-03-06 02:29:37 +08:00
|
|
|
#endif
|