[ 
https://issues.apache.org/jira/browse/FLINK-9808?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16658676#comment-16658676
 ] 

ASF GitHub Bot commented on FLINK-9808:
---------------------------------------

tzulitai 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_r226912089
 
 

 ##########
 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<>(
+                       stateDesc.getType(),
+                       stateDesc.getName(),
+                       namespaceSerializer,
+                       stateSerializer,
+                       snapshotTransformer);
+
+               CompatibilityResult<N> namespaceCompatibility = 
CompatibilityUtil.resolveCompatibilityResult(
 
 Review comment:
   Yes, this indeed is not nice. We actually have a newer replacement class 
called `TypeSerializerSchemaCompatibility`, but at the moment the use of 
`CompatibilityResult` can't be completely avoided yet.
   
   I have been discussing with @dawidwys that we maybe should just remove 
`CompatibilityResult` completely in favor of the newer replacement, but this 
might come up as a separate commit / PR.

----------------------------------------------------------------
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:
us...@infra.apache.org


> Implement state conversion procedure in state backends
> ------------------------------------------------------
>
>                 Key: FLINK-9808
>                 URL: https://issues.apache.org/jira/browse/FLINK-9808
>             Project: Flink
>          Issue Type: Sub-task
>          Components: State Backends, Checkpointing
>            Reporter: Tzu-Li (Gordon) Tai
>            Assignee: Aljoscha Krettek
>            Priority: Critical
>              Labels: pull-request-available
>             Fix For: 1.7.0
>
>
> With FLINK-9377 in place and that config snapshots serve as the single source 
> of truth for recreating restore serializers, the next step would be to 
> utilize this when performing a full-pass state conversion (i.e., read with 
> old / restore serializer, write with new serializer).
> For Flink's heap-based backends, it can be seen that state conversion 
> inherently happens, since all state is always deserialized after restore with 
> the restore serializer, and written with the new serializer on snapshots.
> For the RocksDB state backend, since state is lazily deserialized, state 
> conversion needs to happen for per-registered state on their first access if 
> the registered new serializer has a different serialization schema than the 
> previous serializer.
> This task should consist of three parts:
> 1. Allow {{CompatibilityResult}} to correctly distinguish between whether the 
> new serializer's schema is a) compatible with the serializer as it is, b) 
> compatible after the serializer has been reconfigured, or c) incompatible.
> 2. Introduce state conversion procedures in the RocksDB state backend. This 
> should occur on the first state access.
> 3. Make sure that all other backends no longer do redundant serializer 
> compatibility checks. That is not required because those backends always 
> perform full-pass state conversions.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to