Class: DpStmMap::ClientTransactionManager

Inherits:
Object
  • Object
show all
Defined in:
lib/dp_stm_map/Manager.rb

Instance Method Summary collapse

Constructor Details

#initialize(current_values, reference_counts, transaction_log) ⇒ ClientTransactionManager

Returns a new instance of ClientTransactionManager.



317
318
319
320
321
# File 'lib/dp_stm_map/Manager.rb', line 317

def initialize current_values, reference_counts, transaction_log
  @current_values=current_values
  @reference_counts=reference_counts
  @transaction_log=transaction_log
end

Instance Method Details

#apply_transaction(transitions, new_values) ⇒ Object



324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
# File 'lib/dp_stm_map/Manager.rb', line 324

def apply_transaction transitions, new_values

  values_to_remove=Set.new
  values_to_add={}
  references_to_change={}

  transitions.each do |k,(old,new)|
    current=@current_values[k]
    raise StaleTransactionError, "transaction changing stale state" if (current != old)

    next if old == new

    if new && !@reference_counts.has_references?(new)
      unless new_values.has_key? new
        raise StaleTransactionError, "referencing not existing data"
      else
        values_to_add[new]=new_values[new]
      end

    end
  end

  transitions.each do |k,(old,new)|
    if (old != new)
      values_to_remove << old
      references_to_change[k]=new
      @current_values[k]=new
      @reference_counts.add_reference(new) if new
      @reference_counts.remove_reference(old) if old
    end
  end

  values_to_remove=values_to_remove.select {|v| v && !@reference_counts.has_references?(v)}

  # unless references_to_change.empty?
  @transaction_log.store_transaction references_to_change, values_to_add, values_to_remove.to_set.to_a
  # end



end