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


##########
server-common/src/main/java/org/apache/kafka/server/mirror/MirrorPartitionMetadata.java:
##########
@@ -0,0 +1,49 @@
+/*
+ * 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 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.
+ */
+public record MirrorPartitionMetadata(
+    MirrorPartitionState state,
+    int leaderEpoch,
+    int stateEpoch,
+    int lastMirrorEpoch,
+    long lastMirrorOffset,

Review Comment:
   Given these two fields are always read and written together as they 
represent a single logical position, I would wrap them in an EpochOffset(epoch, 
offset) object that is generic enough to be reused in other parts of the code. 
I would add an EMPTY constant initialized to (-1, -1).



##########
server-common/src/main/java/org/apache/kafka/server/mirror/MirrorPartitionMetadata.java:
##########
@@ -0,0 +1,49 @@
+/*
+ * 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 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.
+ */
+public record MirrorPartitionMetadata(

Review Comment:
   Can we add a Builder and an EMPTY constant initialized to default values?



##########
server-common/src/main/java/org/apache/kafka/server/mirror/MirrorPartitionMetadata.java:
##########
@@ -0,0 +1,49 @@
+/*
+ * 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 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.
+ */
+public record MirrorPartitionMetadata(
+    MirrorPartitionState state,
+    int leaderEpoch,

Review Comment:
   Yes, leaderEpoch will only be tracked by the coordinator shard and used for 
fencing stale writes (see the Coordinator framework, and ShareGroups 
implementation for an example of that). There is no need to cache it on the 
broker side. Instead, we use stateEpoch to know when we can safely update the 
cache on the broker side (cache consistency).



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