class Roma::MakeRecentData

Public Class Methods

new(argv = nil) click to toggle source
   # File lib/roma/tools/mkrecent.rb
16 def initialize(argv = nil)
17   if argv.length != 6
18     STDERR.puts "usage:mkrecent dgst-bits div-bits divnum storage-path1 storage-path2 recent-storage-path"
19     exit
20   end
21 
22   dgst_bits = argv[0].to_i
23   div_bits = argv[1].to_i
24   @divnum = argv[2].to_i
25   @strgpath1 = argv[3]
26   @strgpath2 = argv[4]
27   @recentpath = argv[5]
28 
29   @vnodes = []
30   (2**div_bits).times{|i|
31     @vnodes << ( i<<(dgst_bits-div_bits) )
32   }
33 end

Public Instance Methods

close_storage() click to toggle source
   # File lib/roma/tools/mkrecent.rb
84 def close_storage
85   @st1.closedb
86   @st2.closedb
87   @rst.closedb
88 end
exec(hname) click to toggle source
    # File lib/roma/tools/mkrecent.rb
 90 def exec(hname)
 91   n = 0
 92   @vnodes.each{|vn|
 93     printf "#{hname}:#{n}/#{@vnodes.length}\r"
 94     n+=1
 95     buf = @st1.dump(vn)
 96     @rst.load( buf ) if buf
 97     buf = @st2.dump(vn)
 98     @rst.load( buf ) if buf
 99   }
100 end
open_storage(p1,p2,rp) click to toggle source
   # File lib/roma/tools/mkrecent.rb
55 def open_storage(p1,p2,rp)
56   puts "Open #{p1}"
57   @st1 = ropen(p1)
58   @st1.each_vn_dump_sleep = 0
59   exit unless @st1
60   puts "Open #{p2}"
61   @st2 = ropen(p2)
62   @st2.each_vn_dump_sleep = 0
63   unless @st2
64     STDERR.puts ""
65     @st1.closedb
66     exit
67   end
68 
69   if @st1.class != @st2.class
70     STDERR.puts "#{p1} and #{p2} that file type is different."
71     @st1.closedb
72     @st2.closedb
73     exit
74   end
75 
76   puts "Open #{rp}"
77   @rst = @st1.class.new
78   @rst.divnum = @divnum
79   @rst.vn_list = @vnodes
80   @rst.storage_path = rp
81   @rst.opendb
82 end
suite() click to toggle source
   # File lib/roma/tools/mkrecent.rb
35 def suite
36   if File::directory?(@recentpath)
37     STDERR.puts "#{@recentpath} exists."
38     exit
39   end
40 
41   Dir::mkdir(@recentpath)
42 
43   Dir::glob("#{@strgpath1}/*").each{|dir|
44     next unless File::directory?(dir)
45     hname = dir[dir.rindex('/')+1..-1]
46     open_storage(dir,
47                  "#{@strgpath2}/#{hname}",
48                  "#{@recentpath}/#{hname}")
49     exec(hname)
50 
51     close_storage
52   }
53 end

Private Instance Methods

new_storage(ext) click to toggle source
    # File lib/roma/tools/mkrecent.rb
120 def new_storage(ext)
121   case(ext)
122   when 'tc'
123     return ::Roma::Storage::TCStorage.new
124   when 'dbm'
125     return Roma::Storage::DbmStorage.new
126   when 'sql3'
127     return Roma::Storage::SQLite3Storage.new
128   else
129     return nil
130   end
131 end
ropen(path) click to toggle source
    # File lib/roma/tools/mkrecent.rb
104 def ropen(path)
105   unless File::directory?(path)
106     STDERR.puts "#{path} does not found."
107     return nil
108   end
109 
110   ext = File::extname(Dir::glob("#{path}/0.*")[0])[1..-1]
111 
112   storage = new_storage(ext)
113   storage.divnum = @divnum
114   storage.vn_list = @vnodes
115   storage.storage_path = path
116   storage.opendb
117   storage
118 end