Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions sharding/src/distribution/modrange.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
pub struct ModRange {
slot: u64,
interval: u64,
shards: usize,
}

// ModRange 分布方法,默认总范围是[0,256),否则指定slot
Expand All @@ -17,6 +18,7 @@ impl ModRange {
ModRange {
slot,
interval: slot / shards as u64,
shards,
}
}

Expand All @@ -27,6 +29,11 @@ impl ModRange {
val = val.wrapping_abs();
}
let rs = val as u64 / self.interval;
if rs >= self.shards as u64 {
// 超出范围,返回最后一个分片
log::warn!("found modrange slot out of bound, rs:{}, shards:{}", rs, self.shards);
return self.shards - 1;
}
rs as usize
}
}
7 changes: 7 additions & 0 deletions sharding/src/distribution/range.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use crate::distribution::DIST_RANGE_SLOT_COUNT_DEFAULT;
pub struct Range {
slot: u64,
interval: u64,
shards: usize,
}

// Range 分布方法,默认总范围是[0,256),否则用
Expand All @@ -16,6 +17,7 @@ impl Range {
Range {
slot,
interval: slot / shards as u64,
shards,
}
}

Expand All @@ -28,6 +30,11 @@ impl Range {
val = val.wrapping_abs();
}
let rs = val as u64 / self.interval;
if rs >= self.shards as u64 {
// 超出范围,返回最后一个分片
log::warn!("found range slot out of bound, rs:{}, shards:{}", rs, self.shards);
return self.shards - 1;
}
rs as usize
}
}
Loading