Class: Karafka::Cli::Topics::Repartition

Inherits:
Base
  • Object
show all
Defined in:
lib/karafka/cli/topics/repartition.rb

Overview

Increases number of partitions on topics that have less partitions than defined Will not create topics if missing.

Instance Method Summary collapse

Methods included from Helpers::Colorize

#green, #grey, #red, #yellow

Instance Method Details

#callBoolean

Returns true if anything was repartitioned, otherwise false.

Returns:

  • (Boolean)

    true if anything was repartitioned, otherwise false



10
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/karafka/cli/topics/repartition.rb', line 10

def call
  any_repartitioned = false

  existing_partitions = existing_topics.map do |topic|
    [topic.fetch(:topic_name), topic.fetch(:partition_count)]
  end.to_h

  declaratives_routing_topics.each do |topic|
    name = topic.name

    desired_count = topic.config.partitions
    existing_count = existing_partitions.fetch(name, false)

    if existing_count && existing_count < desired_count
      puts "Increasing number of partitions to #{desired_count} on topic #{name}..."
      Admin.create_partitions(name, desired_count)
      change = desired_count - existing_count
      puts "#{green('Created')} #{change} additional partitions on topic #{name}."
      any_repartitioned = true
    elsif existing_count
      puts "#{yellow('Skipping')} because topic #{name} has #{existing_count} partitions."
    else
      puts "#{yellow('Skipping')} because topic #{name} does not exist."
    end
  end

  any_repartitioned
end