Class: PartitionGardener::PlanApplier

Inherits:
Object
  • Object
show all
Includes:
Naming
Defined in:
lib/partition_gardener/plan_applier.rb

Instance Method Summary collapse

Methods included from Naming

current_partition_name, default_partition_name, future_partition_name, open_partition_name, rebalance_staging_partition_name

Constructor Details

#initialize(config, executor: nil, job_class_name: "PartitionGardener") ⇒ PlanApplier

Returns a new instance of PlanApplier.



5
6
7
8
9
# File 'lib/partition_gardener/plan_applier.rb', line 5

def initialize(config, executor: nil, job_class_name: "PartitionGardener")
  @config = config
  @executor = executor || Executor.for_config(config)
  @job_class_name = job_class_name
end

Instance Method Details

#apply!(plan) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/partition_gardener/plan_applier.rb', line 11

def apply!(plan)
  DefaultPartition.ensure!(@config, executor: @executor)
  attached = attached_tail_segments
  return unless plan.changed?(attached)

  table_name = @config[:table_name]
  staging_name = rebalance_staging_partition_name(table_name)
  plan_signature = PlanDiff.plan_signature(plan.segments)
  PartitionGardener.configuration.current_run_metrics&.plan_signature = plan_signature
  record = run_record_enabled? ? RunRecord.load(table_name) : nil

  guard_against_orphaned_staging!(staging_name, record, plan_signature)
  operations = PlanDiff.operations(attached, plan.segments)

  if resumable_run?(record, plan_signature, staging_name)
    notify_resume(record)
    apply_resuming!(plan, operations, staging_name, record)
  elsif incremental_rebalance?
    apply_incremental!(plan, operations, staging_name, plan_signature)
  else
    apply_full!(plan, staging_name, plan_signature)
  end

  analyze_parent_table!(table_name)
  notify_rebalance_complete(table_name, plan)
  RunRecord.clear(table_name) if run_record_enabled?
end