org.apache.flink.runtime.state.metainfo.StateMetaInfoSnapshot Java Examples

The following examples show how to use org.apache.flink.runtime.state.metainfo.StateMetaInfoSnapshot. 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: RegisteredPriorityQueueStateBackendMetaInfo.java    From flink with Apache License 2.0 6 votes vote down vote up
private StateMetaInfoSnapshot computeSnapshot() {
	TypeSerializer<T> elementSerializer = getElementSerializer();
	Map<String, TypeSerializer<?>> serializerMap =
		Collections.singletonMap(
			StateMetaInfoSnapshot.CommonSerializerKeys.VALUE_SERIALIZER.toString(),
			elementSerializer.duplicate());
	Map<String, TypeSerializerSnapshot<?>> serializerSnapshotMap =
		Collections.singletonMap(
			StateMetaInfoSnapshot.CommonSerializerKeys.VALUE_SERIALIZER.toString(),
			elementSerializer.snapshotConfiguration());

	return new StateMetaInfoSnapshot(
		name,
		StateMetaInfoSnapshot.BackendStateType.PRIORITY_QUEUE,
		Collections.emptyMap(),
		serializerSnapshotMap,
		serializerMap);
}
 
Example #2
Source File: RegisteredKeyValueStateBackendMetaInfo.java    From flink with Apache License 2.0 6 votes vote down vote up
@Nonnull
private StateMetaInfoSnapshot computeSnapshot() {
	Map<String, String> optionsMap = Collections.singletonMap(
		StateMetaInfoSnapshot.CommonOptionsKeys.KEYED_STATE_TYPE.toString(),
		stateType.toString());
	Map<String, TypeSerializer<?>> serializerMap = new HashMap<>(2);
	Map<String, TypeSerializerSnapshot<?>> serializerConfigSnapshotsMap = new HashMap<>(2);
	String namespaceSerializerKey = StateMetaInfoSnapshot.CommonSerializerKeys.NAMESPACE_SERIALIZER.toString();
	String valueSerializerKey = StateMetaInfoSnapshot.CommonSerializerKeys.VALUE_SERIALIZER.toString();

	TypeSerializer<N> namespaceSerializer = getNamespaceSerializer();
	serializerMap.put(namespaceSerializerKey, namespaceSerializer.duplicate());
	serializerConfigSnapshotsMap.put(namespaceSerializerKey, namespaceSerializer.snapshotConfiguration());

	TypeSerializer<S> stateSerializer = getStateSerializer();
	serializerMap.put(valueSerializerKey, stateSerializer.duplicate());
	serializerConfigSnapshotsMap.put(valueSerializerKey, stateSerializer.snapshotConfiguration());

	return new StateMetaInfoSnapshot(
		name,
		StateMetaInfoSnapshot.BackendStateType.KEY_VALUE,
		optionsMap,
		serializerConfigSnapshotsMap,
		serializerMap);
}
 
Example #3
Source File: HeapSnapshotStrategy.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
private void processSnapshotMetaInfoForAllStates(
	List<StateMetaInfoSnapshot> metaInfoSnapshots,
	Map<StateUID, StateSnapshot> cowStateStableSnapshots,
	Map<StateUID, Integer> stateNamesToId,
	Map<String, ? extends StateSnapshotRestore> registeredStates,
	StateMetaInfoSnapshot.BackendStateType stateType) {

	for (Map.Entry<String, ? extends StateSnapshotRestore> kvState : registeredStates.entrySet()) {
		final StateUID stateUid = StateUID.of(kvState.getKey(), stateType);
		stateNamesToId.put(stateUid, stateNamesToId.size());
		StateSnapshotRestore state = kvState.getValue();
		if (null != state) {
			final StateSnapshot stateSnapshot = state.stateSnapshot();
			metaInfoSnapshots.add(stateSnapshot.getMetaInfoSnapshot());
			cowStateStableSnapshots.put(stateUid, stateSnapshot);
		}
	}
}
 
