Skip to content

KAFKA-7235: Detect outdated control requests and bounced brokers using broker generation - #5821

Merged
junrao merged 16 commits into
apache:trunkfrom
hzxa21:KIP-380-PR
Dec 3, 2018
Merged

KAFKA-7235: Detect outdated control requests and bounced brokers using broker generation#5821
junrao merged 16 commits into
apache:trunkfrom
hzxa21:KIP-380-PR

Conversation

@hzxa21

@hzxa21 hzxa21 commented Oct 20, 2018

Copy link
Copy Markdown
Contributor

This PR introduces the broker generation concept and leverage it to allow controller to detect fast bounced brokers and allow broker to reject outdated control requests.

It has the changes required to implement KIP-380:

[Common]

  • Refactor ZookeeperClient to expose the zookeeper multi request directly
  • Refactor KafkaZkClient to use MultiRequest instead of raw zookeeper transaciton
  • Atomically get creation transaction id (czxid) with broker znode creation and use it as broker epoch to identify broker gerneration across bounces
  • Introduce LeaderAndIsrRequest V2, UpdateMetadataRequest V5 and StopReplicaRequest V1 to include broker epoch in control requests and normalize their schemas to make it more memory efficient
  • Add STALE_BROKER_EPOCH error

[Broker]

  • Cache the current broker epoch after broker znode registration
  • Reject LeaderAndIsrRequest, UpdateMetadataRequest and StopReplicaRequest if the request's broker epoch < current broker epoch, and respond back with STALE_BROKER_EPOCH error

[Controller]

  • Cache/update broker epochs in controllerContext.brokerEpochsCache after reading from zk when processing BrokerChange event and onControllerFailover
  • Detect bounced brokers in BrokerChange event by comparing the broker epochs get from zk and cached broker epochs and trigger necessary state changes
  • Avoid sending out requests to dead brokers

[Test]

  • Add BrokerEpochIntegrationTest to test broker processing new versions of the control requests and rejecting requests with stale broker epoch
  • Add a test case in ControllerIntegrationTest to test controller detecting bounced brokers
  • Add test cases in RequestResponseTest to test seralization and de-seralization for new versions of the control requests
  • Add ControlRequstTest unit test to test control requests schemas normalization

Committer Checklist (excluded from commit message)

  • Verify design and implementation
  • Verify test coverage and CI build status
  • Verify documentation (including upgrade notes)

@hzxa21

hzxa21 commented Nov 2, 2018

Copy link
Copy Markdown
Contributor Author

@junrao @ijuma @lindong28 Can you help to review this PR when you have time? Thanks!

@lindong28 lindong28 self-assigned this Nov 6, 2018

@lindong28 lindong28 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.

Thanks for the patch! Left some comments below.

Comment thread clients/src/main/java/org/apache/kafka/common/requests/StopReplicaRequest.java Outdated
Comment thread clients/src/main/java/org/apache/kafka/common/requests/LeaderAndIsrResponse.java Outdated
Comment thread core/src/main/scala/kafka/server/ReplicaManager.scala Outdated
Comment thread core/src/main/scala/kafka/zk/KafkaZkClient.scala Outdated
Comment thread core/src/main/scala/kafka/zk/KafkaZkClient.scala Outdated
Comment thread core/src/main/scala/kafka/zk/KafkaZkClient.scala Outdated
Comment thread core/src/main/scala/kafka/zk/KafkaZkClient.scala Outdated

@lindong28 lindong28 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.

Thanks for the update! Left some more comments below.

Comment thread clients/src/main/java/org/apache/kafka/common/protocol/Errors.java Outdated
Comment thread clients/src/main/java/org/apache/kafka/common/requests/LeaderAndIsrRequest.java Outdated
Comment thread clients/src/main/java/org/apache/kafka/common/requests/LeaderAndIsrRequest.java Outdated
Comment thread clients/src/main/java/org/apache/kafka/common/requests/UpdateMetadataRequest.java Outdated
Comment thread core/src/main/scala/kafka/server/KafkaApis.scala Outdated
Comment thread core/src/main/scala/kafka/zk/KafkaZkClient.scala Outdated
Comment thread core/src/main/scala/kafka/zk/KafkaZkClient.scala Outdated
Comment thread core/src/main/scala/kafka/zk/KafkaZkClient.scala Outdated
Comment thread core/src/main/scala/kafka/zookeeper/ZooKeeperClient.scala Outdated

@lindong28 lindong28 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.

Thanks for the update. Looks good overall. Left a few more minor comments. Can you rebase the patch onto trunk?

Comment thread core/src/main/scala/kafka/controller/ControllerChannelManager.scala Outdated
Comment thread core/src/main/scala/kafka/server/KafkaApis.scala Outdated
Comment thread core/src/main/scala/kafka/zk/KafkaZkClient.scala Outdated
Comment thread core/src/main/scala/kafka/controller/KafkaController.scala Outdated
@lindong28

lindong28 commented Nov 12, 2018

Copy link
Copy Markdown
Member

@hzxa21 LGTM. Thanks for the update. Could you rebase the patch?

Hey @junrao @ijuma, would you like to review the patch or it is OK for me to merge it?

@junrao

junrao commented Nov 12, 2018

