ServerCounter.traceAll()

This commit is contained in:
Xiaoxi Wang 2022-08-05 15:01:49 -07:00
parent 3252d420a2
commit 07b7627361
2 changed files with 55 additions and 12 deletions

View File

@ -541,10 +541,23 @@ struct DDQueue {
struct ServerCounter {
enum CountType { ProposedSource = 0, QueuedSource, LaunchedSource, LaunchedDest };
private:
typedef std::array<int, 4> Item; // one for each CountType
typedef std::array<Item, 3> ReasonItem; // one for each RelocateReason
std::unordered_map<UID, ReasonItem> counter;
std::string toString(const Item& item) const {
return format("%d %d %d %d", item[0], item[1], item[2], item[3]);
}
void traceReasonItem(TraceEvent* event, const ReasonItem& item) const {
for (int i = 0; i < item.size(); ++i) {
event->detail(RelocateReason(i).toString(), toString(item[i]));
}
}
public:
void clear() { counter.clear(); }
bool has(const UID& id) const { return counter.find(id) != counter.end(); }
int& get(const UID& id, RelocateReason reason, CountType type) {
@ -558,6 +571,14 @@ struct DDQueue {
get(id, reason, type)++;
}
}
void traceAll(const UID& debugId = UID()) const {
for (auto& [id, reasonItem] : counter) {
TraceEvent event("DDQueueServerCounter", debugId);
event.detail("ServerId", id);
traceReasonItem(&event, reasonItem);
}
}
};
ActorCollectionNoErrors noErrorActors; // has to be the last one to be destroyed because other Actors may use it.
@ -662,17 +683,17 @@ struct DDQueue {
}
DDQueue(UID mid,
MoveKeysLock lock,
Database cx,
std::vector<TeamCollectionInterface> teamCollections,
Reference<ShardsAffectedByTeamFailure> sABTF,
PromiseStream<Promise<int64_t>> getAverageShardBytes,
int teamSize,
int singleRegionTeamSize,
PromiseStream<RelocateShard> output,
FutureStream<RelocateShard> input,
PromiseStream<GetMetricsRequest> getShardMetrics,
PromiseStream<GetTopKMetricsRequest> getTopKMetrics)
MoveKeysLock lock,
Database cx,
std::vector<TeamCollectionInterface> teamCollections,
Reference<ShardsAffectedByTeamFailure> sABTF,
PromiseStream<Promise<int64_t>> getAverageShardBytes,
int teamSize,
int singleRegionTeamSize,
PromiseStream<RelocateShard> output,
FutureStream<RelocateShard> input,
PromiseStream<GetMetricsRequest> getShardMetrics,
PromiseStream<GetTopKMetricsRequest> getTopKMetrics)
: distributorId(mid), lock(lock), cx(cx), txnProcessor(new DDTxnProcessor(cx)), teamCollections(teamCollections),
shardsAffectedByTeamFailure(sABTF), getAverageShardBytes(getAverageShardBytes),
startMoveKeysParallelismLock(SERVER_KNOBS->DD_MOVE_KEYS_PARALLELISM),

View File

@ -36,7 +36,29 @@
#include "flow/actorcompiler.h" // This must be the last #include.
enum class RelocateReason { INVALID = -1, OTHER, REBALANCE_DISK, REBALANCE_READ };
class RelocateReason {
public:
enum Value : int8_t { INVALID = -1, OTHER, REBALANCE_DISK, REBALANCE_READ };
RelocateReason(Value v = INVALID) : value(v) {}
explicit RelocateReason(int v) : value((Value)v) {}
std::string toString() const {
switch (value) {
case OTHER:
return "Other";
case REBALANCE_DISK:
return "RebalanceDisk";
case REBALANCE_READ:
return "RebalanceRead";
case INVALID:
default:
return "Invalid";
}
}
operator int() const { return (int)value; }
private:
Value value;
};
// One-to-one relationship to the priority knobs
enum class DataMovementReason {