/** * Takes config snapshots of the given serializers. In case where the config snapshots * are still extending the old {@code TypeSerializerConfigSnapshot} class, the snapshots * are set up properly (with their originating serializer) such that the backwards * compatible code paths work. */ public static TypeSerializerSnapshot<?>[] snapshotBackwardsCompatible( TypeSerializer<?>... originatingSerializers) { return Arrays.stream(originatingSerializers) .map((s) -> configureForBackwardsCompatibility(s.snapshotConfiguration(), s)) .toArray(TypeSerializerSnapshot[]::new); }
/** * Snapshots the timers (both processing and event time ones) for a given {@code keyGroupIdx}. * * @param keyGroupIdx the id of the key-group to be put in the snapshot. * @return a snapshot containing the timers for the given key-group, and the serializers for them */ public InternalTimersSnapshot<K, N> snapshotTimersForKeyGroup(int keyGroupIdx) { return new InternalTimersSnapshot<>( keySerializer, keySerializer.snapshotConfiguration(), namespaceSerializer, namespaceSerializer.snapshotConfiguration(), eventTimeTimersQueue.getSubsetForKeyGroup(keyGroupIdx), processingTimeTimersQueue.getSubsetForKeyGroup(keyGroupIdx)); }
fieldToSerializerConfigSnapshots.put( fields[i].getName(), new Tuple2<>(fieldSerializers[i], fieldSerializers[i].snapshotConfiguration())); new Tuple2<>( registeredSubclassSerializers[entry.getValue()], registeredSubclassSerializers[entry.getValue()].snapshotConfiguration())); nonRegisteredSubclassesToSerializerConfigSnapshots.put( entry.getKey(), new Tuple2<>(entry.getValue(), entry.getValue().snapshotConfiguration()));
public CompositeTypeSerializerConfigSnapshot(TypeSerializer<?>... nestedSerializers) { Preconditions.checkNotNull(nestedSerializers); this.nestedSerializersAndConfigs = new ArrayList<>(nestedSerializers.length); for (TypeSerializer<?> nestedSerializer : nestedSerializers) { TypeSerializerSnapshot<?> configSnapshot = nestedSerializer.snapshotConfiguration(); this.nestedSerializersAndConfigs.add( new Tuple2<>(nestedSerializer.duplicate(), Preconditions.checkNotNull(configSnapshot))); } }
@SuppressWarnings("deprecation") @Test public void movingForward() throws IOException { TypeSerializerSnapshot<ElementT> previousSnapshot = snapshotUnderTest(); TypeSerializer<ElementT> restoredSerializer = previousSnapshot.restoreSerializer(); TypeSerializerSnapshot<ElementT> nextSnapshot = restoredSerializer.snapshotConfiguration(); assertThat(nextSnapshot, instanceOf(testSpecification.snapshotClass)); TypeSerializerSnapshot<ElementT> nextSnapshotDeserialized = writeAndThenReadTheSnapshot(restoredSerializer, nextSnapshot); assertThat(nextSnapshotDeserialized, allOf( notNullValue(), not(instanceOf(TypeSerializerConfigSnapshot.class)) )); }
@Test public void testConfigSnapshotInstantiation() { TypeSerializerSnapshot<T> configSnapshot = getSerializer().snapshotConfiguration(); InstantiationUtil.instantiate(configSnapshot.getClass()); }
@Test public void testSnapshotConfigurationAndReconfigure() throws Exception { final TypeSerializer<T> serializer = getSerializer(); final 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(), getSerializer()); } TypeSerializerSchemaCompatibility<T> strategy = restoredConfig.resolveSchemaCompatibility(getSerializer()); assertTrue(strategy.isCompatibleAsIs()); TypeSerializer<T> restoreSerializer = restoredConfig.restoreSerializer(); assertEquals(serializer.getClass(), restoreSerializer.getClass()); }
new Tuple2<>( ser.getFieldSerializers()[3], ser.getFieldSerializers()[3].snapshotConfiguration())); mockOriginalFieldToSerializerConfigSnapshot.put( mockOriginalFieldOrder[1].getName(), new Tuple2<>( ser.getFieldSerializers()[2], ser.getFieldSerializers()[2].snapshotConfiguration())); mockOriginalFieldToSerializerConfigSnapshot.put( mockOriginalFieldOrder[2].getName(), new Tuple2<>( ser.getFieldSerializers()[5], ser.getFieldSerializers()[5].snapshotConfiguration())); mockOriginalFieldToSerializerConfigSnapshot.put( mockOriginalFieldOrder[3].getName(), new Tuple2<>( ser.getFieldSerializers()[0], ser.getFieldSerializers()[0].snapshotConfiguration())); mockOriginalFieldToSerializerConfigSnapshot.put( mockOriginalFieldOrder[4].getName(), new Tuple2<>( ser.getFieldSerializers()[1], ser.getFieldSerializers()[1].snapshotConfiguration())); mockOriginalFieldToSerializerConfigSnapshot.put( mockOriginalFieldOrder[5].getName(), new Tuple2<>( ser.getFieldSerializers()[4], ser.getFieldSerializers()[4].snapshotConfiguration()));
@Override public TypeSerializerConfigSnapshot snapshotConfiguration() { // we return the configuration of the actually used serializer here return serializer.snapshotConfiguration(); }
/** * Takes config snapshots of the given serializers. In case where the config snapshots * are still extending the old {@code TypeSerializerConfigSnapshot} class, the snapshots * are set up properly (with their originating serializer) such that the backwards * compatible code paths work. */ public static TypeSerializerSnapshot<?>[] snapshotBackwardsCompatible( TypeSerializer<?>... originatingSerializers) { return Arrays.stream(originatingSerializers) .map((s) -> configureForBackwardsCompatibility(s.snapshotConfiguration(), s)) .toArray(TypeSerializerSnapshot[]::new); }
public RegisteredBroadcastBackendStateMetaInfo.Snapshot<K, V> snapshot() { return new RegisteredBroadcastBackendStateMetaInfo.Snapshot<>( name, assignmentMode, keySerializer.duplicate(), valueSerializer.duplicate(), keySerializer.snapshotConfiguration(), valueSerializer.snapshotConfiguration()); }
public Snapshot<N, S> snapshot() { return new Snapshot<>( stateType, name, namespaceSerializer.duplicate(), stateSerializer.duplicate(), namespaceSerializer.snapshotConfiguration(), stateSerializer.snapshotConfiguration()); }
public Snapshot<S> snapshot() { return new Snapshot<>( name, assignmentMode, partitionStateSerializer.duplicate(), partitionStateSerializer.snapshotConfiguration()); }
public Snapshot<S> snapshot() { return new Snapshot<>( name, assignmentMode, partitionStateSerializer.duplicate(), partitionStateSerializer.snapshotConfiguration()); }
public CompositeTypeSerializerConfigSnapshot(TypeSerializer<?>... nestedSerializers) { Preconditions.checkNotNull(nestedSerializers); this.nestedSerializersAndConfigs = new ArrayList<>(nestedSerializers.length); for (TypeSerializer<?> nestedSerializer : nestedSerializers) { TypeSerializerSnapshot<?> configSnapshot = nestedSerializer.snapshotConfiguration(); this.nestedSerializersAndConfigs.add( new Tuple2<>(nestedSerializer.duplicate(), Preconditions.checkNotNull(configSnapshot))); } }
public CompositeTypeSerializerConfigSnapshot(TypeSerializer<?>... nestedSerializers) { Preconditions.checkNotNull(nestedSerializers); this.nestedSerializersAndConfigs = new ArrayList<>(nestedSerializers.length); for (TypeSerializer<?> nestedSerializer : nestedSerializers) { TypeSerializerConfigSnapshot configSnapshot = nestedSerializer.snapshotConfiguration(); this.nestedSerializersAndConfigs.add( new Tuple2<TypeSerializer<?>, TypeSerializerConfigSnapshot>( nestedSerializer.duplicate(), Preconditions.checkNotNull(configSnapshot))); } }
public KeyedBackendSerializationProxy( TypeSerializer<K> keySerializer, List<StateMetaInfoSnapshot> stateMetaInfoSnapshots, boolean compression) { this.usingKeyGroupCompression = compression; this.keySerializer = Preconditions.checkNotNull(keySerializer); this.keySerializerConfigSnapshot = Preconditions.checkNotNull(keySerializer.snapshotConfiguration()); Preconditions.checkNotNull(stateMetaInfoSnapshots); Preconditions.checkArgument(stateMetaInfoSnapshots.size() <= Short.MAX_VALUE); this.stateMetaInfoSnapshots = stateMetaInfoSnapshots; }
public KeyedBackendSerializationProxy( TypeSerializer<K> keySerializer, List<RegisteredKeyedBackendStateMetaInfo.Snapshot<?, ?>> stateMetaInfoSnapshots) { this.keySerializer = Preconditions.checkNotNull(keySerializer); this.keySerializerConfigSnapshot = Preconditions.checkNotNull(keySerializer.snapshotConfiguration()); Preconditions.checkNotNull(stateMetaInfoSnapshots); Preconditions.checkArgument(stateMetaInfoSnapshots.size() <= Short.MAX_VALUE); this.stateMetaInfoSnapshots = stateMetaInfoSnapshots; }
public KeyedBackendSerializationProxy( TypeSerializer<K> keySerializer, List<StateMetaInfoSnapshot> stateMetaInfoSnapshots, boolean compression) { this.usingKeyGroupCompression = compression; this.keySerializer = Preconditions.checkNotNull(keySerializer); this.keySerializerConfigSnapshot = Preconditions.checkNotNull(keySerializer.snapshotConfiguration()); Preconditions.checkNotNull(stateMetaInfoSnapshots); Preconditions.checkArgument(stateMetaInfoSnapshots.size() <= Short.MAX_VALUE); this.stateMetaInfoSnapshots = stateMetaInfoSnapshots; }
public KeyedBackendSerializationProxy( TypeSerializer<K> keySerializer, List<RegisteredKeyedBackendStateMetaInfo.Snapshot<?, ?>> stateMetaInfoSnapshots, boolean compression) { this.usingKeyGroupCompression = compression; this.keySerializer = Preconditions.checkNotNull(keySerializer); this.keySerializerConfigSnapshot = Preconditions.checkNotNull(keySerializer.snapshotConfiguration()); Preconditions.checkNotNull(stateMetaInfoSnapshots); Preconditions.checkArgument(stateMetaInfoSnapshots.size() <= Short.MAX_VALUE); this.stateMetaInfoSnapshots = stateMetaInfoSnapshots; }