Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id C855A200D26 for ; Fri, 20 Oct 2017 20:47:04 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id C6ECA160BED; Fri, 20 Oct 2017 18:47:04 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 188111609ED for ; Fri, 20 Oct 2017 20:47:03 +0200 (CEST) Received: (qmail 48864 invoked by uid 500); 20 Oct 2017 18:47:03 -0000 Mailing-List: contact jira-help@kafka.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: jira@kafka.apache.org Delivered-To: mailing list jira@kafka.apache.org Received: (qmail 48851 invoked by uid 99); 20 Oct 2017 18:47:03 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd3-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 20 Oct 2017 18:47:03 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd3-us-west.apache.org (ASF Mail Server at spamd3-us-west.apache.org) with ESMTP id 66CD818079D for ; Fri, 20 Oct 2017 18:47:02 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd3-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: -99.202 X-Spam-Level: X-Spam-Status: No, score=-99.202 tagged_above=-999 required=6.31 tests=[KAM_ASCII_DIVIDERS=0.8, RP_MATCHES_RCVD=-0.001, SPF_PASS=-0.001, USER_IN_WHITELIST=-100] autolearn=disabled Received: from mx1-lw-us.apache.org ([10.40.0.8]) by localhost (spamd3-us-west.apache.org [10.40.0.10]) (amavisd-new, port 10024) with ESMTP id m5beOI4tom4m for ; Fri, 20 Oct 2017 18:47:01 +0000 (UTC) Received: from mailrelay1-us-west.apache.org (mailrelay1-us-west.apache.org [209.188.14.139]) by mx1-lw-us.apache.org (ASF Mail Server at mx1-lw-us.apache.org) with ESMTP id DAD655FC38 for ; Fri, 20 Oct 2017 18:47:00 +0000 (UTC) Received: from jira-lw-us.apache.org (unknown [207.244.88.139]) by mailrelay1-us-west.apache.org (ASF Mail Server at mailrelay1-us-west.apache.org) with ESMTP id 599C8E045B for ; Fri, 20 Oct 2017 18:47:00 +0000 (UTC) Received: from jira-lw-us.apache.org (localhost [127.0.0.1]) by jira-lw-us.apache.org (ASF Mail Server at jira-lw-us.apache.org) with ESMTP id 1CA7821EE6 for ; Fri, 20 Oct 2017 18:47:00 +0000 (UTC) Date: Fri, 20 Oct 2017 18:47:00 +0000 (UTC) From: "Ismael Juma (JIRA)" To: jira@kafka.apache.org Message-ID: In-Reply-To: References: Subject: [jira] [Commented] (KAFKA-6098) Delete and Re-create topic operation could result in race condition MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 archived-at: Fri, 20 Oct 2017 18:47:05 -0000 [ https://issues.apache.org/jira/browse/KAFKA-6098?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16213044#comment-16213044 ] Ismael Juma commented on KAFKA-6098: ------------------------------------ [~guozhang], that's a good point. Because deletion actually happens asynchronously at the broker level, it happens reasonably fast and we could wait until the path is removed before returning a success. Having said that, if the call times out, a user may still rely on `listTopics`, so it would be good to handle the case where the delete is in progress during the create call. > Delete and Re-create topic operation could result in race condition > ------------------------------------------------------------------- > > Key: KAFKA-6098 > URL: https://issues.apache.org/jira/browse/KAFKA-6098 > Project: Kafka > Issue Type: Bug > Reporter: Guozhang Wang > > Here is the following process to re-produce this issue: > 1. Delete a topic using the delete topic request. > 2. Confirm the topic is deleted using the list topics request. > 3. Create the topic using the create topic request. > In step 3) a race condition can happen that the response returns a {{TOPIC_ALREADY_EXISTS}} error code, indicating the topic has already existed. > The root cause of the above issue is in the {{TopicDeletionManager}} class: > {code} > controller.partitionStateMachine.handleStateChanges(partitionsForDeletedTopic.toSeq, OfflinePartition) > controller.partitionStateMachine.handleStateChanges(partitionsForDeletedTopic.toSeq, NonExistentPartition) > topicsToBeDeleted -= topic > partitionsToBeDeleted.retain(_.topic != topic) > kafkaControllerZkUtils.deleteTopicZNode(topic) > kafkaControllerZkUtils.deleteTopicConfigs(Seq(topic)) > kafkaControllerZkUtils.deleteTopicDeletions(Seq(topic)) > controllerContext.removeTopic(topic) > {code} > I.e. it first update the broker's metadata cache through the ISR and metadata update request, then delete the topic zk path, and then delete the topic-deletion zk path. However, upon handling the create topic request, the broker will simply try to write to the topic zk path directly. Hence there is a race condition that between brokers update their metadata cache (hence list topic request not returning this topic anymore) and zk path for the topic be deleted (hence the create topic succeed). > The reason this problem could be exposed, is through current handling logic of the create topic response, most of which takes {{TOPIC_ALREADY_EXISTS}} as "OK" and moves on, and the zk path will be deleted later, hence leaving the topic to be not created at all: > https://github.com/apache/kafka/blob/249e398bf84cdd475af6529e163e78486b43c570/streams/src/main/java/org/apache/kafka/streams/processor/internals/StreamsKafkaClient.java#L221 > https://github.com/apache/kafka/blob/1a653c813c842c0b67f26fb119d7727e272cf834/connect/runtime/src/main/java/org/apache/kafka/connect/util/TopicAdmin.java#L232 > Looking at the code history, it seems this race condition always exist, but testing on trunk / 1.0 with the above steps it is more likely to happen than before. I wonder if the ZK async calls have an effect here. cc [~junrao] [~onurkaraman] -- This message was sent by Atlassian JIRA (v6.4.14#64029)