Skip to content

Commit dbe7509

Browse files
committed
Add static shard picker
1 parent 340dcbe commit dbe7509

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

internal/routing/shard_picker.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,22 @@ type ShardPicker interface {
1111
Next(total int) int // returns an index in [0,total)
1212
}
1313

14+
// StaticShardPicker always returns the same shard index.
15+
type StaticShardPicker struct {
16+
index int
17+
}
18+
19+
func NewStaticShardPicker(index int) *StaticShardPicker {
20+
return &StaticShardPicker{index: index}
21+
}
22+
23+
func (p *StaticShardPicker) Next(total int) int {
24+
if total == 0 || p.index >= total {
25+
return 0
26+
}
27+
return p.index
28+
}
29+
1430
/*───────────────────────────────
1531
Round-robin (default)
1632
────────────────────────────────*/

0 commit comments

Comments
 (0)