Example #4
Source File: RocksIncrementalSnapshotStrategy.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
private Set<StateHandleID> snapshotMetaData(
	long checkpointId,
	@Nonnull List<StateMetaInfoSnapshot> stateMetaInfoSnapshots) {

	final long lastCompletedCheckpoint;
	final Set<StateHandleID> baseSstFiles;

	// use the last completed checkpoint as the comparison base.
	synchronized (materializedSstFiles) {
		lastCompletedCheckpoint = lastCompletedCheckpointId;
		baseSstFiles = materializedSstFiles.get(lastCompletedCheckpoint);
	}
	LOG.trace("Taking incremental snapshot for checkpoint {}. Snapshot is based on last completed checkpoint {} " +
		"assuming the following (shared) files as base: {}.", checkpointId, lastCompletedCheckpoint, baseSstFiles);

	// snapshot meta data to save
	for (Map.Entry<String, RocksDbKvStateInfo> stateMetaInfoEntry : kvStateInformation.entrySet()) {
		stateMetaInfoSnapshots.add(stateMetaInfoEntry.getValue().metaInfo.snapshot());
	}
	return baseSstFiles;
}
 
Example #5
Source File: RocksIncrementalSnapshotStrategy.java    From flink with Apache License 2.0 6 votes vote down vote up
private Set<StateHandleID> snapshotMetaData(
	long checkpointId,
	@Nonnull List<StateMetaInfoSnapshot> stateMetaInfoSnapshots) {

	final long lastCompletedCheckpoint;
	final Set<StateHandleID> baseSstFiles;

	// use the last completed checkpoint as the comparison base.
	synchronized (materializedSstFiles) {
		lastCompletedCheckpoint = lastCompletedCheckpointId;
		baseSstFiles = materializedSstFiles.get(lastCompletedCheckpoint);
	}
	LOG.trace("Taking incremental snapshot for checkpoint {}. Snapshot is based on last completed checkpoint {} " +
		"assuming the following (shared) files as base: {}.", checkpointId, lastCompletedCheckpoint, baseSstFiles);

	// snapshot meta data to save
	for (Map.Entry<String, RocksDbKvStateInfo> stateMetaInfoEntry : kvStateInformation.entrySet()) {
		stateMetaInfoSnapshots.add(stateMetaInfoEntry.getValue().metaInfo.snapshot());
	}
	return baseSstFiles;
}
 
Example #6
Source File: RegisteredOperatorStateBackendMetaInfo.java    From flink with Apache License 2.0 6 votes vote down vote up
@Nonnull
private StateMetaInfoSnapshot computeSnapshot() {
	Map<String, String> optionsMap = Collections.singletonMap(
		StateMetaInfoSnapshot.CommonOptionsKeys.OPERATOR_STATE_DISTRIBUTION_MODE.toString(),
		assignmentMode.toString());
	String valueSerializerKey = StateMetaInfoSnapshot.CommonSerializerKeys.VALUE_SERIALIZER.toString();

	TypeSerializer<S> partitionStateSerializer = getPartitionStateSerializer();
	Map<String, TypeSerializer<?>> serializerMap =
		Collections.singletonMap(valueSerializerKey, partitionStateSerializer.duplicate());
	Map<String, TypeSerializerSnapshot<?>> serializerConfigSnapshotsMap =
		Collections.singletonMap(valueSerializerKey, partitionStateSerializer.snapshotConfiguration());

	return new StateMetaInfoSnapshot(
		name,
		StateMetaInfoSnapshot.BackendStateType.OPERATOR,
		optionsMap,
		serializerConfigSnapshotsMap,
		serializerMap);
}
 
Example #7
Source File: RocksDBFullRestoreOperation.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
/**
 * Restore the KV-state / ColumnFamily meta data for all key-groups referenced by the current state handle.
 */
private void restoreKVStateMetaData() throws IOException, StateMigrationException {
	KeyedBackendSerializationProxy<K> serializationProxy = readMetaData(currentStateHandleInView);

	this.keygroupStreamCompressionDecorator = serializationProxy.isUsingKeyGroupCompression() ?
		SnappyStreamCompressionDecorator.INSTANCE : UncompressedStreamCompressionDecorator.INSTANCE;

	List<StateMetaInfoSnapshot> restoredMetaInfos =
		serializationProxy.getStateMetaInfoSnapshots();
	currentStateHandleKVStateColumnFamilies = new ArrayList<>(restoredMetaInfos.size());

	for (StateMetaInfoSnapshot restoredMetaInfo : restoredMetaInfos) {
		RocksDbKvStateInfo registeredStateCFHandle =
			getOrRegisterStateColumnFamilyHandle(null, restoredMetaInfo);
		currentStateHandleKVStateColumnFamilies.add(registeredStateCFHandle.columnFamilyHandle);
	}
}
 
