showuon commented on code in PR #24261:
URL: https://github.com/apache/kafka/pull/24261#discussion_r4675082864


##########
server-common/src/main/java/org/apache/kafka/server/mirror/MirrorPartitionMetadata.java:
##########
@@ -0,0 +1,122 @@
+/*
+ * 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.server.mirror;
+
+import org.apache.kafka.common.mirror.LastMirror;
+
+import java.util.Objects;
+
+/**
+ * An immutable snapshot of the mirror metadata of a partition.
+ *
+ * @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 offset and epoch, or {@link 
LastMirror#EMPTY} 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 {@link #NON_RETRYABLE_ERROR} 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 stateEpoch,
+    LastMirror lastMirror,
+    String errorMessage,
+    short retryAttempt,
+    MirrorPartitionState previousState
+) {
+    /**
+     * The retry attempt of a partition which failed with a non-retryable 
error.
+     */
+    public static final short NON_RETRYABLE_ERROR = -1;
+
+    /**
+     * The metadata of a partition with no recorded state, with the default 
value of every field.
+     */
+    public static final MirrorPartitionMetadata EMPTY = new 
MirrorPartitionMetadata(
+        MirrorPartitionState.UNKNOWN, 0, LastMirror.EMPTY, null, (short) 0, 
MirrorPartitionState.UNKNOWN);
+
+    public MirrorPartitionMetadata {
+        Objects.requireNonNull(state);
+        Objects.requireNonNull(lastMirror);
+        Objects.requireNonNull(previousState);
+    }

Review Comment:
   I think this is confusing that we don't allow `null` for these 3 fields, but 
allow `null` in `errorMessage` field. Maybe we can consider to use `Optional` 
type for `errorMessage`?



-- 
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]

Reply via email to