You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jira@kafka.apache.org by "mumrah (via GitHub)" <gi...@apache.org> on 2023/01/31 21:51:15 UTC

[GitHub] [kafka] mumrah opened a new pull request, #13180: Add a summarizer for the metadata migration

mumrah opened a new pull request, #13180:
URL: https://github.com/apache/kafka/pull/13180

   *More detailed description of your change,
   if necessary. The PR title and PR message become
   the squashed commit message, so use a separate
   comment to ping reviewers.*
   
   *Summary of testing strategy (including rationale)
   for the feature or bug fix. Unit and/or integration
   tests are expected for any behaviour change and
   system tests should be considered for larger changes.*
   
   ### Committer Checklist (excluded from commit message)
   - [ ] Verify design and implementation 
   - [ ] Verify test coverage and CI build status
   - [ ] Verify documentation (including upgrade notes)
   


-- 
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] mumrah commented on pull request #13180: MINOR: Add a summary of the metadata migration

Posted by "mumrah (via GitHub)" <gi...@apache.org>.
mumrah commented on PR #13180:
URL: https://github.com/apache/kafka/pull/13180#issuecomment-1414048688

   @cmccabe, here's the new metadata summary format:
   
   
   > [2023-02-02 11:21:52,175] TRACE Sending RPCs to broker before moving to dual-write mode. Metadata at offset 122 and epoch 1 includes 3 brokers (0 changed), 3 topics (0 changed), 0 features (0 changed), 10 configs (0 changed), 1 producer id (0 changed) (org.apache.kafka.metadata.migration.KRaftMigrationDriver:461)
   
   The migration manifest format is the same as before:
   
   > [2023-02-02 11:38:01,569] INFO Completed migration of metadata from ZooKeeper to KRaft. 71 records were generated in 342 ms across 4 batches. The record types were {TOPIC_RECORD=2, PARTITION_RECORD=2, CONFIG_RECORD=2, PRODUCER_IDS_RECORD=1}. The current metadata offset is now 121 with an epoch of 1. Saw 3 brokers in the migrated metadata [0, 1, 2]. (org.apache.kafka.metadata.migration.KRaftMigrationDriver:428)
   


-- 
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] clolov commented on a diff in pull request #13180: MINOR: Add a summary of the metadata migration

Posted by "clolov (via GitHub)" <gi...@apache.org>.
clolov commented on code in PR #13180:
URL: https://github.com/apache/kafka/pull/13180#discussion_r1094798424


##########
metadata/src/main/java/org/apache/kafka/metadata/migration/KRaftMigrationDriver.java:
##########
@@ -415,7 +416,7 @@ public void run() throws Exception {
                             log.info("Migrating {} records from ZK", batch.size());
                         }
                         CompletableFuture<?> future = zkRecordConsumer.acceptBatch(batch);
-                        count.addAndGet(batch.size());
+                        summary.acceptBatch(batch);

Review Comment:
   Got it and thank you for the explanation!



-- 
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 diff in pull request #13180: MINOR: Add a summary of the metadata migration

Posted by "cmccabe (via GitHub)" <gi...@apache.org>.
cmccabe commented on code in PR #13180:
URL: https://github.com/apache/kafka/pull/13180#discussion_r1093639638


