Skip to content

KAFKA-4914: Partition re-assignment tool should check types before pe…#2708

Merged
ijuma merged 12 commits into
apache:trunkfrom
nicktrav:nickt.reassign-partitions-validation
Mar 31, 2018
Merged

KAFKA-4914: Partition re-assignment tool should check types before pe…#2708
ijuma merged 12 commits into
apache:trunkfrom
nicktrav:nickt.reassign-partitions-validation

Conversation

@nicktrav

@nicktrav nicktrav commented Mar 19, 2017

Copy link
Copy Markdown
Contributor

…rsisting state in ZooKeeper

Prior to this, there have been instances where invalid data was allowed to be persisted in ZooKeeper, which causes ClassCastExceptions when a broker is restarted and reads this type-unsafe data.

Adds basic structural and type validation for the reassignment JSON via introduction of Scala case classes that map to the expected JSON structure.

@asfbot

asfbot commented Mar 20, 2017

Copy link
Copy Markdown

Refer to this link for build results (access rights to CI server needed):
https://builds.apache.org/job/kafka-pr-jdk8-scala2.11/2269/
Test PASSed (JDK 8 and Scala 2.11).

@asfbot

asfbot commented Mar 20, 2017

Copy link
Copy Markdown

Refer to this link for build results (access rights to CI server needed):
https://builds.apache.org/job/kafka-pr-jdk7-scala2.10/2266/
Test PASSed (JDK 7 and Scala 2.10).

@asfbot

asfbot commented Mar 20, 2017

Copy link
Copy Markdown

Refer to this link for build results (access rights to CI server needed):
https://builds.apache.org/job/kafka-pr-jdk8-scala2.12/2266/
Test PASSed (JDK 8 and Scala 2.12).

@nicktrav

Copy link
Copy Markdown
Contributor Author

Hey @ijuma - would you mind taking a look? I see you've worked on this previously.

@nicktrav

Copy link
Copy Markdown
Contributor Author

@ewencp @ijuma - any chance of a review on this one?

@asfbot

asfbot commented Apr 14, 2017

Copy link
Copy Markdown

Refer to this link for build results (access rights to CI server needed):
https://builds.apache.org/job/kafka-pr-jdk8-scala2.11/2952/
Test PASSed (JDK 8 and Scala 2.11).

@asfbot

asfbot commented Apr 14, 2017

Copy link
Copy Markdown

Refer to this link for build results (access rights to CI server needed):
https://builds.apache.org/job/kafka-pr-jdk7-scala2.10/2947/
Test PASSed (JDK 7 and Scala 2.10).

@asfbot

asfbot commented Apr 14, 2017

Copy link
Copy Markdown

Refer to this link for build results (access rights to CI server needed):
https://builds.apache.org/job/kafka-pr-jdk8-scala2.12/2948/
Test PASSed (JDK 8 and Scala 2.12).

@omkreddy

Copy link
Copy Markdown
Contributor

@nicktrav Thanks for the patch. LGTM. We also faced this issue in production. Can you rebase the PR?

@asfgit

asfgit commented Jul 19, 2017

Copy link
Copy Markdown

Refer to this link for build results (access rights to CI server needed):
https://builds.apache.org/job/kafka-pr-jdk7-scala2.11/6169/
Test FAILed (JDK 7 and Scala 2.11).

@asfgit

asfgit commented Jul 19, 2017

Copy link
Copy Markdown

Refer to this link for build results (access rights to CI server needed):
https://builds.apache.org/job/kafka-pr-jdk8-scala2.12/6153/
Test FAILed (JDK 8 and Scala 2.12).

@nicktrav
nicktrav force-pushed the nickt.reassign-partitions-validation branch from a5bb980 to 9cb5002 Compare July 22, 2017 05:09
@nicktrav

Copy link
Copy Markdown
Contributor Author

@omkreddy - thanks for checking this one out! I completely forgot that I had this open. I've rebased.

Would love to get it merged, as it was the source of a reasonable amount of (avoidable) pain for us a few months ago, and would love to save some others from that. Are you able to merge this in when green?