Example #8
Source File: RocksIncrementalSnapshotStrategy.java    From flink with Apache License 2.0 6 votes vote down vote up
@Nonnull
@Override
protected RunnableFuture<SnapshotResult<KeyedStateHandle>> doSnapshot(
	long checkpointId,
	long checkpointTimestamp,
	@Nonnull CheckpointStreamFactory checkpointStreamFactory,
	@Nonnull CheckpointOptions checkpointOptions) throws Exception {

	final SnapshotDirectory snapshotDirectory = prepareLocalSnapshotDirectory(checkpointId);
	LOG.trace("Local RocksDB checkpoint goes to backup path {}.", snapshotDirectory);

	final List<StateMetaInfoSnapshot> stateMetaInfoSnapshots = new ArrayList<>(kvStateInformation.size());
	final Set<StateHandleID> baseSstFiles = snapshotMetaData(checkpointId, stateMetaInfoSnapshots);

	takeDBNativeCheckpoint(snapshotDirectory);

	final RocksDBIncrementalSnapshotOperation snapshotOperation =
		new RocksDBIncrementalSnapshotOperation(
			checkpointId,
			checkpointStreamFactory,
			snapshotDirectory,
			baseSstFiles,
			stateMetaInfoSnapshots);

	return snapshotOperation.toAsyncSnapshotFutureTask(cancelStreamRegistry);
}
 
Example #9
Source File: RocksDBFullRestoreOperation.java    From flink with Apache License 2.0 6 votes vote down vote up
/**
 * Restore the KV-state / ColumnFamily meta data for all key-groups referenced by the current state handle.
 */
private void restoreKVStateMetaData() throws IOException, StateMigrationException {
	KeyedBackendSerializationProxy<K> serializationProxy = readMetaData(currentStateHandleInView);

	this.keygroupStreamCompressionDecorator = serializationProxy.isUsingKeyGroupCompression() ?
		SnappyStreamCompressionDecorator.INSTANCE : UncompressedStreamCompressionDecorator.INSTANCE;

	List<StateMetaInfoSnapshot> restoredMetaInfos =
		serializationProxy.getStateMetaInfoSnapshots();
	currentStateHandleKVStateColumnFamilies = new ArrayList<>(restoredMetaInfos.size());

	for (StateMetaInfoSnapshot restoredMetaInfo : restoredMetaInfos) {
		RocksDbKvStateInfo registeredStateCFHandle =
			getOrRegisterStateColumnFamilyHandle(null, restoredMetaInfo);
		currentStateHandleKVStateColumnFamilies.add(registeredStateCFHandle.columnFamilyHandle);
	}
}
 
Example #10
Source File: RegisteredStateMetaInfoBase.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
public static RegisteredStateMetaInfoBase fromMetaInfoSnapshot(@Nonnull StateMetaInfoSnapshot snapshot) {

		final StateMetaInfoSnapshot.BackendStateType backendStateType = snapshot.getBackendStateType();
		switch (backendStateType) {
			case KEY_VALUE:
				return new RegisteredKeyValueStateBackendMetaInfo<>(snapshot);
			case OPERATOR:
				return new RegisteredOperatorStateBackendMetaInfo<>(snapshot);
			case BROADCAST:
				return new RegisteredBroadcastStateBackendMetaInfo<>(snapshot);
			case PRIORITY_QUEUE:
				return new RegisteredPriorityQueueStateBackendMetaInfo<>(snapshot);
			default:
				throw new IllegalArgumentException("Unknown backend state type: " + backendStateType);
		}
	}
 
Example #11
Source File: RocksDBCheckpointIterator.java    From bravo with Apache License 2.0 6 votes vote down vote up
public RocksDBCheckpointIterator(IncrementalKeyedStateHandle handle, FilterFunction<String> stateFilter,
		String localPath) {
	this.localPath = localPath;
	this.cancelStreamRegistry = new CloseableRegistry();
	List<StateMetaInfoSnapshot> stateMetaInfoSnapshots = StateMetadataUtils
			.getKeyedBackendSerializationProxy(handle.getMetaStateHandle()).getStateMetaInfoSnapshots();

	stateColumnFamilyHandles = new ArrayList<>(stateMetaInfoSnapshots.size() + 1);
	List<ColumnFamilyDescriptor> stateColumnFamilyDescriptors = createAndRegisterColumnFamilyDescriptors(
			stateMetaInfoSnapshots);
	try {
		transferAllStateDataToDirectory(handle, new Path(localPath));
		this.db = openDB(localPath, stateColumnFamilyDescriptors, stateColumnFamilyHandles);
		createColumnIterators(stateFilter, stateMetaInfoSnapshots);
	} catch (Exception e) {
		throw new IllegalStateException(e);
	}
}
 
