Skip to content
Merged
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 @@ -138,6 +138,13 @@ public TypeSerializerSchemaCompatibility<S> updateStateSerializer(
return stateSerializerProvider.registerNewSerializerForRestoredState(newStateSerializer);
}

@Nonnull
public TypeSerializerSchemaCompatibility<N> updateNamespaceSerializer(
TypeSerializer<N> newNamespaceSerializer) {
return namespaceSerializerProvider.registerNewSerializerForRestoredState(
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: is the New in the method name required?
registerNewSerializerForRestoredState -> registerSerializerForRestoredState

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well this is the name of existing interface, we'd better keep this in current PR.

newNamespaceSerializer);
}

@Override
public boolean equals(Object o) {
if (this == o) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,22 @@ private <N, UK, SV> RegisteredKeyValueStateBackendMetaInfo<N, SV> updateRestored

RegisteredKeyValueStateBackendMetaInfo<N, SV> restoredKvStateMetaInfo = oldStateInfo.f1;

// fetch current namespace serializer now because if it is incompatible, we can't access
// it anymore to improve the error message
TypeSerializer<N> previousNamespaceSerializer =
restoredKvStateMetaInfo.getNamespaceSerializer();

TypeSerializerSchemaCompatibility<N> s =
restoredKvStateMetaInfo.updateNamespaceSerializer(namespaceSerializer);
if (s.isCompatibleAfterMigration() || s.isIncompatible()) {
Copy link
Copy Markdown
Contributor

@davidradl davidradl Apr 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am curious about the difference between isCompatibleAfterMigration() and isIncompatible(). If the difference is meaningful, should we include these different incompatibilities in the error message to help make the message more useful?

It would even better if the compatibility checks returned the reason for the incompatibility. Maybe throwing an exception in a checkIncompatibility method and construct different messages in the Exception might be better as we then log out the root cause of the incompatibility. WDYT?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mayuehappy We could distinguish the messages for two cases. For the isCompatibleAfterMigration, we may say 'The new namespace serializer () can be compatible with the old one () after migration. But ForSt does not support state migration yet.'

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Zakelly Thanks for the reply. As I remember, NamespaceSerializer should not support migration, even RocksdbStateBackend does. So do we still need to distinguish here?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mayuehappy we can keep it if so.

throw new StateMigrationException(
"The new namespace serializer ("
+ namespaceSerializer
+ ") must be compatible with the old namespace serializer ("
+ previousNamespaceSerializer
+ ").");
}

restoredKvStateMetaInfo.checkStateMetaInfo(stateDesc);

// fetch current serializer now because if it is incompatible, we can't access it anymore to
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -265,4 +265,56 @@ void testKryoRestoreResilienceWithDifferentRegistrationOrder(@TempDir File newTm
}
snapshot1.get().discardState();
}

@Test
void testStateNamespaceSerializerChanged() throws Exception {
MapStateDescriptor<Integer, String> descriptor =
new MapStateDescriptor<>(
"testState", IntSerializer.INSTANCE, StringSerializer.INSTANCE);

// set the old namespace serializer to IntSerializer.INSTANCE
MapState<Integer, String> mapState =
keyedBackend.createState(1, IntSerializer.INSTANCE, descriptor);

RunnableFuture<SnapshotResult<KeyedStateHandle>> snapshot =
keyedBackend.snapshot(
1L,
System.currentTimeMillis(),
env.getCheckpointStorageAccess()
.resolveCheckpointStorageLocation(
1L, CheckpointStorageLocationReference.getDefault()),
CheckpointOptions.forCheckpointWithDefaultLocation());

if (!snapshot.isDone()) {
snapshot.run();
}
SnapshotResult<KeyedStateHandle> snapshotResult = snapshot.get();
KeyedStateHandle stateHandle = snapshotResult.getJobManagerOwnedSnapshot();
IOUtils.closeQuietly(keyedBackend);
keyedBackend.dispose();

FileSystem.initialize(new Configuration(), null);
Configuration configuration = new Configuration();
ForStStateBackend forStStateBackend =
new ForStStateBackend().configure(configuration, null);
keyedBackend =
createKeyedStateBackend(
forStStateBackend,
env,
StringSerializer.INSTANCE,
Collections.singletonList(stateHandle));
keyedBackend.setup(aec);
try {

// change new NSSerializer to StringSerializer
keyedBackend.createState("String", StringSerializer.INSTANCE, descriptor);
fail("Expected a state migration exception.");
} catch (Exception e) {
if (CommonTestUtils.containsCause(e, StateMigrationException.class)) {
// StateMigrationException expected
} else {
throw e;
}
}
}
}