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

[PR] KAFKA-17003: Implemented SharePartitionManager close() functionality [kafka]

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

   ### About
   Implemented close() functionality of SharePartitionManager to avoid any chances of memory leak. The functionality will be utilized when the `sharePartitionObject` is closed, at the time when `BrokerServer` is killed.
   
   ### Testing
   Added unit tests to cover the new functionality added.


-- 
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-17003: Implemented SharePartitionManager close() functionality [kafka]

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


##########
core/src/test/java/kafka/server/share/SharePartitionManagerTest.java:
##########
@@ -1221,6 +1224,36 @@ public void testReplicaManagerFetchShouldProceed() {
             any(), any(), any(ReplicaQuota.class), any());
     }
 
+    @Test
+    public void testCloseSharePartitionManager() throws Exception {
+        SharePartitionManager sharePartitionManager = SharePartitionManagerBuilder.builder()
+                .withShareGroupPersister(mock(Persister.class)).build();
+
+        List<Integer> mockList = new ArrayList<>();
+        sharePartitionManager.timer().add(createTimerTask(mockList));
+        // Allowing first timer task to expire. The timer task will add an element to mockList.
+        TestUtils.waitForCondition(
+                () -> mockList.size() == 1,
+                DEFAULT_MAX_WAIT_TIMER_TASK_TIMEOUT_MS,
+                () -> "Timer task never got timed out.");
+
+        sharePartitionManager.timer().add(createTimerTask(mockList));
+        // Closing the sharePartitionManager closes timer object in sharePartitionManager.
+        sharePartitionManager.close();
+        // Allowing second timer task to expire. It won't be able to add an element to mockList.
+        Thread.sleep(DEFAULT_MAX_WAIT_TIMER_TASK_TIMEOUT_MS);

Review Comment:
   For that, we need to have a function in SharePartitionManager to set the timer object to this mockTimer object. We can mark it as `// Only for testing.` Do we want to take that route?



-- 
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-17003: Implemented SharePartitionManager close() functionality [kafka]

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


##########
core/src/test/java/kafka/server/share/SharePartitionManagerTest.java:
##########
@@ -1221,6 +1224,36 @@ public void testReplicaManagerFetchShouldProceed() {
             any(), any(), any(ReplicaQuota.class), any());
     }
 
