StefanRRichter commented on a change in pull request #6875: [FLINK-9808] [state
backends] Migrate state when necessary in state backends
URL: https://github.com/apache/flink/pull/6875#discussion_r226669120
##########
File path:
flink-state-backends/flink-statebackend-rocksdb/src/main/java/org/apache/flink/contrib/streaming/state/RocksDBKeyedStateBackend.java
##########
@@ -1389,6 +1388,149 @@ private void copyStateDataHandleData(
return Tuple2.of(stateInfo.f0, newMetaInfo);
}
+ private <N, S extends State, SV>
RegisteredKeyValueStateBackendMetaInfo<N, SV> migrateStateIfNecessary(
+ StateDescriptor<S, SV> stateDesc,
+ TypeSerializer<N> namespaceSerializer,
+ Tuple2<ColumnFamilyHandle, RegisteredStateMetaInfoBase>
stateInfo,
+ @Nullable StateSnapshotTransformer<SV>
snapshotTransformer) throws Exception {
+
+ StateMetaInfoSnapshot restoredMetaInfoSnapshot =
restoredKvStateMetaInfos.get(stateDesc.getName());
+
+ Preconditions.checkState(
+ restoredMetaInfoSnapshot != null,
+ "Requested to check compatibility of a restored
RegisteredKeyedBackendStateMetaInfo," +
+ " but its corresponding restored snapshot
cannot be found.");
+
+
Preconditions.checkState(restoredMetaInfoSnapshot.getBackendStateType()
+ ==
StateMetaInfoSnapshot.BackendStateType.KEY_VALUE,
+ "Incompatible state types. " +
+ "Was [" +
restoredMetaInfoSnapshot.getBackendStateType() + "], " +
+ "registered as [" +
StateMetaInfoSnapshot.BackendStateType.KEY_VALUE + "].");
+
+ Preconditions.checkState(
+ Objects.equals(stateDesc.getName(),
restoredMetaInfoSnapshot.getName()),
+ "Incompatible state names. " +
+ "Was [" + restoredMetaInfoSnapshot.getName() +
"], " +
+ "registered with [" + stateDesc.getName() +
"].");
+
+ final StateDescriptor.Type restoredType =
+ StateDescriptor.Type.valueOf(
+ restoredMetaInfoSnapshot.getOption(
+
StateMetaInfoSnapshot.CommonOptionsKeys.KEYED_STATE_TYPE));
+
+ if (!Objects.equals(stateDesc.getType(),
StateDescriptor.Type.UNKNOWN)
+ && !Objects.equals(restoredType,
StateDescriptor.Type.UNKNOWN)) {
+
+ Preconditions.checkState(
+ stateDesc.getType() == restoredType,
+ "Incompatible key/value state types. " +
+ "Was [" + restoredType + "], " +
+ "registered with [" +
stateDesc.getType() + "].");
+ }
+
+ TypeSerializer<SV> stateSerializer = stateDesc.getSerializer();
+
+ RegisteredKeyValueStateBackendMetaInfo<N, SV> newMetaInfo = new
RegisteredKeyValueStateBackendMetaInfo<>(
Review comment:
It seems that now both branches in the calling method
`tryRegisterKvStateInformation` create a `newMetaInfo`. Why not always create
it there and pass it as only argument to this function which can then transform
it if needed? Could deduplicate and simplify some code.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services