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 21:49:56 UTC

[GitHub] [kafka] cmccabe opened a new pull request #11527: MINOR: store producer IDs in broker snapshots

cmccabe opened a new pull request #11527:
URL: https://github.com/apache/kafka/pull/11527


   When creating snapshots, controllers generate a ProducerIdsRecord indicating the highest producer ID
   that has been used so far. Brokers should generate the same record, so that the snapshots can be
   compared.
   
   Also, fix a bug in MetadataDelta#finishSnapshot. The current logic will produce the wrong result if
   all objects of a certain type are completely removed in the snapshot. The fix is to unconditionally
   create each delta object.


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



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

Posted by GitBox <gi...@apache.org>.
cmccabe commented on a change in pull request #11527:
URL: https://github.com/apache/kafka/pull/11527#discussion_r754714034



##########
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:
       yes, we will need to have some versioning code in after KIP-778, so that we generate a snapshot at the appropriate `metadata.version`. Probably this will take the form of adding a `version` parameter to the snapshot generation function. cc @mumrah 




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



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

Posted by GitBox <gi...@apache.org>.
cmccabe commented on a change in pull request #11527:
URL: https://github.com/apache/kafka/pull/11527#discussion_r754714660



##########
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:
       It's useful in the log as a kind of record of what happened. I think it's much less useful in the snapshot since at most we would be just giving the very latest broker to request producer ids, which isn't very interesting for debugging, 99% of the time.




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



[GitHub] [kafka] jsancio closed pull request #11527: KAFKA-13357: store producer IDs in broker snapshots

Posted by GitBox <gi...@apache.org>.
jsancio closed pull request #11527:
URL: https://github.com/apache/kafka/pull/11527


   


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



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

Posted by GitBox <gi...@apache.org>.
jsancio commented on pull request #11527:
URL: https://github.com/apache/kafka/pull/11527#issuecomment-978162625


   Closing since I merged https://github.com/apache/kafka/commit/e8b53caab475a976fc2ce97d4b41977752b64633.
   
   I think GitHub didn't close this PR because I didn't reference the PR number in the title.


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



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

Posted by GitBox <gi...@apache.org>.
jsancio commented on a change in pull request #11527:
URL: https://github.com/apache/kafka/pull/11527#discussion_r755272758



##########
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:
       @cmccabe I think you missed this change.




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



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

Posted by GitBox <gi...@apache.org>.
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