You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jira@kafka.apache.org by "ASF GitHub Bot (JIRA)" <ji...@apache.org> on 2018/11/28 10:49:00 UTC

[jira] [Commented] (KAFKA-7037) delete topic command replaces '+' from the topic name which leads incorrect topic deletion

    [ https://issues.apache.org/jira/browse/KAFKA-7037?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16701690#comment-16701690 ] 

ASF GitHub Bot commented on KAFKA-7037:
---------------------------------------

omkreddy closed pull request #5193: KAFKA-7037: Improve the topic command description of `--topic` option  
URL: https://github.com/apache/kafka/pull/5193
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/core/src/main/scala/kafka/admin/TopicCommand.scala b/core/src/main/scala/kafka/admin/TopicCommand.scala
index 9d284521a6e..37dd233913b 100755
--- a/core/src/main/scala/kafka/admin/TopicCommand.scala
+++ b/core/src/main/scala/kafka/admin/TopicCommand.scala
@@ -308,8 +308,9 @@ object TopicCommand extends Logging {
     val deleteOpt = parser.accepts("delete", "Delete a topic")
     val alterOpt = parser.accepts("alter", "Alter the number of partitions, replica assignment, and/or configuration for the topic.")
     val describeOpt = parser.accepts("describe", "List details for the given topics.")
-    val topicOpt = parser.accepts("topic", "The topic to be create, alter or describe. Can also accept a regular " +
-                                           "expression except for --create option")
+    val topicOpt = parser.accepts("topic", "The topic to create, alter, describe or delete. It also accepts a regular " +
+                                           "expression, except for --create option. Put topic name in double quotes and use the '\\' prefix " +
+                                           "to escape regular expression symbols; e.g. \"test\\.topic\".")
                          .withRequiredArg
                          .describedAs("topic")
                          .ofType(classOf[String])
diff --git a/core/src/test/scala/unit/kafka/admin/TopicCommandTest.scala b/core/src/test/scala/unit/kafka/admin/TopicCommandTest.scala
index a469f8efe04..5d2d873425f 100644
--- a/core/src/test/scala/unit/kafka/admin/TopicCommandTest.scala
+++ b/core/src/test/scala/unit/kafka/admin/TopicCommandTest.scala
@@ -278,4 +278,37 @@ class TopicCommandTest extends ZooKeeperTestHarness with Logging with RackAwareT
     assertTrue(output.contains(topic))
     assertFalse(output.contains(Topic.GROUP_METADATA_TOPIC_NAME))
   }
+
+  @Test
+  def testTopicOperationsWithRegexSymbolInTopicName(): Unit = {
+    val topic1 = "test.topic"
+    val topic2 = "test-topic"
+    val escapedTopic = "\"test\\.topic\""
+    val unescapedTopic = "test.topic"
+    val numPartitionsOriginal = 1
+
+    // create brokers
+    val brokers = List(0, 1, 2)
+    TestUtils.createBrokersInZk(zkClient, brokers)
+
+    // create the topics
+    val createOpts = new TopicCommandOptions(Array("--partitions", numPartitionsOriginal.toString,
+      "--replication-factor", "1", "--topic", topic1))
+    TopicCommand.createTopic(zkClient, createOpts)
+    val createOpts2 = new TopicCommandOptions(Array("--partitions", numPartitionsOriginal.toString,
+      "--replication-factor", "1", "--topic", topic2))
+    TopicCommand.createTopic(zkClient, createOpts2)
+
+    val escapedCommandOpts = new TopicCommandOptions(Array("--topic", escapedTopic))
+    val unescapedCommandOpts = new TopicCommandOptions(Array("--topic", unescapedTopic))
+
+    // topic actions with escaped regex do not affect 'test-topic'
+    // topic actions with unescaped topic affect 'test-topic'
+
+    assertFalse(TestUtils.grabConsoleOutput(TopicCommand.describeTopic(zkClient, escapedCommandOpts)).contains(topic2))
+    assertTrue(TestUtils.grabConsoleOutput(TopicCommand.describeTopic(zkClient, unescapedCommandOpts)).contains(topic2))
+
+    assertFalse(TestUtils.grabConsoleOutput(TopicCommand.deleteTopic(zkClient, escapedCommandOpts)).contains(topic2))
+    assertTrue(TestUtils.grabConsoleOutput(TopicCommand.deleteTopic(zkClient, unescapedCommandOpts)).contains(topic2))
+  }
 }


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


> delete topic command replaces '+' from the topic name which leads incorrect topic deletion
> ------------------------------------------------------------------------------------------
>
>                 Key: KAFKA-7037
>                 URL: https://issues.apache.org/jira/browse/KAFKA-7037
>             Project: Kafka
>          Issue Type: Bug
>    Affects Versions: 0.10.1.0, 1.0.0
>            Reporter: Sandeep Nemuri
>            Assignee: Vahid Hashemian
>            Priority: Major
>             Fix For: 2.2.0
>
>
> While executing a delete command kafka cli tool is removing the "+" symbol and deleting the incorrect topic. In below case if  _"*test+topic"*_ is deleted kafka deletes  _*testtopic.*_
> {code:java}
> [kafka@localhost~]$ /usr/hdp/current/kafka-broker/bin/kafka-topics.sh --create --zookeeper `hostname`:2181 --replication-factor 1 --partitions 1 --topic testtopic
> Created topic "testtopic".
> [kafka@localhost~]$ /usr/hdp/current/kafka-broker/bin/kafka-topics.sh --zookeeper `hostname`:2181 --topic test+topic --delete
> Topic testtopic is marked for deletion.{code}
>  delete topic replaces '+' from the topic name  



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)