Class: Pcrd::Commands::Verify

Inherits:
Object
  • Object
show all
Defined in:
lib/pcrd/commands/verify.rb

Overview

Compares row counts and spot-checks random rows between source and target.

Safe to run at any time after backfill completes. Does not modify either cluster.

Defined Under Namespace

Classes: Result, TableResult

Constant Summary collapse

MismatchError =
Class.new(StandardError)

Instance Method Summary collapse

Constructor Details

#initialize(config, options = {}) ⇒ Verify

Returns a new instance of Verify.



15
16
17
18
# File 'lib/pcrd/commands/verify.rb', line 15

def initialize(config, options = {})
  @config  = config
  @options = Options.normalize(options)
end

Instance Method Details

#runObject



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/pcrd/commands/verify.rb', line 20

def run
  validate_config!

  source_pool = Connection::Client.new(@config.source)
  target_pool = Connection::Client.new(@config.target)
  sample_size = @options[:"sample-size"] || @config.verify&.sample_size || 1_000

  table_results = (@config.migrate&.tables || []).map do |table_config|
    verify_table(source_pool, target_pool, table_config, sample_size)
  end

  source_pool.close
  target_pool.close

  Result.new(
    passed: table_results.all? { |r| r.mismatches.empty? && r.source_count == r.target_count },
    tables: table_results
  )
end