Class ProtobufGeneratedSerializerSnapshot<T extends com.google.protobuf.Message>

java.lang.Object
io.github.flink.gcp.protobuf.ProtobufGeneratedSerializerSnapshot<T>
Type Parameters:
T - concrete generated message type
All Implemented Interfaces:
org.apache.flink.api.common.typeutils.TypeSerializerSnapshot<T>

@Internal public final class ProtobufGeneratedSerializerSnapshot<T extends com.google.protobuf.Message> extends Object implements org.apache.flink.api.common.typeutils.TypeSerializerSnapshot<T>
Version-1 metadata for restoring generated Protobuf value serializers.

The persisted class name and payload layout are state-format identities. Reading metadata does not load a generated class. Restoration uses Flink's supplied user-code classloader. Both compatibility resolution and restoration delegate to the directional schema evaluator, which accepts unchanged descriptors and the supported schema changes and permits only nondecreasing reader limits; deterministic writing and large-payload aliasing may change in either direction.

  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates an empty snapshot for Flink's versioned metadata reader.
  • Method Summary

    Modifier and Type
    Method
    Description
    int
     
    void
    readSnapshot(int readVersion, org.apache.flink.core.memory.DataInputView in, ClassLoader userCodeClassLoader)
    Validates metadata without loading the saved generated class.
    org.apache.flink.api.common.typeutils.TypeSerializerSchemaCompatibility<T>
    resolveSchemaCompatibility(org.apache.flink.api.common.typeutils.TypeSerializerSnapshot<T> oldSerializerSnapshot)
    Checks whether this new configuration can read values permitted by an old configuration.
    org.apache.flink.api.common.typeutils.TypeSerializer<T>
    Resolves the generated class using the loader retained by this snapshot and checks that it can read the saved schema.
    void
    writeSnapshot(org.apache.flink.core.memory.DataOutputView out)
    Writes the fixed version-1 payload with deterministic descriptor bytes and their SHA-256.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • ProtobufGeneratedSerializerSnapshot

      public ProtobufGeneratedSerializerSnapshot()
      Creates an empty snapshot for Flink's versioned metadata reader.
  • Method Details

    • getCurrentVersion

      public int getCurrentVersion()
      Specified by:
      getCurrentVersion in interface org.apache.flink.api.common.typeutils.TypeSerializerSnapshot<T extends com.google.protobuf.Message>
      Returns:
      the version of the payload following Flink's class/version envelope
    • writeSnapshot

      public void writeSnapshot(org.apache.flink.core.memory.DataOutputView out) throws IOException
      Writes the fixed version-1 payload with deterministic descriptor bytes and their SHA-256.
      Specified by:
      writeSnapshot in interface org.apache.flink.api.common.typeutils.TypeSerializerSnapshot<T extends com.google.protobuf.Message>
      Parameters:
      out - destination immediately after Flink's snapshot version
      Throws:
      IOException - if metadata is uninitialized, exceeds format limits, or cannot be written
    • readSnapshot

      public void readSnapshot(int readVersion, org.apache.flink.core.memory.DataInputView in, ClassLoader userCodeClassLoader) throws IOException
      Validates metadata without loading the saved generated class.
      Specified by:
      readSnapshot in interface org.apache.flink.api.common.typeutils.TypeSerializerSnapshot<T extends com.google.protobuf.Message>
      Parameters:
      readVersion - version read from Flink's envelope
      in - source positioned at the snapshot payload
      userCodeClassLoader - loader to use later for serializer restoration
      Throws:
      IOException - for unsupported versions, malformed metadata, corruption, or truncation
    • restoreSerializer

      public org.apache.flink.api.common.typeutils.TypeSerializer<T> restoreSerializer()
      Resolves the generated class using the loader retained by this snapshot and checks that it can read the saved schema.

      The class may declare a supported evolution of the saved schema; it need not be the class that wrote the state.

      Specified by:
      restoreSerializer in interface org.apache.flink.api.common.typeutils.TypeSerializerSnapshot<T extends com.google.protobuf.Message>
      Returns:
      a reader of the resolved class with this snapshot's recorded settings
      Throws:
      IllegalStateException - if metadata is uninitialized or the class is missing, unsupported, or cannot read the saved schema; the message names the first incompatibility
    • resolveSchemaCompatibility

      public org.apache.flink.api.common.typeutils.TypeSerializerSchemaCompatibility<T> resolveSchemaCompatibility(org.apache.flink.api.common.typeutils.TypeSerializerSnapshot<T> oldSerializerSnapshot)
      Checks whether this new configuration can read values permitted by an old configuration.
      Specified by:
      resolveSchemaCompatibility in interface org.apache.flink.api.common.typeutils.TypeSerializerSnapshot<T extends com.google.protobuf.Message>
      Parameters:
      oldSerializerSnapshot - saved metadata, without requiring its generated class
      Returns:
      compatible as is when the schema evaluator accepts the saved schema and settings, otherwise incompatible
      Throws:
      IllegalStateException - if either Protobuf snapshot is uninitialized