-
Notifications
You must be signed in to change notification settings - Fork 241
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(issues1169): optimize partition reassignment logic to avoid NotL…
…eaderOrFollowerException Signed-off-by: Robin Han <[email protected]>
- Loading branch information
Showing
21 changed files
with
273 additions
and
25 deletions.
There are no files selected for viewing
37 changes: 37 additions & 0 deletions
37
core/src/main/scala/kafka/log/streamaspect/DefaultOpenStreamChecker.java
This file contains 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,37 @@ | ||
/* | ||
* Copyright 2024, AutoMQ CO.,LTD. | ||
* | ||
* Use of this software is governed by the Business Source License | ||
* included in the file BSL.md | ||
* | ||
* As of the Change Date specified in that file, in accordance with | ||
* the Business Source License, use of this software will be governed | ||
* by the Apache License, Version 2.0 | ||
*/ | ||
|
||
package kafka.log.streamaspect; | ||
|
||
import com.automq.stream.s3.metadata.StreamState; | ||
import kafka.server.metadata.KRaftMetadataCache; | ||
import org.apache.kafka.common.errors.s3.StreamFencedException; | ||
import org.apache.kafka.image.S3StreamMetadataImage; | ||
|
||
public class DefaultOpenStreamChecker implements OpenStreamChecker { | ||
private final KRaftMetadataCache metadataCache; | ||
|
||
public DefaultOpenStreamChecker(KRaftMetadataCache metadataCache) { | ||
this.metadataCache = metadataCache; | ||
} | ||
|
||
@Override | ||
public boolean check(long streamId, long epoch) throws StreamFencedException { | ||
S3StreamMetadataImage stream = metadataCache.currentImage().streamsMetadata().getStreamMetadata(streamId); | ||
if (stream == null) { | ||
throw new StreamFencedException("streamId=" + streamId + " cannot be found, it may be deleted or not created yet"); | ||
} | ||
if (stream.getEpoch() > epoch) { | ||
throw new StreamFencedException("streamId=" + streamId + " with epoch=" + epoch + " is fenced by new epoch=" + stream.getEpoch()); | ||
} | ||
return StreamState.CLOSED.equals(stream.state()); | ||
} | ||
} |
This file contains 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 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 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
27 changes: 27 additions & 0 deletions
27
core/src/main/scala/kafka/log/streamaspect/OpenStreamChecker.java
This file contains 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,27 @@ | ||
/* | ||
* Copyright 2024, AutoMQ CO.,LTD. | ||
* | ||
* Use of this software is governed by the Business Source License | ||
* included in the file BSL.md | ||
* | ||
* As of the Change Date specified in that file, in accordance with | ||
* the Business Source License, use of this software will be governed | ||
* by the Apache License, Version 2.0 | ||
*/ | ||
|
||
package kafka.log.streamaspect; | ||
|
||
import org.apache.kafka.common.errors.s3.StreamFencedException; | ||
|
||
/** | ||
* Check whether a stream is ready for open. | ||
*/ | ||
public interface OpenStreamChecker { | ||
OpenStreamChecker NOOP = (streamId, epoch) -> true; | ||
|
||
/** | ||
* Check whether a stream is ready for open. | ||
*/ | ||
boolean check(long streamId, long epoch) throws StreamFencedException; | ||
|
||
} |
This file contains 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 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 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 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 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 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 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 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 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 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.