Module Rufus::Tokyo::CabinetConfig

  1. lib/rufus/tokyo/config.rb

Methods for setting up / tuning a Cabinet.

Constants

CABINET_SUFFIXES = { :hash => '.tch', :btree => '.tcb', :fixed => '.tcf', :table => '.tct' }
CABINET_TYPES = CABINET_SUFFIXES.invert

Protected instance methods

determine_cache_values (params)
[show source]
     # File lib/rufus/tokyo/config.rb, line 124
124:     def determine_cache_values (params) #:nodoc#
125: 
126:       {
127:         :rcnum => params[:rcnum].to_i,
128:         :lcnum => (params[:lcnum] || 2048).to_i,
129:         :ncnum => (params[:ncnum] || 512).to_i
130:       }
131:     end
determine_conf (path, params, required_type=nil)

Given a path, a hash of parameters and a suffix,

a) makes sure that the path has the given suffix or raises an exception b) gathers params found in the path (#) or in params c) determines the config as set by the parameters

Suffix is optional, if present, it will be enforced.

[show source]
    # File lib/rufus/tokyo/config.rb, line 44
44:     def determine_conf (path, params, required_type=nil)
45: 
46:       if path.index('#')
47: 
48:         ss = path.split('#')
49:         path = ss.shift
50: 
51:         ss.each { |p| pp = p.split('='); params[pp[0]] = pp[1] }
52:       end
53: 
54:       params = params.inject({}) { |h, (k, v)| h[k.to_sym] = v; h }
55: 
56:       [
57:         {
58:           :params => params,
59:           :mode => determine_open_mode(params),
60:           :mutex => (params[:mutex].to_s == 'true'),
61:           #:indexes => params[:idx] || params[:indexes],
62:           :xmsiz => (params[:xmsiz] || 67108864).to_i,
63:         },
64:         determine_type_and_path(path, params, required_type),
65:         determine_tuning_values(params),
66:         determine_cache_values(params)
67: 
68:       ].inject({}) { |h, hh| h.merge(hh) }
69:     end
determine_open_mode (params)
[show source]
    # File lib/rufus/tokyo/config.rb, line 71
71:     def determine_open_mode (params) #:nodoc#
72: 
73:       mode = params[:mode].to_s
74:       mode = 'wc' if mode.size < 1
75: 
76:       {
77:         'r' => (1 << 0), # open as a reader
78:         'w' => (1 << 1), # open as a writer
79:         'c' => (1 << 2), # writer creating
80:         't' => (1 << 3), # writer truncating
81:         'e' => (1 << 4), # open without locking
82:         'f' => (1 << 5), # lock without blocking
83:         's' => (1 << 6), # synchronize every transaction (tctdb.h)
84: 
85:       }.inject(0) { |r, (c, v)|
86: 
87:         r = r | v if mode.index(c); r
88:       }
89:     end
determine_tuning_values (params)
[show source]
     # File lib/rufus/tokyo/config.rb, line 91
 91:     def determine_tuning_values (params) #:nodoc#
 92: 
 93:       o = params[:opts] || ''
 94:       o = {
 95:         'l' => 1 << 0, # large
 96:         'd' => 1 << 1, # deflate
 97:         'b' => 1 << 2, # bzip2
 98:         't' => 1 << 3, # tcbs
 99:         'x' => 1 << 4
100:       }.inject(0) { |i, (k, v)| i = i | v if o.index(k); i }
101: 
102:       {
103:         :bnum => (params[:bnum] || 131071).to_i,
104:         :apow => (params[:apow] || 4).to_i,
105:         :fpow => (params[:fpow] || 10).to_i,
106:         :opts => o,
107: 
108:         :lmemb => (params[:lmemb] || 128).to_i,
109:           # number of members in each leaf page (:btree)
110:         :nmemb => (params[:nmemb] || 256).to_i,
111:           # number of members in each non-leaf page (:btree)
112: 
113:         :width => (params[:width] || 255).to_i,
114:           # width of the value of each record (:fixed)
115:         :limsiz => (params[:limsiz] || 26_8435_456).to_i,
116:           # limit size of the database file (:fixed)
117: 
118:         :dfunit => (params[:dfunit] || 0).to_i
119:           # unit step number. If it is not more than 0,
120:           # the auto defragmentation is disabled.
121:       }
122:     end
determine_type_and_path (path, params, required_type)
[show source]
     # File lib/rufus/tokyo/config.rb, line 139
139:     def determine_type_and_path (path, params, required_type) #:nodoc#
140: 
141:       type = required_type || params[:type]
142:       ext = File.extname(path)
143: 
144:       if ext == ''
145:         suffix = CABINET_SUFFIXES[type]
146:         path = path + suffix
147:       else
148:         suffix = ext
149:         type ||= CABINET_TYPES[ext]
150:       end
151: 
152:       raise "path '#{path}' must be suffixed with #{suffix}" \
153:         if suffix and File.extname(path) != suffix
154: 
155:       { :path => path, :type => type }
156:     end