Java Code Examples for org.apache.flink.api.common.typeutils.TypeSerializerSchemaCompatibility#isCompatibleWithReconfiguredSerializer()

The following examples show how to use org.apache.flink.api.common.typeutils.TypeSerializerSchemaCompatibility#isCompatibleWithReconfiguredSerializer() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: StateSerializerProvider.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@Nonnull
@Override
@SuppressWarnings("ConstantConditions")
public TypeSerializerSchemaCompatibility<T> registerNewSerializerForRestoredState(TypeSerializer<T> newSerializer) {
	checkNotNull(newSerializer);
	if (registeredSerializer != null) {
		throw new UnsupportedOperationException("A serializer has already been registered for the state; re-registration is not allowed.");
	}

	TypeSerializerSchemaCompatibility<T> result = previousSerializerSnapshot.resolveSchemaCompatibility(newSerializer);
	if (result.isIncompatible()) {
		invalidateCurrentSchemaSerializerAccess();
	}
	if (result.isCompatibleWithReconfiguredSerializer()) {
		this.registeredSerializer = result.getReconfiguredSerializer();
	} else {
		this.registeredSerializer = newSerializer;
	}
	return result;
}
 
Example 2
Source File: StateSerializerProvider.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@Nonnull
@Override
public TypeSerializerSchemaCompatibility<T> setPreviousSerializerSnapshotForRestoredState(TypeSerializerSnapshot<T> previousSerializerSnapshot) {
	checkNotNull(previousSerializerSnapshot);
	if (this.previousSerializerSnapshot != null) {
		throw new UnsupportedOperationException("The snapshot of the state's previous serializer has already been set; cannot reset.");
	}

	this.previousSerializerSnapshot = previousSerializerSnapshot;

	TypeSerializerSchemaCompatibility<T> result = previousSerializerSnapshot.resolveSchemaCompatibility(registeredSerializer);
	if (result.isIncompatible()) {
		invalidateCurrentSchemaSerializerAccess();
	}
	if (result.isCompatibleWithReconfiguredSerializer()) {
		this.registeredSerializer = result.getReconfiguredSerializer();
	}
	return result;
}
 
Example 3
Source File: StateSerializerProvider.java    From flink with Apache License 2.0 6 votes vote down vote up
@Nonnull
@Override
@SuppressWarnings("ConstantConditions")
public TypeSerializerSchemaCompatibility<T> registerNewSerializerForRestoredState(TypeSerializer<T> newSerializer) {
	checkNotNull(newSerializer);
	if (registeredSerializer != null) {
		throw new UnsupportedOperationException("A serializer has already been registered for the state; re-registration is not allowed.");
	}

	TypeSerializerSchemaCompatibility<T> result = previousSerializerSnapshot.resolveSchemaCompatibility(newSerializer);
	if (result.isIncompatible()) {
		invalidateCurrentSchemaSerializerAccess();
	}
	if (result.isCompatibleWithReconfiguredSerializer()) {
		this.registeredSerializer = result.getReconfiguredSerializer();
	} else {
		this.registeredSerializer = newSerializer;
	}
	return result;
}
 
Example 4
Source File: StateSerializerProvider.java    From flink with Apache License 2.0 6 votes vote down vote up
@Nonnull
@Override
public TypeSerializerSchemaCompatibility<T> setPreviousSerializerSnapshotForRestoredState(TypeSerializerSnapshot<T> previousSerializerSnapshot) {
	checkNotNull(previousSerializerSnapshot);
	if (this.previousSerializerSnapshot != null) {
		throw new UnsupportedOperationException("The snapshot of the state's previous serializer has already been set; cannot reset.");
	}

	this.previousSerializerSnapshot = previousSerializerSnapshot;

	TypeSerializerSchemaCompatibility<T> result = previousSerializerSnapshot.resolveSchemaCompatibility(registeredSerializer);
	if (result.isIncompatible()) {
		invalidateCurrentSchemaSerializerAccess();
	}
	if (result.isCompatibleWithReconfiguredSerializer()) {
		this.registeredSerializer = result.getReconfiguredSerializer();
	}
	return result;
}
 
Example 5
Source File: StateSerializerProvider.java    From flink with Apache License 2.0 6 votes vote down vote up
@Nonnull
@Override
@SuppressWarnings("ConstantConditions")
public TypeSerializerSchemaCompatibility<T> registerNewSerializerForRestoredState(TypeSerializer<T> newSerializer) {
	checkNotNull(newSerializer);
	if (registeredSerializer != null) {
		throw new UnsupportedOperationException("A serializer has already been registered for the state; re-registration is not allowed.");
	}

	TypeSerializerSchemaCompatibility<T> result = previousSerializerSnapshot.resolveSchemaCompatibility(newSerializer);
	if (result.isIncompatible()) {
		invalidateCurrentSchemaSerializerAccess();
	}
	if (result.isCompatibleWithReconfiguredSerializer()) {
		this.registeredSerializer = result.getReconfiguredSerializer();
	} else {
		this.registeredSerializer = newSerializer;
	}
	return result;
}
 
