Class: PartitionGardener::PlanReport

Inherits:
Object
  • Object
show all
Defined in:
lib/partition_gardener/plan_report.rb

Constant Summary collapse

SCHEMA_VERSION =
"1.0"

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(table_name:, layout:, changed:, plan_signature:, target_segments:, attached_segments:, operations:, gaps:, hot_buckets:) ⇒ PlanReport

Returns a new instance of PlanReport.



37
38
39
40
41
42
43
44
45
46
47
# File 'lib/partition_gardener/plan_report.rb', line 37

def initialize(table_name:, layout:, changed:, plan_signature:, target_segments:, attached_segments:, operations:, gaps:, hot_buckets:)
  @table_name = table_name
  @layout = layout
  @changed = changed
  @plan_signature = plan_signature
  @target_segments = target_segments
  @attached_segments = attached_segments
  @operations = operations
  @gaps = gaps
  @hot_buckets = hot_buckets
end

Instance Attribute Details

#attached_segmentsObject (readonly)

Returns the value of attribute attached_segments.



27
28
29
# File 'lib/partition_gardener/plan_report.rb', line 27

def attached_segments
  @attached_segments
end

#changedObject (readonly)

Returns the value of attribute changed.



27
28
29
# File 'lib/partition_gardener/plan_report.rb', line 27

def changed
  @changed
end

#gapsObject (readonly)

Returns the value of attribute gaps.



27
28
29
# File 'lib/partition_gardener/plan_report.rb', line 27

def gaps
  @gaps
end

#hot_bucketsObject (readonly)

Returns the value of attribute hot_buckets.



27
28
29
# File 'lib/partition_gardener/plan_report.rb', line 27

def hot_buckets
  @hot_buckets
end

#layoutObject (readonly)

Returns the value of attribute layout.



27
28
29
# File 'lib/partition_gardener/plan_report.rb', line 27

def layout
  @layout
end

#operationsObject (readonly)

Returns the value of attribute operations.



27
28
29
# File 'lib/partition_gardener/plan_report.rb', line 27

def operations
  @operations
end

#plan_signatureObject (readonly)

Returns the value of attribute plan_signature.



27
28
29
# File 'lib/partition_gardener/plan_report.rb', line 27

def plan_signature
  @plan_signature
end

#table_nameObject (readonly)

Returns the value of attribute table_name.



27
28
29
# File 'lib/partition_gardener/plan_report.rb', line 27

def table_name
  @table_name
end

#target_segmentsObject (readonly)

Returns the value of attribute target_segments.



27
28
29
# File 'lib/partition_gardener/plan_report.rb', line 27

def target_segments
  @target_segments
end

Class Method Details

.build(config) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/partition_gardener/plan_report.rb', line 7

def self.build(config)
  planner = Planner.new(config)
  plan = planner.build
  attached_segments = planner.attached_tail_segments
  operations = PlanDiff.operations(attached_segments, plan.segments)
  gaps = GapDetection.call(config[:table_name], config: config)

  new(
    table_name: config[:table_name],
    layout: config.fetch(:layout, :sliding_window),
    changed: PlanDiff.changed?(attached_segments, plan.segments),
    plan_signature: PlanDiff.plan_signature(plan.segments),
    target_segments: plan.segments,
    attached_segments: attached_segments,
    operations: operations,
    gaps: gaps,
    hot_buckets: plan.hot_buckets
  )
end

Instance Method Details

#to_hObject



49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/partition_gardener/plan_report.rb', line 49

def to_h
  {
    schema_version: self.class::SCHEMA_VERSION,
    table_name: table_name,
    layout: layout,
    changed: changed,
    plan_signature: plan_signature,
    target_segments: target_segments.map { |segment| segment_to_h(segment) },
    attached_segments: attached_segments.map { |segment| segment_to_h(segment) },
    operations: operations.map { |operation| operation_to_h(operation) },
    gaps: gaps.map { |gap| gap_to_h(gap) },
    hot_buckets: hot_buckets
  }
end

#to_jsonObject



64
65
66
# File 'lib/partition_gardener/plan_report.rb', line 64

def to_json(...)
  to_h.to_json(...)
end