@asfgit

asfgit commented Jul 22, 2017

Copy link
Copy Markdown

Refer to this link for build results (access rights to CI server needed):
https://builds.apache.org/job/kafka-pr-jdk7-scala2.11/6281/
Test PASSed (JDK 7 and Scala 2.11).

@asfgit

asfgit commented Jul 22, 2017

Copy link
Copy Markdown

Refer to this link for build results (access rights to CI server needed):
https://builds.apache.org/job/kafka-pr-jdk8-scala2.12/6265/
Test PASSed (JDK 8 and Scala 2.12).

@omkreddy

Copy link
Copy Markdown
Contributor

LGTM.

Though we are deprecating "--zookeeper" option in KIP-179 (Change ReassignPartitionsCommand to use adminClient), It is good to have this check.

cc @ijuma pinging for review.

@ijuma

ijuma commented Aug 4, 2017

Copy link
Copy Markdown
Member

Thanks for the PR. I think we should consider using Jackson to parse into classes with the expected structure. That will do the necessary validation in a more robust way. Thoughts?

@asfgit

asfgit commented Aug 4, 2017

Copy link
Copy Markdown

Refer to this link for build results (access rights to CI server needed):
https://builds.apache.org/job/kafka-pr-jdk7-scala2.11/6565/
Test FAILed (JDK 7 and Scala 2.11).

@asfgit

asfgit commented Aug 4, 2017

Copy link
Copy Markdown

Refer to this link for build results (access rights to CI server needed):
https://builds.apache.org/job/kafka-pr-jdk8-scala2.12/6550/
Test FAILed (JDK 8 and Scala 2.12).

@nicktrav

nicktrav commented Aug 4, 2017

Copy link
Copy Markdown
Contributor Author

Sounds reasonable, @ijuma. I'll take another pass at it.

@nicktrav
nicktrav force-pushed the nickt.reassign-partitions-validation branch from 9cb5002 to 0231adf Compare August 5, 2017 21:22
@nicktrav

nicktrav commented Aug 5, 2017

Copy link
Copy Markdown
Contributor Author

@ijuma - I've taken a different approach, as suggested, using case classes to hold the deserialized json. PTAL.

cc: @omkreddy

@asfgit

asfgit commented Aug 5, 2017

Copy link
Copy Markdown

Refer to this link for build results (access rights to CI server needed):
https://builds.apache.org/job/kafka-pr-jdk7-scala2.11/6593/
Test PASSed (JDK 7 and Scala 2.11).

@asfgit

asfgit commented Aug 5, 2017

Copy link
Copy Markdown

Refer to this link for build results (access rights to CI server needed):
https://builds.apache.org/job/kafka-pr-jdk8-scala2.12/6578/
Test PASSed (JDK 8 and Scala 2.12).

@ijuma

ijuma commented Aug 8, 2017

Copy link
Copy Markdown
Member

Thanks, I'll take a look tomorrow.

@nicktrav

Copy link
Copy Markdown
Contributor Author

@ijuma - sorry to keep pinging you on this. How is this looking? Happy to address any feedback you might have.

@nicktrav

nicktrav commented Sep 7, 2017

Copy link
Copy Markdown
Contributor Author

Ping @omkreddy

@omkreddy

omkreddy commented Sep 8, 2017

Copy link
Copy Markdown
Contributor

@nicktrav Thanks for your patience. committers are busy with 0.11.0.1 release and other tasks. I am sure this will get merged into 1.0.0/October release. Pls, rebase the PR when you get a chance.

cc @ijuma

@nicktrav
nicktrav force-pushed the nickt.reassign-partitions-validation branch from 0231adf to 17fc8cf Compare September 17, 2017 17:16
@nicktrav

Copy link
Copy Markdown
Contributor Author

Retest this please.

