Class: PartitionGardener::Strategy::HashBranches

Inherits:
Object
  • Object
show all
Includes:
Naming, CursorColumns, RequiresDefaultPartition
Defined in:
lib/partition_gardener/strategy/hash_branches.rb

Constant Summary collapse

DEFAULT_MODULUS =
32

Instance Method Summary collapse

Methods included from CursorColumns

#cursor_columns, #partition_key_base

Methods included from Naming

current_partition_name, default_partition_name, future_partition_name, open_partition_name, rebalance_staging_partition_name

Constructor Details

#initialize(config) ⇒ HashBranches

Returns a new instance of HashBranches.



10
11
12
# File 'lib/partition_gardener/strategy/hash_branches.rb', line 10

def initialize(config)
  @config = config
end

Instance Method Details

#active_windowObject



14
15
16
# File 'lib/partition_gardener/strategy/hash_branches.rb', line 14

def active_window
  {start: 0, end: modulus}
end

#archive_bucket?(_bucket) ⇒ Boolean

Returns:

  • (Boolean)


98
99
100
# File 'lib/partition_gardener/strategy/hash_branches.rb', line 98

def archive_bucket?(_bucket)
  false
end

#archive_bucket_from_partition_name(partition_name) ⇒ Object



106
107
108
# File 'lib/partition_gardener/strategy/hash_branches.rb', line 106

def archive_bucket_from_partition_name(partition_name)
  hash_remainder_from_partition_name(partition_name)
end

#attached_tail_segmentsObject



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/partition_gardener/strategy/hash_branches.rb', line 35

def attached_tail_segments
  Connection.attached_partitions(table_name).filter_map do |partition|
    next if partition.default
    next unless hash_partition_name?(partition.name)

    remainder = hash_remainder_from_partition_name(partition.name)
    next if remainder.nil?

    hot = hot_bucket_partition_name?(partition.name)
    Plan::Segment.new(
      name: partition.name,
      range_start: {modulus: modulus, remainder: remainder},
      range_end: nil,
      kind: hot ? :hot_bucket : :archive
    )
  end
end

#bucket_where_condition(_bucket) ⇒ Object



94
95
96
# File 'lib/partition_gardener/strategy/hash_branches.rb', line 94

def bucket_where_condition(_bucket)
  "TRUE"
end

#build_planObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/partition_gardener/strategy/hash_branches.rb', line 18

def build_plan
  heatmap = collect_heatmap(active_window)
  hot_buckets = hot_buckets_in_window(heatmap, active_window)

  segments = (0...modulus).map do |remainder|
    hot = hot_buckets.include?(remainder)
    Plan::Segment.new(
      name: hash_partition_name(remainder, hot: hot),
      range_start: {modulus: modulus, remainder: remainder},
      range_end: nil,
      kind: hot ? :hot_bucket : :archive
    )
  end

  Plan::Result.new(segments: segments, hot_buckets: hot_buckets)
end

#collect_heatmap(_window) ⇒ Object



53
54
55
56
57
# File 'lib/partition_gardener/strategy/hash_branches.rb', line 53

def collect_heatmap(_window)
  bucket_counts = HashRouting.collect_bucket_counts(@config)

  {bucket_counts: bucket_counts, default_rows: default_row_count}
end

#current_and_future_where_condition(window: active_window) ⇒ Object



78
79
80
# File 'lib/partition_gardener/strategy/hash_branches.rb', line 78

def current_and_future_where_condition(window: active_window)
  "FALSE"
end

#default_partition_drain_where_condition(window: active_window) ⇒ Object



90
91
92
# File 'lib/partition_gardener/strategy/hash_branches.rb', line 90

def default_partition_drain_where_condition(window: active_window)
  "TRUE"
end

#default_partition_required?Boolean

Returns:

  • (Boolean)


82
83
84
# File 'lib/partition_gardener/strategy/hash_branches.rb', line 82

def default_partition_required?
  false
end

#future_bucket?(_bucket) ⇒ Boolean

Returns:

  • (Boolean)


102
103
104
# File 'lib/partition_gardener/strategy/hash_branches.rb', line 102

def future_bucket?(_bucket)
  false
end

#hot_buckets_in_window(heatmap, _window) ⇒ Object



59
60
61
62
63
# File 'lib/partition_gardener/strategy/hash_branches.rb', line 59

def hot_buckets_in_window(heatmap, _window)
  heatmap[:bucket_counts].filter_map do |remainder, row_count|
    remainder if row_count >= split_row_threshold
  end.sort
end

#managed_tail_partition_names(window: active_window) ⇒ Object



65
66
67
68
69
70
71
72
# File 'lib/partition_gardener/strategy/hash_branches.rb', line 65

def managed_tail_partition_names(window: active_window)
  Connection.attached_partitions(table_name).filter_map do |partition|
    next if partition.default
    next unless hash_partition_name?(partition.name)

    partition.name
  end
end

#rebalance_default_drain_where_condition(window: active_window) ⇒ Object



86
87
88
# File 'lib/partition_gardener/strategy/hash_branches.rb', line 86

def rebalance_default_drain_where_condition(window: active_window)
  "FALSE"
end

#segment_for_values_clause(segment) ⇒ Object



110
111
112
# File 'lib/partition_gardener/strategy/hash_branches.rb', line 110

def segment_for_values_clause(segment)
  "WITH (modulus #{segment.range_start[:modulus]}, remainder #{segment.range_start[:remainder]})"
end

#tail_slot_name?(_partition_name) ⇒ Boolean

Returns:

  • (Boolean)


74
75
76
# File 'lib/partition_gardener/strategy/hash_branches.rb', line 74

def tail_slot_name?(_partition_name)
  false
end