From 655ce2a8cdd83f2338b2de23bef1133cf4e1916a Mon Sep 17 00:00:00 2001 From: Shanicky Chen Date: Thu, 29 Aug 2024 18:14:53 +0800 Subject: [PATCH] fix: Sort by actor_id in CustomFragmentInfo and rebalance_actor_vnode for consistent ordering (#18317) Signed-off-by: Shanicky Chen --- src/meta/src/stream/scale.rs | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/meta/src/stream/scale.rs b/src/meta/src/stream/scale.rs index 6ecb061e509b4..634cca76f0d7e 100644 --- a/src/meta/src/stream/scale.rs +++ b/src/meta/src/stream/scale.rs @@ -163,7 +163,12 @@ impl From<&PbFragment> for CustomFragmentInfo { .first() .cloned() .expect("no actor in fragment"), - actors: fragment.actors.iter().map(CustomActorInfo::from).collect(), + actors: fragment + .actors + .iter() + .map(CustomActorInfo::from) + .sorted_by(|actor_a, actor_b| actor_a.actor_id.cmp(&actor_b.actor_id)) + .collect(), } } } @@ -275,8 +280,12 @@ pub fn rebalance_actor_vnode( .partition(|(actor_id, _)| actors_to_remove.contains(actor_id)); let order_by_bitmap_desc = - |(_, bitmap_a): &(ActorId, Bitmap), (_, bitmap_b): &(ActorId, Bitmap)| -> Ordering { - bitmap_a.count_ones().cmp(&bitmap_b.count_ones()).reverse() + |(id_a, bitmap_a): &(ActorId, Bitmap), (id_b, bitmap_b): &(ActorId, Bitmap)| -> Ordering { + bitmap_a + .count_ones() + .cmp(&bitmap_b.count_ones()) + .reverse() + .then(id_a.cmp(id_b)) }; let builder_from_bitmap = |bitmap: &Bitmap| -> BitmapBuilder {