You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jira@kafka.apache.org by GitBox <gi...@apache.org> on 2021/11/22 22:44:33 UTC

[GitHub] [kafka] jsancio commented on a change in pull request #11527: KAFKA-13357: store producer IDs in broker snapshots

jsancio commented on a change in pull request #11527:
URL: https://github.com/apache/kafka/pull/11527#discussion_r754683139



##########
File path: metadata/src/main/java/org/apache/kafka/image/ProducerIdsImage.java
##########
@@ -0,0 +1,77 @@
+/*
+ * 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.image;
+
+import org.apache.kafka.common.metadata.ProducerIdsRecord;
+import org.apache.kafka.server.common.ApiMessageAndVersion;
+
+import java.util.Collections;
+import java.util.List;
+import java.util.Objects;
+import java.util.function.Consumer;
+
+
+/**
+ * Stores the highest seen producer ID in the metadata image.
+ *
+ * This class is thread-safe.
+ */
+public final class ProducerIdsImage {
+    public final static ProducerIdsImage EMPTY = new ProducerIdsImage(-1L);
+
+    private final long highestSeenProducerId;
+
+    public ProducerIdsImage(long highestSeenProducerId) {
+        this.highestSeenProducerId = highestSeenProducerId;
+    }
+
+    public long highestSeenProducerId() {
+        return highestSeenProducerId;
+    }
+
+    public void write(Consumer<List<ApiMessageAndVersion>> out) {
+        if (highestSeenProducerId >= 0) {
+            out.accept(Collections.singletonList(new ApiMessageAndVersion(
+                new ProducerIdsRecord().
+                    setBrokerId(-1).
+                    setBrokerEpoch(-1).
+                    setProducerIdsEnd(highestSeenProducerId), (short) 0)));

Review comment:
       Okay. Is it fair to assume that we will revisit this code regarding the version in `ApiMessageAndVersion`as part of KIP-778?

##########
File path: metadata/src/test/java/org/apache/kafka/image/ProducerIdsImageTest.java
##########
@@ -0,0 +1,89 @@
+/*
+ * 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.image;
+
+import org.apache.kafka.common.metadata.ProducerIdsRecord;
+import org.apache.kafka.metadata.RecordTestUtils;
+import org.apache.kafka.server.common.ApiMessageAndVersion;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.Timeout;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+
+@Timeout(value = 40)
+public class ProducerIdsImageTest {
+    final static ProducerIdsImage IMAGE1;
+
+    final static List<ApiMessageAndVersion> DELTA1_RECORDS;
+
+    final static ProducerIdsDelta DELTA1;
+
+    final static ProducerIdsImage IMAGE2;
+
+    static {
+        IMAGE1 = new ProducerIdsImage(123);
+
+        DELTA1_RECORDS = new ArrayList<>();
+        DELTA1_RECORDS.add(new ApiMessageAndVersion(new ProducerIdsRecord().
+            setBrokerId(2).
+            setBrokerId(100).

Review comment:
       Did you mean: 
   ```suggestion
               setBrokerId(2).
               setBrokerEpoch(100).
   ```

##########
File path: metadata/src/main/java/org/apache/kafka/image/ProducerIdsImage.java
##########
@@ -0,0 +1,77 @@
+/*
+ * 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.image;
+
+import org.apache.kafka.common.metadata.ProducerIdsRecord;
+import org.apache.kafka.server.common.ApiMessageAndVersion;
+
+import java.util.Collections;
+import java.util.List;
+import java.util.Objects;
+import java.util.function.Consumer;
+
+
+/**
+ * Stores the highest seen producer ID in the metadata image.
+ *
+ * This class is thread-safe.
+ */
+public final class ProducerIdsImage {
+    public final static ProducerIdsImage EMPTY = new ProducerIdsImage(-1L);
+
+    private final long highestSeenProducerId;
+
+    public ProducerIdsImage(long highestSeenProducerId) {
+        this.highestSeenProducerId = highestSeenProducerId;
+    }
+
+    public long highestSeenProducerId() {
+        return highestSeenProducerId;
+    }
+
+    public void write(Consumer<List<ApiMessageAndVersion>> out) {
+        if (highestSeenProducerId >= 0) {
+            out.accept(Collections.singletonList(new ApiMessageAndVersion(
+                new ProducerIdsRecord().
+                    setBrokerId(-1).
+                    setBrokerEpoch(-1).

Review comment:
       Broker id and epoch are only used to debugging right? Neither the broker nor the controller use these values, right? Do you think it makes sense to just remember and persist this value in the snapshot just for consistency with the log?

##########
File path: metadata/src/test/java/org/apache/kafka/image/ProducerIdsImageTest.java
##########
@@ -0,0 +1,89 @@
+/*
+ * 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.image;
+
+import org.apache.kafka.common.metadata.ProducerIdsRecord;
+import org.apache.kafka.metadata.RecordTestUtils;
+import org.apache.kafka.server.common.ApiMessageAndVersion;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.Timeout;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+
+@Timeout(value = 40)
+public class ProducerIdsImageTest {
+    final static ProducerIdsImage IMAGE1;
+
+    final static List<ApiMessageAndVersion> DELTA1_RECORDS;
+
+    final static ProducerIdsDelta DELTA1;
+
+    final static ProducerIdsImage IMAGE2;
+
+    static {
+        IMAGE1 = new ProducerIdsImage(123);
+
+        DELTA1_RECORDS = new ArrayList<>();
+        DELTA1_RECORDS.add(new ApiMessageAndVersion(new ProducerIdsRecord().
+            setBrokerId(2).
+            setBrokerId(100).
+            setProducerIdsEnd(456), (short) 0));
+        DELTA1_RECORDS.add(new ApiMessageAndVersion(new ProducerIdsRecord().
+            setBrokerId(3).
+            setBrokerId(100).

Review comment:
       Did you mean:
   ```suggestion
               setBrokerId(3).
               setBrokerEpoch(100).
   ```




-- 
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: jira-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org