Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[HUDI-8484] Instant heartbeats memory leak #12212

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -184,13 +184,14 @@ public void start(String instantTime) {
* @param instantTime The instant time for the heartbeat.
* @throws HoodieException
*/
public void stop(String instantTime) throws HoodieException {
Heartbeat heartbeat = instantToHeartbeatMap.get(instantTime);
public Heartbeat stop(String instantTime) throws HoodieException {
Heartbeat heartbeat = instantToHeartbeatMap.remove(instantTime);
if (isHeartbeatStarted(heartbeat)) {
stopHeartbeatTimer(heartbeat);
HeartbeatUtils.deleteHeartbeatFile(storage, basePath, instantTime);
LOG.info("Deleted heartbeat file for instant " + instantTime);
}
return heartbeat;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@

import static java.util.concurrent.TimeUnit.SECONDS;
import static org.awaitility.Awaitility.await;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;

public class TestHoodieHeartbeatClient extends HoodieCommonTestHarness {
Expand Down Expand Up @@ -64,10 +66,10 @@ public void testStopHeartbeat() {
new HoodieHeartbeatClient(metaClient.getStorage(), metaClient.getBasePath().toString(),
heartBeatInterval, numTolerableMisses);
hoodieHeartbeatClient.start(instantTime1);
hoodieHeartbeatClient.stop(instantTime1);
await().atMost(5, SECONDS).until(() -> hoodieHeartbeatClient.getHeartbeat(instantTime1).getNumHeartbeats() > 0);
Integer numHeartBeats = hoodieHeartbeatClient.getHeartbeat(instantTime1).getNumHeartbeats();
assertTrue(numHeartBeats == 1);
HoodieHeartbeatClient.Heartbeat heartbeat = hoodieHeartbeatClient.stop(instantTime1);
await().atMost(5, SECONDS).until(() -> heartbeat.getNumHeartbeats() > 0);
assertEquals(1, (int) heartbeat.getNumHeartbeats());
assertNull(hoodieHeartbeatClient.getHeartbeat(instantTime1), "Heartbeat should be removed from client cache after explicit stop");
}

@Test
Expand All @@ -77,7 +79,7 @@ public void testIsHeartbeatExpired() throws IOException {
heartBeatInterval, numTolerableMisses);
hoodieHeartbeatClient.start(instantTime1);
hoodieHeartbeatClient.stop(instantTime1);
assertFalse(hoodieHeartbeatClient.isHeartbeatExpired(instantTime1));
assertTrue(hoodieHeartbeatClient.isHeartbeatExpired(instantTime1), "The explicit stopped instant is deemed expiry for heartbeats");
}

@Test
Expand All @@ -91,7 +93,7 @@ public void testNumHeartbeatsGenerated() {
}

@Test
public void testDeleteWrongHeartbeat() throws IOException {
public void testDeleteWrongHeartbeat() {
HoodieHeartbeatClient hoodieHeartbeatClient =
new HoodieHeartbeatClient(metaClient.getStorage(), metaClient.getBasePath().toString(),
heartBeatInterval, numTolerableMisses);
Expand Down
Loading