TaiJuWu commented on code in PR #24261:
URL: https://github.com/apache/kafka/pull/24261#discussion_r4651892187
##########
server-common/src/main/java/org/apache/kafka/server/mirror/MirrorPartitionMetadata.java:
##########
@@ -16,34 +16,91 @@
*/
package org.apache.kafka.server.mirror;
+import org.apache.kafka.server.common.OffsetAndEpoch;
+
import java.util.Objects;
/**
* An immutable snapshot of the mirror metadata of a partition.
*
- * @param state The mirror partition state.
- * @param leaderEpoch The highest leader epoch seen for the partition,
or -1 if not available.
- * @param stateEpoch The current state epoch for the partition.
- * @param lastMirrorEpoch The last mirror epoch, or -1 if not available.
- * @param lastMirrorOffset The last mirror offset, or -1 if not available.
- * @param errorMessage The error message when in {@link
MirrorPartitionState#FAILED} state, or null otherwise.
- * @param retryAttempt The retry attempt count in {@link
MirrorPartitionState#FAILED} state, 0 if not failed,
- * or -1 if non-retryable.
- * @param previousState The mirror partition state before entering {@link
MirrorPartitionState#FAILED},
- * or {@link MirrorPartitionState#UNKNOWN} if not
recorded.
+ * @param state The mirror partition state.
+ * @param stateEpoch The current state epoch for the partition, which
tells when the cached metadata can be safely
+ * updated.
+ * @param lastMirror The last mirror epoch and offset, or {@link
#EMPTY_LAST_MIRROR} if not available.
+ * @param errorMessage The error message when in {@link
MirrorPartitionState#FAILED} state, or null otherwise.
+ * @param retryAttempt The retry attempt count in {@link
MirrorPartitionState#FAILED} state, 0 if not failed,
+ * or -1 if non-retryable.
+ * @param previousState The mirror partition state before entering {@link
MirrorPartitionState#FAILED},
+ * or {@link MirrorPartitionState#UNKNOWN} if not
recorded.
*/
public record MirrorPartitionMetadata(
MirrorPartitionState state,
- int leaderEpoch,
int stateEpoch,
- int lastMirrorEpoch,
- long lastMirrorOffset,
+ OffsetAndEpoch lastMirror,
String errorMessage,
short retryAttempt,
MirrorPartitionState previousState
) {
+ /**
+ * The last mirror epoch and offset when they are not available.
+ */
+ public static final OffsetAndEpoch EMPTY_LAST_MIRROR = new
OffsetAndEpoch(-1L, -1);
+
+ /**
+ * The metadata of a partition with no recorded state, with the default
value of every field.
+ */
+ public static final MirrorPartitionMetadata EMPTY = builder().build();
+
public MirrorPartitionMetadata {
Objects.requireNonNull(state);
+ Objects.requireNonNull(lastMirror);
Objects.requireNonNull(previousState);
}
+
+ public static Builder builder() {
+ return new Builder();
+ }
+
+ public static class Builder {
+ private MirrorPartitionState state = MirrorPartitionState.UNKNOWN;
+ private int stateEpoch = 0;
+ private OffsetAndEpoch lastMirror = EMPTY_LAST_MIRROR;
+ private String errorMessage = null;
+ private short retryAttempt = 0;
+ private MirrorPartitionState previousState =
MirrorPartitionState.UNKNOWN;
+
+ public Builder setState(MirrorPartitionState state) {
Review Comment:
I am ok with both naming, I don't think kafka have requirement about this.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]