Deterministic cluster-state translation for the partition mapper
harbor run -t mimo-v2.6-rl/format-code-task-000069harbor download mimo-v2.6-rl/format-code-task-000069Fix the following issue:
The mapper package turns Kafka cluster state into the objects our rebalancing/reassignment
logic consumes. Two pieces of that translation are currently underspecified and need to be made
reliable.
mapper.PartitionMapFromTopicStates translates a kafkaadmin.TopicStates into a
*mapper.PartitionMap. Today the partitions in the returned map come out in whatever order the
underlying maps happen to iterate, so two calls with the same input can produce maps whose
partition lists differ in order. That makes downstream diffs and output noisy and forces every
caller to re-sort.
Make the returned partition map deterministic:
Partitions list must be sorted ascending by topic name, and within a topic ascending by
partition ID, regardless of the iteration order of the input.nil TopicStates yields an empty but non-nil *PartitionMap with no
partitions and a nil error.Broker metadata assembled from the cluster needs storage metrics (collected out-of-band) merged
in before the planner can use it. Add a way to populate a mapper.BrokerMetaMap from a
mapper.BrokerMetricsMap:
StorageFree from it.StorageFree is left untouched in that case.Expose this as a method on BrokerMetaMap with the signature
LoadMetrics(metrics BrokerMetricsMap) []error.