Uploaded image for project: 'Kafka'
  1. Kafka
  2. KAFKA-6084

ReassignPartitionsCommand should propagate JSON parsing failures

    XMLWordPrintableJSON

    Details

    • Type: Improvement
    • Status: In Progress
    • Priority: Minor
    • Resolution: Unresolved
    • Affects Version/s: 0.11.0.0
    • Fix Version/s: None
    • Component/s: admin
    • Labels:

      Description

      Basically looking at Json.scala it will always swallow any parsing errors:

        def parseFull(input: String): Option[JsonValue] =
          try Option(mapper.readTree(input)).map(JsonValue(_))
          catch { case _: JsonProcessingException => None }
      

      However sometimes it is easy to figure out the problem by simply looking at the JSON, in some cases it is not very trivial, such as some invisible characters (like byte order mark) won't be displayed by most of the text editors and can people spend time on figuring out what's the problem.

      As Jackson provides a really detailed exception about what failed and how, it is easy to propagate the failure to the user.

      As an example I attached a BOM prefixed JSON which fails with the following error which is very counterintuitive:

      [root@localhost ~]# kafka-reassign-partitions --zookeeper localhost:2181 --reassignment-json-file /root/increase-replication-factor.json --execute
      Partitions reassignment failed due to Partition reassignment data file /root/increase-replication-factor.json is empty
      kafka.common.AdminCommandFailedException: Partition reassignment data file /root/increase-replication-factor.json is empty
      at kafka.admin.ReassignPartitionsCommand$.executeAssignment(ReassignPartitionsCommand.scala:120)
      at kafka.admin.ReassignPartitionsCommand$.main(ReassignPartitionsCommand.scala:52)
      at kafka.admin.ReassignPartitionsCommand.main(ReassignPartitionsCommand.scala)
      ...
      

      In case of the above error it would be much better to see what fails exactly:

      kafka.common.AdminCommandFailedException: Admin command failed
      	at kafka.admin.ReassignPartitionsCommand$.parsePartitionReassignmentData(ReassignPartitionsCommand.scala:267)
      	at kafka.admin.ReassignPartitionsCommand$.parseAndValidate(ReassignPartitionsCommand.scala:275)
      	at kafka.admin.ReassignPartitionsCommand$.executeAssignment(ReassignPartitionsCommand.scala:197)
      	at kafka.admin.ReassignPartitionsCommand$.executeAssignment(ReassignPartitionsCommand.scala:193)
      	at kafka.admin.ReassignPartitionsCommand$.main(ReassignPartitionsCommand.scala:64)
      	at kafka.admin.ReassignPartitionsCommand.main(ReassignPartitionsCommand.scala)
      Caused by: com.fasterxml.jackson.core.JsonParseException: Unexpected character ('' (code 65279 / 0xfeff)): expected a valid value (number, String, array, object, 'true', 'false' or 'null')
       at [Source: (String)"{"version":1,
        "partitions":[
         {"topic": "test1", "partition": 0, "replicas": [1,2]},
         {"topic": "test2", "partition": 1, "replicas": [2,3]}
      ]}"; line: 1, column: 2]
      	at com.fasterxml.jackson.core.JsonParser._constructError(JsonParser.java:1798)
      	at com.fasterxml.jackson.core.base.ParserMinimalBase._reportError(ParserMinimalBase.java:663)
      	at com.fasterxml.jackson.core.base.ParserMinimalBase._reportUnexpectedChar(ParserMinimalBase.java:561)
      	at com.fasterxml.jackson.core.json.ReaderBasedJsonParser._handleOddValue(ReaderBasedJsonParser.java:1892)
      	at com.fasterxml.jackson.core.json.ReaderBasedJsonParser.nextToken(ReaderBasedJsonParser.java:747)
      	at com.fasterxml.jackson.databind.ObjectMapper._readTreeAndClose(ObjectMapper.java:4030)
      	at com.fasterxml.jackson.databind.ObjectMapper.readTree(ObjectMapper.java:2539)
      	at kafka.utils.Json$.kafka$utils$Json$$doParseFull(Json.scala:46)
      	at kafka.utils.Json$$anonfun$tryParseFull$1.apply(Json.scala:44)
      	at kafka.utils.Json$$anonfun$tryParseFull$1.apply(Json.scala:44)
      	at scala.util.Try$.apply(Try.scala:192)
      	at kafka.utils.Json$.tryParseFull(Json.scala:44)
      	at kafka.admin.ReassignPartitionsCommand$.parsePartitionReassignmentData(ReassignPartitionsCommand.scala:241)
      	... 5 more
      

        Attachments

        1. Screen Shot 2017-10-18 at 23.31.22.png
          32 kB
          Viktor Somogyi-Vass

          Issue Links

            Activity

              People

              • Assignee:
                viktorsomogyi Viktor Somogyi-Vass
                Reporter:
                viktorsomogyi Viktor Somogyi-Vass
              • Votes:
                1 Vote for this issue
                Watchers:
                5 Start watching this issue

                Dates

                • Created:
                  Updated: