-
Notifications
You must be signed in to change notification settings - Fork 15.4k
KAFKA-15263 Check KRaftMigrationDriver state in each event #14115
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
mumrah
merged 8 commits into
apache:trunk
from
mumrah:KAFKA-15263-check-migration-driver-state
Jul 28, 2023
Merged
Changes from 3 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
c92ae7d
Check internal state in each event
mumrah 0f0c446
debug
mumrah c819752
add comment to test
mumrah 1ca4e32
info log level
mumrah 8ac3e36
remove some superfluous logging
mumrah a038522
wakeup driver if broker registered
mumrah 074769c
wake up if cluster delta is present
mumrah 8281dca
increase timeout in ZkMigrationIntegrationTest
mumrah 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
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 |
|---|---|---|
|
|
@@ -297,6 +297,16 @@ private boolean isValidStateChange(MigrationDriverState newState) { | |
| } | ||
| } | ||
|
|
||
| private boolean checkDriverState(MigrationDriverState expectedState) { | ||
| if (migrationState.equals(expectedState)) { | ||
| return true; | ||
| } else { | ||
| log.debug("Expected driver state {} but found {}. Not running this event {}.", | ||
| expectedState, migrationState, this.getClass().getSimpleName()); | ||
| return false; | ||
| } | ||
| } | ||
|
|
||
| private void transitionTo(MigrationDriverState newState) { | ||
| if (!isValidStateChange(newState)) { | ||
| throw new IllegalStateException( | ||
|
|
@@ -520,7 +530,7 @@ class WaitForControllerQuorumEvent extends MigrationEvent { | |
|
|
||
| @Override | ||
| public void run() throws Exception { | ||
| if (migrationState.equals(MigrationDriverState.WAIT_FOR_CONTROLLER_QUORUM)) { | ||
| if (checkDriverState(MigrationDriverState.WAIT_FOR_CONTROLLER_QUORUM)) { | ||
| if (!firstPublish) { | ||
| log.trace("Waiting until we have received metadata before proceeding with migration"); | ||
| return; | ||
|
|
@@ -564,24 +574,19 @@ public void run() throws Exception { | |
| class WaitForZkBrokersEvent extends MigrationEvent { | ||
| @Override | ||
| public void run() throws Exception { | ||
| switch (migrationState) { | ||
| case WAIT_FOR_BROKERS: | ||
| if (areZkBrokersReadyForMigration()) { | ||
| log.info("Zk brokers are registered and ready for migration"); | ||
| transitionTo(MigrationDriverState.BECOME_CONTROLLER); | ||
| } | ||
| break; | ||
| default: | ||
| // Ignore the event as we're not in the appropriate state anymore. | ||
| break; | ||
| if (checkDriverState(MigrationDriverState.WAIT_FOR_BROKERS)) { | ||
| if (areZkBrokersReadyForMigration()) { | ||
| log.info("Zk brokers are registered and ready for migration"); | ||
| transitionTo(MigrationDriverState.BECOME_CONTROLLER); | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| class BecomeZkControllerEvent extends MigrationEvent { | ||
| @Override | ||
| public void run() throws Exception { | ||
| if (migrationState == MigrationDriverState.BECOME_CONTROLLER) { | ||
| if (checkDriverState(MigrationDriverState.BECOME_CONTROLLER)) { | ||
| applyMigrationOperation("Claiming ZK controller leadership", zkMigrationClient::claimControllerLeadership); | ||
| if (migrationLeadershipState.zkControllerEpochZkVersion() == -1) { | ||
| log.info("Unable to claim leadership, will retry until we learn of a different KRaft leader"); | ||
|
|
@@ -599,6 +604,9 @@ public void run() throws Exception { | |
| class MigrateMetadataEvent extends MigrationEvent { | ||
| @Override | ||
| public void run() throws Exception { | ||
| if (!checkDriverState(MigrationDriverState.ZK_MIGRATION)) { | ||
| return; | ||
| } | ||
|
Comment on lines
+617
to
+619
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the actual fix. The rest of the changes are for cleanliness/readability |
||
| Set<Integer> brokersInMetadata = new HashSet<>(); | ||
| log.info("Starting ZK migration"); | ||
| MigrationManifest.Builder manifestBuilder = MigrationManifest.newBuilder(time); | ||
|
|
@@ -655,7 +663,7 @@ public void run() throws Exception { | |
| class SyncKRaftMetadataEvent extends MigrationEvent { | ||
| @Override | ||
| public void run() throws Exception { | ||
| if (migrationState == MigrationDriverState.SYNC_KRAFT_TO_ZK) { | ||
| if (checkDriverState(MigrationDriverState.SYNC_KRAFT_TO_ZK)) { | ||
| log.info("Performing a full metadata sync from KRaft to ZK."); | ||
| Map<String, Integer> dualWriteCounts = new TreeMap<>(); | ||
| zkMetadataWriter.handleSnapshot(image, countingOperationConsumer( | ||
|
|
@@ -671,7 +679,7 @@ class SendRPCsToBrokersEvent extends MigrationEvent { | |
| @Override | ||
| public void run() throws Exception { | ||
| // Ignore sending RPCs to the brokers since we're no longer in the state. | ||
| if (migrationState == MigrationDriverState.KRAFT_CONTROLLER_TO_BROKER_COMM) { | ||
| if (checkDriverState(MigrationDriverState.KRAFT_CONTROLLER_TO_BROKER_COMM)) { | ||
| if (image.highestOffsetAndEpoch().compareTo(migrationLeadershipState.offsetAndEpoch()) >= 0) { | ||
| log.trace("Sending RPCs to broker before moving to dual-write mode using " + | ||
| "at offset and epoch {}", image.highestOffsetAndEpoch()); | ||
|
|
||
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be
info? It won't happen often, will it?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It shouldn't happen often, no. INFO sounds good to me