Parent

Included Modules

Class/Module Index [+]

Quicksearch

RR::ReplicationHelper

Provides helper functionality for replicators. The methods exposed by this class are intended to provide a stable interface for third party replicators.

Attributes

replication_run[RW]

The current ReplicationRun instance

Public Class Methods

new(replication_run) click to toggle source

Creates a new SyncHelper for the given TableSync instance.

# File lib/rubyrep/replication_helper.rb, line 133
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[options[:committer]]
  @committer = committer_class.new(session)
end

Public Instance Methods

corresponding_table(db_arm, table) click to toggle source

Delegates to Session#corresponding_table

# File lib/rubyrep/replication_helper.rb, line 30
def corresponding_table(db_arm, table); session.corresponding_table(db_arm, table); end
delete_record(database, table, values) click to toggle source

Delegates to Committers::BufferedCommitter#delete_record

# File lib/rubyrep/replication_helper.rb, line 49
def delete_record(database, table, values)
  committer.delete_record(database, table, values)
end
finalize(success = true) click to toggle source

Asks the committer (if it exists) to finalize any open transactions success should be true if there were no problems, false otherwise.

# File lib/rubyrep/replication_helper.rb, line 76
def finalize(success = true)
  committer.finalize(success)
end
insert_record(database, table, values) click to toggle source

Delegates to Committers::BufferedCommitter#insert_record

# File lib/rubyrep/replication_helper.rb, line 39
def insert_record(database, table, values)
  committer.insert_record(database, table, values)
end
load_record(database, table, key) click to toggle source

Loads the specified record. Returns an according column_name => value hash. Parameters:

  • database: either :left or :right

  • table: name of the table

  • key: A column_name => value hash for all primary key columns.

# File lib/rubyrep/replication_helper.rb, line 58
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) click to toggle source

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

# File lib/rubyrep/replication_helper.rb, line 104
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|
      %("#{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 "#{options[: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
new_transaction?() click to toggle source

Returns true if a new transaction was started since the last insert / update / delete.

# File lib/rubyrep/replication_helper.rb, line 34
def new_transaction?
  committer.new_transaction?
end
options() click to toggle source

Current options

# File lib/rubyrep/replication_helper.rb, line 17
def options; @options ||= session.configuration.options; end
options_for_table(table) click to toggle source

Returns the options for the specified table name.

  • table: name of the table (left database version)

# File lib/rubyrep/replication_helper.rb, line 21
def options_for_table(table)
  @options_for_table ||= {}
  unless @options_for_table.include? table
    @options_for_table[table] = session.configuration.options_for_table(table)
  end
  @options_for_table[table]
end
session() click to toggle source

The active Session

# File lib/rubyrep/replication_helper.rb, line 14
def session; replication_run.session; end
type_cast(table, row) click to toggle source

Converts the row values into their proper types as per table definition.

  • table: name of the table after whose columns is type-casted.

  • row: A column_name => value hash of the row

Returns a copy of the column_name => value hash (with type-casted values).

# File lib/rubyrep/replication_helper.rb, line 84
def type_cast(table, row)
  @table_columns ||= {}
  unless @table_columns.include?(table)
    column_array = session.left.columns(table)
    column_hash = {}
    column_array.each {|column| column_hash[column.name] = column}
    @table_columns[table] = column_hash
  end
  columns = @table_columns[table]
  type_casted_row = {}
  row.each_pair do |column_name, value|
    type_casted_row[column_name] = columns[column_name].type_cast(value)
  end
  type_casted_row
end
update_record(database, table, values, old_key = nil) click to toggle source

Delegates to Committers::BufferedCommitter#update_record

# File lib/rubyrep/replication_helper.rb, line 44
def update_record(database, table, values, old_key = nil)
  committer.update_record(database, table, values, old_key)
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.