Github user aljoscha commented on a diff in the pull request:
https://github.com/apache/flink/pull/4413#discussion_r130075052
--- Diff:
flink-runtime/src/test/java/org/apache/flink/runtime/state/IncrementalKeyedStateHandleTest.java
---
@@ -186,6 +187,77 @@ public void testSharedStateDeRegistration() throws
Exception {
verify(stateHandle2.getMetaStateHandle(),
times(1)).discardState();
}
+ /**
+ * This tests that re-registration of shared state with another
registry works as expected. This simulates a
+ * recovery from a checkpoint, when the checkpoint coordinator creates
a new shared state registry and re-registers
+ * all live checkpoint states.
+ */
+ @Test
+ public void testSharedStateReRegistration() throws Exception {
+
+ SharedStateRegistry stateRegistryA = spy(new
SharedStateRegistry());
+
+ // Create two state handles with overlapping shared state
+ IncrementalKeyedStateHandle stateHandleX = create(new
Random(1));
+ IncrementalKeyedStateHandle stateHandleY = create(new
Random(2));
+ IncrementalKeyedStateHandle stateHandleZ = create(new
Random(3));
+
+ // Now we register first time ...
+ stateHandleX.registerSharedStates(stateRegistryA);
+ stateHandleY.registerSharedStates(stateRegistryA);
+ stateHandleZ.registerSharedStates(stateRegistryA);
+
+ try {
+ // Second attempt should fail
+ stateHandleX.registerSharedStates(stateRegistryA);
+ fail("Should not be able to register twice with the
same registry.");
+ } catch (IllegalStateException ignore) {
+ }
+
+ // Everything should be discarded for this handle
+ stateHandleZ.discardState();
+ verify(stateHandleZ.getMetaStateHandle(),
times(1)).discardState();
+ for (StreamStateHandle stateHandle :
stateHandleZ.getSharedState().values()) {
+ verify(stateHandle, times(1)).discardState();
+ }
+
+ // Close the first registry
+ stateRegistryA.close();
+
+ // Attempt to register to closed registry should trigger
exception
+ try {
+ create(new
Random(4)).registerSharedStates(stateRegistryA);
+ fail("Should not be able to register new state to
closed registry.");
+ } catch (IllegalStateException ignore) {
+ }
+
+ // All state should still get dicarded
--- End diff --
Nit: discarded
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---