Class: Calvin::Sequencer
- Inherits:
-
Spinoza::Model
- Object
- Spinoza::Model
- Calvin::Sequencer
- Defined in:
- lib/spinoza/calvin/sequencer.rb
Overview
Accepts transaction requests from clients. The requests accepted in an epoch are grouped as a batch, given a sequential id, and replicated to the transaction schedulers on each node.
Instance Attribute Summary collapse
-
#dt_epoch ⇒ Object
readonly
Length of epoch in seconds.
-
#id ⇒ Object
readonly
ID used to construct UUID for batch.
-
#node ⇒ Object
readonly
Returns the value of attribute node.
Attributes inherited from Spinoza::Model
Class Method Summary collapse
Instance Method Summary collapse
- #accept_transaction(txn) ⇒ Object
- #append_batch_to_meta_log(batch_id: batch_id) ⇒ Object
-
#initialize(node: raise, dt_epoch: 0.010) ⇒ Sequencer
constructor
A new instance of Sequencer.
- #inspect ⇒ Object
- #log ⇒ Object
- #meta_log ⇒ Object
- #step_epoch ⇒ Object
Methods inherited from Spinoza::Model
Constructor Details
#initialize(node: raise, dt_epoch: 0.010) ⇒ Sequencer
Returns a new instance of Sequencer.
22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/spinoza/calvin/sequencer.rb', line 22 def initialize node: raise, dt_epoch: 0.010 super timeline: node.timeline @node = node @dt_epoch = dt_epoch @batch = [] @epoch = 0 @id = self.class.next_id step_epoch end |
Instance Attribute Details
#dt_epoch ⇒ Object (readonly)
Length of epoch in seconds.
13 14 15 |
# File 'lib/spinoza/calvin/sequencer.rb', line 13 def dt_epoch @dt_epoch end |
#id ⇒ Object (readonly)
ID used to construct UUID for batch.
10 11 12 |
# File 'lib/spinoza/calvin/sequencer.rb', line 10 def id @id end |
#node ⇒ Object (readonly)
Returns the value of attribute node.
7 8 9 |
# File 'lib/spinoza/calvin/sequencer.rb', line 7 def node @node end |
Class Method Details
.next_id ⇒ Object
17 18 19 |
# File 'lib/spinoza/calvin/sequencer.rb', line 17 def next_id @seq_id += 1 end |
Instance Method Details
#accept_transaction(txn) ⇒ Object
71 72 73 |
# File 'lib/spinoza/calvin/sequencer.rb', line 71 def accept_transaction txn @batch << txn end |
#append_batch_to_meta_log(batch_id: batch_id) ⇒ Object
59 60 61 |
# File 'lib/spinoza/calvin/sequencer.rb', line 59 def batch_id: batch_id .append batch_id, node: node end |
#inspect ⇒ Object
34 35 36 |
# File 'lib/spinoza/calvin/sequencer.rb', line 34 def inspect "<#{self.class} on #{node.inspect}>" end |
#log ⇒ Object
63 64 65 |
# File 'lib/spinoza/calvin/sequencer.rb', line 63 def log node.log end |
#meta_log ⇒ Object
67 68 69 |
# File 'lib/spinoza/calvin/sequencer.rb', line 67 def node. end |
#step_epoch ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/spinoza/calvin/sequencer.rb', line 38 def step_epoch unless @batch.empty? batch_id = [@id, @epoch] # globally unique, but not ordered log.write batch_id, @batch, node: node log.when_durable batch_id, actor: self, action: :append_batch_to_meta_log, batch_id: batch_id @batch = [] end @epoch += 1 timeline.schedule Spinoza::Event[ time: time_now + dt_epoch, actor: self, action: :step_epoch ] end |