Copy link
Copy Markdown
Contributor

@hzxa21 , @lindong28 : Yes, I will make another pass in the next couple of days.

@junrao junrao 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.

@hzxa21 : Thanks for the patch. Left a few comments below.

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.

Could we fix the javadoc above?

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.

Fixed.

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.

It would be useful to avoid _1/_2 for better readability. We could do foreach { case (broker, epoch) => ...}

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.

Fixed.

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.

It would be useful to avoid _1/_2 for better readability.

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.

Fixed.

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.

It would be useful to avoid _1 for better readability.

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.

Fixed.

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.

Instead of bouncedBrokerIds(broker.id), it might be clearer to do bouncedBrokerIds.contains(broker.id).

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.

Done.

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.

The code in this method is quite similar to that in testControlRequestWithCorrectBrokerEpoch(). Should we merged them somehow?

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.

Sure. I have merged them into a single function.

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.

Should this be volatile?

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.

Yes. Fixed.

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.

This is unnecessary. Great test!

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.

Remove. Thanks!

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.

indentation

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.

Fixed.

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.

indentation

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.

Fixed.

@hzxa21

hzxa21 commented Nov 29, 2018

Copy link
Copy Markdown
Contributor Author

@lindong28 @junrao I have updated the PR to address all the comments. Could you take a second look?

@junrao junrao 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.

@hzxa21 : Thanks for the update patch. Just a few more minor comments below.

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.

Could initialBrokerEpoch be right after initialBrokerInfo?

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.

Sure. Done.

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.

indentation

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.

Fixed.

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.

control request => controlled shutdown request

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.

I mean LeaderAndIsr/UpdateMetadata/StopReplica requests here, not controlled shutdown request. I have updated the comment to avoid confusion.

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.

The controller part is not right. Non-controllers are registered through this api too.

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.

Fixed.

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.

It seems that this logging is redundant since registerBroker() logs the same info already?

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.

Thanks for pointing out. I have removed the log here.

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.

normalize => normalizes

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.

Fixed.

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.

Perhaps add a comment on how v1 differs from v0?

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.

Sure. Added.

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.

normalize => normalizes

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.

Fixed.

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.

unused import

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.

Removed.

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.

typo Reuest

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.

Fixed.

@hzxa21

hzxa21 commented Nov 30, 2018

Copy link
Copy Markdown
Contributor Author

@junrao Thanks for the prompt reply. I have updated the PR to address your comments and rebase.

@junrao junrao 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.

@hzxa21 : Thanks for the rebase. LGTM. Just a couple of minor comments below.

def registerBroker(brokerInfo: BrokerInfo): Unit = {
/**
* Registers the broker in zookeeper and return the broker epoch.
* @return broker epoch (znode create transaction id)

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.

Could we put return after param ?

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.

Sure. Done.


/**
* Gets all brokers with broker epoch in the cluster.
* @return sequence of brokers in the cluster.

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.

Could we change the comment accordingly?

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.

Done.

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.

It seems that you fixed a different line?

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.

Ah. My bad. I mislooked this one. Fixed.

@hzxa21

hzxa21 commented Nov 30, 2018

Copy link
Copy Markdown
Contributor Author

@junrao Thanks for the comments. I have addressed your comments in the updated commit.

@junrao

junrao commented Nov 30, 2018

Copy link
Copy Markdown
Contributor

@lindong28 : Do you want to take another look of this PR before merging?

@lindong36

Copy link
Copy Markdown

LGTM. Thanks for the in-depth review @junrao! I am currently not able to access my original github account due to loss of my phone number and can not merge this PR myself.

@junrao

junrao commented Dec 1, 2018

Copy link
Copy Markdown
Contributor

@hzxa21 : Could you address the last comment on line 415 in KafkaZkClient.scala?

@hzxa21

hzxa21 commented Dec 1, 2018

Copy link
Copy Markdown
Contributor Author

@junrao My bad. Updated the PR to fix that.

@junrao junrao 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.

@hzxa21 : Thanks for the latest patch. LGTM. Also note that broker epoch can potentially be used to improve KAFKA-6029 as well.

@junrao
junrao merged commit 2155c6d into apache:trunk Dec 3, 2018
@hzxa21

hzxa21 commented Dec 3, 2018

Copy link
Copy Markdown
Contributor Author

@junrao Thanks a lot for the review. There are several follow-ups (KAFKA-6029 & KAFKA-7283) we can do after getting the broker epoch. I will address them accordingly and submit PRs. If you are aware of anything that can also benefit from broker epoch, do let me know and I am open to more discussion. Thanks again!

pengxiaolong pushed a commit to pengxiaolong/kafka that referenced this pull request Jun 14, 2019
…g broker generation (apache#5821)

* KAFKA-7235: Detect outdated control requests and bounced brokers using broker generation

* Add broker_epoch in controlled shutdown request

* Move broker epoch check into controller for ControlledShutdownRequest

* Refactor schema definition for controler requests/responses

* Address comments

* Address comments

* Address comments

* Send back STALE_BROKER_EPOCH error in ControlledShutdown response

* Fix build issue

* Address comments

* Address comments

* Address comments

* Address comments

* Fix tests after rebase

* Address comments

* Address comments
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.

4 participants