@ijuma ijuma left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the delay @nicktrav. I left a few comments.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The result type can be Either[JsonProcessingException, T].

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Field name should be partition

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like we'd want to include the original exception as the cause. Also, why is it a ConfigException?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should be using this in ReassignPartitionsZNode as in my PR.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should use ReassignPartitionsZNode.decode

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should rewrite these tests to use ReassignPartitionsZNode. Also, since they don't require ZooKeeper, they should be unit tests. Perhaps ReassignPartitionsZNodeTest.

@nicktrav

nicktrav commented Jan 5, 2018

Copy link
Copy Markdown
Contributor Author

Thanks for the review @ijuma. I pushed a new commit addressing your last round of comments. I'm sure some of it is not idiomatic Scala, so would appreciate some guidance, if any.

@omkreddy

omkreddy commented Jan 8, 2018

Copy link
Copy Markdown
Contributor

Can we use zkUtils.parsePartitionReassignmentData here
https://github.com/apache/kafka/blob/trunk/core/src/main/scala/kafka/admin/ReassignPartitionsCommand.scala#L245
above change will solve KAFKA-6084. This can be done in another PR.

@ijuma

ijuma commented Jan 8, 2018

Copy link
Copy Markdown
Member

@omkreddy Ideally, we should not be using ZkUtils in ReassignPartitionsCommand (i.e. we should use KafkaZkClient). Also, ReassignPartitionsCommand also parses a log_dirs field which is not handled in ZkUtils (or KafkaZkClient). Let's do that clean-up in a separate PR.

@nicktrav

Copy link
Copy Markdown
Contributor Author

@omkreddy @ijuma - any action for me to take here based on the last two comments?

@omkreddy

Copy link
Copy Markdown
Contributor

LGTM. +1

@ijuma

ijuma commented Jan 18, 2018

Copy link
Copy Markdown
Member

Sorry, I have just moved countries and won't have time until next week.

@nicktrav

Copy link
Copy Markdown
Contributor Author

No worries at all. Good luck with the move!

@nicktrav
nicktrav force-pushed the nickt.reassign-partitions-validation branch from 2954d4c to b7b210e Compare February 8, 2018 17:22
@nicktrav

Copy link
Copy Markdown
Contributor Author

Any chance of an update on this @ijuma @omkreddy? (coincidentally, today is the 1 year birthday of the ticket! 🍰)

Nicholas Travers and others added 11 commits March 19, 2018 20:26
…rsisting state in ZooKeeper

Prior to this, there have been instances where invalid data was allowed to be persisted in ZooKeeper, which causes ClassCastExceptions when a broker is restarted and reads this type-unsafe data.

Adds basic structural and type validation for the reassignment JSON via
introduction of Scala case classes that map to the expected JSON
structure.
@nicktrav
nicktrav force-pushed the nickt.reassign-partitions-validation branch from b7b210e to ec7f36d Compare March 20, 2018 03:33
@omkreddy

Copy link
Copy Markdown
Contributor

maybe @hachikuji can help to merge this patch.

@viktorsomogyi viktorsomogyi left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Although (as mentioned on my JIRA) this PR seems to aim bit different goals then mine, I reviewed this PR and made one minor comment/question.
All in all I think the PR looks good. Would be happy to see this merged.

* Parse a JSON string into either a generic type T, or a JsonProcessingException in the case of
* exception.
*/
def parseStringAs[T](input: String)(implicit tag: ClassTag[T]): Either[JsonProcessingException, T] = {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, just a very basic question: why are you using here Either/Left/Right instead of Try/Success/Failure?
As from my previous experiences we used Try when we wanted to propagate the exception.
And please not I don't mind using Either, just asking for reasons. :)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My (idiomatic) Scala isn't great, but this came at the suggestion of @ijuma (above):
#2708 (comment)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Try doesn't let you specify an exception subclass and behaves a bit different if an exception is thrown during map, etc.

@ijuma ijuma left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I pushed minor changes and it now LGTM. Will merge it after the tests pass. Thanks so much for your patience.

@ijuma
ijuma merged commit 4106cb1 into apache:trunk Mar 31, 2018
@nicktrav

Copy link
Copy Markdown
Contributor Author

Thanks @ijuma!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants