개발 일지

Expand Kafka Cluster

북극곰은콜라 2023. 6. 13. 19:12
반응형


개요

Kafka Cluster를 확장할 시 발생하는 이펙트에 대한 조사

 


Broker Data Reassignment Strategy

단순 Broker Add

기본적으로 Broker가 추가되는 경우 기존 topic 및 Data에 대해서는 아무런 작업을 진행하지 않는다. 앞으로 추가되는 topic에 대해서 신규 브로커가 포함된 형태로 Cluster가 동작한다.

Migrate data to new Broker

수동적으로 트리거링하여 기존 데이터를 새 Broker에 마이그레이션 할 수 있다.
시스템 중단 없이 작업 가능한 방법
내부적으로 다음 프로세스를 적용하여 마이그레이션이 진행됩니다.
 1. 신규 Broker를 기존 파티션의 follower로 지정
 2. 신규 Broker는 기존 파티션의 모든 Data를 replicate
 3. replication 완료 후 신규 브로커는 해당 topic의 ISR (In-Sync-Replica)로 편입
 3. ISR중 누군가는 해당 topic의 replication을 delete

Data Migration Tool

파티션재할당을 위해서는 Reassignment Tool을 활용 (kafka-reassign-partitions.sh)
모든 작업은 관리자가 수동으로 진행
Tool의 3가지 옵션 (단계)
 1. --generate: Topic과 Broker list를 지정하여, target Broker들에 Topic들을 재할당 합니다.
 2. --execute: reassignment-json-file을 통해 계획에 따라 재할당 진행
 3. --verify: execute의 진행 상황을 확인
generate를 통해 토픽과 브로커의 리스트를 지정하면, kafka tool이 execute plan을 생성합니다.

reassign topics 선정

> cat topics-to-move.json
{"topics": [{"topic": "foo1"},
            {"topic": "foo2"}],
"version":1
}

reassign 계획 생성

> bin/kafka-reassign-partitions.sh --bootstrap-server localhost:9092 --topics-to-move-json-file topics-to-move.json --broker-list "5,6" --generate
Current partition replica assignment

{"version":1,
"partitions":[{"topic":"foo1","partition":0,"replicas":[2,1]},
              {"topic":"foo1","partition":1,"replicas":[1,3]},
              {"topic":"foo1","partition":2,"replicas":[3,4]},
              {"topic":"foo2","partition":0,"replicas":[4,2]},
              {"topic":"foo2","partition":1,"replicas":[2,1]},
              {"topic":"foo2","partition":2,"replicas":[1,3]}]
}

Proposed partition reassignment configuration

{"version":1,
"partitions":[{"topic":"foo1","partition":0,"replicas":[6,5]},
              {"topic":"foo1","partition":1,"replicas":[5,6]},
              {"topic":"foo1","partition":2,"replicas":[6,5]},
              {"topic":"foo2","partition":0,"replicas":[5,6]},
              {"topic":"foo2","partition":1,"replicas":[6,5]},
              {"topic":"foo2","partition":2,"replicas":[5,6]}]
}

execute

> bin/kafka-reassign-partitions.sh --bootstrap-server localhost:9092 --reassignment-json-file expand-cluster-reassignment.json --execute
Current partition replica assignment

{"version":1,
"partitions":[{"topic":"foo1","partition":0,"replicas":[2,1]},
              {"topic":"foo1","partition":1,"replicas":[1,3]},
              {"topic":"foo1","partition":2,"replicas":[3,4]},
              {"topic":"foo2","partition":0,"replicas":[4,2]},
              {"topic":"foo2","partition":1,"replicas":[2,1]},
              {"topic":"foo2","partition":2,"replicas":[1,3]}]
}

Save this to use as the --reassignment-json-file option during rollback
Successfully started partition reassignments for foo1-0,foo1-1,foo1-2,foo2-0,foo2-1,foo2-2

verify

> bin/kafka-reassign-partitions.sh --bootstrap-server localhost:9092 --reassignment-json-file expand-cluster-reassignment.json --verify
Status of partition reassignment:
Reassignment of partition [foo1,0] is completed
Reassignment of partition [foo1,1] is still in progress
Reassignment of partition [foo1,2] is still in progress
Reassignment of partition [foo2,0] is completed
Reassignment of partition [foo2,1] is completed
Reassignment of partition [foo2,2] is completed

 


REFERENCE

 - https://kafka.apache.org/documentation/#basic_ops_cluster_expansion

 

 

 

반응형