목적 |
3개의 node로 구성된 cluster 의 replication factor값이 1일 때와, 3일 때의 차이점 확인 ( 3 node cluster 구성은 replication factor 값이 3을 권장 ) |
시나리오 |
1. Replication factor 값이 1인 것과 3인 topic생성 2. 생성 완료 후 각 topic 별로 broker id 0,1,2 log 조회 3. |
구성 |
|
Dir 위치 |
Broker id Broker의 topic 위치
0 /tmp/kafka-logs 1 /tmp/kafka-logs2 2 /tmp/kafka-logs3 |
[ test 방법 ]
1.replication factor 1인 topic 과 replication factor 3인 topic 만듦
1-1. Replication factor를 1로 지정해서 topic만들었을 경우 ( 명령어 : bin/kafka-topics.sh --create --bootstrap-server {bootstrap.server}:9092 --partitions 1 --topic cluster_test )
Topic: cluster_test TopicId: r7E6C7rGQDKiXz5ZKjws5A PartitionCount: 3 ReplicationFactor: 1 Configs: Topic: cluster_test Partition: 0 Leader: 1 Replicas: 1 Isr: 1 Topic: cluster_test Partition: 1 Leader: 0 Replicas: 0 Isr: 0 Topic: cluster_test Partition: 2 Leader: 2 Replicas: 2 Isr: 2 |
1-2.Replication factor를 3으로 지정해서 topic 만들었을 경우 ( 명령어 : bin/kafka-topics.sh --create --bootstrap-server {bootstrap.server}:9092 --replication-factor 3 --partitions 1 --topic cluster_test )
Topic: clusterTest TopicId: soZaAzOsRQyTXwLxXeHMVA PartitionCount: 1 ReplicationFactor: 3 Configs: Topic: clusterTest Partition: 0 Leader: 2 Replicas: 2,0,1 Isr: 2,0,1 |
2. replication factor 1 (topic : cluster_test) 의 log dir 확인
2-1. broker 0 의 partition number 및 patition dir 조회
Broker 0 |
drwxrwxr-x. 2 kafka kafka 167 2월 16 09:58 cluster_test-1 |
broker0의 partition 확인 (cluster_test-1조회) |
-rw-rw-r--. 1 kafka kafka 10485760 2월 16 09:58 00000000000000000003.index -rw-rw-r--. 1 kafka kafka 0 2월 14 09:24 00000000000000000003.log -rw-rw-r--. 1 kafka kafka 10485756 2월 16 09:58 00000000000000000003.timeindex -rw-rw-r--. 1 kafka kafka 9 2월 16 09:58 leader-epoch-checkpoint -rw-rw-r--. 1 kafka kafka 43 1월 30 12:43 partition.metadata |
2-2. broker 1 의 partition number 및 patition dir 조회
Broker 1 |
drwxrwxr-x. 2 kafka kafka 167 2월 16 09:58 cluster_test-0 |
broker1의 partition 확인 (cluster_test-0 조회) |
-rw-rw-r--. 1 kafka kafka 10485760 2월 16 09:58 00000000000000000004.index -rw-rw-r--. 1 kafka kafka 0 2월 14 09:24 00000000000000000004.log -rw-rw-r--. 1 kafka kafka 10485756 2월 16 09:58 00000000000000000004.timeindex -rw-rw-r--. 1 kafka kafka 9 2월 16 09:58 leader-epoch-checkpoint -rw-rw-r--. 1 kafka kafka 43 1월 30 12:43 partition.metadata |
2-3. broker 2 의 partition number 및 patition dir 조회
Broker 2 |
drwxrwxr-x. 2 kafka kafka 167 2월 16 09:58 cluster_test-2 |
broker2의 partition 확인 (cluster_test-2 조회) |
-rw-rw-r--. 1 kafka kafka 10485760 2월 16 09:58 00000000000000000000.index -rw-rw-r--. 1 kafka kafka 0 2월 15 15:07 00000000000000000000.log -rw-rw-r--. 1 kafka kafka 10485756 2월 16 09:58 00000000000000000000.timeindex -rw-rw-r--. 1 kafka kafka 9 2월 16 09:59 leader-epoch-checkpoint -rw-rw-r--. 1 kafka kafka 43 1월 30 12:43 partition.metadata |
3. replication factor 3 (topic : clusterTest) 의 log dir 확인
3-1. broker 0,1,2 의 partition number 및 patition dir 조회하여 모두 같은 number를 지닌 partition이 있는지 확인
Broker 0 |
drwxrwxr-x. 2 kafka kafka 167 2월 16 09:58 clusterTest-0 drwxrwxr-x. 2 kafka kafka 167 2월 16 09:58 clusterTest2-0 drwxrwxr-x. 2 kafka kafka 167 2월 16 09:58 clusterTest_topic_1-0 |
Broker 1 |
drwxrwxr-x. 2 kafka kafka 167 2월 15 15:46 clusterTest-0 drwxrwxr-x. 2 kafka kafka 167 2월 15 16:09 clusterTest2-0 drwxrwxr-x. 2 kafka kafka 167 2월 16 09:58 clusterTest_topic_1-2 |
Broker 2 |
drwxrwxr-x. 2 kafka kafka 167 2월 16 10:03 clusterTest-0 drwxrwxr-x. 2 kafka kafka 167 2월 16 10:03 clusterTest2-0 drwxrwxr-x. 2 kafka kafka 167 2월 16 09:59 clusterTest_topic_1-1 |
4. replication factor 1인 topic에 console을 이용하여 데이터 전송
데이터 전송 ( broker 9092 port 사용) |
[kafka@localhost bin]$ ./kafka-console-producer.sh --bootstrap-server 192.168.56.105:9092 --topic cluster_test >1 >2 >3 >4 >5 |
데이터 취득 ( broker1 9093 port) |
[kafka@localhost bin]$ ./kafka-console-consumer.sh --bootstrap-server 192.168.56.105:9093 --topic cluster_test 1 2 3 4 5 Processed a total of 5 messages |
데이터 취득 ( broker2 9094 port) |
1 2 3 4 5 Processed a total of 5 messages |
5. replication factor 3인 topic에 console을 이용하여 데이터 전송
데이터 전송 (9092 포트 사용) |
[kafka@localhost bin]$ ./kafka-console-producer.sh --bootstrap-server 192.168.56.105:9092 --topic clusterTest >1 >2 >3 >4 >5 |
데이터 취득 ( broker2 9093 port) |
[kafka@localhost bin]$ ./kafka-console-consumer.sh --bootstrap-server 192.168.56.105:9093 --topic clusterTest 1 2 3 4 5 Processed a total of 5 messages |
데이터 취득 ( broker3 9094 port) |
1 2 3 4 5 Processed a total of 5 messages |
[ 결과 ]
replication factor가 1일경우에도 일시적으로 broker 2,3 모두 데이터 취득이 가능하나, topic log 확인 결과 복제되진 않음
[ 의견 ]
replication 과 replication factor는 엄연히 다른 의미를 지니므로, console에서 데이터가 동기화되어 출력하였다고 해도 이는 log dir에 남지 않으므로 복제된 것은 아님을 유의.