T
- the type of the state.@Internal public abstract class StateSerializerProvider<T> extends Object
StateSerializerProvider
wraps logic on how to obtain serializers for registered state,
either with the previous schema of state in checkpoints or the current schema of state.Modifier and Type | Method and Description |
---|---|
abstract TypeSerializer<T> |
currentSchemaSerializer()
Gets the serializer that recognizes the current serialization schema of the state.
|
static <T> StateSerializerProvider<T> |
fromNewState(TypeSerializer<T> registeredStateSerializer)
Creates a
StateSerializerProvider for new state from the registered state serializer. |
static <T> StateSerializerProvider<T> |
fromRestoredState(TypeSerializerSnapshot<T> stateSerializerSnapshot)
Creates a
StateSerializerProvider for restored state from the previous serializer's snapshot. |
abstract TypeSerializer<T> |
previousSchemaSerializer()
Gets the serializer that recognizes the previous serialization schema of the state.
|
abstract TypeSerializerSchemaCompatibility<T> |
registerNewSerializerForRestoredState(TypeSerializer<T> newSerializer)
For restored state, register a new serializer that potentially has a new serialization schema.
|
public static <T> StateSerializerProvider<T> fromRestoredState(TypeSerializerSnapshot<T> stateSerializerSnapshot)
StateSerializerProvider
for restored state from the previous serializer's snapshot.
Once a new serializer is registered for the state, it should be provided via
the registerNewSerializerForRestoredState(TypeSerializer)
method.
T
- the type of the state.stateSerializerSnapshot
- the previous serializer's snapshot.StateSerializerProvider
for restored state.public static <T> StateSerializerProvider<T> fromNewState(TypeSerializer<T> registeredStateSerializer)
StateSerializerProvider
for new state from the registered state serializer.T
- the type of the state.registeredStateSerializer
- the new state's registered serializer.StateSerializerProvider
for new state.@Nonnull public abstract TypeSerializer<T> currentSchemaSerializer()
If this provider was created from a restored state's serializer snapshot, while a
new serializer (with a new schema) was not registered for the state (i.e., because
the state was never accessed after it was restored), then the schema of state remains
identical. Therefore, in this case, it is guaranteed that the serializer returned by
this method is the same as the one returned by previousSchemaSerializer()
.
If this provider was created from new state, then this always returns the serializer that the new state was registered with.
@Nonnull public abstract TypeSerializer<T> previousSchemaSerializer()
This method can only be used if this provider was created from a restored state's serializer snapshot. If this provider was created from new state, then this method is irrelevant, since there doesn't exist any previous version of the state schema.
@Nonnull public abstract TypeSerializerSchemaCompatibility<T> registerNewSerializerForRestoredState(TypeSerializer<T> newSerializer)
Users are allowed to register serializers for state only once. Therefore, this method is irrelevant if this provider was created from new state, since a state serializer had been registered already.
For the case where this provider was created from restored state, then this method should be called at most once. The new serializer will be checked for its schema compatibility with the previous serializer's schema, and returned to the caller. The caller is responsible for checking the result and react appropriately to it, as follows:
TypeSerializerSchemaCompatibility.isCompatibleAsIs()
: nothing needs to be done.
currentSchemaSerializer()
now returns the newly registered serializer.TypeSerializerSchemaCompatibility.isCompatibleAfterMigration()
()}: state needs to be
migrated before the serializer returned by currentSchemaSerializer()
can be used.
The migration should be performed by reading the state with previousSchemaSerializer()
,
and then writing it again with currentSchemaSerializer()
.TypeSerializerSchemaCompatibility.isIncompatible()
: the registered serializer is
incompatible. currentSchemaSerializer()
can no longer return a serializer for
the state, and therefore this provider shouldn't be used anymore.Copyright © 2014–2020 The Apache Software Foundation. All rights reserved.