Class | RR::Replicators::TwoWayReplicator |
In: |
lib/rubyrep/replicators/two_way_replicator.rb
|
Parent: | Object |
This replicator implements a two way replication. Options:
Example of using a Proc object for custom behaviour:
lambda do |rep_helper, diff| # if specified as replication_conflict_handling option, logs all # conflicts to a text file File.open('/var/log/rubyrep_conflict_log', 'a') do |f| f.puts <<-end_str #{Time.now}: conflict * in table #{diff.changes[:left].table} * for record '#{diff.changes[:left].key}' * change type in left db: '#{diff.changes[:left].type}' * change type in right db: '#{diff.changes[:right].type}' end_str end end
OTHER_SIDE | = | { :left => :right, :right => :left | Shortcut to calculate the "other" database. | |
CONFLICT_STATE_MATRIX | = | { :insert => {:insert => :update, :update => :update, :delete => :insert}, :update => {:insert => :update, :update => :update, :delete => :insert}, :delete => {:insert => :delete, :update => :delete, :delete => :delete} | Specifies how to clear conflicts. The outer hash keys describe the type of the winning change. The inner hash keys describe the type of the loosing change. The inser hash values describe the action to take on the loosing side. | |
MAX_REPLICATION_ATTEMPTS | = | 2 | How often a replication will be attempted (in case it fails because the record in question was removed from the source or inserted into the target database after the ReplicationDifference was loaded |
rep_helper | [RW] | The current ReplicationHelper object |
Initializes the TwoWayReplicator Raises an ArgumentError if any of the replication options is invalid.
Parameters:
Helper for execution of insert / update / delete attempts. Wraps those attempts into savepoints and handles exceptions.
Note: Savepoints have to be used for PostgreSQL (as a failed SQL statement will otherwise invalidate the complete transaction.)
Attempts to delete the source record from the target database.
:right.
Attempts to read the specified record from the source database and insert it into the target database. Retries if insert fails due to missing source or suddenly existing target record.
Attempts to read the specified record from the source database and update the specified record in the target database. Retries if update fails due to missing source
Helper function that clears a conflict by taking the change from the specified winning database and updating the other database accordingly.
Logs replication of the specified difference as per configured :replication_conflict_logging / :left_change_logging / :right_change_logging options.
Called to replicate the specified difference.
Verifies if the :left_change_handling / :right_change_handling options are valid. Raises an ArgumentError if an option is invalid
Verifies if the given :replication_conflict_handling options are valid. Raises an ArgumentError if an option is invalid.
Verifies if the given :replication_logging option /options is / are valid. Raises an ArgumentError if invalid
Checks if an option is configured correctly. Raises an ArgumentError if not.