Parent

Class/Module Index [+]

Quicksearch

RR::ReplicationDifference

Describes a (record specific) difference between both databases as identifed via change log.

Constants

DIFF_TYPES

Resulting diff type based on types of left changes (outer hash) and right changes (inner hash)

OTHER_SIDE

Shortcut to calculate the “other” database.

Attributes

loaded[W]

Should be set to true if this ReplicationDifference instance was successfully loaded.

loaders[RW]

The current LoggedChangeLoaders instance

second_chance[RW]

Is set to true if first replication attempt failed but it should be tried again later

second_chance?[RW]

Is set to true if first replication attempt failed but it should be tried again later

type[RW]

The type of the difference. Either

  • :left: change in left database

  • :right: change in right database

  • :conflict: change in both databases

  • :no_diff: changes in both databases constitute no difference

Public Class Methods

new(loaders) click to toggle source

Creates a new ReplicationDifference instance. loaders is teh current LoggedChangeLoaders instance

# File lib/rubyrep/replication_difference.rb, line 34
def initialize(loaders)
  self.loaders = loaders
end

Public Instance Methods

amend() click to toggle source

Amends a difference according to new entries in the change log table

# File lib/rubyrep/replication_difference.rb, line 63
def amend
  loaders.update
  changes[:left].load
  changes[:right].load
  self.type = DIFF_TYPES[changes[:left].type][changes[:right].type]
end
changes() click to toggle source

A hash with keys :left and / or :right. Hash values are LoggedChange instances.

# File lib/rubyrep/replication_difference.rb, line 28
def changes
  @changes ||= {}
end
load() click to toggle source

Loads a difference

# File lib/rubyrep/replication_difference.rb, line 71
def load
  change_times = {}
  [:left, :right].each do |database|
    changes[database] = LoggedChange.new loaders[database]
    change_times[database] = loaders[database].oldest_change_time
  end
  return if change_times[:left] == nil and change_times[:right] == nil

  oldest = nil
  [:left, :right].each do |database|
    oldest = OTHER_SIDE[database] if change_times[database] == nil
  end
  oldest ||= change_times[:left] <= change_times[:right] ? :left : :right
  changes[oldest].load_oldest

  changes[OTHER_SIDE[oldest]].load_specified(
    session.corresponding_table(oldest, changes[oldest].table),
    changes[oldest].key)

  self.type = DIFF_TYPES[changes[:left].type][changes[:right].type]
  self.loaded = true
end
loaded?() click to toggle source

Returns true if a replication difference was loaded

# File lib/rubyrep/replication_difference.rb, line 43
def loaded?
  @loaded
end
session() click to toggle source

The current Session.

# File lib/rubyrep/replication_difference.rb, line 8
def session
  @session ||= loaders.session
end
to_yaml_properties() click to toggle source

Prevents session and change loaders from going into YAML output

# File lib/rubyrep/replication_difference.rb, line 95
def to_yaml_properties
  instance_variables.sort.reject {|var_name| ['@session', '@loaders'].include? var_name}
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.