class DpStmMap::ClientLocalStore
Public Class Methods
new(store_dir)
click to toggle source
# File lib/dp_stm_map/ClientLocalStore.rb, line 18 def initialize store_dir @store_dir=store_dir @mapping_dir="%s/mapping" % store_dir FileUtils.mkdir_p(@mapping_dir) unless File.exist? @mapping_dir @content_dir="%s/content" % store_dir FileUtils.mkdir_p(@content_dir) unless File.exist? @content_dir transaction_sequence_file_name="%s/transaction_sequence.txt" % @store_dir File.open(transaction_sequence_file_name,"w") {|f| f.write(0)} unless File.exist? transaction_sequence_file_name @content_cache=ThreadSafeLru::LruCache.new 9000 @mapping_cache=ThreadSafeLru::LruCache.new 9000 end
Public Instance Methods
[](key)
click to toggle source
# File lib/dp_stm_map/ClientLocalStore.rb, line 110 def [] key get_content(get_mapping(key)) end
current_transaction_sequence()
click to toggle source
# File lib/dp_stm_map/ClientLocalStore.rb, line 75 def current_transaction_sequence File.open("%s/transaction_sequence.txt" % @store_dir,"r") {|f| f.read().to_i} end
get_content(h)
click to toggle source
# File lib/dp_stm_map/ClientLocalStore.rb, line 84 def get_content h @content_cache.get(h) do |hash| if hash == nil nil else File.open("%s/%s" % [@content_dir,hash],"r") {|f| f.read } end end end
get_mapping(k)
click to toggle source
# File lib/dp_stm_map/ClientLocalStore.rb, line 94 def get_mapping k @mapping_cache.get(k) do |key| if key == nil nil else if File.exist? "%s/%s" % [@mapping_dir,key] File.open("%s/%s" % [@mapping_dir,key],"r") {|f| f.read } else nil end end end end
has_content?(hash)
click to toggle source
# File lib/dp_stm_map/ClientLocalStore.rb, line 80 def has_content? hash File.exist?("%s/%s" % [@content_dir,hash]) end
has_key?(key)
click to toggle source
# File lib/dp_stm_map/ClientLocalStore.rb, line 114 def has_key? key File.exist?("%s/%s" % [@mapping_dir,key]) end
update(transaction_sequence, new_content, updates, to_delete)
click to toggle source
# File lib/dp_stm_map/ClientLocalStore.rb, line 38 def update transaction_sequence, new_content, updates, to_delete File.open("%s/transaction_sequence.txt" % @store_dir,"w") {|f| f.write(transaction_sequence)} new_content.each_pair do |k,v| File.open("%s/%s" % [@content_dir,k],"w") {|f| f.write(v)} end changes=updates.inject({}) do |c, (k, new_hash)| c[k]=[self[k],get_content(new_hash)] c end to_delete.each do |hash| File.delete("%s/%s" % [@content_dir,hash]) end updates.each_pair do |k,v| @mapping_cache.drop(k) if v == nil File.delete("%s/%s" % [@mapping_dir,k]) else raise StandardError, "unknown content #{v} for key #{k}" unless has_content?(v) File.open("%s/%s" % [@mapping_dir,k],"w") {|f| f.write(v)} end end changes end