-
Notifications
You must be signed in to change notification settings - Fork 15.4k
KAFKA-7235: Detect outdated control requests and bounced brokers using broker generation #5821
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
9802486
KAFKA-7235: Detect outdated control requests and bounced brokers usin…
hzxa21 c381b2d
Add broker_epoch in controlled shutdown request
hzxa21 2506649
Move broker epoch check into controller for ControlledShutdownRequest
hzxa21 4dc29cd
Refactor schema definition for controler requests/responses
hzxa21 0f91e82
Address comments
hzxa21 02746fd
Address comments
hzxa21 5362018
Address comments
hzxa21 c0780f6
Send back STALE_BROKER_EPOCH error in ControlledShutdown response
hzxa21 43f3497
Fix build issue
hzxa21 bc91c3b
Address comments
hzxa21 c25fdef
Address comments
hzxa21 d422da0
Address comments
hzxa21 565a016
Address comments
hzxa21 f33808b
Fix tests after rebase
hzxa21 82d7437
Address comments
hzxa21 aec83c3
Address comments
hzxa21 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
31 changes: 31 additions & 0 deletions
31
clients/src/main/java/org/apache/kafka/common/errors/StaleBrokerEpochException.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one or more | ||
| * contributor license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright ownership. | ||
| * The ASF licenses this file to You under the Apache License, Version 2.0 | ||
| * (the "License"); you may not use this file except in compliance with | ||
| * the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package org.apache.kafka.common.errors; | ||
|
|
||
| public class StaleBrokerEpochException extends ApiException { | ||
|
|
||
| private static final long serialVersionUID = 1L; | ||
|
|
||
| public StaleBrokerEpochException(String message) { | ||
| super(message); | ||
| } | ||
|
|
||
| public StaleBrokerEpochException(String message, Throwable cause) { | ||
| super(message, cause); | ||
| } | ||
|
|
||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 80 additions & 0 deletions
80
clients/src/main/java/org/apache/kafka/common/requests/AbstractControlRequest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one or more | ||
| * contributor license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright ownership. | ||
| * The ASF licenses this file to You under the Apache License, Version 2.0 | ||
| * (the "License"); you may not use this file except in compliance with | ||
| * the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package org.apache.kafka.common.requests; | ||
|
|
||
| import org.apache.kafka.common.protocol.ApiKeys; | ||
| import org.apache.kafka.common.protocol.types.Field; | ||
| import org.apache.kafka.common.protocol.types.Struct; | ||
|
|
||
| // Abstract class for all control requests including UpdateMetadataRequest, LeaderAndIsrRequest and StopReplicaRequest | ||
| public abstract class AbstractControlRequest extends AbstractRequest { | ||
| public static final long UNKNOWN_BROKER_EPOCH = -1L; | ||
|
|
||
| protected static final Field.Int32 CONTROLLER_ID = new Field.Int32("controller_id", "The controller id"); | ||
| protected static final Field.Int32 CONTROLLER_EPOCH = new Field.Int32("controller_epoch", "The controller epoch"); | ||
| protected static final Field.Int64 BROKER_EPOCH = new Field.Int64("broker_epoch", "The broker epoch"); | ||
|
|
||
| protected final int controllerId; | ||
| protected final int controllerEpoch; | ||
| protected final long brokerEpoch; | ||
|
|
||
| public static abstract class Builder<T extends AbstractRequest> extends AbstractRequest.Builder<T> { | ||
| protected final int controllerId; | ||
| protected final int controllerEpoch; | ||
| protected final long brokerEpoch; | ||
|
|
||
| protected Builder(ApiKeys api, short version, int controllerId, int controllerEpoch, long brokerEpoch) { | ||
| super(api, version); | ||
| this.controllerId = controllerId; | ||
| this.controllerEpoch = controllerEpoch; | ||
| this.brokerEpoch = brokerEpoch; | ||
| } | ||
|
|
||
| } | ||
|
|
||
| public int controllerId() { | ||
| return controllerId; | ||
| } | ||
|
|
||
| public int controllerEpoch() { | ||
| return controllerEpoch; | ||
| } | ||
|
|
||
| public long brokerEpoch() { | ||
| return brokerEpoch; | ||
| } | ||
|
|
||
| protected AbstractControlRequest(ApiKeys api, short version, int controllerId, int controllerEpoch, long brokerEpoch) { | ||
| super(api, version); | ||
| this.controllerId = controllerId; | ||
| this.controllerEpoch = controllerEpoch; | ||
| this.brokerEpoch = brokerEpoch; | ||
| } | ||
|
|
||
| protected AbstractControlRequest(ApiKeys api, Struct struct, short version) { | ||
| super(api, version); | ||
| this.controllerId = struct.get(CONTROLLER_ID); | ||
| this.controllerEpoch = struct.get(CONTROLLER_EPOCH); | ||
| this.brokerEpoch = struct.getOrElse(BROKER_EPOCH, UNKNOWN_BROKER_EPOCH); | ||
| } | ||
|
|
||
| // Used for test | ||
| long size() { | ||
| return toStruct().sizeOf(); | ||
| } | ||
|
|
||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.