class Roma::Storage::TCStorage

Public Class Methods

new() click to toggle source
Calls superclass method Roma::Storage::BasicStorage::new
   # File lib/roma/storage/tc_storage.rb
37 def initialize
38   super
39   @ext_name = 'tc'
40 end

Public Instance Methods

closedb() click to toggle source
Calls superclass method Roma::Storage::BasicStorage#closedb
   # File lib/roma/storage/tc_storage.rb
64 def closedb
65   super
66 
67   File.unlink(@fname_lock) if @fname_lock
68   @fname_lock = nil
69 end
get_stat() click to toggle source
Calls superclass method Roma::Storage::BasicStorage#get_stat
   # File lib/roma/storage/tc_storage.rb
43 def get_stat
44   ret = super
45   @hdb.each_with_index{|hdb,idx|
46     ret["storage[#{idx}].path"] = File.expand_path(hdb.path)
47     ret["storage[#{idx}].rnum"] = hdb.rnum
48     ret["storage[#{idx}].fsiz"] = hdb.fsiz
49   }
50   ret
51 end
Also aliased as: get_stat_org
get_stat_org()
Alias for: get_stat
opendb() click to toggle source
Calls superclass method Roma::Storage::BasicStorage#opendb
   # File lib/roma/storage/tc_storage.rb
53 def opendb
54   @fname_lock = "#{@storage_path}/lock"
55   if File.exist?(@fname_lock)
56     raise RuntimeError.new("Lock file already exists.")
57   end
58 
59   super
60 
61   open(@fname_lock,"w"){}
62 end

Protected Instance Methods

set_options(hdb) click to toggle source
   # File lib/roma/storage/tc_storage.rb
73 def set_options(hdb)
74   prop = parse_options
75 
76   prop.each_key{|k|
77     unless /^(bnum|apow|fpow|opts|xmsiz|rcnum|dfunit)$/ =~ k
78       raise RuntimeError.new("Syntax error, unexpected option #{k}")
79     end
80   }
81   
82   opts = 0
83   if prop.key?('opts')
84     opts |= HDB::TLARGE if prop['opts'].include?('l')
85     opts |= HDB::TDEFLATE if prop['opts'].include?('d')
86     opts |= HDB::TBZIP if prop['opts'].include?('b')
87     opts |= HDB::TTCBS if prop['opts'].include?('t')
88   end
89 
90   hdb.tune(prop['bnum'].to_i,prop['apow'].to_i,prop['fpow'].to_i,opts)
91 
92   hdb.setxmsiz(prop['xmsiz'].to_i) if prop.key?('xmsiz')
93   hdb.setcache(prop['rcnum'].to_i) if prop.key?('rcnum')
94   hdb.setdfunit(prop['dfunit'].to_i) if prop.key?('dfunit')
95 end

Private Instance Methods

close_db(hdb) click to toggle source
    # File lib/roma/storage/tc_storage.rb
125 def close_db(hdb)
126   if !hdb.close
127     ecode = hdb.ecode
128     raise RuntimeError.new("tcdb close error #{hdb.errmsg(ecode)}")
129   end
130 end
open_db(fname) click to toggle source
    # File lib/roma/storage/tc_storage.rb
113 def open_db(fname)
114   hdb = HDB::new
115 
116   set_options(hdb)
117   
118   if !hdb.open(fname, HDB::OWRITER | HDB::OCREAT | HDB::ONOLCK)
119     ecode = hdb.ecode
120     raise RuntimeError.new("tcdb open error #{hdb.errmsg(ecode)}")
121   end
122   hdb
123 end
parse_options() click to toggle source
    # File lib/roma/storage/tc_storage.rb
 99 def parse_options
100   return Hash.new(-1) unless @option
101   buf = @option.split('#')
102   prop = Hash.new(-1)
103   buf.each{|equ|
104     if /(\S+)\s*=\s*(\S+)/ =~ equ
105       prop[$1] = $2
106     else
107       raise RuntimeError.new("Option string parse error.")
108     end
109   }
110   prop
111 end