|
|
@ -16,7 +16,7 @@ module Crystal::Scatter |
|
|
|
getter rings : Array(Ring) |
|
|
|
getter ring_graph : RingGraph |
|
|
|
|
|
|
|
def initialize(@shards : UInt32) |
|
|
|
def initialize(@shards : UInt32, @split_ratio : BigRational = BigRational.new(1,2)) |
|
|
|
@rings = Array(Ring).new |
|
|
|
@ring_graph = RingGraph.new |
|
|
|
@lock = Mutex.new |
|
|
@ -27,10 +27,10 @@ module Crystal::Scatter |
|
|
|
end |
|
|
|
|
|
|
|
private def update_impl |
|
|
|
@ring_graph.generate_ring |
|
|
|
@ring_graph.generate_ring @split_ratio |
|
|
|
ring = Ring.new |
|
|
|
@ring_graph.snapshot do |daemon| |
|
|
|
ring.push RingSlice.new(daemon.range_effector.not_nil!.[0],daemon.range_effector.not_nil!.[1],daemon.react_at) |
|
|
|
ring.push b">Slice.new(daemon.range_effector.not_nil!.[0],daemon.range_effector.not_nil!.[1],daemon.reach_at) |
|
|
|
end |
|
|
|
@rings.push ring |
|
|
|
end |
|
|
@ -69,8 +69,8 @@ module Crystal::Scatter |
|
|
|
end |
|
|
|
|
|
|
|
def get_slices_for(data : String) |
|
|
|
ret = Array.new(@shards) |
|
|
|
ring? : Ring | Nil |
|
|
|
ret = Arrayp">(Slice).new(@shards) |
|
|
|
ring? o">= nil : Ring | Nil |
|
|
|
@lock.synchronize do |
|
|
|
ring? = @rings.last |
|
|
|
end |
|
|
@ -78,7 +78,7 @@ module Crystal::Scatter |
|
|
|
h = hash_impl data |
|
|
|
space=UInt64::MAX/@shards |
|
|
|
targets = Array(UInt64).new |
|
|
|
(1..n">shards).each do || |
|
|
|
(1..vi">@shards).each do |
|
|
|
targets << h |
|
|
|
h+=space |
|
|
|
end |
|
|
|