require 'rubygems' require 'bud' class AtomicReads include Bud state do table :write, [:wid] => [:batch, :name, :val] table :commit, [:batch] table :write_log, [:wid] => [:batch, :name, :val, :prev_wid] table :dom, [:wid] scratch :live, write_log.schema scratch :write_commit_event, write.schema table :read, [:batch] range :read_commit, [:batch] table :snapshot, [:effective, :wid, :batch, :name, :val, :prev_wid] range :snapshot_exists, [:batch] scratch :read_event, read.schema scratch :read_view, snapshot.schema end bloom do write_commit_event <= (write * commit).lefts(:batch => :batch).notin(write_log, 0 => :wid) write_log <+ (write_commit_event * live).outer(:name => :name){|e, l| e + [l.wid.nil? ? 0 : l.wid]} dom <= write_log {|l| [l.prev_wid]} live <= write_log.notin(dom, :wid => :wid) snapshot_exists <= snapshot {|r| [r.effective]} read_event <= read.notin(snapshot_exists, :batch => :batch) snapshot <+ (read_event * live).pairs {|r,l| r + l} read_view <= snapshot.notin(read_commit, :effective => :batch) end end