Example #12
Source File: RegisteredPriorityQueueStateBackendMetaInfo.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
private StateMetaInfoSnapshot computeSnapshot() {
	TypeSerializer<T> elementSerializer = getElementSerializer();
	Map<String, TypeSerializer<?>> serializerMap =
		Collections.singletonMap(
			StateMetaInfoSnapshot.CommonSerializerKeys.VALUE_SERIALIZER.toString(),
			elementSerializer.duplicate());
	Map<String, TypeSerializerSnapshot<?>> serializerSnapshotMap =
		Collections.singletonMap(
			StateMetaInfoSnapshot.CommonSerializerKeys.VALUE_SERIALIZER.toString(),
			elementSerializer.snapshotConfiguration());

	return new StateMetaInfoSnapshot(
		name,
		StateMetaInfoSnapshot.BackendStateType.PRIORITY_QUEUE,
		Collections.emptyMap(),
		serializerSnapshotMap,
		serializerMap);
}
 
Example #13
Source File: RegisteredOperatorStateBackendMetaInfo.java    From flink with Apache License 2.0 6 votes vote down vote up
@Nonnull
private StateMetaInfoSnapshot computeSnapshot() {
	Map<String, String> optionsMap = Collections.singletonMap(
		StateMetaInfoSnapshot.CommonOptionsKeys.OPERATOR_STATE_DISTRIBUTION_MODE.toString(),
		assignmentMode.toString());
	String valueSerializerKey = StateMetaInfoSnapshot.CommonSerializerKeys.VALUE_SERIALIZER.toString();

	TypeSerializer<S> partitionStateSerializer = getPartitionStateSerializer();
	Map<String, TypeSerializer<?>> serializerMap =
		Collections.singletonMap(valueSerializerKey, partitionStateSerializer.duplicate());
	Map<String, TypeSerializerSnapshot<?>> serializerConfigSnapshotsMap =
		Collections.singletonMap(valueSerializerKey, partitionStateSerializer.snapshotConfiguration());

	return new StateMetaInfoSnapshot(
		name,
		StateMetaInfoSnapshot.BackendStateType.OPERATOR,
		optionsMap,
		serializerConfigSnapshotsMap,
		serializerMap);
}
 
Example #14
Source File: RocksDBIncrementalRestoreOperation.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
private void restoreFromLocalState(IncrementalLocalKeyedStateHandle localKeyedStateHandle) throws Exception {
	KeyedBackendSerializationProxy<K> serializationProxy = readMetaData(localKeyedStateHandle.getMetaDataState());
	List<StateMetaInfoSnapshot> stateMetaInfoSnapshots = serializationProxy.getStateMetaInfoSnapshots();
	columnFamilyDescriptors = createAndRegisterColumnFamilyDescriptors(stateMetaInfoSnapshots, true);
	columnFamilyHandles = new ArrayList<>(columnFamilyDescriptors.size() + 1);

	Path restoreSourcePath = localKeyedStateHandle.getDirectoryStateHandle().getDirectory();

	LOG.debug("Restoring keyed backend uid in operator {} from incremental snapshot to {}.",
		operatorIdentifier, backendUID);

	if (!instanceRocksDBPath.mkdirs()) {
		String errMsg = "Could not create RocksDB data directory: " + instanceBasePath.getAbsolutePath();
		LOG.error(errMsg);
		throw new IOException(errMsg);
	}

	restoreInstanceDirectoryFromPath(restoreSourcePath, dbPath);

	openDB();

	registerColumnFamilyHandles(stateMetaInfoSnapshots);
}
 
Example #15
Source File: HeapSnapshotStrategy.java    From flink with Apache License 2.0 6 votes vote down vote up
private void processSnapshotMetaInfoForAllStates(
	List<StateMetaInfoSnapshot> metaInfoSnapshots,
	Map<StateUID, StateSnapshot> cowStateStableSnapshots,
	Map<StateUID, Integer> stateNamesToId,
	Map<String, ? extends StateSnapshotRestore> registeredStates,
	StateMetaInfoSnapshot.BackendStateType stateType) {

	for (Map.Entry<String, ? extends StateSnapshotRestore> kvState : registeredStates.entrySet()) {
		final StateUID stateUid = StateUID.of(kvState.getKey(), stateType);
		stateNamesToId.put(stateUid, stateNamesToId.size());
		StateSnapshotRestore state = kvState.getValue();
		if (null != state) {
			final StateSnapshot stateSnapshot = state.stateSnapshot();
			metaInfoSnapshots.add(stateSnapshot.getMetaInfoSnapshot());
			cowStateStableSnapshots.put(stateUid, stateSnapshot);
		}
	}
}
 
