Class: Pcrd::Cutover::Orchestrator
- Inherits:
-
Object
- Object
- Pcrd::Cutover::Orchestrator
- Defined in:
- lib/pcrd/cutover/orchestrator.rb
Overview
Orchestrates the cutover sequence.
Preconditions (operator’s responsibility):
- Application is in maintenance mode (writes to source have stopped)
- pcrd migrate is running in streaming mode (or was cleanly stopped)
Steps:
1. Verify the migration is at a cuttable phase (backfill complete)
2. Drain remaining replication lag to zero (with timeout)
3. Advance sequences on target
4. Verify row counts match
5. Print cutover report and "READY" signal
Defined Under Namespace
Classes: Result
Instance Method Summary collapse
-
#initialize(source_pool:, target_pool:, config:) ⇒ Orchestrator
constructor
A new instance of Orchestrator.
-
#run(on_progress: nil) ⇒ Object
Runs the full cutover sequence.
Constructor Details
#initialize(source_pool:, target_pool:, config:) ⇒ Orchestrator
Returns a new instance of Orchestrator.
26 27 28 29 30 |
# File 'lib/pcrd/cutover/orchestrator.rb', line 26 def initialize(source_pool:, target_pool:, config:) @source = source_pool @target = target_pool @config = config end |
Instance Method Details
#run(on_progress: nil) ⇒ Object
Runs the full cutover sequence. on_progress: optional Proc called with a status string during drain
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/pcrd/cutover/orchestrator.rb', line 34 def run(on_progress: nil) warnings = [] table_names = (@config.migrate&.tables || []).map(&:name) # 1. Drain remaining lag on_progress&.call("Draining replication lag...") lag = drain_lag(table_names, on_progress: on_progress) # 2. Advance sequences on_progress&.call("Advancing target sequences...") seq_results = Sequences.new( source_pool: @source, target_pool: @target, safety_buffer: @config.cutover&.sequence_buffer || 1_000 ).advance(table_names) # 3. Row count verification on_progress&.call("Verifying row counts...") row_counts = verify_counts(table_names, warnings) passed = row_counts.all? { |_, v| v[:source] == v[:target] } Result.new( passed: passed, row_counts: row_counts, sequence_results: seq_results, lag_at_cutover: lag, warnings: warnings ) end |