Permalink
Browse files

all tests pass!

  • Loading branch information...
1 parent 7501f46 commit ee4eb7b09fd11379f7f588772f0e300716064436 Shane Brinkman-Davis committed Jun 30, 2012
@@ -148,7 +148,7 @@ def chunk_servers(internal_key,work_log=nil)
end
def chunk_master(internal_key,work_log=nil)
- chunk_servers(internal_key).master
+ find(internal_key,work_log).master
end
# same as #chunk_servers, only cached
@@ -36,39 +36,12 @@ def balance
while chunks.length > local_store.chunks.length+1
chunk_key = chunks.pop
- master_client = # find master server, then just call "move_chunk" on its client
-
- chunk_data = client.chunk chunk_key
- chunk = local_store.add_chunk MemoryChunk.new(:data=>chunk_data)
- global_index.add_local_replica(chunk)
-
- client.delete_chunk chunk_key
+ master_client = cluster_manager[global_index.chunk_master(chunk_key)]
+ master_client.move_chunk(chunk_key,client,cluster_manager.local_server)
chunks_moved[chunk_key]=client.to_s
end
chunks_moved
end
- private
- # takes a neighbor and its list of chunks, and moves one chunk at a time to us until balanced
- def async_balance_neighbor(neighbor,chunks,chunks_moved={},&block)
-
- # if the most_loaded_neighbor has at most 1 or more chunks than we do, we're balanced enough
- return yield chunks_moved if chunks.length+1 <= local_store.chunks.length
-
- chunk_key = chunks.pop
- neighbor.up_replicate_chunk chunk_key do
- local_store.add_chunk chunk_data
- client.down_replicate_chunk chunk_key do
- chunks_moved[chunk_key]=client.to_s
- async_balance_neighbor(neighbor,chunks,chunks_moved,&block) # async recursion
- end
- end
- end
- public
-
- def async_balance(&block)
- most_loaded_neighbor {|n,c| async_balance_neighbor(n,c,&block)}
- end
-
end
end
@@ -62,10 +62,11 @@ def get_record(key)
def validate_index_records_for_chunks_on_server(client,internal_client=nil)
internal_client||=client.internal
- server_name = client.server.split("http://")[1]
+ server_name = client.server
client.chunks.each do |chunk|
next if chunk==""
index_record = Monotable::GlobalIndex.index_record(chunk,internal_client)
+# Monotable::Tools.debug :chunk => chunk, :index_record => index_record
index_record.servers.should == [server_name]
end
end
@@ -140,14 +141,14 @@ def test_records
end
server_client(0).chunk_keys("u/bret").should == ["u/bret"]
- server_client(1).chunk_keys("u/bret").should == []
+ server_client(1).chunk_keys("u/bret").should == nil
res = server_client(1).balance
server_client(0).chunks.should == ["", "++0", "+0", "0", "u/bret"]
server_client(1).chunks.should == ["u/craig", "u/dan", "u/evan", "u/frank"]
server_client.chunk_keys("u/bret").should == ["u/bret"]
- server_client(1).chunk_keys("u/bret").should == []
+ server_client(1).chunk_keys("u/bret").should == nil
test_records.each do |key,fields|
r0 = server_client(0).get(key)
@@ -188,8 +189,8 @@ def populate_balanced_store
# verify one record is on server-0 and another is on server-1
server_client(0).chunk_keys("u/bret").should == ["u/bret"]
- server_client(1).chunk_keys("u/bret").should == []
- server_client(0).chunk_keys("u/craig").should == []
+ server_client(1).chunk_keys("u/bret").should == nil
+ server_client(0).chunk_keys("u/craig").should == nil
server_client(1).chunk_keys("u/craig").should == ["u/craig"]
# validate we can read we can read each record from either server
@@ -73,8 +73,8 @@
end
# verify records can be read from the correct servers
- server_clients.collect{|c|c.chunk_keys("u/bret")}.should == [[],[],["u/bret"],[]]
- server_clients.collect{|c|c.chunk_keys("u/dan")}.should == [[],["u/dan"],[],[]]
- server_clients.collect{|c|c.chunk_keys("u/frank")}.should == [[],[],[],["u/frank"]]
+ server_clients.collect{|c|c.chunk_keys("u/bret")}.should == [nil,nil,["u/bret"],nil]
+ server_clients.collect{|c|c.chunk_keys("u/dan")}.should == [nil,["u/dan"],nil,nil]
+ server_clients.collect{|c|c.chunk_keys("u/frank")}.should == [nil,nil,nil,["u/frank"]]
end
end
@@ -17,7 +17,7 @@ module Monotable
end
before(:each) do
- @client=ServerClient.new(daemon_uri)
+ @client=nil
end
attr_accessor :client
@@ -26,12 +26,12 @@ module Monotable
end
def client
- ServerClient.new(daemon_uri)
+ @client ||= ServerClient.new daemon_address
end
def blank_store
clear_store
- ServerClient.new(daemon_uri)
+ client
end
it "should fail locally to set with invalid fields" do
@@ -41,7 +41,7 @@ def blank_store
it "should be comparable" do
client.should == client
- client.should_not == ServerClient.new(daemon_uri(1))
+ client.should_not == ServerClient.new(daemon_address(1))
end
it "should be accessible via HTTP" do

0 comments on commit ee4eb7b

Please sign in to comment.