rkhachatryan commented on code in PR #19448:
URL: https://github.com/apache/flink/pull/19448#discussion_r901886009
##########
flink-runtime/src/main/java/org/apache/flink/runtime/checkpoint/CheckpointsCleaner.java:
##########
@@ -65,6 +77,50 @@ public void cleanCheckpoint(
cleanup(checkpoint, discardObject::discard, postCleanAction, executor);
}
+ /**
+ * Add one subsumed checkpoint to CheckpointsCleaner, the subsumed
checkpoint would be discarded
+ * at {@link #cleanSubsumedCheckpoints(long, Set, Runnable, Executor)}.
+ *
+ * @param completedCheckpoint which is subsumed.
+ */
+ public void addSubsumedCheckpoint(CompletedCheckpoint completedCheckpoint)
{
+ synchronized (lock) {
+ subsumedCheckpoints.add(completedCheckpoint);
+ }
+ }
+
+ /**
+ * Clean checkpoint that is not in the given {@param stillInUse}.
+ *
+ * @param upTo lowest CheckpointID which is still valid.
+ * @param stillInUse that the state of it is still being referenced.
+ * @param postCleanAction
+ * @param executor
Review Comment:
Remove `@param' or describe them?
##########
flink-runtime/src/test/java/org/apache/flink/runtime/checkpoint/CheckpointsCleanerTest.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.flink.runtime.checkpoint;
+
+import
org.apache.flink.runtime.checkpoint.CompletedCheckpointStoreTest.TestCompletedCheckpoint;
+import org.apache.flink.runtime.state.SharedStateRegistry;
+import org.apache.flink.runtime.state.SharedStateRegistryImpl;
+import org.apache.flink.runtime.state.SharedStateRegistryKey;
+import org.apache.flink.runtime.state.TestingStreamStateHandle;
+import org.apache.flink.util.concurrent.Executors;
+
+import org.junit.Test;
+
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
+
+import static
org.apache.flink.runtime.checkpoint.CompletedCheckpointStoreTest.createCheckpoint;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+/** {@link CheckpointsCleaner} test. */
+public class CheckpointsCleanerTest {
+
+ @Test
+ public void testCleanSubsumedCheckpointNormal() {
+ SharedStateRegistry sharedStateRegistry = new
SharedStateRegistryImpl();
+ CheckpointsCleaner checkpointsCleaner = new CheckpointsCleaner();
+ TestCompletedCheckpoint cp1 = createCheckpoint(1, sharedStateRegistry);
+ sharedStateRegistry.registerReference(
+ new SharedStateRegistryKey("test_cp_in_use"), new
TestingStreamStateHandle(), 1L);
+ checkpointsCleaner.addSubsumedCheckpoint(cp1);
+ TestCompletedCheckpoint cp2 = createCheckpoint(2, sharedStateRegistry);
+ sharedStateRegistry.registerReference(
+ new SharedStateRegistryKey("test_cp_in_use"), new
TestingStreamStateHandle(), 2L);
+ checkpointsCleaner.addSubsumedCheckpoint(cp2);
+ Set<Long> stillInUse = sharedStateRegistry.unregisterUnusedState(2);
+ Set<Long> expectedInUse = new HashSet<>();
+ expectedInUse.add(1L);
+ assertEquals(expectedInUse, stillInUse);
+ checkpointsCleaner.cleanSubsumedCheckpoints(
+ 3, stillInUse, () -> {}, Executors.directExecutor());
+ assertFalse(cp1.isDiscarded());
+ assertTrue(cp2.isDiscarded());
+ TestCompletedCheckpoint cp3 = createCheckpoint(3, sharedStateRegistry);
+ TestCompletedCheckpoint cp4 = createCheckpoint(4, sharedStateRegistry);
+ checkpointsCleaner.addSubsumedCheckpoint(cp3);
+ checkpointsCleaner.addSubsumedCheckpoint(cp4);
+ checkpointsCleaner.cleanSubsumedCheckpoints(
+ 4, Collections.EMPTY_SET, () -> {},
Executors.directExecutor());
Review Comment:
nit: `Collections.emptySet()`
##########
flink-runtime/src/test/java/org/apache/flink/runtime/checkpoint/CheckpointsCleanerTest.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.flink.runtime.checkpoint;
+
+import
org.apache.flink.runtime.checkpoint.CompletedCheckpointStoreTest.TestCompletedCheckpoint;
+import org.apache.flink.runtime.state.SharedStateRegistry;
+import org.apache.flink.runtime.state.SharedStateRegistryImpl;
+import org.apache.flink.runtime.state.SharedStateRegistryKey;
+import org.apache.flink.runtime.state.TestingStreamStateHandle;
+import org.apache.flink.util.concurrent.Executors;
+
+import org.junit.Test;
+
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
+
+import static
org.apache.flink.runtime.checkpoint.CompletedCheckpointStoreTest.createCheckpoint;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+/** {@link CheckpointsCleaner} test. */
+public class CheckpointsCleanerTest {
+
+ @Test
+ public void testCleanSubsumedCheckpointNormal() {
Review Comment:
I'd split this test into several smaller tests:
1. The set returned from `sharedStateRegistry.unregisterUnusedState` - this
should be in `SharedStateRegistryTest`
2. Not discarding checkpoints higher than `upTo` (and discarding lower than
or equal to)
3. Not discarding checkpoints still in use (and discarding not in use)
##########
flink-runtime/src/main/java/org/apache/flink/runtime/checkpoint/CheckpointsCleaner.java:
##########
@@ -43,13 +49,19 @@ public class CheckpointsCleaner implements Serializable,
AutoCloseableAsync {
private static final Logger LOG =
LoggerFactory.getLogger(CheckpointsCleaner.class);
private static final long serialVersionUID = 2545865801947537790L;
- @GuardedBy("this")
+ private final Object lock = new Object();
Review Comment:
There are now sections synchronized on this field and on `this`.
Should it be a single object (either `this` or `lock`)?
##########
flink-runtime/src/test/java/org/apache/flink/runtime/checkpoint/CheckpointsCleanerTest.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.flink.runtime.checkpoint;
+
+import
org.apache.flink.runtime.checkpoint.CompletedCheckpointStoreTest.TestCompletedCheckpoint;
+import org.apache.flink.runtime.state.SharedStateRegistry;
+import org.apache.flink.runtime.state.SharedStateRegistryImpl;
+import org.apache.flink.runtime.state.SharedStateRegistryKey;
+import org.apache.flink.runtime.state.TestingStreamStateHandle;
+import org.apache.flink.util.concurrent.Executors;
+
+import org.junit.Test;
+
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
+
+import static
org.apache.flink.runtime.checkpoint.CompletedCheckpointStoreTest.createCheckpoint;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+/** {@link CheckpointsCleaner} test. */
+public class CheckpointsCleanerTest {
+
+ @Test
+ public void testCleanSubsumedCheckpointNormal() {
+ SharedStateRegistry sharedStateRegistry = new
SharedStateRegistryImpl();
+ CheckpointsCleaner checkpointsCleaner = new CheckpointsCleaner();
+ TestCompletedCheckpoint cp1 = createCheckpoint(1, sharedStateRegistry);
+ sharedStateRegistry.registerReference(
+ new SharedStateRegistryKey("test_cp_in_use"), new
TestingStreamStateHandle(), 1L);
+ checkpointsCleaner.addSubsumedCheckpoint(cp1);
+ TestCompletedCheckpoint cp2 = createCheckpoint(2, sharedStateRegistry);
+ sharedStateRegistry.registerReference(
+ new SharedStateRegistryKey("test_cp_in_use"), new
TestingStreamStateHandle(), 2L);
+ checkpointsCleaner.addSubsumedCheckpoint(cp2);
+ Set<Long> stillInUse = sharedStateRegistry.unregisterUnusedState(2);
+ Set<Long> expectedInUse = new HashSet<>();
+ expectedInUse.add(1L);
Review Comment:
nit: `Collections.singleton(1L)`
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]