Example #16
Source File: SerializationProxiesTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testKeyedStateMetaInfoSerialization() throws Exception {

	String name = "test";
	TypeSerializer<?> namespaceSerializer = LongSerializer.INSTANCE;
	TypeSerializer<?> stateSerializer = DoubleSerializer.INSTANCE;

	StateMetaInfoSnapshot metaInfo = new RegisteredKeyValueStateBackendMetaInfo<>(
		StateDescriptor.Type.VALUE, name, namespaceSerializer, stateSerializer).snapshot();

	byte[] serialized;
	try (ByteArrayOutputStreamWithPos out = new ByteArrayOutputStreamWithPos()) {
		StateMetaInfoSnapshotReadersWriters.getWriter().
			writeStateMetaInfoSnapshot(metaInfo, new DataOutputViewStreamWrapper(out));
		serialized = out.toByteArray();
	}

	try (ByteArrayInputStreamWithPos in = new ByteArrayInputStreamWithPos(serialized)) {
		final StateMetaInfoReader reader = StateMetaInfoSnapshotReadersWriters.getReader(
			CURRENT_STATE_META_INFO_SNAPSHOT_VERSION, StateMetaInfoSnapshotReadersWriters.StateTypeHint.KEYED_STATE);
		metaInfo = reader.readStateMetaInfoSnapshot(
			new DataInputViewStreamWrapper(in), Thread.currentThread().getContextClassLoader());
	}

	Assert.assertEquals(name, metaInfo.getName());
}
 
Example #17
Source File: RocksIncrementalSnapshotStrategy.java    From flink with Apache License 2.0 6 votes vote down vote up
private Set<StateHandleID> snapshotMetaData(
	long checkpointId,
	@Nonnull List<StateMetaInfoSnapshot> stateMetaInfoSnapshots) {

	final long lastCompletedCheckpoint;
	final Set<StateHandleID> baseSstFiles;

	// use the last completed checkpoint as the comparison base.
	synchronized (materializedSstFiles) {
		lastCompletedCheckpoint = lastCompletedCheckpointId;
		baseSstFiles = materializedSstFiles.get(lastCompletedCheckpoint);
	}
	LOG.trace("Taking incremental snapshot for checkpoint {}. Snapshot is based on last completed checkpoint {} " +
		"assuming the following (shared) files as base: {}.", checkpointId, lastCompletedCheckpoint, baseSstFiles);

	// snapshot meta data to save
	for (Map.Entry<String, RocksDbKvStateInfo> stateMetaInfoEntry : kvStateInformation.entrySet()) {
		stateMetaInfoSnapshots.add(stateMetaInfoEntry.getValue().metaInfo.snapshot());
	}
	return baseSstFiles;
}
 
Example #18
Source File: RocksDBIncrementalRestoreOperation.java    From flink with Apache License 2.0 6 votes vote down vote up
/**
 * This method recreates and registers all {@link ColumnFamilyDescriptor} from Flink's state meta data snapshot.
 */
private List<ColumnFamilyDescriptor> createAndRegisterColumnFamilyDescriptors(
	List<StateMetaInfoSnapshot> stateMetaInfoSnapshots,
	boolean registerTtlCompactFilter) {

	List<ColumnFamilyDescriptor> columnFamilyDescriptors =
		new ArrayList<>(stateMetaInfoSnapshots.size());

	for (StateMetaInfoSnapshot stateMetaInfoSnapshot : stateMetaInfoSnapshots) {
		RegisteredStateMetaInfoBase metaInfoBase =
			RegisteredStateMetaInfoBase.fromMetaInfoSnapshot(stateMetaInfoSnapshot);
		ColumnFamilyDescriptor columnFamilyDescriptor = RocksDBOperationUtils.createColumnFamilyDescriptor(
			metaInfoBase, columnFamilyOptionsFactory, registerTtlCompactFilter ? ttlCompactFiltersManager : null);
		columnFamilyDescriptors.add(columnFamilyDescriptor);
	}
	return columnFamilyDescriptors;
}
 
