LoginSignup
0
0

More than 5 years have passed since last update.

Apache Kafkaのトピックパーティション・レプリカ配置先をマニュアル選択する方法

Posted at

やりかた

Kafkaでのトピック作成時にパーティションとそのレプリカの配置先を特定のKafka Brokerにしたい場合は、トピック作成時にreplica-assignmentオプションを指定します。

$ ${KAFKA_HOME}/bin/kafka-topics.sh --create --topic replica-assignment-test --zookeeper localhost:2181  --replica-assignment 1:2,2:3

配置するBrokerをIDで指定(上の例だと1,2)します。
上の例だと、1つ目のパーティションはBrokerIDが1,2に配置され、2つ目のパーティションはBrokerIDが2,3に配置されることを意味しています。
つまり、このreplica-assignment-testトピックは2パーティションで構成され、それぞれのパーティションのレプリカ数は2ということになります。

確認してみるとちゃんとそのように配置されています。

$ ${KAFKA_HOME}/bin/kafka-topics.sh --describe --zookeeper localhost --topic replica-assignment-test
Topic:replica-assignment-test   PartitionCount:2    ReplicationFactor:2 Configs:
    Topic: replica-assignment-test  Partition: 0    Leader: 1   Replicas: 1,2   Isr: 1,2
    Topic: replica-assignment-test  Partition: 1    Leader: 2   Replicas: 2,3   Isr: 2,3

ちなみに各パーティションのレプリカのリーダーは、コロンの先頭に指定したものが選択されるようです。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0