Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
205 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1 @@ | ||
#!/usr/bin/env ruby | ||
Dir[File.expand_path(File.join(File.dirname(__FILE__),'lib','**','*.rb'))].each {|f| require f} | ||
|
||
N_PIECES = 4 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
module Eraser | ||
class Node | ||
attr_reader :id | ||
attr_reader :root_path | ||
def initialize(id) | ||
@id = id | ||
end | ||
|
||
def self.spawn_nodes(n) | ||
(1..n).map {|id| Node.new(id)} | ||
end | ||
|
||
def copy_pieces(pieces) | ||
puts "copying #{pieces.join(',')}" | ||
pieces.each{|p| copy_piece(p)} | ||
end | ||
|
||
def copy_piece(piece) | ||
p = Piece.new(piece.original_filename, piece.bitmask, storage_path) | ||
p.overwrite(piece.content) | ||
end | ||
|
||
def storage_path | ||
"#{id}" | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
module Eraser | ||
class Service | ||
def num_pieces | ||
4 | ||
end | ||
|
||
def num_nodes | ||
5 | ||
end | ||
|
||
def put(file) | ||
input_file = Eraser::File.new ::File.expand_path(file) | ||
encoder = Eraser::Encoder.new(input_file, num_pieces) | ||
pieces = encoder.encode | ||
# distribute_pieces(pieces) | ||
end | ||
|
||
def distribute_pieces(pieces) | ||
puts "distributing #{pieces.join(',')}" | ||
nodes = Node.spawn_nodes(5) | ||
nodes.each do |node| | ||
puts "node #{node.id}" | ||
nodes_pieces = pieces.select do |p| | ||
bitmasks = Eraser::Code.basis_vectors_for_node(node.id) | ||
puts "bitmasks: #{bitmasks.join(',')}" | ||
bitmasks.include?(p.bitmask) | ||
end | ||
node.copy_pieces(nodes_pieces) | ||
end | ||
pieces.each(&:destroy) | ||
end | ||
|
||
def retrieve(id) | ||
|
||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
require File.join(File.dirname(__FILE__), *%w[.. .. eraser]) | ||
describe Eraser::Node do | ||
let(:node_id) {mock} | ||
let(:node) {Eraser::Node.new(node_id)} | ||
subject {node} | ||
|
||
describe "copy_piece" do | ||
it "makes a new piece with the contents of the given piece" do | ||
piece = mock | ||
content, filename, bitmask = mock, mock, mock | ||
piece.stub(:content).and_return content | ||
piece.stub(:original_filename).and_return filename | ||
piece.stub(:bitmask).and_return bitmask | ||
node.stub(:storage_path).and_return storage_path = mock | ||
Eraser::Piece.should_receive(:new).with(filename, bitmask, storage_path).and_return new_piece = mock | ||
new_piece.should_receive(:overwrite).with(content) | ||
node.copy_piece piece | ||
end | ||
end | ||
|
||
describe "copy_pieces(pieces)" do | ||
it "copies the pieces" do | ||
m1, m2 = mock, mock | ||
subject.should_receive(:copy_piece).with(m1).ordered | ||
subject.should_receive(:copy_piece).with(m2).ordered | ||
subject.copy_pieces [m1, m2] | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
require File.join(File.dirname(__FILE__), *%w[.. .. eraser]) | ||
describe Eraser::Service do | ||
let(:service) {Eraser::Service.new} | ||
describe "put(filepath_string)" do | ||
let(:filepath) {mock} | ||
let(:encoder) {mock} | ||
let(:wrapped_input_file) {mock} | ||
before(:each) do | ||
Eraser::File.stub(:new).and_return wrapped_input_file | ||
Eraser::Encoder.stub(:new).and_return encoder | ||
service.stub(:distribute_pieces) | ||
encoder.stub(:encode) | ||
end | ||
|
||
it "normalises the path & wraps the file in an Eraser::File" do | ||
File.should_receive(:expand_path).with(filepath).and_return filepath | ||
Eraser::File.should_receive(:new).with(filepath).and_return wrapped_input_file | ||
service.put(filepath) | ||
end | ||
|
||
it "encodes the file in 4 pieces" do | ||
Eraser::Encoder.should_receive(:new).with(wrapped_input_file, 4) | ||
encoder.should_receive(:encode) | ||
service.put(filepath) | ||
end | ||
|
||
it "distributes the pieces across 5 nodes" do | ||
pieces = mock | ||
encoder.should_receive(:encode).and_return pieces | ||
service.should_receive(:distribute_pieces).with(pieces) | ||
service.put(filepath) | ||
end | ||
end | ||
|
||
describe "distribute_pieces(pieces)" do | ||
|
||
let(:node) {mock} | ||
let(:nodes) {[node]} | ||
let(:bitmask) {0b0010} | ||
let(:piece) {mock(:bitmask => bitmask)} | ||
let(:pieces) {[piece]} | ||
before(:each) do | ||
Node.stub(:spawn_nodes).and_return nodes | ||
Eraser::Code.stub(:basis_vectors_for_node).and_return [bitmask] | ||
piece.stub(:destroy) | ||
node.stub(:copy_pieces) | ||
end | ||
|
||
it "spawns 5 nodes" do | ||
Node.should_receive(:spawn_nodes).with(5).and_return nodes | ||
service.distribute_pieces(pieces) | ||
end | ||
|
||
it "sends the basis vector decided pieces to each node" do | ||
node_id = mock | ||
node.should_receive(:id).and_return node_id | ||
Eraser::Code.should_receive(:basis_vectors_for_node).with(node_id).and_return [bitmask] | ||
node.should_receive(:copy_pieces).with([piece]) | ||
service.distribute_pieces(pieces) | ||
end | ||
|
||
it "deletes local pieces generated during encoding" do | ||
piece.should_receive(:destroy) | ||
service.distribute_pieces(pieces) | ||
end | ||
end | ||
|
||
describe "retrieve" do | ||
it "takes a filename and returns the file contents" | ||
end | ||
|
||
describe "regenerate" do | ||
context "when 1 node has failed (and its pieces are lost)" do | ||
it "finds the missing pieces" | ||
it "reconstructs the missing node and its pieces" | ||
end | ||
end | ||
end |