+    @Test
+    public void testCloseSharePartitionManager() throws Exception {
+        SharePartitionManager sharePartitionManager = SharePartitionManagerBuilder.builder()
+                .withShareGroupPersister(mock(Persister.class)).build();
+
+        List<Integer> mockList = new ArrayList<>();
+        sharePartitionManager.timer().add(createTimerTask(mockList));
+        // Allowing first timer task to expire. The timer task will add an element to mockList.
+        TestUtils.waitForCondition(
+                () -> mockList.size() == 1,
+                DEFAULT_MAX_WAIT_TIMER_TASK_TIMEOUT_MS,
+                () -> "Timer task never got timed out.");
+
+        sharePartitionManager.timer().add(createTimerTask(mockList));
+        // Closing the sharePartitionManager closes timer object in sharePartitionManager.
+        sharePartitionManager.close();
+        // Allowing second timer task to expire. It won't be able to add an element to mockList.
+        Thread.sleep(DEFAULT_MAX_WAIT_TIMER_TASK_TIMEOUT_MS);
+        assertEquals(1, mockList.size());
+    }
+
+    private TimerTask createTimerTask(List<Integer> mockList) {
+        return new TimerTask(100) {
+            @Override

Review Comment:
   since, this functionality is required at 2 places, I thought to create it as a different function `createTimerTask`



-- 
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-17003: Implemented SharePartitionManager close() functionality [kafka]

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


##########
core/src/test/java/kafka/server/share/SharePartitionManagerTest.java:
##########
@@ -1221,6 +1224,36 @@ public void testReplicaManagerFetchShouldProceed() {
             any(), any(), any(ReplicaQuota.class), any());
     }
 
+    @Test
+    public void testCloseSharePartitionManager() throws Exception {
+        SharePartitionManager sharePartitionManager = SharePartitionManagerBuilder.builder()
+                .withShareGroupPersister(mock(Persister.class)).build();
+
+        List<Integer> mockList = new ArrayList<>();
+        sharePartitionManager.timer().add(createTimerTask(mockList));
+        // Allowing first timer task to expire. The timer task will add an element to mockList.
+        TestUtils.waitForCondition(
+                () -> mockList.size() == 1,
+                DEFAULT_MAX_WAIT_TIMER_TASK_TIMEOUT_MS,
+                () -> "Timer task never got timed out.");
+
+        sharePartitionManager.timer().add(createTimerTask(mockList));
+        // Closing the sharePartitionManager closes timer object in sharePartitionManager.
+        sharePartitionManager.close();
+        // Allowing second timer task to expire. It won't be able to add an element to mockList.
+        Thread.sleep(DEFAULT_MAX_WAIT_TIMER_TASK_TIMEOUT_MS);

Review Comment:
   I don't think it's a good idea to sleep. Can't we use mocktimer?



##########
core/src/test/java/kafka/server/share/SharePartitionManagerTest.java:
##########
@@ -1221,6 +1224,36 @@ public void testReplicaManagerFetchShouldProceed() {
             any(), any(), any(ReplicaQuota.class), any());
     }
 
+    @Test
+    public void testCloseSharePartitionManager() throws Exception {
+        SharePartitionManager sharePartitionManager = SharePartitionManagerBuilder.builder()
+                .withShareGroupPersister(mock(Persister.class)).build();
+
+        List<Integer> mockList = new ArrayList<>();
+        sharePartitionManager.timer().add(createTimerTask(mockList));
+        // Allowing first timer task to expire. The timer task will add an element to mockList.
+        TestUtils.waitForCondition(
+                () -> mockList.size() == 1,
+                DEFAULT_MAX_WAIT_TIMER_TASK_TIMEOUT_MS,
+                () -> "Timer task never got timed out.");
+
+        sharePartitionManager.timer().add(createTimerTask(mockList));
+        // Closing the sharePartitionManager closes timer object in sharePartitionManager.
+        sharePartitionManager.close();
+        // Allowing second timer task to expire. It won't be able to add an element to mockList.
+        Thread.sleep(DEFAULT_MAX_WAIT_TIMER_TASK_TIMEOUT_MS);
+        assertEquals(1, mockList.size());
+    }
+
+    private TimerTask createTimerTask(List<Integer> mockList) {
+        return new TimerTask(100) {
+            @Override

Review Comment:
   nit: It can be a lambda method.



##########
core/src/test/java/kafka/server/share/SharePartitionManagerTest.java:
##########
@@ -1221,6 +1224,36 @@ public void testReplicaManagerFetchShouldProceed() {
             any(), any(), any(ReplicaQuota.class), any());
     }
 
+    @Test
+    public void testCloseSharePartitionManager() throws Exception {
+        SharePartitionManager sharePartitionManager = SharePartitionManagerBuilder.builder()
+                .withShareGroupPersister(mock(Persister.class)).build();

Review Comment:
   Why do we require a persister mock when we are not using the mock instance?



-- 
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-17003: Implemented SharePartitionManager close() functionality [kafka]

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


##########
core/src/test/java/kafka/server/share/SharePartitionManagerTest.java:
##########
@@ -1221,6 +1224,36 @@ public void testReplicaManagerFetchShouldProceed() {
             any(), any(), any(ReplicaQuota.class), any());
     }
 
+    @Test
+    public void testCloseSharePartitionManager() throws Exception {
+        SharePartitionManager sharePartitionManager = SharePartitionManagerBuilder.builder()
+                .withShareGroupPersister(mock(Persister.class)).build();
+
+        List<Integer> mockList = new ArrayList<>();
+        sharePartitionManager.timer().add(createTimerTask(mockList));
+        // Allowing first timer task to expire. The timer task will add an element to mockList.
+        TestUtils.waitForCondition(
+                () -> mockList.size() == 1,
+                DEFAULT_MAX_WAIT_TIMER_TASK_TIMEOUT_MS,
+                () -> "Timer task never got timed out.");
+
+        sharePartitionManager.timer().add(createTimerTask(mockList));
+        // Closing the sharePartitionManager closes timer object in sharePartitionManager.
+        sharePartitionManager.close();
+        // Allowing second timer task to expire. It won't be able to add an element to mockList.
+        Thread.sleep(DEFAULT_MAX_WAIT_TIMER_TASK_TIMEOUT_MS);
+        assertEquals(1, mockList.size());
+    }
+
+    private TimerTask createTimerTask(List<Integer> mockList) {
+        return new TimerTask(100) {
+            @Override

Review Comment:
   since, this functionality is required at 2 places, I thought to create it as a different function `createTimerTask`



-- 
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-17003: Implemented SharePartitionManager close() functionality [kafka]

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


##########
core/src/test/java/kafka/server/share/SharePartitionManagerTest.java:
##########
@@ -1221,6 +1224,36 @@ public void testReplicaManagerFetchShouldProceed() {
             any(), any(), any(ReplicaQuota.class), any());
     }
 
+    @Test
+    public void testCloseSharePartitionManager() throws Exception {
+        SharePartitionManager sharePartitionManager = SharePartitionManagerBuilder.builder()
+                .withShareGroupPersister(mock(Persister.class)).build();
+
+        List<Integer> mockList = new ArrayList<>();
+        sharePartitionManager.timer().add(createTimerTask(mockList));
+        // Allowing first timer task to expire. The timer task will add an element to mockList.
+        TestUtils.waitForCondition(
+                () -> mockList.size() == 1,
+                DEFAULT_MAX_WAIT_TIMER_TASK_TIMEOUT_MS,
+                () -> "Timer task never got timed out.");
+
+        sharePartitionManager.timer().add(createTimerTask(mockList));
+        // Closing the sharePartitionManager closes timer object in sharePartitionManager.
+        sharePartitionManager.close();
+        // Allowing second timer task to expire. It won't be able to add an element to mockList.
+        Thread.sleep(DEFAULT_MAX_WAIT_TIMER_TASK_TIMEOUT_MS);

Review Comment:
   For that, we need to have a function in SharePartitionManager to set the timer data member to this mockTimer object. We can mark it as `// Only for testing.` Do we want to take that route?



-- 
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-17003: Implemented SharePartitionManager close() functionality [kafka]

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


##########
core/src/test/java/kafka/server/share/SharePartitionManagerTest.java:
##########
@@ -1221,6 +1224,36 @@ public void testReplicaManagerFetchShouldProceed() {
             any(), any(), any(ReplicaQuota.class), any());
     }
 
+    @Test
+    public void testCloseSharePartitionManager() throws Exception {
+        SharePartitionManager sharePartitionManager = SharePartitionManagerBuilder.builder()
+                .withShareGroupPersister(mock(Persister.class)).build();

Review Comment:
   you're right, we don't need to mock it. I have removed it.



-- 
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-17003: Implemented SharePartitionManager close() functionality [kafka]

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


##########
core/src/test/java/kafka/server/share/SharePartitionManagerTest.java:
##########
@@ -1221,6 +1224,36 @@ public void testReplicaManagerFetchShouldProceed() {
             any(), any(), any(ReplicaQuota.class), any());
     }
 
+    @Test
+    public void testCloseSharePartitionManager() throws Exception {
+        SharePartitionManager sharePartitionManager = SharePartitionManagerBuilder.builder()
+                .withShareGroupPersister(mock(Persister.class)).build();
+
+        List<Integer> mockList = new ArrayList<>();
+        sharePartitionManager.timer().add(createTimerTask(mockList));
+        // Allowing first timer task to expire. The timer task will add an element to mockList.
+        TestUtils.waitForCondition(
+                () -> mockList.size() == 1,
+                DEFAULT_MAX_WAIT_TIMER_TASK_TIMEOUT_MS,
+                () -> "Timer task never got timed out.");
+
+        sharePartitionManager.timer().add(createTimerTask(mockList));
+        // Closing the sharePartitionManager closes timer object in sharePartitionManager.
+        sharePartitionManager.close();
+        // Allowing second timer task to expire. It won't be able to add an element to mockList.
+        Thread.sleep(DEFAULT_MAX_WAIT_TIMER_TASK_TIMEOUT_MS);

Review Comment:
   For that, we need to have a function in SharePartitionManager to set the `timer` data member to this mockTimer object. We can mark it as `// Only for testing.` Do we want to take that route?



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