add lastStateChange

This commit is contained in:
Xiaoxi Wang 2022-05-08 23:05:43 -07:00
parent 13bbd062c4
commit 487a81b62c
5 changed files with 17 additions and 7 deletions

View File

@ -5076,11 +5076,11 @@ bool DDTeamCollection::exclusionSafetyCheck(std::vector<UID>& excludeServerIDs)
return true;
}
StorageWiggler::State DDTeamCollection::getStorageWigglerState() const {
std::pair<StorageWiggler::State, double> DDTeamCollection::getStorageWigglerState() const {
if (storageWiggler) {
return storageWiggler->getState();
return { storageWiggler->getState(), storageWiggler->lastStateChangeTs };
}
return StorageWiggler::INVALID;
return { StorageWiggler::INVALID, 0.0 };
}
Future<Void> DDTeamCollection::run(Reference<DDTeamCollection> teamCollection,

View File

@ -664,7 +664,8 @@ public:
bool isPrimary() const { return primary; }
StorageWiggler::State getStorageWigglerState() const;
// state and last state change timestamp
std::pair<StorageWiggler::State, double> getStorageWigglerState() const;
UID getDistributorId() const { return distributorId; }

View File

@ -1230,9 +1230,10 @@ static int64_t getMedianShardSize(VectorRef<DDMetricsRef> metricVec) {
GetStorageWigglerStateReply getStorageWigglerStates(Reference<DataDistributorData> self) {
GetStorageWigglerStateReply reply;
if (self->teamCollection) {
reply.primary = self->teamCollection->getStorageWigglerState();
std::tie(reply.primary, reply.lastStateChangePrimary) = self->teamCollection->getStorageWigglerState();
if (self->teamCollection->teamCollections.size() > 1) {
reply.remote = self->teamCollection->teamCollections[1]->getStorageWigglerState();
std::tie(reply.remote, reply.lastStateChangeRemote) =
self->teamCollection->teamCollections[1]->getStorageWigglerState();
}
}
return reply;

View File

@ -402,6 +402,8 @@ struct StorageWiggler : ReferenceCounted<StorageWiggler> {
std::unordered_map<UID, decltype(wiggle_pq)::handle_type> pq_handles;
State _state = State::INVALID;
double lastStateChangeTs = 0.0; // timestamp describes when did the state change
explicit StorageWiggler(DDTeamCollection* collection) : nonEmpty(false), teamCollection(collection){};
// add server to wiggling queue
void addServer(const UID& serverId, const StorageMetadataType& metadata);
@ -414,7 +416,12 @@ struct StorageWiggler : ReferenceCounted<StorageWiggler> {
Optional<UID> getNextServerId();
State getState() const { return _state; }
void setState(State s) { _state = s; }
void setState(State s) {
if (_state != s) {
_state = s;
lastStateChangeTs = g_network->now();
}
}
static std::string getStateStr(State s) {
switch (s) {
case State::RUN:

View File

@ -170,6 +170,7 @@ struct DistributorSplitRangeRequest {
struct GetStorageWigglerStateReply {
constexpr static FileIdentifier file_identifier = 356721;
uint8_t primary = 0, remote = 0; // StorageWiggler::State enum
double lastStateChangePrimary = 0.0, lastStateChangeRemote = 0.0;
GetStorageWigglerStateReply() {}
template <class Ar>