Example #19
Source File: RocksDBIncrementalRestoreOperation.java    From flink with Apache License 2.0 6 votes vote down vote up
private void restoreFromLocalState(IncrementalLocalKeyedStateHandle localKeyedStateHandle) throws Exception {
	KeyedBackendSerializationProxy<K> serializationProxy = readMetaData(localKeyedStateHandle.getMetaDataState());
	List<StateMetaInfoSnapshot> stateMetaInfoSnapshots = serializationProxy.getStateMetaInfoSnapshots();
	columnFamilyDescriptors = createAndRegisterColumnFamilyDescriptors(stateMetaInfoSnapshots, true);
	columnFamilyHandles = new ArrayList<>(columnFamilyDescriptors.size() + 1);

	Path restoreSourcePath = localKeyedStateHandle.getDirectoryStateHandle().getDirectory();

	LOG.debug("Restoring keyed backend uid in operator {} from incremental snapshot to {}.",
		operatorIdentifier, backendUID);

	if (!instanceRocksDBPath.mkdirs()) {
		String errMsg = "Could not create RocksDB data directory: " + instanceBasePath.getAbsolutePath();
		LOG.error(errMsg);
		throw new IOException(errMsg);
	}

	restoreInstanceDirectoryFromPath(restoreSourcePath, dbPath);

	openDB();

	registerColumnFamilyHandles(stateMetaInfoSnapshots);
}
 
Example #20
Source File: RocksDBFullRestoreOperation.java    From flink with Apache License 2.0 6 votes vote down vote up
/**
 * Restore the KV-state / ColumnFamily meta data for all key-groups referenced by the current state handle.
 */
private void restoreKVStateMetaData() throws IOException, StateMigrationException {
	KeyedBackendSerializationProxy<K> serializationProxy = readMetaData(currentStateHandleInView);

	this.keygroupStreamCompressionDecorator = serializationProxy.isUsingKeyGroupCompression() ?
		SnappyStreamCompressionDecorator.INSTANCE : UncompressedStreamCompressionDecorator.INSTANCE;

	List<StateMetaInfoSnapshot> restoredMetaInfos =
		serializationProxy.getStateMetaInfoSnapshots();
	currentStateHandleKVStateColumnFamilies = new ArrayList<>(restoredMetaInfos.size());

	for (StateMetaInfoSnapshot restoredMetaInfo : restoredMetaInfos) {
		RocksDbKvStateInfo registeredStateCFHandle =
			getOrRegisterStateColumnFamilyHandle(null, restoredMetaInfo);
		currentStateHandleKVStateColumnFamilies.add(registeredStateCFHandle.columnFamilyHandle);
	}
}
 
Example #21
Source File: SerializationProxiesTest.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@Test
public void testKeyedStateMetaInfoSerialization() throws Exception {

	String name = "test";
	TypeSerializer<?> namespaceSerializer = LongSerializer.INSTANCE;
	TypeSerializer<?> stateSerializer = DoubleSerializer.INSTANCE;

	StateMetaInfoSnapshot metaInfo = new RegisteredKeyValueStateBackendMetaInfo<>(
		StateDescriptor.Type.VALUE, name, namespaceSerializer, stateSerializer).snapshot();

	byte[] serialized;
	try (ByteArrayOutputStreamWithPos out = new ByteArrayOutputStreamWithPos()) {
		StateMetaInfoSnapshotReadersWriters.getWriter().
			writeStateMetaInfoSnapshot(metaInfo, new DataOutputViewStreamWrapper(out));
		serialized = out.toByteArray();
	}

	try (ByteArrayInputStreamWithPos in = new ByteArrayInputStreamWithPos(serialized)) {
		final StateMetaInfoReader reader = StateMetaInfoSnapshotReadersWriters.getReader(
			CURRENT_STATE_META_INFO_SNAPSHOT_VERSION, StateMetaInfoSnapshotReadersWriters.StateTypeHint.KEYED_STATE);
		metaInfo = reader.readStateMetaInfoSnapshot(
			new DataInputViewStreamWrapper(in), Thread.currentThread().getContextClassLoader());
	}

	Assert.assertEquals(name, metaInfo.getName());
}
 
