bud 0.1.0.pre1 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,10 +1,9 @@
1
1
  require 'dbm'
2
2
 
3
3
  module Bud
4
- # Persistent table implementation based on ndbm.
4
+ # Persistent table implementation based on dbm.
5
5
  class BudDbmTable < BudPersistentCollection # :nodoc: all
6
6
  def initialize(name, bud_instance, given_schema)
7
- @invalidated = true
8
7
  dbm_dir = bud_instance.options[:dbm_dir]
9
8
  raise Bud::Error, "dbm support must be enabled via 'dbm_dir'" unless dbm_dir
10
9
  if bud_instance.port.nil?
@@ -23,6 +22,7 @@ module Bud
23
22
 
24
23
  super(name, bud_instance, given_schema)
25
24
  @to_delete = []
25
+ @invalidated = true
26
26
 
27
27
  db_fname = "#{dirname}/#{name}.dbm"
28
28
  flags = DBM::WRCREAT
@@ -70,7 +70,6 @@ module Bud
70
70
  end
71
71
 
72
72
  def make_tuple(k_ary, v_ary)
73
- #t = Array.new(k_ary.length + v_ary.length)
74
73
  t = @struct.new
75
74
  @key_colnums.each_with_index do |k,i|
76
75
  t[k] = k_ary[i]
@@ -85,7 +84,7 @@ module Bud
85
84
  each_from([@delta], &block)
86
85
  each_storage(&block)
87
86
  end
88
-
87
+
89
88
  def each_raw(&block)
90
89
  each_storage(&block)
91
90
  end
@@ -142,7 +141,7 @@ module Bud
142
141
  def tick_deltas
143
142
  unless @delta.empty?
144
143
  merge_to_db(@delta)
145
- @tick_delta += @delta.values
144
+ @tick_delta += @delta.values if accumulate_tick_deltas
146
145
  @delta.clear
147
146
  end
148
147
  unless @new_delta.empty?
@@ -151,7 +150,7 @@ module Bud
151
150
  end
152
151
  return !(@delta.empty?)
153
152
  end
154
-
153
+
155
154
  public
156
155
  def flush_deltas
157
156
  unless @delta.empty?
@@ -164,21 +163,20 @@ module Bud
164
163
  end
165
164
 
166
165
  # This is verbatim from BudTable. Need to DRY up. Should we be a subclass of BudTable?
167
- public
166
+ public
168
167
  def pending_delete(o)
169
168
  if o.class <= Bud::PushElement
170
169
  o.wire_to_delete self
171
- elsif o.class <= Bud::BudCollection
172
- o.pro.wire_to_delete self
173
- else
174
- @to_delete = @to_delete + o.map{|t| prep_tuple(t) unless t.nil?}
175
- end
170
+ elsif o.class <= Bud::BudCollection
171
+ o.pro.wire_to_delete self
172
+ else
173
+ @to_delete = @to_delete + o.map{|t| prep_tuple(t) unless t.nil?}
174
+ end
176
175
  end
177
176
  superator "<-" do |o|
178
177
  pending_delete(o)
179
178
  end
180
-
181
-
179
+
182
180
  def insert(tuple)
183
181
  key = get_key_vals(tuple)
184
182
  merge_tuple_to_db(key, tuple)
@@ -215,15 +213,7 @@ module Bud
215
213
  def invalidate_cache
216
214
  end
217
215
 
218
- def method_missing(sym, *args, &block)
219
- @dbm.send sym, *args, &block
220
- end
221
-
222
- public
223
- def length
224
- @dbm.length
225
- end
226
-
216
+ # XXX: shouldn't this check @delta as well?
227
217
  public
228
218
  def empty?
229
219
  @dbm.empty?
@@ -36,10 +36,6 @@ module Bud
36
36
  stat_and_watch
37
37
  end
38
38
 
39
- def clone_empty
40
- raise Bud::Error
41
- end
42
-
43
39
  def stat_and_watch
44
40
  r = @zk.stat(:path => @zk_path, :watcher => @stat_watcher)
45
41
  @stat_watch_id = r[:req_id]