Skip to content

Commit

Permalink
Refactor ActorMapping iteration and worker lookup in mapping.rs
Browse files Browse the repository at this point in the history
  • Loading branch information
shanicky committed Jul 19, 2024
1 parent 5c9991d commit d1df7f8
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/common/src/hash/consistent_hash/mapping.rs
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,12 @@ impl ActorMapping {
/// Transform the actor mapping to the worker slot mapping. Note that the parameter is a mapping from actor to worker.
pub fn to_worker_slot(&self, actor_to_worker: &HashMap<ActorId, u32>) -> WorkerSlotMapping {
let mut worker_actors = HashMap::new();
for (actor_id, worker_id) in actor_to_worker {
for actor_id in self.iter_unique() {
let worker_id = actor_to_worker
.get(&actor_id)
.cloned()
.unwrap_or_else(|| panic!("location for actor {} not found", actor_id));

worker_actors
.entry(worker_id)
.or_insert(BTreeSet::new())
Expand All @@ -342,7 +347,7 @@ impl ActorMapping {
let mut actor_location = HashMap::new();
for (worker, actors) in worker_actors {
for (idx, &actor) in actors.iter().enumerate() {
actor_location.insert(*actor, WorkerSlotId::new(*worker, idx));
actor_location.insert(actor, WorkerSlotId::new(worker, idx));
}
}

Expand Down

0 comments on commit d1df7f8

Please sign in to comment.