Example 6
Source File: StateSerializerProvider.java    From flink with Apache License 2.0 6 votes vote down vote up
@Nonnull
@Override
public TypeSerializerSchemaCompatibility<T> setPreviousSerializerSnapshotForRestoredState(TypeSerializerSnapshot<T> previousSerializerSnapshot) {
	checkNotNull(previousSerializerSnapshot);
	if (this.previousSerializerSnapshot != null) {
		throw new UnsupportedOperationException("The snapshot of the state's previous serializer has already been set; cannot reset.");
	}

	this.previousSerializerSnapshot = previousSerializerSnapshot;

	TypeSerializerSchemaCompatibility<T> result = previousSerializerSnapshot.resolveSchemaCompatibility(registeredSerializer);
	if (result.isIncompatible()) {
		invalidateCurrentSchemaSerializerAccess();
	}
	if (result.isCompatibleWithReconfiguredSerializer()) {
		this.registeredSerializer = result.getReconfiguredSerializer();
	}
	return result;
}
 
Example 7
Source File: SerializerTestUtil.java    From flink with Apache License 2.0 5 votes vote down vote up
/**
 * Snapshot and restore the given serializer. Returns the restored serializer.
 */
public static <T> TypeSerializer<T> snapshotAndReconfigure(
	TypeSerializer<T> serializer, SerializerGetter<T> serializerGetter) throws IOException {
	TypeSerializerSnapshot<T> configSnapshot = serializer.snapshotConfiguration();

	byte[] serializedConfig;
	try (ByteArrayOutputStream out = new ByteArrayOutputStream()) {
		TypeSerializerSnapshotSerializationUtil.writeSerializerSnapshot(
			new DataOutputViewStreamWrapper(out), configSnapshot, serializer);
		serializedConfig = out.toByteArray();
	}

	TypeSerializerSnapshot<T> restoredConfig;
	try (ByteArrayInputStream in = new ByteArrayInputStream(serializedConfig)) {
		restoredConfig = TypeSerializerSnapshotSerializationUtil.readSerializerSnapshot(
			new DataInputViewStreamWrapper(in),
			Thread.currentThread().getContextClassLoader(),
			serializerGetter.getSerializer());
	}

	TypeSerializerSchemaCompatibility<T> strategy =
		restoredConfig.resolveSchemaCompatibility(serializerGetter.getSerializer());
	final TypeSerializer<T> restoredSerializer;
	if (strategy.isCompatibleAsIs()) {
		restoredSerializer = restoredConfig.restoreSerializer();
	}
	else if (strategy.isCompatibleWithReconfiguredSerializer()) {
		restoredSerializer = strategy.getReconfiguredSerializer();
	}
	else {
		throw new AssertionError("Unable to restore serializer with " + strategy);
	}
	assertEquals(serializer.getClass(), restoredSerializer.getClass());

	return restoredSerializer;
}
 
Example 8
Source File: SerializerTestUtil.java    From flink with Apache License 2.0 5 votes vote down vote up
/**
 * Snapshot and restore the given serializer. Returns the restored serializer.
 */
public static <T> TypeSerializer<T> snapshotAndReconfigure(
	TypeSerializer<T> serializer, SerializerGetter<T> serializerGetter) throws IOException {
	TypeSerializerSnapshot<T> configSnapshot = serializer.snapshotConfiguration();

	byte[] serializedConfig;
	try (ByteArrayOutputStream out = new ByteArrayOutputStream()) {
		TypeSerializerSnapshotSerializationUtil.writeSerializerSnapshot(
			new DataOutputViewStreamWrapper(out), configSnapshot, serializer);
		serializedConfig = out.toByteArray();
	}

	TypeSerializerSnapshot<T> restoredConfig;
	try (ByteArrayInputStream in = new ByteArrayInputStream(serializedConfig)) {
		restoredConfig = TypeSerializerSnapshotSerializationUtil.readSerializerSnapshot(
			new DataInputViewStreamWrapper(in),
			Thread.currentThread().getContextClassLoader(),
			serializerGetter.getSerializer());
	}

	TypeSerializerSchemaCompatibility<T> strategy =
		restoredConfig.resolveSchemaCompatibility(serializerGetter.getSerializer());
	final TypeSerializer<T> restoredSerializer;
	if (strategy.isCompatibleAsIs()) {
		restoredSerializer = restoredConfig.restoreSerializer();
	}
	else if (strategy.isCompatibleWithReconfiguredSerializer()) {
		restoredSerializer = strategy.getReconfiguredSerializer();
	}
	else {
		throw new AssertionError("Unable to restore serializer with " + strategy);
	}
	assertEquals(serializer.getClass(), restoredSerializer.getClass());

	return restoredSerializer;
}