##########
metadata/src/main/java/org/apache/kafka/metadata/migration/MigrationSummary.java:
##########
@@ -0,0 +1,71 @@
+/*
+ * 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.metadata.migration;
+
+import org.apache.kafka.common.metadata.MetadataRecordType;
+import org.apache.kafka.common.utils.Time;
+import org.apache.kafka.server.common.ApiMessageAndVersion;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.TimeUnit;
+
+/**
+ * Tracks the records generated as part of a ZK migration and creates a textual summary.
+ */
+public class MigrationSummary {
+    private final Time time;
+    private final long startTimeNanos;
+    private final Map<MetadataRecordType, Integer> counts = new HashMap<>();
+    private int batches = 0;
+    private int total = 0;
+    private long endTimeNanos = 0;
+
+    MigrationSummary(Time time) {
+        this.time = time;
+        this.startTimeNanos = time.nanoseconds();
+    }
+
+    public void acceptBatch(List<ApiMessageAndVersion> recordBatch) {
+        batches += 1;

Review Comment:
   this is java, you can just do ++



-- 
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] mumrah commented on a diff in pull request #13180: MINOR: Add a summary of the metadata migration

Posted by "mumrah (via GitHub)" <gi...@apache.org>.
mumrah commented on code in PR #13180:
URL: https://github.com/apache/kafka/pull/13180#discussion_r1094684342


##########
metadata/src/main/java/org/apache/kafka/metadata/migration/MigrationSummary.java:
##########
@@ -0,0 +1,71 @@
+/*
+ * 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.metadata.migration;
+
+import org.apache.kafka.common.metadata.MetadataRecordType;
+import org.apache.kafka.common.utils.Time;
+import org.apache.kafka.server.common.ApiMessageAndVersion;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.TimeUnit;
+
+/**
+ * Tracks the records generated as part of a ZK migration and creates a textual summary.
+ */
+public class MigrationSummary {
+    private final Time time;
+    private final long startTimeNanos;
+    private final Map<MetadataRecordType, Integer> counts = new HashMap<>();
+    private int batches = 0;
+    private int total = 0;
+    private long endTimeNanos = 0;
+
+    MigrationSummary(Time time) {
+        this.time = time;
+        this.startTimeNanos = time.nanoseconds();
+    }
+
+    public void acceptBatch(List<ApiMessageAndVersion> recordBatch) {
+        batches += 1;
+        recordBatch.forEach(apiMessageAndVersion -> {
+            MetadataRecordType type = MetadataRecordType.fromId(apiMessageAndVersion.message().apiKey());
+            counts.merge(type, 1, (__, count) -> count + 1);

Review Comment:
   Yea, it's a bit more succinct than the `compute` method for doing a Map of counters



-- 
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 diff in pull request #13180: MINOR: Add a summary of the metadata migration

Posted by "cmccabe (via GitHub)" <gi...@apache.org>.
cmccabe commented on code in PR #13180:
URL: https://github.com/apache/kafka/pull/13180#discussion_r1093640509


##########
metadata/src/main/java/org/apache/kafka/metadata/migration/MigrationSummary.java:
##########
@@ -0,0 +1,71 @@
+/*
+ * 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.metadata.migration;
+
+import org.apache.kafka.common.metadata.MetadataRecordType;
+import org.apache.kafka.common.utils.Time;
+import org.apache.kafka.server.common.ApiMessageAndVersion;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.TimeUnit;
+
+/**
+ * Tracks the records generated as part of a ZK migration and creates a textual summary.
+ */
+public class MigrationSummary {
+    private final Time time;
+    private final long startTimeNanos;
+    private final Map<MetadataRecordType, Integer> counts = new HashMap<>();
+    private int batches = 0;
+    private int total = 0;
+    private long endTimeNanos = 0;
+
+    MigrationSummary(Time time) {
+        this.time = time;
+        this.startTimeNanos = time.nanoseconds();
+    }
+
+    public void acceptBatch(List<ApiMessageAndVersion> recordBatch) {
+        batches += 1;
+        recordBatch.forEach(apiMessageAndVersion -> {
+            MetadataRecordType type = MetadataRecordType.fromId(apiMessageAndVersion.message().apiKey());
+            counts.merge(type, 1, (__, count) -> count + 1);

Review Comment:
   interesting. I didn't know about `merge`



-- 
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] mumrah closed pull request #13180: MINOR: Add a summary of the metadata migration

Posted by "mumrah (via GitHub)" <gi...@apache.org>.
mumrah closed pull request #13180: MINOR: Add a summary of the metadata migration
URL: https://github.com/apache/kafka/pull/13180


-- 
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] github-actions[bot] commented on pull request #13180: MINOR: Add a summary of the metadata migration

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #13180:
URL: https://github.com/apache/kafka/pull/13180#issuecomment-1585813252

   This PR is being marked as stale since it has not had any activity in 90 days. If you would like to keep this PR alive, please ask a committer for review. If the PR has  merge conflicts, please update it with the latest from trunk (or appropriate release branch)
   If this PR is no longer valid or desired, please feel free to close it. If no activity occurrs in the next 30 days, it will be automatically closed.


-- 
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 pull request #13180: MINOR: Add a summary of the metadata migration

Posted by "cmccabe (via GitHub)" <gi...@apache.org>.
cmccabe commented on PR #13180:
URL: https://github.com/apache/kafka/pull/13180#issuecomment-1412624413

   Thanks for the PR. WIth regard to the formatting changes, can we use the style we've been doing elsewhere in the scala code of:
   ```
   functionName(
     parameterA: typeA,
     parameterB: typeB,
   ...
   ): Unit = {
   ...
   }
   ```
   I find it more readable than the style where we have lots of indenting
   ```
   functionName(parameterA: typeA,
                parameterB: typeB,
   ...
   ): Unit = {
   ...
   }
   ```
   
   Can we have `MigrationSummary` be `MigrationManifest`? And be immutable and have equals(), hashCode() and all that for the sake of unit tests. That does imply we'd need a `MigrationManifest.Builder` or something, but that seems OK?
   
   I think `toSummaryString` really would be better off as a method inside `MetadataImage`. We are not going to remember to update it if it's stored off the side. It would also be good to be clearer what is coming from the image and what from the delta. Like `123 topics (5 changed)` or something...


-- 
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] clolov commented on a diff in pull request #13180: MINOR: Add a summary of the metadata migration

Posted by "clolov (via GitHub)" <gi...@apache.org>.
clolov commented on code in PR #13180:
URL: https://github.com/apache/kafka/pull/13180#discussion_r1094398310


##########
metadata/src/main/java/org/apache/kafka/metadata/migration/KRaftMigrationDriver.java:
##########
@@ -415,7 +416,7 @@ public void run() throws Exception {
                             log.info("Migrating {} records from ZK", batch.size());
                         }
                         CompletableFuture<?> future = zkRecordConsumer.acceptBatch(batch);
-                        count.addAndGet(batch.size());
+                        summary.acceptBatch(batch);

Review Comment:
   I am new to this part of the codebase, so this might have an obvious answer, but previously we used an AtomicInteger, which leads me to believe there was a race-condition which the author was trying to avoid. If this is true, the new MigrationSummary class does not impose any synchronization barriers, is this correct?



-- 
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] mumrah commented on a diff in pull request #13180: MINOR: Add a summary of the metadata migration

Posted by "mumrah (via GitHub)" <gi...@apache.org>.
mumrah commented on code in PR #13180:
URL: https://github.com/apache/kafka/pull/13180#discussion_r1094683166


##########
metadata/src/main/java/org/apache/kafka/metadata/migration/KRaftMigrationDriver.java:
##########
@@ -415,7 +416,7 @@ public void run() throws Exception {
                             log.info("Migrating {} records from ZK", batch.size());
                         }
                         CompletableFuture<?> future = zkRecordConsumer.acceptBatch(batch);
-                        count.addAndGet(batch.size());
+                        summary.acceptBatch(batch);

Review Comment:
   @clolov thanks for taking a look and welcome to our corner of Kafka 😄 
   
   The reason I added the atomic integer here is because `count.addAndGet(batch.size());` happens inside an anonymous function (lambda). E.g., 
   
   ```java
   zkMigrationClient.readAllMetadata(batch -> {
     // ...
     count.addAndGet(batch.size());
     // ...
   });
   ```
   
   Inside lambdas, you can only reference final or effectively final fields from an outer scope. The `AtomicInteger` reference is effectively final since we never change the assignment. It's kind of an annoying side-effect of using lambdas for simple things like for-loops, but it's a good safety measure since sometimes the lambda can be run in another thread or in parallel (depending on what you're doing). 
   
   With this change, I'm moving the counting into `MigrationSummary`. Since I know this lambda is executed by a single thread in ZkMigrationClient, I can safely use a plain `int` to count.
   
   HTH



##########
metadata/src/main/java/org/apache/kafka/metadata/migration/KRaftMigrationDriver.java:
##########
@@ -415,7 +416,7 @@ public void run() throws Exception {
                             log.info("Migrating {} records from ZK", batch.size());
                         }
                         CompletableFuture<?> future = zkRecordConsumer.acceptBatch(batch);
-                        count.addAndGet(batch.size());
+                        summary.acceptBatch(batch);

Review Comment:
   @clolov thanks for taking a look and welcome to our corner of Kafka 😄 
   
   The reason I added the atomic integer here is because `count.addAndGet(batch.size());` happens inside an anonymous function (lambda). E.g., 
   
   ```java
   zkMigrationClient.readAllMetadata(batch -> {
     // ...
     count.addAndGet(batch.size());
     // ...
   });
   ```
   
   Inside lambdas, you can only reference final or effectively final fields from an outer scope. The `AtomicInteger` reference is effectively final since we never change the assignment. It's kind of an annoying side-effect of using lambdas for simple things like for-loops, but it's a good safety measure since sometimes the lambda can be run in another thread or in parallel (depending on what you're doing). 
   
   With this change, I'm moving the counting into `MigrationSummary`. Since I know this lambda is executed by a single thread in ZkMigrationClient, I can safely use a plain `int` to count.



-- 
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] mumrah commented on pull request #13180: MINOR: Add a summary of the metadata migration

Posted by "mumrah (via GitHub)" <gi...@apache.org>.
mumrah commented on PR #13180:
URL: https://github.com/apache/kafka/pull/13180#issuecomment-1634899885

   Closing in favor of #14008


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