Class: Calvin::Readcaster
- Inherits:
-
Object
- Object
- Calvin::Readcaster
- Defined in:
- lib/spinoza/calvin/readcaster.rb
Instance Attribute Summary collapse
-
#node ⇒ Object
readonly
Returns the value of attribute node.
Instance Method Summary collapse
- #execute_local_reads(txn) ⇒ Object
-
#initialize(node: nil) ⇒ Readcaster
constructor
A new instance of Readcaster.
- #inspect ⇒ Object
-
#links ⇒ Object
Pre-computed map, by table, of which nodes might need data from this node: => Set[link, …] In other, words, excludes ‘table,link` pairs for which link.dst already has `table`.
- #send_read(link, **opts) ⇒ Object
- #serve_reads(txn, local_read_results) ⇒ Object
Constructor Details
#initialize(node: nil) ⇒ Readcaster
Returns a new instance of Readcaster.
7 8 9 10 11 |
# File 'lib/spinoza/calvin/readcaster.rb', line 7 def initialize node: nil @node = node @links = nil @tables = node.tables end |
Instance Attribute Details
#node ⇒ Object (readonly)
Returns the value of attribute node.
5 6 7 |
# File 'lib/spinoza/calvin/readcaster.rb', line 5 def node @node end |
Instance Method Details
#execute_local_reads(txn) ⇒ Object
32 33 34 35 |
# File 'lib/spinoza/calvin/readcaster.rb', line 32 def execute_local_reads txn local_reads = txn.all_read_ops.select {|r| @tables.include? r.table} node.store.execute *local_reads end |
#inspect ⇒ Object
13 14 15 |
# File 'lib/spinoza/calvin/readcaster.rb', line 13 def inspect "<#{self.class} on #{node.inspect}>" end |
#links ⇒ Object
Pre-computed map, by table, of which nodes might need data from this node: => Set[link, …] In other, words, excludes ‘table,link` pairs for which link.dst already has `table`.
20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/spinoza/calvin/readcaster.rb', line 20 def links unless @links @links = Hash.new {|h,k| h[k] = Set[]} node.links.each do |there, link| (@tables - there.tables).each do |table| @links[table] << link end end end @links end |
#send_read(link, **opts) ⇒ Object
47 48 49 |
# File 'lib/spinoza/calvin/readcaster.rb', line 47 def send_read link, **opts link. **opts end |
#serve_reads(txn, local_read_results) ⇒ Object
37 38 39 40 41 42 43 44 45 |
# File 'lib/spinoza/calvin/readcaster.rb', line 37 def serve_reads txn, local_read_results local_read_results.group_by {|r| r.op.table}.each do |table, results| links[table].each do |link| if txn.active?(link.dst) send_read link, transaction: txn, table: table, read_results: results end end end end |