Example #22
Source File: RegisteredKeyValueStateBackendMetaInfo.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@Nonnull
private StateMetaInfoSnapshot computeSnapshot() {
	Map<String, String> optionsMap = Collections.singletonMap(
		StateMetaInfoSnapshot.CommonOptionsKeys.KEYED_STATE_TYPE.toString(),
		stateType.toString());
	Map<String, TypeSerializer<?>> serializerMap = new HashMap<>(2);
	Map<String, TypeSerializerSnapshot<?>> serializerConfigSnapshotsMap = new HashMap<>(2);
	String namespaceSerializerKey = StateMetaInfoSnapshot.CommonSerializerKeys.NAMESPACE_SERIALIZER.toString();
	String valueSerializerKey = StateMetaInfoSnapshot.CommonSerializerKeys.VALUE_SERIALIZER.toString();

	TypeSerializer<N> namespaceSerializer = getNamespaceSerializer();
	serializerMap.put(namespaceSerializerKey, namespaceSerializer.duplicate());
	serializerConfigSnapshotsMap.put(namespaceSerializerKey, namespaceSerializer.snapshotConfiguration());

	TypeSerializer<S> stateSerializer = getStateSerializer();
	serializerMap.put(valueSerializerKey, stateSerializer.duplicate());
	serializerConfigSnapshotsMap.put(valueSerializerKey, stateSerializer.snapshotConfiguration());

	return new StateMetaInfoSnapshot(
		name,
		StateMetaInfoSnapshot.BackendStateType.KEY_VALUE,
		optionsMap,
		serializerConfigSnapshotsMap,
		serializerMap);
}
 
Example #23
Source File: RocksDBIncrementalRestoreOperation.java    From flink with Apache License 2.0 6 votes vote down vote up
/**
 * This method recreates and registers all {@link ColumnFamilyDescriptor} from Flink's state meta data snapshot.
 */
private List<ColumnFamilyDescriptor> createAndRegisterColumnFamilyDescriptors(
	List<StateMetaInfoSnapshot> stateMetaInfoSnapshots,
	boolean registerTtlCompactFilter) {

	List<ColumnFamilyDescriptor> columnFamilyDescriptors =
		new ArrayList<>(stateMetaInfoSnapshots.size());

	for (StateMetaInfoSnapshot stateMetaInfoSnapshot : stateMetaInfoSnapshots) {
		RegisteredStateMetaInfoBase metaInfoBase =
			RegisteredStateMetaInfoBase.fromMetaInfoSnapshot(stateMetaInfoSnapshot);
		ColumnFamilyDescriptor columnFamilyDescriptor = RocksDBOperationUtils.createColumnFamilyDescriptor(
			metaInfoBase, columnFamilyOptionsFactory, registerTtlCompactFilter ? ttlCompactFiltersManager : null);
		columnFamilyDescriptors.add(columnFamilyDescriptor);
	}
	return columnFamilyDescriptors;
}
 
Example #24
Source File: SerializationProxiesTest.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
private void assertEqualStateMetaInfoSnapshotsLists(
	List<StateMetaInfoSnapshot> expected,
	List<StateMetaInfoSnapshot> actual) {
	Assert.assertEquals(expected.size(), actual.size());
	for (int i = 0; i < expected.size(); ++i) {
		assertEqualStateMetaInfoSnapshots(expected.get(i), actual.get(i));
	}
}
 
Example #25
Source File: RegisteredPriorityQueueStateBackendMetaInfo.java    From flink with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
public RegisteredPriorityQueueStateBackendMetaInfo(StateMetaInfoSnapshot snapshot) {
	this(
		snapshot.getName(),
		StateSerializerProvider.fromPreviousSerializerSnapshot(
			(TypeSerializerSnapshot<T>) Preconditions.checkNotNull(
				snapshot.getTypeSerializerSnapshot(StateMetaInfoSnapshot.CommonSerializerKeys.VALUE_SERIALIZER))));

	Preconditions.checkState(StateMetaInfoSnapshot.BackendStateType.PRIORITY_QUEUE == snapshot.getBackendStateType());
}
 
Example #26
Source File: KeyedBackendSerializationProxy.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public void write(DataOutputView out) throws IOException {
	super.write(out);

	// write the compression format used to write each key-group
	out.writeBoolean(usingKeyGroupCompression);

	TypeSerializerSnapshotSerializationUtil.writeSerializerSnapshot(out, keySerializerSnapshot, keySerializer);

	// write individual registered keyed state metainfos
	out.writeShort(stateMetaInfoSnapshots.size());
	for (StateMetaInfoSnapshot metaInfoSnapshot : stateMetaInfoSnapshots) {
		StateMetaInfoSnapshotReadersWriters.getWriter().writeStateMetaInfoSnapshot(metaInfoSnapshot, out);
	}
}
 
