@Override public void read(DataInputView in) throws IOException { super.read(in); serializationFormatIdentifier = in.readUTF(); }
@Override public void write(DataOutputView out) throws IOException { super.write(out); TypeSerializerSerializationUtil.writeSerializersAndConfigsWithResilience(out, nestedSerializersAndConfigs); }
/** * This cannot be removed until {@link TypeSerializerConfigSnapshot} is no longer supported. */ @Override public CompatibilityResult<Lockable<E>> ensureCompatibility(TypeSerializerConfigSnapshot<?> configSnapshot) { // backwards compatibility path CompatibilityResult<E> inputCompatibilityResult = CompatibilityUtil.resolveCompatibilityResult( configSnapshot.restoreSerializer(), UnloadableDummyTypeSerializer.class, configSnapshot, elementSerializer); return (inputCompatibilityResult.isRequiresMigration()) ? CompatibilityResult.requiresMigration() : CompatibilityResult.compatible(); }
@Override public final void readSnapshot(int readVersion, DataInputView in, ClassLoader userCodeClassLoader) throws IOException { if (readVersion != ADAPTER_VERSION) { throw new IOException("Wrong/unexpected version for the TypeSerializerConfigSnapshot: " + readVersion); } serializer = TypeSerializerSerializationUtil.tryReadSerializer(in, userCodeClassLoader, true); // now delegate to the snapshots own reading code setUserCodeClassLoader(userCodeClassLoader); read(in); }
/** * Deserialization path for Flink versions in [1.4, 1.6]. */ @VisibleForTesting @SuppressWarnings("deprecation") static <T> TypeSerializerSnapshot<T> deserializeV1( DataInputView in, ClassLoader cl, @Nullable TypeSerializer<T> serializer) throws IOException { TypeSerializerSnapshot<T> snapshot = readAndInstantiateSnapshotClass(in, cl); // if the snapshot was created before Flink 1.7, we need to distinguish the following cases: // - old snapshot type that needs serializer from the outside // - new snapshot type that understands the old format and can produce a restore serializer from it if (snapshot instanceof TypeSerializerConfigSnapshot) { TypeSerializerConfigSnapshot<T> oldTypeSnapshot = (TypeSerializerConfigSnapshot<T>) snapshot; oldTypeSnapshot.setPriorSerializer(serializer); oldTypeSnapshot.setUserCodeClassLoader(cl); oldTypeSnapshot.read(in); } else { // new type, simple case int readVersion = in.readInt(); snapshot.readSnapshot(readVersion, in, cl); } return snapshot; }
private void testWriteAndReadConfigSnapshot(Coder<String> coder) throws IOException { CoderTypeSerializer<String> serializer = new CoderTypeSerializer<>(coder); TypeSerializerConfigSnapshot writtenSnapshot = serializer.snapshotConfiguration(); ComparatorTestBase.TestOutputView outView = new ComparatorTestBase.TestOutputView(); writtenSnapshot.write(outView); TypeSerializerConfigSnapshot readSnapshot = new CoderTypeSerializerConfigSnapshot<>(); readSnapshot.read(outView.getInputView()); assertThat(readSnapshot, is(writtenSnapshot)); } }
@Override public CompatibilityResult<T> ensureCompatibility(TypeSerializerConfigSnapshot configSnapshot) { if (snapshotConfiguration().equals(configSnapshot)) { return CompatibilityResult.compatible(); } return CompatibilityResult.requiresMigration(); }
@Override public int hashCode() { int result = name.hashCode(); result = 31 * result + assignmentMode.hashCode(); result = 31 * result + ((keySerializer != null) ? keySerializer.hashCode() : 0); result = 31 * result + ((valueSerializer != null) ? valueSerializer.hashCode() : 0); result = 31 * result + keySerializerConfigSnapshot.hashCode(); result = 31 * result + valueSerializerConfigSnapshot.hashCode(); return result; } }
/** * Utility method to bind the serializer and serializer snapshot to a common * generic type variable. */ @SuppressWarnings({"unchecked", "deprecation"}) private static <T> TypeSerializerSnapshot<T> configureForBackwardsCompatibility( TypeSerializerSnapshot<?> snapshot, TypeSerializer<?> serializer) { TypeSerializerSnapshot<T> typedSnapshot = (TypeSerializerSnapshot<T>) snapshot; TypeSerializer<T> typedSerializer = (TypeSerializer<T>) serializer; if (snapshot instanceof TypeSerializerConfigSnapshot) { ((TypeSerializerConfigSnapshot<T>) typedSnapshot).setPriorSerializer(typedSerializer); } return typedSnapshot; }
private void testWriteAndReadConfigSnapshot(Coder<String> coder) throws IOException { CoderTypeSerializer<String> serializer = new CoderTypeSerializer<>(coder); TypeSerializerConfigSnapshot writtenSnapshot = serializer.snapshotConfiguration(); ComparatorTestBase.TestOutputView outView = new ComparatorTestBase.TestOutputView(); writtenSnapshot.write(outView); TypeSerializerConfigSnapshot readSnapshot = new CoderTypeSerializerConfigSnapshot<>(); readSnapshot.read(outView.getInputView()); assertThat(readSnapshot, is(writtenSnapshot)); } }
@Override public final void readSnapshot(int readVersion, DataInputView in, ClassLoader userCodeClassLoader) throws IOException { if (readVersion != ADAPTER_VERSION) { throw new IOException("Wrong/unexpected version for the TypeSerializerConfigSnapshot: " + readVersion); } serializer = TypeSerializerSerializationUtil.tryReadSerializer(in, userCodeClassLoader, true); // now delegate to the snapshots own reading code setUserCodeClassLoader(userCodeClassLoader); read(in); }
/** * Deserialization path for Flink versions in [1.4, 1.6]. */ @VisibleForTesting @SuppressWarnings("deprecation") static <T> TypeSerializerSnapshot<T> deserializeV1( DataInputView in, ClassLoader cl, @Nullable TypeSerializer<T> serializer) throws IOException { TypeSerializerSnapshot<T> snapshot = readAndInstantiateSnapshotClass(in, cl); // if the snapshot was created before Flink 1.7, we need to distinguish the following cases: // - old snapshot type that needs serializer from the outside // - new snapshot type that understands the old format and can produce a restore serializer from it if (snapshot instanceof TypeSerializerConfigSnapshot) { TypeSerializerConfigSnapshot<T> oldTypeSnapshot = (TypeSerializerConfigSnapshot<T>) snapshot; oldTypeSnapshot.setPriorSerializer(serializer); oldTypeSnapshot.setUserCodeClassLoader(cl); oldTypeSnapshot.read(in); } else { // new type, simple case int readVersion = in.readInt(); snapshot.readSnapshot(readVersion, in, cl); } return snapshot; }
@Override public CompatibilityResult<T> ensureCompatibility(TypeSerializerConfigSnapshot configSnapshot) { if (snapshotConfiguration().equals(configSnapshot)) { return CompatibilityResult.compatible(); } return CompatibilityResult.requiresMigration(); }
@Override public int hashCode() { int result = getName().hashCode(); result = 31 * result + getStateType().hashCode(); result = 31 * result + getKeySerializer().hashCode(); result = 31 * result + getValueSerializer().hashCode(); result = 31 * result + getNamespaceSerializer().hashCode(); result = 31 * result + getKeySerializerConfigSnapshot().hashCode(); result = 31 * result + getValueSerializerConfigSnapshot().hashCode(); result = 31 * result + getNamespaceSerializerConfigSnapshot().hashCode(); return result; }
@SuppressWarnings("deprecation") private static <T> void setSerializerForWriteIfOldPath( TypeSerializerSnapshot<T> serializerSnapshot, TypeSerializer<T> serializer) { // for compatibility with non-upgraded serializers, put the serializer into the // config snapshot if it of the old version if (serializerSnapshot instanceof TypeSerializerConfigSnapshot) { checkState(serializer != null); ((TypeSerializerConfigSnapshot<T>) serializerSnapshot).setPriorSerializer(serializer); } } }
@Override public void write(DataOutputView out) throws IOException { super.write(out); out.writeUTF(serializationFormatIdentifier); }
@SuppressWarnings("unchecked") @Override public void read(DataInputView in) throws IOException { super.read(in); String genericTypeClassname = in.readUTF(); try { typeClass = (Class<T>) Class.forName(genericTypeClassname, true, getUserCodeClassLoader()); } catch (ClassNotFoundException e) { throw new IOException("Could not find the requested class " + genericTypeClassname + " in classpath.", e); } }
private void testWriteAndReadConfigSnapshot(Coder<String> coder) throws IOException { CoderTypeSerializer<String> serializer = new CoderTypeSerializer<>(coder); TypeSerializerConfigSnapshot writtenSnapshot = serializer.snapshotConfiguration(); ComparatorTestBase.TestOutputView outView = new ComparatorTestBase.TestOutputView(); writtenSnapshot.write(outView); TypeSerializerConfigSnapshot readSnapshot = new CoderTypeSerializerConfigSnapshot<>(); readSnapshot.read(outView.getInputView()); assertThat(readSnapshot, is(writtenSnapshot)); } }
@SuppressWarnings("unchecked") @Override public void read(DataInputView in) throws IOException { super.read(in); String serializerConfigClassname = in.readUTF(); Class<? extends TypeSerializerConfigSnapshot> serializerConfigSnapshotClass; try { serializerConfigSnapshotClass = (Class<? extends TypeSerializerConfigSnapshot>) Class.forName(serializerConfigClassname, true, userCodeClassLoader); } catch (ClassNotFoundException e) { throw new IOException( "Could not find requested TypeSerializerConfigSnapshot class " + serializerConfigClassname + " in classpath.", e); } serializerConfigSnapshot = InstantiationUtil.instantiate(serializerConfigSnapshotClass); serializerConfigSnapshot.setUserCodeClassLoader(userCodeClassLoader); serializerConfigSnapshot.read(in); }
@Override public CompatibilityResult<T> ensureCompatibility(TypeSerializerConfigSnapshot configSnapshot) { if (snapshotConfiguration().equals(configSnapshot)) { return CompatibilityResult.compatible(); } return CompatibilityResult.requiresMigration(); }