From d5a101a1eba37f0a11a729542f836d2b24ee4370 Mon Sep 17 00:00:00 2001 From: Xiaoxi Wang Date: Mon, 8 Aug 2022 21:44:45 -0700 Subject: [PATCH] remove RelocateShard::INVALID; add priority uniqueness check --- fdbserver/DataDistributionQueue.actor.cpp | 106 ++++++++---------- .../fdbserver/DataDistribution.actor.h | 8 +- 2 files changed, 51 insertions(+), 63 deletions(-) diff --git a/fdbserver/DataDistributionQueue.actor.cpp b/fdbserver/DataDistributionQueue.actor.cpp index 90f78c81f6..ee9efda1e4 100644 --- a/fdbserver/DataDistributionQueue.actor.cpp +++ b/fdbserver/DataDistributionQueue.actor.cpp @@ -67,65 +67,53 @@ inline bool isDataMovementForValleyFiller(DataMovementReason reason) { reason == DataMovementReason::REBALANCE_READ_UNDERUTIL_TEAM; } -int dataMovementPriority(DataMovementReason reason) { - int priority; - switch (reason) { - case DataMovementReason::INVALID: - priority = -1; - break; - case DataMovementReason::RECOVER_MOVE: - priority = SERVER_KNOBS->PRIORITY_RECOVER_MOVE; - break; - case DataMovementReason::REBALANCE_UNDERUTILIZED_TEAM: - priority = SERVER_KNOBS->PRIORITY_REBALANCE_UNDERUTILIZED_TEAM; - break; - case DataMovementReason::REBALANCE_OVERUTILIZED_TEAM: - priority = SERVER_KNOBS->PRIORITY_REBALANCE_OVERUTILIZED_TEAM; - break; - case DataMovementReason::REBALANCE_READ_OVERUTIL_TEAM: - priority = SERVER_KNOBS->PRIORITY_REBALANCE_READ_OVERUTIL_TEAM; - break; - case DataMovementReason::REBALANCE_READ_UNDERUTIL_TEAM: - priority = SERVER_KNOBS->PRIORITY_REBALANCE_READ_UNDERUTIL_TEAM; - break; - case DataMovementReason::PERPETUAL_STORAGE_WIGGLE: - priority = SERVER_KNOBS->PRIORITY_PERPETUAL_STORAGE_WIGGLE; - break; - case DataMovementReason::TEAM_HEALTHY: - priority = SERVER_KNOBS->PRIORITY_TEAM_HEALTHY; - break; - case DataMovementReason::TEAM_CONTAINS_UNDESIRED_SERVER: - priority = SERVER_KNOBS->PRIORITY_TEAM_CONTAINS_UNDESIRED_SERVER; - break; - case DataMovementReason::TEAM_REDUNDANT: - priority = SERVER_KNOBS->PRIORITY_TEAM_REDUNDANT; - break; - case DataMovementReason::MERGE_SHARD: - priority = SERVER_KNOBS->PRIORITY_MERGE_SHARD; - break; - case DataMovementReason::POPULATE_REGION: - priority = SERVER_KNOBS->PRIORITY_POPULATE_REGION; - break; - case DataMovementReason::TEAM_UNHEALTHY: - priority = SERVER_KNOBS->PRIORITY_TEAM_UNHEALTHY; - break; - case DataMovementReason::TEAM_2_LEFT: - priority = SERVER_KNOBS->PRIORITY_TEAM_2_LEFT; - break; - case DataMovementReason::TEAM_1_LEFT: - priority = SERVER_KNOBS->PRIORITY_TEAM_1_LEFT; - break; - case DataMovementReason::TEAM_FAILED: - priority = SERVER_KNOBS->PRIORITY_TEAM_FAILED; - break; - case DataMovementReason::TEAM_0_LEFT: - priority = SERVER_KNOBS->PRIORITY_TEAM_0_LEFT; - break; - case DataMovementReason::SPLIT_SHARD: - priority = SERVER_KNOBS->PRIORITY_SPLIT_SHARD; - break; +typedef std::map DmReasonPriorityMapping; +typedef std::map PriorityDmReasonMapping; +std::pair buildPriorityMappings() { + static DmReasonPriorityMapping reasonPriority{ + { DataMovementReason::INVALID, -1 }, + { DataMovementReason::RECOVER_MOVE, SERVER_KNOBS->PRIORITY_RECOVER_MOVE }, + { DataMovementReason::REBALANCE_UNDERUTILIZED_TEAM, SERVER_KNOBS->PRIORITY_REBALANCE_UNDERUTILIZED_TEAM }, + { DataMovementReason::REBALANCE_OVERUTILIZED_TEAM, SERVER_KNOBS->PRIORITY_REBALANCE_OVERUTILIZED_TEAM }, + { DataMovementReason::REBALANCE_READ_OVERUTIL_TEAM, SERVER_KNOBS->PRIORITY_REBALANCE_READ_OVERUTIL_TEAM }, + { DataMovementReason::REBALANCE_READ_UNDERUTIL_TEAM, SERVER_KNOBS->PRIORITY_REBALANCE_READ_UNDERUTIL_TEAM }, + { DataMovementReason::PERPETUAL_STORAGE_WIGGLE, SERVER_KNOBS->PRIORITY_PERPETUAL_STORAGE_WIGGLE }, + { DataMovementReason::TEAM_HEALTHY, SERVER_KNOBS->PRIORITY_TEAM_HEALTHY }, + { DataMovementReason::TEAM_CONTAINS_UNDESIRED_SERVER, SERVER_KNOBS->PRIORITY_TEAM_CONTAINS_UNDESIRED_SERVER }, + { DataMovementReason::TEAM_REDUNDANT, SERVER_KNOBS->PRIORITY_TEAM_REDUNDANT }, + { DataMovementReason::MERGE_SHARD, SERVER_KNOBS->PRIORITY_MERGE_SHARD }, + { DataMovementReason::POPULATE_REGION, SERVER_KNOBS->PRIORITY_POPULATE_REGION }, + { DataMovementReason::TEAM_UNHEALTHY, SERVER_KNOBS->PRIORITY_TEAM_UNHEALTHY }, + { DataMovementReason::TEAM_2_LEFT, SERVER_KNOBS->PRIORITY_TEAM_2_LEFT }, + { DataMovementReason::TEAM_1_LEFT, SERVER_KNOBS->PRIORITY_TEAM_1_LEFT }, + { DataMovementReason::TEAM_FAILED, SERVER_KNOBS->PRIORITY_TEAM_FAILED }, + { DataMovementReason::TEAM_0_LEFT, SERVER_KNOBS->PRIORITY_TEAM_0_LEFT }, + { DataMovementReason::SPLIT_SHARD, SERVER_KNOBS->PRIORITY_SPLIT_SHARD } + }; + + static PriorityDmReasonMapping priorityReason; + if (priorityReason.empty()) { // only build once + for (const auto& [r, p] : reasonPriority) { + priorityReason[p] = r; + } + // Don't allow 2 priorities value being the same. + if (priorityReason.size() != reasonPriority.size()) { + TraceEvent(SevError, "DuplicateDataMovementPriority").log(); + ASSERT(false); + } } - return priority; + + return std::make_pair(reasonPriority, priorityReason); +} + +int dataMovementPriority(DataMovementReason reason) { + const auto& [reasonPriority, _] = buildPriorityMappings(); + return reasonPriority.at(reason); +} + +DataMovementReason priorityToDataMovementReason(int priority) { + const auto& [_, priorityReason] = buildPriorityMappings(); + return priorityReason.at(priority); } struct RelocateData { @@ -148,7 +136,7 @@ struct RelocateData { std::shared_ptr dataMove; RelocateData() - : priority(-1), boundaryPriority(-1), healthPriority(-1), reason(RelocateReason::INVALID), startTime(-1), + : priority(-1), boundaryPriority(-1), healthPriority(-1), reason(RelocateReason::OTHER), startTime(-1), dataMoveId(anonymousShardId), workFactor(0), wantsNewServers(false), cancellable(false), interval("QueuedRelocation") {} explicit RelocateData(RelocateShard const& rs) diff --git a/fdbserver/include/fdbserver/DataDistribution.actor.h b/fdbserver/include/fdbserver/DataDistribution.actor.h index 1f37651477..a845cd95cf 100644 --- a/fdbserver/include/fdbserver/DataDistribution.actor.h +++ b/fdbserver/include/fdbserver/DataDistribution.actor.h @@ -36,7 +36,7 @@ #include "flow/actorcompiler.h" // This must be the last #include. -enum class RelocateReason { INVALID = -1, OTHER, REBALANCE_DISK, REBALANCE_READ }; +enum class RelocateReason { OTHER = 0, REBALANCE_DISK, REBALANCE_READ }; // One-to-one relationship to the priority knobs enum class DataMovementReason { @@ -59,11 +59,11 @@ enum class DataMovementReason { TEAM_0_LEFT, SPLIT_SHARD }; +extern int dataMovementPriority(DataMovementReason moveReason); +extern DataMovementReason priorityToDataMovementReason(int priority); struct DDShardInfo; -extern int dataMovementPriority(DataMovementReason moveReason); - // Represents a data move in DD. struct DataMove { DataMove() : meta(DataMoveMetaData()), restore(false), valid(false), cancelled(false) {} @@ -95,7 +95,7 @@ struct RelocateShard { RelocateReason reason; DataMovementReason moveReason; RelocateShard() - : priority(0), cancelled(false), dataMoveId(anonymousShardId), reason(RelocateReason::INVALID), + : priority(0), cancelled(false), dataMoveId(anonymousShardId), reason(RelocateReason::OTHER), moveReason(DataMovementReason::INVALID) {} RelocateShard(KeyRange const& keys, DataMovementReason moveReason, RelocateReason reason) : keys(keys), cancelled(false), dataMoveId(anonymousShardId), reason(reason), moveReason(moveReason) {