Example #27
Source File: OperatorBackendSerializationProxy.java    From flink with Apache License 2.0 5 votes vote down vote up
public OperatorBackendSerializationProxy(
		List<StateMetaInfoSnapshot> operatorStateMetaInfoSnapshots,
		List<StateMetaInfoSnapshot> broadcastStateMetaInfoSnapshots) {

	this.operatorStateMetaInfoSnapshots = Preconditions.checkNotNull(operatorStateMetaInfoSnapshots);
	this.broadcastStateMetaInfoSnapshots = Preconditions.checkNotNull(broadcastStateMetaInfoSnapshots);
	Preconditions.checkArgument(
			operatorStateMetaInfoSnapshots.size() <= Short.MAX_VALUE &&
					broadcastStateMetaInfoSnapshots.size() <= Short.MAX_VALUE
	);
}
 
Example #28
Source File: SerializationProxiesTest.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
private void assertEqualStateMetaInfoSnapshots(StateMetaInfoSnapshot expected, StateMetaInfoSnapshot actual) {
	Assert.assertEquals(expected.getName(), actual.getName());
	Assert.assertEquals(expected.getBackendStateType(), actual.getBackendStateType());
	Assert.assertEquals(expected.getOptionsImmutable(), actual.getOptionsImmutable());
	Assert.assertEquals(
		expected.getSerializerSnapshotsImmutable(),
		actual.getSerializerSnapshotsImmutable());
}
 
Example #29
Source File: RocksIncrementalSnapshotStrategy.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
private RocksDBIncrementalSnapshotOperation(
	long checkpointId,
	@Nonnull CheckpointStreamFactory checkpointStreamFactory,
	@Nonnull SnapshotDirectory localBackupDirectory,
	@Nullable Set<StateHandleID> baseSstFiles,
	@Nonnull List<StateMetaInfoSnapshot> stateMetaInfoSnapshots) {

	this.checkpointStreamFactory = checkpointStreamFactory;
	this.baseSstFiles = baseSstFiles;
	this.checkpointId = checkpointId;
	this.localBackupDirectory = localBackupDirectory;
	this.stateMetaInfoSnapshots = stateMetaInfoSnapshots;
}
 
Example #30
Source File: SerializationProxiesTest.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Test
public void testBroadcastStateMetaInfoSerialization() throws Exception {

	String name = "test";
	TypeSerializer<?> keySerializer = DoubleSerializer.INSTANCE;
	TypeSerializer<?> valueSerializer = StringSerializer.INSTANCE;

	StateMetaInfoSnapshot snapshot =
		new RegisteredBroadcastStateBackendMetaInfo<>(
			name, OperatorStateHandle.Mode.BROADCAST, keySerializer, valueSerializer).snapshot();

	byte[] serialized;
	try (ByteArrayOutputStreamWithPos out = new ByteArrayOutputStreamWithPos()) {
		StateMetaInfoSnapshotReadersWriters.getWriter().
			writeStateMetaInfoSnapshot(snapshot, new DataOutputViewStreamWrapper(out));

		serialized = out.toByteArray();
	}

	try (ByteArrayInputStreamWithPos in = new ByteArrayInputStreamWithPos(serialized)) {
		final StateMetaInfoReader reader = StateMetaInfoSnapshotReadersWriters.getReader(
			CURRENT_STATE_META_INFO_SNAPSHOT_VERSION, StateMetaInfoSnapshotReadersWriters.StateTypeHint.OPERATOR_STATE);
		snapshot = reader.readStateMetaInfoSnapshot(
			new DataInputViewStreamWrapper(in), Thread.currentThread().getContextClassLoader());
	}

	RegisteredBroadcastStateBackendMetaInfo<?, ?> restoredMetaInfo =
		new RegisteredBroadcastStateBackendMetaInfo<>(snapshot);

	Assert.assertEquals(name, restoredMetaInfo.getName());
	Assert.assertEquals(
		OperatorStateHandle.Mode.BROADCAST,
		restoredMetaInfo.getAssignmentMode());
	Assert.assertEquals(keySerializer, restoredMetaInfo.getKeySerializer());
	Assert.assertEquals(valueSerializer, restoredMetaInfo.getValueSerializer());
}