Class: RR::ReplicationHelper
- Inherits:
-
Object
- Object
- RR::ReplicationHelper
- Includes:
- LogHelper
- Defined in:
- lib/rubyrep/replication_helper.rb
Overview
Provides helper functionality for replicators. The methods exposed by this class are intended to provide a stable interface for third party replicators.
Instance Attribute Summary collapse
-
#replication_run ⇒ Object
The current
ReplicationRuninstance.
Instance Method Summary collapse
-
#corresponding_table(db_arm, table) ⇒ Object
Delegates to Session#corresponding_table.
-
#delete_record(database, table, values) ⇒ Object
Delegates to Committer#insert_record.
-
#finalize(success = true) ⇒ Object
Asks the committer (if it exists) to finalize any open transactions
successshould be true if there were no problems, false otherwise. -
#initialize(replication_run) ⇒ ReplicationHelper
constructor
Creates a new SyncHelper for the given
TableSyncinstance. -
#insert_record(database, table, values) ⇒ Object
Delegates to Committer#insert_record.
-
#load_record(database, table, key) ⇒ Object
Loads the specified record.
-
#log_replication_outcome(diff, outcome, details = nil) ⇒ Object
Logs the outcome of a replication into the replication log table.
-
#options ⇒ Object
Current options.
-
#session ⇒ Object
The active
Session. -
#update_record(database, table, values, old_key = nil) ⇒ Object
Delegates to Committer#insert_record.
Constructor Details
#initialize(replication_run) ⇒ ReplicationHelper
Creates a new SyncHelper for the given TableSync instance.
97 98 99 100 101 102 103 104 |
# File 'lib/rubyrep/replication_helper.rb', line 97 def initialize(replication_run) self.replication_run = replication_run # Creates the committer. Important as it gives the committer the # opportunity to start transactions committer_class = Committers::committers[[:committer]] @committer = committer_class.new(session) end |
Instance Attribute Details
#replication_run ⇒ Object
The current ReplicationRun instance
11 12 13 |
# File 'lib/rubyrep/replication_helper.rb', line 11 def replication_run @replication_run end |
Instance Method Details
#corresponding_table(db_arm, table) ⇒ Object
Delegates to Session#corresponding_table
20 |
# File 'lib/rubyrep/replication_helper.rb', line 20 def corresponding_table(db_arm, table); session.corresponding_table(db_arm, table); end |
#delete_record(database, table, values) ⇒ Object
Delegates to Committer#insert_record
33 34 35 |
# File 'lib/rubyrep/replication_helper.rb', line 33 def delete_record(database, table, values) committer.delete_record(database, table, values) end |
#finalize(success = true) ⇒ Object
Asks the committer (if it exists) to finalize any open transactions success should be true if there were no problems, false otherwise.
60 61 62 |
# File 'lib/rubyrep/replication_helper.rb', line 60 def finalize(success = true) committer.finalize(success) end |
#insert_record(database, table, values) ⇒ Object
Delegates to Committer#insert_record
23 24 25 |
# File 'lib/rubyrep/replication_helper.rb', line 23 def insert_record(database, table, values) committer.insert_record(database, table, values) end |
#load_record(database, table, key) ⇒ Object
Loads the specified record. Returns an according column_name => value hash. Parameters:
-
database: either :leftor :right -
table: name of the table -
key: A column_name => value hash for all primary key columns.
42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/rubyrep/replication_helper.rb', line 42 def load_record(database, table, key) cursor = session.send(database).select_cursor( :table => table, :row_keys => [key], :type_cast => true ) row = nil row = cursor.next_row if cursor.next? cursor.clear row end |
#log_replication_outcome(diff, outcome, details = nil) ⇒ Object
Logs the outcome of a replication into the replication log table.
-
diff: the replicated ReplicationDifference -
outcome: string summarizing the outcome of the replication -
details: string with further details regarding the replication
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/rubyrep/replication_helper.rb', line 68 def log_replication_outcome(diff, outcome, details = nil) table = diff.changes[:left].table key = diff.changes[:left].key if key.size == 1 key = key.values[0] else key_parts = session.left.primary_key_names(table).map do |column_name| %Q("#{column_name}"=>#{key[column_name].to_s.inspect}) end key = key_parts.join(', ') end rep_outcome, rep_details = fit_description_columns(outcome, details) diff_dump = diff.to_yaml[0...ReplicationInitializer::DIFF_DUMP_SIZE] session.left.insert_record "#{[:rep_prefix]}_logged_events", { :activity => 'replication', :change_table => table, :diff_type => diff.type.to_s, :change_key => key, :left_change_type => (diff.changes[:left] ? diff.changes[:left].type.to_s : nil), :right_change_type => (diff.changes[:right] ? diff.changes[:right].type.to_s : nil), :description => rep_outcome, :long_description => rep_details, :event_time => Time.now, :diff_dump => diff_dump } end |
#options ⇒ Object
Current options
17 |
# File 'lib/rubyrep/replication_helper.rb', line 17 def ; @options ||= session.configuration.; end |
#session ⇒ Object
The active Session
14 |
# File 'lib/rubyrep/replication_helper.rb', line 14 def session; replication_run.session; end |
#update_record(database, table, values, old_key = nil) ⇒ Object
Delegates to Committer#insert_record
28 29 30 |
# File 'lib/rubyrep/replication_helper.rb', line 28 def update_record(database, table, values, old_key = nil) committer.update_record(database, table, values, old_key) end |