2017-09-27 7 views
1

온라인에서 발견 된 것과 내가 스택에서 발견 한 오버 플로우 게시물에서 주제를 삭제하는 데 주로 두 가지 방법이있는 것 같습니다. 카프카에. 첫 번째 존재한다 : a) delete.topic.enable = true./kafka-topics.sh ---delete --topic <topicName> 두 번째 방법을 실행 : ./zookeeper-shell.sh localhost:2181 rmr brokers/topicszookeeper-shall.sh rmr 브로커/주제를 사용하여 주제를 삭제하는 것과 kafka10의 kafka-topics.sh에서 플래그를 삭제하는 것의 차이점

내가했던 첫 번째 방법은 두 번째 방법은 그들을 삭제로 어디에서 삭제 된 항목을 삭제 얻을 몇 분 동안 할 각 항목을 표시한다는 통보 즉시. 나는 또한 서버를 재시작 할 때 몇 시간이 걸리는 것을 보았다. 이는 정상적인 것인가? 한 브로커에서 1000 개가 넘는 주제가있었습니다 (테스트 용).

답변

1

첫 번째 방법은 zookeper admin/delete_topics/<topic>의 노드를 만들 것입니다, 당신이 그랬던 것처럼 당신이 항목 삭제를 사용하도록 설정 한 경우 delete_topics 차일을 모니터링 카프카 브로커에 주어진 스레드 (TopicDeletionManager)는,이,이 평균으로부터 삭제 처리합니다 동물원뿐만 아니라 모든 카프카 복제본에서 기록을 남기므로 유효하지 않은 상태가되지 않도록하십시오. 전체 프로세스는 여기에 설명되어 있습니다 : https://github.com/apache/kafka/blob/0.11.0/core/src/main/scala/kafka/controller/TopicDeletionManager.scala

/** 
* This manages the state machine for topic deletion. 
* 1. TopicCommand issues topic deletion by creating a new admin path /admin/delete_topics/<topic> 
* 2. The controller listens for child changes on /admin/delete_topic and starts topic deletion for the respective topics 
* 3. The controller's ControllerEventThread handles topic deletion. A topic will be ineligible 
* for deletion in the following scenarios - 
    * 3.1 broker hosting one of the replicas for that topic goes down 
    * 3.2 partition reassignment for partitions of that topic is in progress 
* 4. Topic deletion is resumed when - 
* 4.1 broker hosting one of the replicas for that topic is started 
* 4.2 partition reassignment for partitions of that topic completes 
* 5. Every replica for a topic being deleted is in either of the 3 states - 
* 5.1 TopicDeletionStarted Replica enters TopicDeletionStarted phase when onPartitionDeletion is invoked. 
*  This happens when the child change watch for /admin/delete_topics fires on the controller. As part of this state 
*  change, the controller sends StopReplicaRequests to all replicas. It registers a callback for the 
*  StopReplicaResponse when deletePartition=true thereby invoking a callback when a response for delete replica 
*  is received from every replica) 
* 5.2 TopicDeletionSuccessful moves replicas from 
*  TopicDeletionStarted->TopicDeletionSuccessful depending on the error codes in StopReplicaResponse 
* 5.3 TopicDeletionFailed moves replicas from 
*  TopicDeletionStarted->TopicDeletionFailed depending on the error codes in StopReplicaResponse. 
*  In general, if a broker dies and if it hosted replicas for topics being deleted, the controller marks the 
*  respective replicas in TopicDeletionFailed state in the onBrokerFailure callback. The reason is that if a 
*  broker fails before the request is sent and after the replica is in TopicDeletionStarted state, 
*  it is possible that the replica will mistakenly remain in TopicDeletionStarted state and topic deletion 
*  will not be retried when the broker comes back up. 
* 6. A topic is marked successfully deleted only if all replicas are in TopicDeletionSuccessful 
* state. Topic deletion teardown mode deletes all topic state from the controllerContext 
* as well as from zookeeper. This is the only time the /brokers/topics/<topic> path gets deleted. On the other hand, 
* if no replica is in TopicDeletionStarted state and at least one replica is in TopicDeletionFailed state, then 
* it marks the topic for deletion retry. 

사육사에서 직접 삭제 단지 조정자에서 삭제하는 것을 의미한다. 물론 메타 데이터를 요청할 때, 주제는 더 이상 존재하지 않습니다. (물론 캐시로부터도 가능할 수도 있지만) 로그 파일은 삭제되지 않습니다. (적어도 지금은 그렇지 않습니다. 브로커가 유효하지 않은 로그를 발견하고 얼마 동안 삭제한다고 가정합니다.), 그러나 당신은 브로커에 대해 약간의 불일치가있을 수 있습니다 (만일 당신이 재조정의 한가운데에 있다면, 많은 것을 망칠 수 있습니다). 이것은 일부 브로커가 삭제 된 것으로 간주하는 반면 다른 브로커는 여전히 고려 중일 수 있음을 의미 할 수 있습니다. 이상적입니다.

fom zookeeper (및 브로커의 로그)를 삭제하는 것이 실제로 가능할 수 있지만 충돌, 유효하지 않은 상태, 임의 오류가 발생할 수 있으며 향후 버전에서는 전혀 작동하지 않을 수 있습니다.