Class: Calvin::Node

Inherits:
Spinoza::Node show all
Defined in:
lib/spinoza/calvin/node.rb

Instance Attribute Summary collapse

Attributes inherited from Spinoza::Node

#links, #lock_manager, #name, #store

Attributes inherited from Spinoza::Model

#timeline

Instance Method Summary collapse

Methods inherited from Spinoza::Node

#inspect, #link, #new_name, new_name, #tables, #to_s

Methods inherited from Spinoza::Model

#time_now

Constructor Details

#initialize(*tables, log: nil, meta_log: nil, sequencer: nil, scheduler: nil, **rest) ⇒ Node

Returns a new instance of Node.



9
10
11
12
13
14
15
16
17
18
19
# File 'lib/spinoza/calvin/node.rb', line 9

def initialize *tables, log: nil, meta_log: nil,
    sequencer: nil, scheduler: nil, **rest
  super *tables, **rest

  @log = log
  @meta_log = meta_log
  @sequencer = sequencer || Calvin::Sequencer.new(node: self)
  @scheduler = scheduler || Calvin::Scheduler.new(node: self)

  on_transaction_finish &method(:default_output)
end

Instance Attribute Details

#logObject (readonly)

Returns the value of attribute log.



7
8
9
# File 'lib/spinoza/calvin/node.rb', line 7

def log
  @log
end

#meta_logObject (readonly)

Returns the value of attribute meta_log.



7
8
9
# File 'lib/spinoza/calvin/node.rb', line 7

def meta_log
  @meta_log
end

#schedulerObject (readonly)

Returns the value of attribute scheduler.



6
7
8
# File 'lib/spinoza/calvin/node.rb', line 6

def scheduler
  @scheduler
end

#sequencerObject (readonly)

Returns the value of attribute sequencer.



6
7
8
# File 'lib/spinoza/calvin/node.rb', line 6

def sequencer
  @sequencer
end

Instance Method Details

#default_output(transaction, result) ⇒ Object



21
22
23
24
# File 'lib/spinoza/calvin/node.rb', line 21

def default_output transaction, result
  r = result.map {|rr| [rr.op.table, rr.val].join(":")}.join(", ")
  puts "%07.6f [RESULT] #{transaction} => #{r}" % timeline.now
end

#finished_transaction(transaction, result) ⇒ Object

Override this to put the result somewhere.



39
40
41
42
43
# File 'lib/spinoza/calvin/node.rb', line 39

def finished_transaction transaction, result
  if @finished_transaction_handler
    @finished_transaction_handler[transaction, result]
  end
end

#on_transaction_finish(&b) ⇒ Object



34
35
36
# File 'lib/spinoza/calvin/node.rb', line 34

def on_transaction_finish &b
  @finished_transaction_handler = b
end

#read_batch(batch_id) ⇒ Object



30
31
32
# File 'lib/spinoza/calvin/node.rb', line 30

def read_batch batch_id
  log.read batch_id, node: self
end

#recv(msg: nil) ⇒ Object



26
27
28
# File 'lib/spinoza/calvin/node.rb', line 26

def recv msg: nil
  scheduler.recv_peer_results **msg
end