class Roma::Storage::BasicStorage
Constants
- PACK_HEADER_TEMPLATE
- 0.. 3
-
vn
- 4.. 7
-
physical clock (unix time)
- 8..11
-
logical clock
- 12..15
-
exptime(unix time)
- 16..
-
value data
- PACK_TEMPLATE
Attributes
cleanup_regexp[RW]
dbs[R]
divnum[RW]
do_each_vn_dump[RW]
each_clean_up_sleep[RW]
each_vn_dump_sleep[RW]
each_vn_dump_sleep_count[RW]
error_message[R]
ext_name[R]
hdb[R]
hdiv[R]
logic_clock_expire[RW]
option[W]
st_class[RW]
storage_path[W]
vn_list[W]
Public Class Methods
new()
click to toggle source
# File lib/roma/storage/basic_storage.rb 31 def initialize 32 # database handler 33 @hdb = [] 34 # database cache handler 35 @hdbc = [] 36 # status of a database 37 @dbs = [] 38 @log_fd = nil 39 # file number list of a each_vn_dump while 40 @each_vn_dump_vnodes = [] 41 42 @hdiv = Hash.new(0) 43 44 @ext_name = 'db' 45 46 @st_class = nil 47 @divnum = 10 48 49 @each_vn_dump_sleep = 0.001 50 @each_vn_dump_sleep_count = 100 51 @each_clean_up_sleep = 0.01 52 @cleanup_regexp = nil 53 @logic_clock_expire = 300 54 55 @each_cache_lock = Mutex::new 56 @each_clean_up_lock = Mutex::new 57 @stat_lock = Mutex::new 58 end
Public Instance Methods
add(vn, k, d, expt, v)
click to toggle source
# File lib/roma/storage/basic_storage.rb 238 def add(vn, k, d, expt, v) 239 buf = db_get(vn, k) 240 clk = 0 241 if buf 242 vn, t, clk, expt2, v2 = unpack_data(buf) 243 return nil if Time.now.to_i <= expt2 244 clk = (clk + 1) & 0xffffffff 245 end 246 247 # not exist 248 ret = [vn, Time.now.to_i, clk, expt, v] 249 return ret if db_put(vn, k, pack_data(*ret)) 250 nil 251 end
append(vn, k, d, expt, v)
click to toggle source
# File lib/roma/storage/basic_storage.rb 267 def append(vn, k, d, expt, v) 268 buf = db_get(vn, k) 269 return nil unless buf 270 271 # buf != nil 272 vn, t, clk, expt2, v2 = unpack_data(buf) 273 return nil if Time.now.to_i > expt2 274 clk = (clk + 1) & 0xffffffff 275 276 ret = [vn, Time.now.to_i, clk, expt, v2 + v] 277 return ret if db_put(vn, k, pack_data(*ret)) 278 nil 279 end
cache_file_name(dn)
click to toggle source
# File lib/roma/storage/basic_storage.rb 674 def cache_file_name(dn) 675 "#{@storage_path}/#{dn}.cache.#{@ext_name}" 676 end
cas(vn, k, d, clk, expt, v)
click to toggle source
# File lib/roma/storage/basic_storage.rb 195 def cas(vn, k, d, clk, expt, v) 196 buf = db_get(vn ,k) 197 return :not_found unless buf 198 t = Time.now.to_i 199 data = unpack_data(buf) 200 return :not_found if t > data[3] 201 return :exists if clk != data[2] 202 clk = (data[2] + 1) & 0xffffffff 203 ret = [vn, t, clk, expt, v] 204 return ret if db_put(vn, k, pack_data(*ret)) 205 nil 206 end
close_log()
click to toggle source
# File lib/roma/storage/basic_storage.rb 770 def close_log 771 @log_fd.close if @log_fd 772 @log_fd = nil 773 end
closedb()
click to toggle source
# File lib/roma/storage/basic_storage.rb 130 def closedb 131 stop_clean_up 132 buf = @hdb; @hdb = [] 133 buf.each{ |h| close_db(h) if h } 134 buf = @hdbc; @hdbc = [] 135 buf.each{ |h| close_db(h) if h } 136 close_log 137 end
db_get(vn, k)
click to toggle source
# File lib/roma/storage/basic_storage.rb 162 def db_get(vn, k) 163 n = @hdiv[vn] 164 d = @hdb[n].get(k) 165 return d if @dbs[n] == :normal 166 167 c = @hdbc[n].get(k) 168 return d unless c # in case of out of :normal status 169 170 if @dbs[n] == :cachecleaning && d 171 # in case of existing value is both @hdb and @hdbc 172 vn, lat, clk, expt = unpack_header(d) 173 cvn, clat, cclk, cexpt = unpack_header(c) 174 return d if cmp_clk(clk, cclk) > 0 # if @hdb newer than @hdbc 175 end 176 c 177 end
db_put(vn, k, v)
click to toggle source
# File lib/roma/storage/basic_storage.rb 179 def db_put(vn, k, v) 180 n = @hdiv[vn] 181 if @dbs[n] == :safecopy_flushing || @dbs[n] == :safecopy_flushed 182 ret = @hdbc[n].put(k, v) 183 else 184 ret = @hdb[n].put(k, v) 185 end 186 ret 187 end
decr(vn, k, d, v)
click to toggle source
# File lib/roma/storage/basic_storage.rb 387 def decr(vn, k, d, v) 388 buf = db_get(vn, k) 389 return nil unless buf 390 391 # buf != nil 392 vn, t, clk, expt2, v2 = unpack_data(buf) 393 return nil if Time.now.to_i > expt2 394 clk = (clk + 1) & 0xffffffff 395 396 v = (v2.to_i - v) 397 v = 0 if v < 0 398 v = v & 0xffffffffffffffff 399 400 ret = [vn, Time.now.to_i, clk, expt2, v.to_s] 401 return ret if db_put(vn, k, pack_data(*ret)) 402 nil 403 end
delete(vn, k, d)
click to toggle source
# File lib/roma/storage/basic_storage.rb 342 def delete(vn, k, d) 343 buf = db_get(vn, k) 344 v = ret = nil 345 clk = 0 346 if buf 347 vn, t, clk, expt, v2 = unpack_data(buf) 348 return :deletemark if expt == 0 349 clk = (clk + 1) & 0xffffffff 350 v = v2 if v2 && v2.length != 0 && Time.now.to_i <= expt 351 end 352 353 # [ 0.. 3] vn 354 # [ 4.. 7] physical clock(unix time) 355 # [ 8..11] logical clock 356 # [12..15] exptime(unix time) => 0 357 ret = [vn, Time.now.to_i, clk, 0, v] 358 if db_put(vn, k, pack_header(*ret[0..-2])) 359 return ret 360 else 361 return nil 362 end 363 end
dump(vn)
click to toggle source
Returns the vnode dump.
# File lib/roma/storage/basic_storage.rb 543 def dump(vn) 544 buf = get_vnode_hash(vn) 545 return nil if buf.length == 0 546 Marshal.dump(buf) 547 end
each_cache_by_keys(dn, keys) { |vn, last, clk, expt, k, val| ... }
click to toggle source
Calls the geven block, passes the cache(@hdbc) element.
dn
-
number of database
keys
-
key list
# File lib/roma/storage/basic_storage.rb 619 def each_cache_by_keys(dn, keys) 620 keys.each do |k| 621 v = @hdbc[dn].get(k) 622 vn, last, clk, expt, val = unpack_data(v) 623 yield [vn, last, clk, expt, k, val] 624 end 625 end
each_cache_dump_pack(dn, keys) { |vn_dump_pack(vn, last, clk, expt, k, val)| ... }
click to toggle source
Calls the geven block, passes the cache(@hdbc) element as the spushv command data format.
dn
-
number of database
keys
-
key list
# File lib/roma/storage/basic_storage.rb 631 def each_cache_dump_pack(dn, keys) 632 keys.each do |k| 633 v = @hdbc[dn].get(k) 634 vn, last, clk, expt, val = unpack_data(v) 635 yield vn_dump_pack(vn, last, clk, expt, k, val) 636 end 637 end
each_clean_up(t, vnhash) { |k, vn| ... }
click to toggle source
# File lib/roma/storage/basic_storage.rb 424 def each_clean_up(t, vnhash) 425 @do_clean_up = true 426 427 f = nil; 428 if @cleanup_regexp && File.exist?(@storage_path) 429 f = open(@storage_path + '/klist.txt','w') 430 end 431 432 return unless @each_clean_up_lock.try_lock 433 nt = Time.now.to_i 434 @divnum.times do |i| 435 next if @dbs[i] != :normal 436 hdb = @hdb[i] 437 hdb.each do |k, v| 438 return unless @do_clean_up # 1st check 439 vn, last, clk, expt = unpack_header(v) 440 vn_stat = vnhash[vn] 441 if f && @cleanup_regexp && k =~ /#{@cleanup_regexp}/ 442 # write klist 443 f.puts("#{k},#{last},#{clk}") if hdb.get(k) == v 444 end 445 if vn_stat == :primary && ( (expt != 0 && nt > expt) || (expt == 0 && t > last) ) 446 if yield k, vn 447 hdb.out(k) if hdb.get(k) == v 448 end 449 elsif vn_stat == nil && t > last 450 if yield k, vn 451 hdb.out(k) if hdb.get(k) == v 452 end 453 end 454 return unless @do_clean_up # 2nd ckeck 455 sleep @each_clean_up_sleep 456 end 457 end 458 ensure 459 @each_clean_up_lock.unlock if @each_clean_up_lock.locked? 460 if f 461 @cleanup_regexp = nil 462 f.close 463 end 464 end
each_hdb_dump(i,except_vnh = nil) { |[vn, last, clk, expt, length, k, length, val].pack("NNNNNa#{length}Na#{length}")| ... }
click to toggle source
# File lib/roma/storage/basic_storage.rb 594 def each_hdb_dump(i,except_vnh = nil) 595 count = 0 596 @hdb[i].each{|k,v| 597 vn, last, clk, expt, val = unpack_data(v) 598 if except_vnh && except_vnh.key?(vn) || Time.now.to_i > expt 599 count += 1 600 sleep @each_vn_dump_sleep if count % @each_vn_dump_sleep_count == 0 601 else 602 yield [vn, last, clk, expt, k.length, k, val.length, val].pack("NNNNNa#{k.length}Na#{val.length}") 603 sleep @each_vn_dump_sleep 604 end 605 } 606 end
each_vn_dump(target_vn) { |vn_dump_pack(vn, last, clk, expt, k, val)| ... }
click to toggle source
# File lib/roma/storage/basic_storage.rb 549 def each_vn_dump(target_vn) 550 n = @hdiv[target_vn] 551 @stat_lock.synchronize do 552 return false if @dbs[n] != :normal 553 return false if @each_vn_dump_vnodes.include?(target_vn) 554 @each_vn_dump_vnodes << target_vn 555 end 556 557 begin 558 @do_each_vn_dump = true 559 each_unpacked_db(target_vn, @hdb) do |vn, last, clk, expt, k, val| 560 return unless @do_each_vn_dump 561 yield vn_dump_pack(vn, last, clk, expt, k, val) 562 end 563 ensure 564 @each_vn_dump_vnodes.delete(target_vn) 565 end 566 567 true 568 end
flush_db(dn)
click to toggle source
# File lib/roma/storage/basic_storage.rb 670 def flush_db(dn) 671 @hdb[dn].sync 672 end
get(vn, k, d)
click to toggle source
# File lib/roma/storage/basic_storage.rb 295 def get(vn, k, d) 296 buf = db_get(vn, k) 297 return nil unless buf 298 vn, t, clk, expt, v = unpack_data(buf) 299 300 return nil if Time.now.to_i > expt 301 v 302 end
get_context(vn, k, d)
click to toggle source
# File lib/roma/storage/basic_storage.rb 189 def get_context(vn, k, d) 190 buf = db_get(vn, k) 191 return nil unless buf 192 unpack_header(buf) 193 end
get_keys_in_cache(dn, kn=100)
click to toggle source
Returns a key array in a cache(@hdbc).
dn
-
number of database
kn
-
number of keys which is return value
# File lib/roma/storage/basic_storage.rb 642 def get_keys_in_cache(dn, kn=100) 643 return nil if @do_each_vn_dump 644 ret = [] 645 return ret unless @hdbc[dn] 646 count = 0 647 @each_cache_lock.synchronize do 648 @hdbc[dn].each do |k, v| 649 ret << k 650 break if (count+=1) >= kn 651 end 652 end 653 ret 654 end
get_logfile_list()
click to toggle source
# File lib/roma/storage/basic_storage.rb 731 def get_logfile_list 732 l={} 733 files=Dir.glob("#{@storage_path}/status.log.*") 734 files.each{ |file| 735 if /$.+status\.log\.(\d+)$/=~file 736 l[$1.to_i]=$& 737 end 738 } 739 # sorted by old order 740 l.to_a.sort{|a,b| a[0]<=>b[0]} 741 end
get_raw(vn, k, d)
click to toggle source
# File lib/roma/storage/basic_storage.rb 304 def get_raw(vn, k, d) 305 buf = db_get(vn, k) 306 return nil unless buf 307 308 unpack_data(buf) 309 end
get_raw2(k)
click to toggle source
# File lib/roma/storage/basic_storage.rb 311 def get_raw2(k) 312 @hdb.each{|hdb| 313 buf = hdb.get(k) 314 return unpack_data(buf) if buf 315 } 316 nil 317 end
get_stat()
click to toggle source
# File lib/roma/storage/basic_storage.rb 60 def get_stat 61 ret = {} 62 ret['storage.storage_path'] = File.expand_path(@storage_path) 63 ret['storage.st_class'] = @st_class.to_s.match(/Roma::Storage::(.*)/)[1] 64 ret['storage.divnum'] = @divnum 65 ret['storage.option'] = @option 66 ret['storage.each_vn_dump_sleep'] = @each_vn_dump_sleep 67 ret['storage.each_vn_dump_sleep_count'] = @each_vn_dump_sleep_count 68 ret['storage.each_vn_dump_files'] = @each_vn_dump_files.inspect 69 ret['storage.each_clean_up_sleep'] = @each_clean_up_sleep 70 ret['storage.cleanup_regexp'] = @cleanup_regexp 71 ret['storage.logic_clock_expire'] = @logic_clock_expire 72 ret['storage.safecopy_stats'] = @dbs.inspect 73 ret 74 end
incr(vn, k, d, v)
click to toggle source
# File lib/roma/storage/basic_storage.rb 369 def incr(vn, k, d, v) 370 buf = db_get(vn, k) 371 return nil unless buf 372 373 # buf != nil 374 vn, t, clk, expt2, v2 = unpack_data(buf) 375 return nil if Time.now.to_i > expt2 376 clk = (clk + 1) & 0xffffffff 377 378 v = (v2.to_i + v) 379 v = 0 if v < 0 380 v = v & 0xffffffffffffffff 381 382 ret = [vn, Time.now.to_i, clk, expt2, v.to_s] 383 return ret if db_put(vn, k, pack_data(*ret)) 384 nil 385 end
load(dmp)
click to toggle source
# File lib/roma/storage/basic_storage.rb 478 def load(dmp) 479 n = 0 480 h = Marshal.load(dmp) 481 h.each_pair{ |k, v| 482 # remort data 483 r_vn, r_last, r_clk, r_expt = unpack_header(v) 484 raise "An invalid vnode number is include.key=#{k} vn=#{r_vn}" unless @hdiv.key?(r_vn) 485 local = @hdb[@hdiv[r_vn]].get(k) 486 if local == nil 487 n += 1 488 @hdb[@hdiv[r_vn]].put(k, v) 489 else 490 # local data 491 l_vn, l_last, l_clk, l_expt = unpack_data(local) 492 if r_last - l_last < @logic_clock_expire && cmp_clk(r_clk,l_clk) <= 0 493 else # remort is newer. 494 n += 1 495 @hdb[@hdiv[r_vn]].put(k, v) 496 end 497 end 498 sleep @each_vn_dump_sleep 499 } 500 n 501 end
load_stream_dump(vn, last, clk, expt, k, v)
click to toggle source
# File lib/roma/storage/basic_storage.rb 503 def load_stream_dump(vn, last, clk, expt, k, v) 504 buf = db_get(vn, k) 505 if buf 506 data = unpack_header(buf) 507 if last - data[1] < @logic_clock_expire && cmp_clk(clk,data[2]) <= 0 508 return nil 509 end 510 end 511 512 ret = [vn, last, clk, expt, v] 513 if expt == 0 514 # for the deleted mark 515 return ret if db_put(vn, k, pack_header(*ret[0..3])) 516 else 517 return ret if db_put(vn, k, pack_data(*ret)) 518 end 519 nil 520 end
load_stream_dump_for_cachecleaning(vn, last, clk, expt, k, v)
click to toggle source
# File lib/roma/storage/basic_storage.rb 522 def load_stream_dump_for_cachecleaning(vn, last, clk, expt, k, v) 523 n = @hdiv[vn] 524 buf = @hdb[n].get(k) 525 if buf 526 data = unpack_header(buf) 527 if last - data[1] < @logic_clock_expire && cmp_clk(clk,data[2]) <= 0 528 return nil 529 end 530 end 531 532 ret = [vn, last, clk, expt, v] 533 if expt == 0 534 # for the deleted mark 535 return ret if @hdb[n].put(k, pack_header(*ret[0..3])) 536 else 537 return ret if @hdb[n].put(k, pack_data(*ret)) 538 end 539 nil 540 end
open_log()
click to toggle source
# File lib/roma/storage/basic_storage.rb 743 def open_log 744 logs = get_logfile_list 745 if logs.length == 0 746 @log_name="#{@storage_path}/status.log.1" 747 else 748 if File::stat("#{@fname}.#{logs.last[0]}").size == 0 749 @log_name="#{@fname}.#{logs.last[0]}" 750 else 751 @log_name="#{@fname}.#{logs.last[0]+1}" 752 end 753 end 754 @log_fd=File.open(@log_name,"a") 755 end
opendb()
click to toggle source
# File lib/roma/storage/basic_storage.rb 112 def opendb 113 create_div_hash 114 mkdir_p(@storage_path) 115 @divnum.times do |i| 116 # open database file 117 @hdb[i] = open_db("#{@storage_path}/#{i}.#{@ext_name}") 118 # check cache file 119 if File.exist?(cache_file_name(i)) 120 @hdbc[i] = open_db(cache_file_name(i)) 121 stop_clean_up { @dbs[i] = :safecopy_flushed } 122 else 123 @dbs[i] = :normal 124 @hdbc[i] = nil 125 end 126 end 127 open_log 128 end
out(vn, k, d)
click to toggle source
# File lib/roma/storage/basic_storage.rb 365 def out(vn, k, d) 366 @hdb[@hdiv[vn]].out(k) 367 end
out_cache(dn, key)
click to toggle source
Remove a key for the cache(@hdbc).
dn
-
number of database
key
-
key
# File lib/roma/storage/basic_storage.rb 611 def out_cache(dn, key) 612 @hdbc[dn].out(key) 613 end
prepend(vn, k, d, expt, v)
click to toggle source
# File lib/roma/storage/basic_storage.rb 281 def prepend(vn, k, d, expt, v) 282 buf = db_get(vn, k) 283 return nil unless buf 284 285 # buf != nil 286 vn, t, clk, expt2, v2 = unpack_data(buf) 287 return nil if Time.now.to_i > expt2 288 clk = (clk + 1) & 0xffffffff 289 290 ret = [vn, Time.now.to_i, clk, expt, v + v2] 291 return ret if db_put(vn, k, pack_data(*ret)) 292 nil 293 end
rdelete(vn, k, d, clk)
click to toggle source
# File lib/roma/storage/basic_storage.rb 319 def rdelete(vn, k, d, clk) 320 buf = db_get(vn, k) 321 t = Time.now.to_i 322 if buf 323 data = unpack_header(buf) 324 if t - data[1] < @logic_clock_expire && cmp_clk(clk,data[2]) <= 0 325 @error_message = "error:#{t-data[1]} < #{@logic_clock_expire} && cmp_clk(#{clk},#{data[2]})<=0" 326 return nil 327 end 328 end 329 330 # [ 0.. 3] vn 331 # [ 4.. 7] physical clock(unix time) 332 # [ 8..11] logical clock 333 # [12..15] exptime(unix time) => 0 334 ret = [vn, t, clk, 0] 335 if db_put(vn, k, pack_header(*ret)) 336 return ret 337 else 338 return nil 339 end 340 end
replace(vn, k, d, expt, v)
click to toggle source
# File lib/roma/storage/basic_storage.rb 253 def replace(vn, k, d, expt, v) 254 buf = db_get(vn, k) 255 return nil unless buf 256 257 # buf != nil 258 vn, t, clk, expt2, v2 = unpack_data(buf) 259 return nil if Time.now.to_i > expt2 260 clk = (clk + 1) & 0xffffffff 261 262 ret = [vn, Time.now.to_i, clk, expt, v] 263 return ret if db_put(vn, k, pack_data(*ret)) 264 nil 265 end
rset(vn, k, d, clk, expt, v)
click to toggle source
# File lib/roma/storage/basic_storage.rb 208 def rset(vn, k, d, clk, expt, v) 209 buf = db_get(vn, k) 210 t = Time.now.to_i 211 if buf 212 data = unpack_data(buf) 213 if t - data[1] < @logic_clock_expire && cmp_clk(clk,data[2]) <= 0 214 @error_message = "error:#{t-data[1]} < #{@logic_clock_expire} && cmp_clk(#{clk},#{data[2]})<=0" 215 return nil 216 end 217 end 218 219 ret = [vn, t, clk, expt, v] 220 return ret if db_put(vn, k, pack_data(*ret)) 221 @error_message = "error:put" 222 nil 223 end
set(vn, k, d, expt, v)
click to toggle source
# File lib/roma/storage/basic_storage.rb 225 def set(vn, k, d, expt, v) 226 buf = db_get(vn, k) 227 clk = 0 228 if buf 229 data = unpack_data(buf) 230 clk = (data[2] + 1) & 0xffffffff 231 end 232 233 ret = [vn, Time.now.to_i, clk, expt, v] 234 return ret if db_put(vn , k, pack_data(*ret)) 235 nil 236 end
set_db_stat(dn, stat)
click to toggle source
# File lib/roma/storage/basic_storage.rb 678 def set_db_stat(dn, stat) 679 @stat_lock.synchronize do 680 case @dbs[dn] 681 when :normal 682 @each_vn_dump_vnodes.each do |vn| 683 return false if dn == @hdiv[vn] 684 end 685 if stat == :safecopy_flushing 686 # open cache 687 @hdbc[dn] = open_db(cache_file_name(dn)) 688 stop_clean_up { @dbs[dn] = stat } 689 write_log("#{dn} #{stat.to_s}") 690 stat 691 else 692 false 693 end 694 when :safecopy_flushing 695 if stat == :safecopy_flushed 696 write_log("#{dn} #{stat.to_s}") 697 @dbs[dn] = stat 698 else 699 false 700 end 701 when :safecopy_flushed 702 if stat == :cachecleaning 703 write_log("#{dn} #{stat.to_s}") 704 @dbs[dn] = stat 705 else 706 false 707 end 708 when :cachecleaning 709 if stat == :normal 710 write_log("#{dn} #{stat.to_s}") 711 @dbs[dn] = stat 712 # remove cache 713 close_db(@hdbc[dn]) 714 @hdbc[dn] = nil 715 if File.exist?("#{@storage_path}/#{dn}.cache.#{@ext_name}") 716 File.unlink("#{@storage_path}/#{dn}.cache.#{@ext_name}") 717 end 718 stat 719 elsif stat == :safecopy_flushing 720 write_log("#{dn} #{stat.to_s}") 721 @dbs[dn] = stat 722 else 723 false 724 end 725 else 726 false 727 end 728 end 729 end
set_expt(vn, k, d, expt)
click to toggle source
set expire time
# File lib/roma/storage/basic_storage.rb 406 def set_expt(vn, k, d, expt) 407 buf = db_get(vn, k) 408 if buf 409 vn, t, clk, expt2, v = unpack_data(buf) 410 return nil if Time.now.to_i > expt2 411 clk = (clk + 1) & 0xffffffff 412 ret = [vn, Time.now.to_i, clk, expt, v] 413 return ret if db_put(vn, k, pack_data(*ret)) 414 end 415 nil 416 end
stop_clean_up(&block)
click to toggle source
# File lib/roma/storage/basic_storage.rb 466 def stop_clean_up(&block) 467 @do_clean_up = false 468 if block 469 @each_clean_up_lock.lock 470 begin 471 block.call 472 ensure 473 @each_clean_up_lock.unlock 474 end 475 end 476 end
true_length()
click to toggle source
# File lib/roma/storage/basic_storage.rb 418 def true_length 419 res = 0 420 @hdb.each{ |hdb| res += hdb.rnum } 421 res 422 end
write_log(line)
click to toggle source
# File lib/roma/storage/basic_storage.rb 757 def write_log(line) 758 return unless @log_name 759 # log rotation 760 if File::stat(@log_name).size > 1000 * 1024 761 close_log 762 open_log 763 end 764 t = Time.now 765 tstr = "#{t.strftime('%Y-%m-%dT%H:%M:%S')}.#{t.usec}" 766 @log_fd.write("#{tstr} #{line}\n") 767 @log_fd.flush 768 end
Protected Instance Methods
create_div_hash()
click to toggle source
# File lib/roma/storage/basic_storage.rb 91 def create_div_hash 92 @vn_list.each{ |vn| 93 @hdiv[vn] = Digest::SHA1.hexdigest(vn.to_s).hex % @divnum 94 } 95 end
mkdir_p(md_path)
click to toggle source
# File lib/roma/storage/basic_storage.rb 98 def mkdir_p(md_path) 99 path = '' 100 md_path.split('/').each do |p| 101 if p.length == 0 102 path = '/' 103 next 104 end 105 path << p 106 Dir::mkdir(path) unless File.exist?(path) 107 path << '/' 108 end 109 end
Private Instance Methods
cmp_clk(clk1, clk2)
click to toggle source
Compare this clock with the specified.
-1, 0 or 1 as clk1
is numerically less than, equal to, or greater than the clk2
given as the parameter.
logical clock space is a 32bit ring.
# File lib/roma/storage/basic_storage.rb 82 def cmp_clk(clk1, clk2) 83 if (clk1-clk2).abs < 0x80000000 # 1<<31 84 clk1 <=> clk2 85 else 86 clk2 <=> clk1 87 end 88 end
each_unpacked_db(target_vn, db) { |vn, last, clk, expt, k, val| ... }
click to toggle source
# File lib/roma/storage/basic_storage.rb 579 def each_unpacked_db(target_vn, db) 580 count = 0 581 tn = Time.now.to_i 582 db[@hdiv[target_vn]].each do |k,v| 583 vn, last, clk, expt, val = unpack_data(v) 584 if vn != target_vn || (expt != 0 && tn > expt) 585 count += 1 586 sleep @each_vn_dump_sleep if count % @each_vn_dump_sleep_count == 0 587 next 588 end 589 yield vn, last, clk, expt, k, val 590 end 591 end
get_vnode_hash(vn)
click to toggle source
Create vnode dump.
# File lib/roma/storage/basic_storage.rb 657 def get_vnode_hash(vn) 658 buf = {} 659 count = 0 660 @hdb[@hdiv[vn]].each{ |k, v| 661 count += 1 662 sleep @each_vn_dump_sleep if count % @each_vn_dump_sleep_count == 0 663 dat = unpack_data(v) #v.unpack('NNNN') 664 buf[k] = v if dat[0] == vn 665 } 666 return buf 667 end
pack_data(vn, physical_clock, logical_clock, expire,value)
click to toggle source
# File lib/roma/storage/basic_storage.rb 154 def pack_data(vn, physical_clock, logical_clock, expire,value) 155 [vn,physical_clock, logical_clock, expire, value].pack(PACK_TEMPLATE) 156 end
pack_header(vn, physical_clock, logical_clock, expire)
click to toggle source
# File lib/roma/storage/basic_storage.rb 148 def pack_header(vn, physical_clock, logical_clock, expire) 149 [vn,physical_clock, logical_clock, expire].pack(PACK_HEADER_TEMPLATE) 150 end
unpack_data(str)
click to toggle source
# File lib/roma/storage/basic_storage.rb 157 def unpack_data(str) 158 str.unpack(PACK_TEMPLATE) 159 end
unpack_header(str)
click to toggle source
# File lib/roma/storage/basic_storage.rb 151 def unpack_header(str) 152 str.unpack(PACK_HEADER_TEMPLATE) 153 end
vn_dump_pack(vn, last, clk, expt, k, val)
click to toggle source
# File lib/roma/storage/basic_storage.rb 570 def vn_dump_pack(vn, last, clk, expt, k, val) 571 if val 572 return [vn, last, clk, expt, k.length, k, val.length, val].pack("NNNNNa#{k.length}Na#{val.length}") 573 else 574 return [vn, last, clk, expt, k.length, k, 0].pack("NNNNNa#{k.length}N") 575 end 576 end