Commit 2dc18dbc authored by Tianer Zhou's avatar Tianer Zhou Committed by GitHub
Browse files

fix: potential out-of-bound (#420)


Signed-off-by: default avatarTianer Zhou <ezhoureal@gmail.com>
parent fcdcb12f
...@@ -245,8 +245,7 @@ pub fn select_worker( ...@@ -245,8 +245,7 @@ pub fn select_worker(
let kv_load_ratio = w.data.kv_active_blocks as f64 / w.data.kv_total_blocks as f64; let kv_load_ratio = w.data.kv_active_blocks as f64 / w.data.kv_total_blocks as f64;
let load_deviation = kv_load_ratio - workers.load_avg; let load_deviation = kv_load_ratio - workers.load_avg;
// [FIXME] multiple endpoints of the same worker cause out of bound error let worker_id = w.worker_id();
let worker_id = workers.worker_ids[i];
let overlap_score = request.overlap.scores.get(&worker_id).map_or(0, |x| *x); let overlap_score = request.overlap.scores.get(&worker_id).map_or(0, |x| *x);
let overlap_score = overlap_score as usize * kv_block_size; let overlap_score = overlap_score as usize * kv_block_size;
......
...@@ -16,14 +16,12 @@ ...@@ -16,14 +16,12 @@
//! Scoring functions for the KV router. //! Scoring functions for the KV router.
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use std::collections::HashSet;
use crate::kv_router::scheduler::Endpoint; use crate::kv_router::scheduler::Endpoint;
#[derive(Debug, Default, Serialize, Deserialize, Clone)] #[derive(Debug, Default, Serialize, Deserialize, Clone)]
pub struct ProcessedEndpoints { pub struct ProcessedEndpoints {
pub endpoints: Vec<Endpoint>, pub endpoints: Vec<Endpoint>,
pub worker_ids: Vec<i64>,
pub load_avg: f64, pub load_avg: f64,
pub load_std: f64, pub load_std: f64,
} }
...@@ -43,12 +41,8 @@ impl ProcessedEndpoints { ...@@ -43,12 +41,8 @@ impl ProcessedEndpoints {
/ load_values.len() as f64; / load_values.len() as f64;
let load_std = variance.sqrt(); let load_std = variance.sqrt();
let worker_ids: HashSet<i64> = endpoints.iter().map(|x| x.worker_id()).collect();
let worker_ids: Vec<i64> = worker_ids.into_iter().collect();
ProcessedEndpoints { ProcessedEndpoints {
endpoints, endpoints,
worker_ids,
load_avg, load_avg,
load_std, load_std,
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment