|
@ -16,7 +16,7 @@ module Crystal::Scatter |
|
|
getter rings : Array(Ring) |
|
|
getter rings : Array(Ring) |
|
|
getter ring_graph : RingGraph |
|
|
getter ring_graph : RingGraph |
|
|
|
|
|
|
|
|
def initialize(@shards : UInt32) |
|
|
|
|
|
|
|
|
def initialize(@shards : UInt32, @split_ratio : BigRational = BigRational.new(1,2)) |
|
|
@rings = Array(Ring).new |
|
|
@rings = Array(Ring).new |
|
|
@ring_graph = RingGraph.new |
|
|
@ring_graph = RingGraph.new |
|
|
@lock = Mutex.new |
|
|
@lock = Mutex.new |
|
@ -27,10 +27,10 @@ module Crystal::Scatter |
|
|
end |
|
|
end |
|
|
|
|
|
|
|
|
private def update_impl |
|
|
private def update_impl |
|
|
@ring_graph.generate_ring |
|
|
|
|
|
|
|
|
@ring_graph.generate_ring @split_ratio |
|
|
ring = Ring.new |
|
|
ring = Ring.new |
|
|
@ring_graph.snapshot do |daemon| |
|
|
@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 |
|
|
end |
|
|
@rings.push ring |
|
|
@rings.push ring |
|
|
end |
|
|
end |
|
@ -69,8 +69,8 @@ module Crystal::Scatter |
|
|
end |
|
|
end |
|
|
|
|
|
|
|
|
def get_slices_for(data : String) |
|
|
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 |
|
|
@lock.synchronize do |
|
|
ring? = @rings.last |
|
|
ring? = @rings.last |
|
|
end |
|
|
end |
|
@ -78,7 +78,7 @@ module Crystal::Scatter |
|
|
h = hash_impl data |
|
|
h = hash_impl data |
|
|
space=UInt64::MAX/@shards |
|
|
space=UInt64::MAX/@shards |
|
|
targets = Array(UInt64).new |
|
|
targets = Array(UInt64).new |
|
|
(1..n">shards).each do || |
|
|
|
|
|
|
|
|
(1..vi">@shards).each do |
|
|
targets << h |
|
|
targets << h |
|
|
h+=space |
|
|
h+=space |
|
|
end |
|
|
end |
|
|