You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jira@kafka.apache.org by "jlprat (via GitHub)" <gi...@apache.org> on 2024/08/06 08:33:31 UTC

[PR] KAFKA-15875: Stops leak Snapshot in public methods [kafka]

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

   The Snapshot class is package protected but it's returned in several public methods in SnapshotRegistry.
   To prevent this accidental leakage, these methods are made package protected as well. For getOrCreateSnapshot a new method called IdempotentCreateSnapshot is created that returns void.
   
   ### 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


Re: [PR] KAFKA-15875: Stops leak Snapshot in public methods [kafka]

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

   Test failures seem unrelated to the 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


Re: [PR] KAFKA-15875: Stops leak Snapshot in public methods [kafka]

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

   This PR is the successor of the closed https://github.com/apache/kafka/pull/14816
   In the previous PR I attempted to make the `Snapshot` class public, but this might have been an overkill


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


Re: [PR] KAFKA-15875: Stops leak Snapshot in public methods [kafka]

Posted by "jlprat (via GitHub)" <gi...@apache.org>.
jlprat merged PR #16807:
URL: https://github.com/apache/kafka/pull/16807


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


Re: [PR] KAFKA-15875: Stops leak Snapshot in public methods [kafka]

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


##########
metadata/src/main/java/org/apache/kafka/controller/OffsetControlManager.java:
##########
@@ -71,7 +71,7 @@ Builder setTime(Time time) {
             return this;
         }
 
-        public OffsetControlManager build() {
+        OffsetControlManager build() {

Review Comment:
   nit: The Builder itself can also be package-local.



##########
metadata/src/main/java/org/apache/kafka/controller/OffsetControlManager.java:
##########
@@ -36,7 +36,7 @@
 
 /**
  * Manages read and write offsets, and in-memory snapshots.
- *
+ * <br>

Review Comment:
   nit: I think `<p>` (without `</p>`) is preferred over `<br>`



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


Re: [PR] KAFKA-15875: Stops leak Snapshot in public methods [kafka]

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


##########
metadata/src/main/java/org/apache/kafka/controller/OffsetControlManager.java:
##########
@@ -36,7 +36,7 @@
 
 /**
  * Manages read and write offsets, and in-memory snapshots.
- *
+ * <br>

Review Comment:
   TIL: https://www.oracle.com/technical-resources/articles/java/javadoc-tool.html#format
   But the knowing enough HTML and semantic HTML this makes my brain itch. `<p>` is a tag that comes with the closing pair always and it's meant to embrace a paragraph. `<br>` is the one of the few tags that is allowed to be used without a closing one, and it's solely purpose is to add break lines.
   But I see that Oracle recommends the use of `<p>`, so be it.
   
   



##########
metadata/src/main/java/org/apache/kafka/controller/OffsetControlManager.java:
##########
@@ -71,7 +71,7 @@ Builder setTime(Time time) {
             return this;
         }
 
-        public OffsetControlManager build() {
+        OffsetControlManager build() {

Review Comment:
   Done



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


Re: [PR] KAFKA-15875: Stops leak Snapshot in public methods [kafka]

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


##########
metadata/src/test/java/org/apache/kafka/controller/FeatureControlManagerTest.java:
##########
@@ -213,7 +212,7 @@ public void testUpdateFeaturesErrorCases() {
     }
 
     @Test
-    public void testReplayRecords() throws Exception {

Review Comment:
   This method doesn't throw exceptions



##########
metadata/src/test/java/org/apache/kafka/controller/FeatureControlManagerTest.java:
##########
@@ -54,7 +54,6 @@
 @Timeout(value = 40)
 public class FeatureControlManagerTest {
 
-    @SuppressWarnings("unchecked")

Review Comment:
   This was not really needed



##########
server-common/src/main/java/org/apache/kafka/timeline/SnapshotRegistry.java:
##########
@@ -205,6 +205,18 @@ public Snapshot getOrCreateSnapshot(long epoch) {
         return snapshot;
     }
 
+    /**
+     * Creates a new snapshot at the given epoch.
+     * <br>
+     * If {@code epoch} already exists, and it is the last snapshot then this operation will do nothing.
+     *
+     * @param epoch             The epoch to create the snapshot at. The current epoch
+     *                          will be advanced to one past this epoch.
+     */
+    public void idempotentCreateSnapshot(long epoch) {
+        getOrCreateSnapshot(epoch);
+    }
+

Review Comment:
   This is the new method that calls the existing `getOrCreateSnapshot` but doesn't return anything, as it would leak the class outside its visibility scope.
   I called it idempotent as this is what `getOrCreate` does effectively.



##########
server-common/src/main/java/org/apache/kafka/timeline/SnapshottableHashTable.java:
##########
@@ -408,37 +408,6 @@ Iterator<T> snapshottableIterator(long epoch) {
         }
     }
 
-    String snapshottableToDebugString() {
-        StringBuilder bld = new StringBuilder();
-        bld.append(String.format("SnapshottableHashTable{%n"));
-        bld.append("top tier: ");
-        bld.append(baseToDebugString());
-        bld.append(String.format(",%nsnapshot tiers: [%n"));
-        String prefix = "";
-        for (Iterator<Snapshot> iter = snapshotRegistry.iterator(); iter.hasNext(); ) {
-            Snapshot snapshot = iter.next();
-            bld.append(prefix);
-            bld.append("epoch ").append(snapshot.epoch()).append(": ");
-            HashTier<T> tier = snapshot.getDelta(this);
-            if (tier == null) {
-                bld.append("null");
-            } else {
-                bld.append("HashTier{");
-                bld.append("size=").append(tier.size);
-                bld.append(", deltaTable=");
-                if (tier.deltaTable == null) {
-                    bld.append("null");
-                } else {
-                    bld.append(tier.deltaTable.baseToDebugString());
-                }
-                bld.append("}");
-            }
-            bld.append(String.format("%n"));
-        }
-        bld.append(String.format("]}%n"));
-        return bld.toString();
-    }
-

Review Comment:
   This wasn't used at all



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