Sfoglia il codice sorgente

Slicing confiremed to work in tests

master
Archivist 6 anni fa
parent
commit
4e2f8659fb
2 ha cambiato i file con 21 aggiunte e 6 eliminazioni
  1. +15
    -0
      spec/crystal-scatter_spec.cr
  2. +6
    -6
      src/crystal-scatter/metaring.cr

+ 15
- 0
spec/crystal-scatter_spec.cr Vedi File

@ -3,6 +3,21 @@ require "./spec_helper"
describe Crystal::Scatter do
# TODO: Write tests
it "slices data into multiple pods" do
mr = Crystal::Scatter::MetaRing.new(3)
mr.add Crystal::Scatter::Daemon.new(1,[0,0,0,0,0,0],"OSD0")
mr.add [Crystal::Scatter::Daemon.new(1,[0,0,0,0,0,1],"OSD1"),Crystal::Scatter::Daemon.new(1,[0,0,0,0,0,2],"OSD2")]
(1..1000).each do |numb|
slices = mr.get_slices_for(numb.to_s)
set = Set(String).new
slices.each do |sl|
set<<sl.url
end
set.size.should eq(3)
end
end
it "add elements to RingGraphs" do
rg = Crystal::Scatter::RingGraph.new
rg.add(UInt64.new(1),[0,0,0,0,0,0],"OSD0")

+ 6
- 6
src/crystal-scatter/metaring.cr Vedi File

@ -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

Caricamento…
Annulla
Salva