org.apache.flink.runtime.state.ttl.TtlTimeProvider Java Examples

The following examples show how to use org.apache.flink.runtime.state.ttl.TtlTimeProvider. 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: StateSnapshotCompressionTest.java    From flink with Apache License 2.0 6 votes vote down vote up
private HeapKeyedStateBackend<String> getStringHeapKeyedStateBackend(
	ExecutionConfig executionConfig,
	Collection<KeyedStateHandle> stateHandles)
	throws BackendBuildingException {
	return new HeapKeyedStateBackendBuilder<>(
		mock(TaskKvStateRegistry.class),
		StringSerializer.INSTANCE,
		StateSnapshotCompressionTest.class.getClassLoader(),
		16,
		new KeyGroupRange(0, 15),
		executionConfig,
		TtlTimeProvider.DEFAULT,
		stateHandles,
		AbstractStateBackend.getCompressionDecorator(executionConfig),
		TestLocalRecoveryConfig.disabled(),
		mock(HeapPriorityQueueSetFactory.class),
		true,
		new CloseableRegistry()).build();
}
 
Example #2
Source File: AbstractKeyedStateBackendBuilder.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
public AbstractKeyedStateBackendBuilder(
	TaskKvStateRegistry kvStateRegistry,
	TypeSerializer<K> keySerializer,
	ClassLoader userCodeClassLoader,
	int numberOfKeyGroups,
	KeyGroupRange keyGroupRange,
	ExecutionConfig executionConfig,
	TtlTimeProvider ttlTimeProvider,
	@Nonnull Collection<KeyedStateHandle> stateHandles,
	StreamCompressionDecorator keyGroupCompressionDecorator,
	CloseableRegistry cancelStreamRegistry) {
	this.kvStateRegistry = kvStateRegistry;
	this.keySerializerProvider = StateSerializerProvider.fromNewRegisteredSerializer(keySerializer);
	this.userCodeClassLoader = userCodeClassLoader;
	this.numberOfKeyGroups = numberOfKeyGroups;
	this.keyGroupRange = keyGroupRange;
	this.executionConfig = executionConfig;
	this.ttlTimeProvider = ttlTimeProvider;
	this.keyGroupCompressionDecorator = keyGroupCompressionDecorator;
	this.restoreStateHandles = stateHandles;
	this.cancelStreamRegistry = cancelStreamRegistry;
}
 
Example #3
Source File: StateBackendMigrationTestBase.java    From flink with Apache License 2.0 6 votes vote down vote up
private <K> AbstractKeyedStateBackend<K> restoreKeyedBackend(
	TypeSerializer<K> keySerializer,
	int numberOfKeyGroups,
	KeyGroupRange keyGroupRange,
	List<KeyedStateHandle> state,
	Environment env) throws Exception {
	AbstractKeyedStateBackend<K> backend = getStateBackend().createKeyedStateBackend(
		env,
		new JobID(),
		"test_op",
		keySerializer,
		numberOfKeyGroups,
		keyGroupRange,
		env.getTaskKvStateRegistry(),
		TtlTimeProvider.DEFAULT,
		new UnregisteredMetricsGroup(),
		state,
		new CloseableRegistry());
	return backend;
}
 
Example #4
Source File: RocksDBTestUtils.java    From flink with Apache License 2.0 6 votes vote down vote up
public static <K> RocksDBKeyedStateBackend<K> createKeyedStateBackend(
		RocksDBStateBackend rocksDbBackend,
		Environment env,
		TypeSerializer<K> keySerializer) throws IOException {

	return (RocksDBKeyedStateBackend<K>) rocksDbBackend.createKeyedStateBackend(
		env,
		env.getJobID(),
		"test_op",
		keySerializer,
		1,
		new KeyGroupRange(0, 0),
		env.getTaskKvStateRegistry(),
		TtlTimeProvider.DEFAULT,
		new UnregisteredMetricsGroup(),
		Collections.emptyList(),
		new CloseableRegistry());
}
 
Example #5
Source File: HeapKeyedStateBackend.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
public HeapKeyedStateBackend(
	TaskKvStateRegistry kvStateRegistry,
	StateSerializerProvider<K> keySerializerProvider,
	ClassLoader userCodeClassLoader,
	int numberOfKeyGroups,
	KeyGroupRange keyGroupRange,
	ExecutionConfig executionConfig,
	TtlTimeProvider ttlTimeProvider,
	CloseableRegistry cancelStreamRegistry,
	StreamCompressionDecorator keyGroupCompressionDecorator,
	Map<String, StateTable<K, ?, ?>> registeredKVStates,
	Map<String, HeapPriorityQueueSnapshotRestoreWrapper> registeredPQStates,
	LocalRecoveryConfig localRecoveryConfig,
	HeapPriorityQueueSetFactory priorityQueueSetFactory,
	HeapSnapshotStrategy<K> snapshotStrategy
) {
	super(kvStateRegistry, keySerializerProvider, userCodeClassLoader, numberOfKeyGroups,
		keyGroupRange, executionConfig, ttlTimeProvider, cancelStreamRegistry, keyGroupCompressionDecorator);
	this.registeredKVStates = registeredKVStates;
	this.registeredPQStates = registeredPQStates;
	this.localRecoveryConfig = localRecoveryConfig;
	LOG.info("Initializing heap keyed state backend with stream factory.");
	this.priorityQueueSetFactory = priorityQueueSetFactory;
	this.snapshotStrategy = snapshotStrategy;
}
 
Example #6
Source File: AbstractKeyedStateBackend.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
public AbstractKeyedStateBackend(
	TaskKvStateRegistry kvStateRegistry,
	TypeSerializer<K> keySerializer,
	ClassLoader userCodeClassLoader,
	int numberOfKeyGroups,
	KeyGroupRange keyGroupRange,
	ExecutionConfig executionConfig,
	TtlTimeProvider ttlTimeProvider,
	CloseableRegistry cancelStreamRegistry) {
	this(
		kvStateRegistry,
		StateSerializerProvider.fromNewRegisteredSerializer(keySerializer),
		userCodeClassLoader,
		numberOfKeyGroups,
		keyGroupRange,
		executionConfig,
		ttlTimeProvider,
		cancelStreamRegistry,
		determineStreamCompression(executionConfig)
	);
}
 
Example #7
Source File: KvStateRequestSerializerTest.java    From flink with Apache License 2.0 6 votes vote down vote up
private HeapKeyedStateBackend<Long> getLongHeapKeyedStateBackend(final long key) throws BackendBuildingException {
	final KeyGroupRange keyGroupRange = new KeyGroupRange(0, 0);
	ExecutionConfig executionConfig = new ExecutionConfig();
	// objects for heap state list serialisation
	final HeapKeyedStateBackend<Long> longHeapKeyedStateBackend =
		new HeapKeyedStateBackendBuilder<>(
			mock(TaskKvStateRegistry.class),
			LongSerializer.INSTANCE,
			ClassLoader.getSystemClassLoader(),
			keyGroupRange.getNumberOfKeyGroups(),
			keyGroupRange,
			executionConfig,
			TtlTimeProvider.DEFAULT,
			Collections.emptyList(),
			AbstractStateBackend.getCompressionDecorator(executionConfig),
			TestLocalRecoveryConfig.disabled(),
			new HeapPriorityQueueSetFactory(keyGroupRange, keyGroupRange.getNumberOfKeyGroups(), 128),
			async,
			new CloseableRegistry()).build();
	longHeapKeyedStateBackend.setCurrentKey(key);
	return longHeapKeyedStateBackend;
}
 
Example #8
Source File: StateSnapshotCompressionTest.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
private HeapKeyedStateBackend<String> getStringHeapKeyedStateBackend(
	ExecutionConfig executionConfig,
	Collection<KeyedStateHandle> stateHandles)
	throws BackendBuildingException {
	return new HeapKeyedStateBackendBuilder<>(
		mock(TaskKvStateRegistry.class),
		StringSerializer.INSTANCE,
		StateSnapshotCompressionTest.class.getClassLoader(),
		16,
		new KeyGroupRange(0, 15),
		executionConfig,
		TtlTimeProvider.DEFAULT,
		stateHandles,
		AbstractStateBackend.getCompressionDecorator(executionConfig),
		TestLocalRecoveryConfig.disabled(),
		mock(HeapPriorityQueueSetFactory.class),
		true,
		new CloseableRegistry()).build();
}
 
Example #9
Source File: StateBackendTestBase.java    From flink with Apache License 2.0 6 votes vote down vote up
protected <K> AbstractKeyedStateBackend<K> restoreKeyedBackend(
		TypeSerializer<K> keySerializer,
		int numberOfKeyGroups,
		KeyGroupRange keyGroupRange,
		List<KeyedStateHandle> state,
		Environment env) throws Exception {

	AbstractKeyedStateBackend<K> backend = getStateBackend().createKeyedStateBackend(
		env,
		new JobID(),
		"test_op",
		keySerializer,
		numberOfKeyGroups,
		keyGroupRange,
		env.getTaskKvStateRegistry(),
		TtlTimeProvider.DEFAULT,
		new UnregisteredMetricsGroup(),
		state,
		new CloseableRegistry());

	return backend;
}
 
Example #10
Source File: HeapKeyedStateBackendAsyncByDefaultTest.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
private void validateSupportForAsyncSnapshots(StateBackend backend) throws Exception {

		AbstractKeyedStateBackend<Integer> keyedStateBackend = backend.createKeyedStateBackend(
			new DummyEnvironment("Test", 1, 0),
			new JobID(),
			"testOperator",
			IntSerializer.INSTANCE,
			1,
			new KeyGroupRange(0, 0),
			null,
			TtlTimeProvider.DEFAULT,
			new UnregisteredMetricsGroup(),
			Collections.emptyList(),
			new CloseableRegistry()
		);

		assertTrue(keyedStateBackend.supportsAsynchronousSnapshots());

		IOUtils.closeQuietly(keyedStateBackend);
		keyedStateBackend.dispose();
	}
 
Example #11
Source File: MockStateBackend.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
public <K> AbstractKeyedStateBackend<K> createKeyedStateBackend(
	Environment env,
	JobID jobID,
	String operatorIdentifier,
	TypeSerializer<K> keySerializer,
	int numberOfKeyGroups,
	KeyGroupRange keyGroupRange,
	TaskKvStateRegistry kvStateRegistry,
	TtlTimeProvider ttlTimeProvider,
	MetricGroup metricGroup,
	@Nonnull Collection<KeyedStateHandle> stateHandles,
	CloseableRegistry cancelStreamRegistry) {
	return new MockKeyedStateBackendBuilder<>(
		new KvStateRegistry().createTaskRegistry(jobID, new JobVertexID()),
		keySerializer,
		env.getUserClassLoader(),
		numberOfKeyGroups,
		keyGroupRange,
		env.getExecutionConfig(),
		ttlTimeProvider,
		stateHandles,
		AbstractStateBackend.getCompressionDecorator(env.getExecutionConfig()),
		cancelStreamRegistry).build();
}
 
Example #12
Source File: AbstractKeyedStateBackendBuilder.java    From flink with Apache License 2.0 6 votes vote down vote up
public AbstractKeyedStateBackendBuilder(
	TaskKvStateRegistry kvStateRegistry,
	TypeSerializer<K> keySerializer,
	ClassLoader userCodeClassLoader,
	int numberOfKeyGroups,
	KeyGroupRange keyGroupRange,
	ExecutionConfig executionConfig,
	TtlTimeProvider ttlTimeProvider,
	@Nonnull Collection<KeyedStateHandle> stateHandles,
	StreamCompressionDecorator keyGroupCompressionDecorator,
	CloseableRegistry cancelStreamRegistry) {
	this.kvStateRegistry = kvStateRegistry;
	this.keySerializerProvider = StateSerializerProvider.fromNewRegisteredSerializer(keySerializer);
	this.userCodeClassLoader = userCodeClassLoader;
	this.numberOfKeyGroups = numberOfKeyGroups;
	this.keyGroupRange = keyGroupRange;
	this.executionConfig = executionConfig;
	this.ttlTimeProvider = ttlTimeProvider;
	this.keyGroupCompressionDecorator = keyGroupCompressionDecorator;
	this.restoreStateHandles = stateHandles;
	this.cancelStreamRegistry = cancelStreamRegistry;
}
 
Example #13
Source File: TestSpyWrapperStateBackend.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@Override
public <K> AbstractKeyedStateBackend<K> createKeyedStateBackend(
	Environment env,
	JobID jobID,
	String operatorIdentifier,
	TypeSerializer<K> keySerializer,
	int numberOfKeyGroups,
	KeyGroupRange keyGroupRange,
	TaskKvStateRegistry kvStateRegistry,
	TtlTimeProvider ttlTimeProvider,
	MetricGroup metricGroup,
	@Nonnull Collection<KeyedStateHandle> stateHandles,
	CloseableRegistry cancelStreamRegistry) throws IOException {
	return spy(delegate.createKeyedStateBackend(
		env,
		jobID,
		operatorIdentifier,
		keySerializer,
		numberOfKeyGroups,
		keyGroupRange,
		kvStateRegistry,
		ttlTimeProvider,
		metricGroup,
		stateHandles,
		cancelStreamRegistry));
}
 
Example #14
Source File: StateSnapshotCompressionTest.java    From flink with Apache License 2.0 6 votes vote down vote up
private HeapKeyedStateBackend<String> getStringHeapKeyedStateBackend(
	ExecutionConfig executionConfig,
	Collection<KeyedStateHandle> stateHandles)
	throws BackendBuildingException {
	return new HeapKeyedStateBackendBuilder<>(
		mock(TaskKvStateRegistry.class),
		StringSerializer.INSTANCE,
		StateSnapshotCompressionTest.class.getClassLoader(),
		16,
		new KeyGroupRange(0, 15),
		executionConfig,
		TtlTimeProvider.DEFAULT,
		stateHandles,
		AbstractStateBackend.getCompressionDecorator(executionConfig),
		TestLocalRecoveryConfig.disabled(),
		mock(HeapPriorityQueueSetFactory.class),
		true,
		new CloseableRegistry()).build();
}
 
Example #15
Source File: MockStateBackend.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
public <K> AbstractKeyedStateBackend<K> createKeyedStateBackend(
	Environment env,
	JobID jobID,
	String operatorIdentifier,
	TypeSerializer<K> keySerializer,
	int numberOfKeyGroups,
	KeyGroupRange keyGroupRange,
	TaskKvStateRegistry kvStateRegistry,
	TtlTimeProvider ttlTimeProvider,
	MetricGroup metricGroup,
	@Nonnull Collection<KeyedStateHandle> stateHandles,
	CloseableRegistry cancelStreamRegistry) {
	return new MockKeyedStateBackendBuilder<>(
		new KvStateRegistry().createTaskRegistry(jobID, new JobVertexID()),
		keySerializer,
		env.getUserClassLoader(),
		numberOfKeyGroups,
		keyGroupRange,
		env.getExecutionConfig(),
		ttlTimeProvider,
		stateHandles,
		AbstractStateBackend.getCompressionDecorator(env.getExecutionConfig()),
		cancelStreamRegistry).build();
}
 
Example #16
Source File: StateBackendTestBase.java    From flink with Apache License 2.0 6 votes vote down vote up
protected <K> AbstractKeyedStateBackend<K> restoreKeyedBackend(
		TypeSerializer<K> keySerializer,
		int numberOfKeyGroups,
		KeyGroupRange keyGroupRange,
		List<KeyedStateHandle> state,
		Environment env) throws Exception {

	AbstractKeyedStateBackend<K> backend = getStateBackend().createKeyedStateBackend(
		env,
		new JobID(),
		"test_op",
		keySerializer,
		numberOfKeyGroups,
		keyGroupRange,
		env.getTaskKvStateRegistry(),
		TtlTimeProvider.DEFAULT,
		new UnregisteredMetricsGroup(),
		state,
		new CloseableRegistry());

	return backend;
}
 
Example #17
Source File: StateBackendTestBase.java    From flink with Apache License 2.0 6 votes vote down vote up
protected <K> AbstractKeyedStateBackend<K> createKeyedBackend(
		TypeSerializer<K> keySerializer,
		int numberOfKeyGroups,
		KeyGroupRange keyGroupRange,
		Environment env) throws Exception {

	AbstractKeyedStateBackend<K> backend = getStateBackend().createKeyedStateBackend(
		env,
		new JobID(),
		"test_op",
		keySerializer,
		numberOfKeyGroups,
		keyGroupRange,
		env.getTaskKvStateRegistry(),
		TtlTimeProvider.DEFAULT,
		new UnregisteredMetricsGroup(),
		Collections.emptyList(),
		new CloseableRegistry());

	return backend;
}
 
Example #18
Source File: MockKeyedStateBackendBuilder.java    From flink with Apache License 2.0 6 votes vote down vote up
public MockKeyedStateBackendBuilder(
	TaskKvStateRegistry kvStateRegistry,
	TypeSerializer<K> keySerializer,
	ClassLoader userCodeClassLoader,
	int numberOfKeyGroups,
	KeyGroupRange keyGroupRange,
	ExecutionConfig executionConfig,
	TtlTimeProvider ttlTimeProvider,
	@Nonnull Collection<KeyedStateHandle> stateHandles,
	StreamCompressionDecorator keyGroupCompressionDecorator,
	CloseableRegistry cancelStreamRegistry) {
	super(
		kvStateRegistry,
		keySerializer,
		userCodeClassLoader,
		numberOfKeyGroups,
		keyGroupRange,
		executionConfig,
		ttlTimeProvider,
		stateHandles,
		keyGroupCompressionDecorator,
		cancelStreamRegistry);
}
 
Example #19
Source File: AbstractKeyedStateBackend.java    From flink with Apache License 2.0 6 votes vote down vote up
public AbstractKeyedStateBackend(
	TaskKvStateRegistry kvStateRegistry,
	TypeSerializer<K> keySerializer,
	ClassLoader userCodeClassLoader,
	ExecutionConfig executionConfig,
	TtlTimeProvider ttlTimeProvider,
	CloseableRegistry cancelStreamRegistry,
	StreamCompressionDecorator keyGroupCompressionDecorator,
	InternalKeyContext<K> keyContext) {
	this.keyContext = Preconditions.checkNotNull(keyContext);
	this.numberOfKeyGroups = keyContext.getNumberOfKeyGroups();
	this.keyGroupRange = Preconditions.checkNotNull(keyContext.getKeyGroupRange());
	Preconditions.checkArgument(numberOfKeyGroups >= 1, "NumberOfKeyGroups must be a positive number");
	Preconditions.checkArgument(numberOfKeyGroups >= keyGroupRange.getNumberOfKeyGroups(), "The total number of key groups must be at least the number in the key group range assigned to this backend");

	this.kvStateRegistry = kvStateRegistry;
	this.keySerializer = keySerializer;
	this.userCodeClassLoader = Preconditions.checkNotNull(userCodeClassLoader);
	this.cancelStreamRegistry = cancelStreamRegistry;
	this.keyValueStatesByName = new HashMap<>();
	this.executionConfig = executionConfig;
	this.keyGroupCompressionDecorator = keyGroupCompressionDecorator;
	this.ttlTimeProvider = Preconditions.checkNotNull(ttlTimeProvider);
	this.keySelectionListeners = new ArrayList<>(1);
}
 
Example #20
Source File: AbstractKeyedStateBackendBuilder.java    From flink with Apache License 2.0 6 votes vote down vote up
public AbstractKeyedStateBackendBuilder(
	TaskKvStateRegistry kvStateRegistry,
	TypeSerializer<K> keySerializer,
	ClassLoader userCodeClassLoader,
	int numberOfKeyGroups,
	KeyGroupRange keyGroupRange,
	ExecutionConfig executionConfig,
	TtlTimeProvider ttlTimeProvider,
	@Nonnull Collection<KeyedStateHandle> stateHandles,
	StreamCompressionDecorator keyGroupCompressionDecorator,
	CloseableRegistry cancelStreamRegistry) {
	this.kvStateRegistry = kvStateRegistry;
	this.keySerializerProvider = StateSerializerProvider.fromNewRegisteredSerializer(keySerializer);
	this.userCodeClassLoader = userCodeClassLoader;
	this.numberOfKeyGroups = numberOfKeyGroups;
	this.keyGroupRange = keyGroupRange;
	this.executionConfig = executionConfig;
	this.ttlTimeProvider = ttlTimeProvider;
	this.keyGroupCompressionDecorator = keyGroupCompressionDecorator;
	this.restoreStateHandles = stateHandles;
	this.cancelStreamRegistry = cancelStreamRegistry;
}
 
Example #21
Source File: StateBackendBenchmarkUtils.java    From flink with Apache License 2.0 6 votes vote down vote up
private static HeapKeyedStateBackend<Long> createHeapKeyedStateBackend(File rootDir) throws IOException {
	File recoveryBaseDir = prepareDirectory(recoveryDirName, rootDir);
	KeyGroupRange keyGroupRange = new KeyGroupRange(0, 1);
	int numberOfKeyGroups = keyGroupRange.getNumberOfKeyGroups();
	ExecutionConfig executionConfig = new ExecutionConfig();
	HeapPriorityQueueSetFactory priorityQueueSetFactory =
		new HeapPriorityQueueSetFactory(keyGroupRange, numberOfKeyGroups, 128);
	HeapKeyedStateBackendBuilder<Long> backendBuilder = new HeapKeyedStateBackendBuilder<>(
		null,
		new LongSerializer(),
		Thread.currentThread().getContextClassLoader(),
		numberOfKeyGroups,
		keyGroupRange,
		executionConfig,
		TtlTimeProvider.DEFAULT,
		Collections.emptyList(),
		AbstractStateBackend.getCompressionDecorator(executionConfig),
		new LocalRecoveryConfig(false, new LocalRecoveryDirectoryProviderImpl(recoveryBaseDir, new JobID(), new JobVertexID(), 0)),
		priorityQueueSetFactory,
		false,
		new CloseableRegistry()
	);
	return backendBuilder.build();
}
 
Example #22
Source File: RocksDBStateBackendConfigTest.java    From flink with Apache License 2.0 6 votes vote down vote up
static RocksDBKeyedStateBackend<Integer> createKeyedStateBackend(
		RocksDBStateBackend rocksDbBackend, Environment env) throws Exception {

	return (RocksDBKeyedStateBackend<Integer>) rocksDbBackend.createKeyedStateBackend(
		env,
		env.getJobID(),
		"test_op",
		IntSerializer.INSTANCE,
		1,
		new KeyGroupRange(0, 0),
		env.getTaskKvStateRegistry(),
		TtlTimeProvider.DEFAULT,
		new UnregisteredMetricsGroup(),
		Collections.emptyList(),
		new CloseableRegistry());
}
 
Example #23
Source File: AbstractKeyedStateBackend.java    From flink with Apache License 2.0 6 votes vote down vote up
public AbstractKeyedStateBackend(
	TaskKvStateRegistry kvStateRegistry,
	TypeSerializer<K> keySerializer,
	ClassLoader userCodeClassLoader,
	ExecutionConfig executionConfig,
	TtlTimeProvider ttlTimeProvider,
	CloseableRegistry cancelStreamRegistry,
	StreamCompressionDecorator keyGroupCompressionDecorator,
	InternalKeyContext<K> keyContext) {
	this.keyContext = Preconditions.checkNotNull(keyContext);
	this.numberOfKeyGroups = keyContext.getNumberOfKeyGroups();
	this.keyGroupRange = Preconditions.checkNotNull(keyContext.getKeyGroupRange());
	Preconditions.checkArgument(numberOfKeyGroups >= 1, "NumberOfKeyGroups must be a positive number");
	Preconditions.checkArgument(numberOfKeyGroups >= keyGroupRange.getNumberOfKeyGroups(), "The total number of key groups must be at least the number in the key group range assigned to this backend");

	this.kvStateRegistry = kvStateRegistry;
	this.keySerializer = keySerializer;
	this.userCodeClassLoader = Preconditions.checkNotNull(userCodeClassLoader);
	this.cancelStreamRegistry = cancelStreamRegistry;
	this.keyValueStatesByName = new HashMap<>();
	this.executionConfig = executionConfig;
	this.keyGroupCompressionDecorator = keyGroupCompressionDecorator;
	this.ttlTimeProvider = Preconditions.checkNotNull(ttlTimeProvider);
	this.keySelectionListeners = new ArrayList<>(1);
}
 
Example #24
Source File: AbstractKeyedStateBackend.java    From flink with Apache License 2.0 6 votes vote down vote up
public AbstractKeyedStateBackend(
	TaskKvStateRegistry kvStateRegistry,
	TypeSerializer<K> keySerializer,
	ClassLoader userCodeClassLoader,
	ExecutionConfig executionConfig,
	TtlTimeProvider ttlTimeProvider,
	CloseableRegistry cancelStreamRegistry,
	InternalKeyContext<K> keyContext) {
	this(
		kvStateRegistry,
		keySerializer,
		userCodeClassLoader,
		executionConfig,
		ttlTimeProvider,
		cancelStreamRegistry,
		determineStreamCompression(executionConfig),
		keyContext
	);
}
 
Example #25
Source File: KvStateRequestSerializerTest.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
private HeapKeyedStateBackend<Long> getLongHeapKeyedStateBackend(final long key) throws BackendBuildingException {
	final KeyGroupRange keyGroupRange = new KeyGroupRange(0, 0);
	ExecutionConfig executionConfig = new ExecutionConfig();
	// objects for heap state list serialisation
	final HeapKeyedStateBackend<Long> longHeapKeyedStateBackend =
		new HeapKeyedStateBackendBuilder<>(
			mock(TaskKvStateRegistry.class),
			LongSerializer.INSTANCE,
			ClassLoader.getSystemClassLoader(),
			keyGroupRange.getNumberOfKeyGroups(),
			keyGroupRange,
			executionConfig,
			TtlTimeProvider.DEFAULT,
			Collections.emptyList(),
			AbstractStateBackend.getCompressionDecorator(executionConfig),
			TestLocalRecoveryConfig.disabled(),
			new HeapPriorityQueueSetFactory(keyGroupRange, keyGroupRange.getNumberOfKeyGroups(), 128),
			async,
			new CloseableRegistry()).build();
	longHeapKeyedStateBackend.setCurrentKey(key);
	return longHeapKeyedStateBackend;
}
 
Example #26
Source File: StreamingRuntimeContextTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
private static AbstractStreamOperator<?> createListPlainMockOp() throws Exception {

	AbstractStreamOperator<?> operatorMock = mock(AbstractStreamOperator.class);
	ExecutionConfig config = new ExecutionConfig();

	KeyedStateBackend keyedStateBackend = mock(KeyedStateBackend.class);

	DefaultKeyedStateStore keyedStateStore = new DefaultKeyedStateStore(keyedStateBackend, config);

	when(operatorMock.getExecutionConfig()).thenReturn(config);

	doAnswer(new Answer<ListState<String>>() {

		@Override
		public ListState<String> answer(InvocationOnMock invocationOnMock) throws Throwable {
			ListStateDescriptor<String> descr =
					(ListStateDescriptor<String>) invocationOnMock.getArguments()[2];

			AbstractKeyedStateBackend<Integer> backend = new MemoryStateBackend().createKeyedStateBackend(
				new DummyEnvironment("test_task", 1, 0),
				new JobID(),
				"test_op",
				IntSerializer.INSTANCE,
				1,
				new KeyGroupRange(0, 0),
				new KvStateRegistry().createTaskRegistry(new JobID(), new JobVertexID()),
				TtlTimeProvider.DEFAULT,
				new UnregisteredMetricsGroup(),
				Collections.emptyList(),
				new CloseableRegistry());
			backend.setCurrentKey(0);
			return backend.getPartitionedState(VoidNamespace.INSTANCE, VoidNamespaceSerializer.INSTANCE, descr);
		}
	}).when(keyedStateBackend).getPartitionedState(Matchers.any(), any(TypeSerializer.class), any(ListStateDescriptor.class));

	when(operatorMock.getKeyedStateStore()).thenReturn(keyedStateStore);
	when(operatorMock.getOperatorID()).thenReturn(new OperatorID());
	return operatorMock;
}
 
Example #27
Source File: TriggerTestHarness.java    From flink with Apache License 2.0 5 votes vote down vote up
public TriggerTestHarness(
		Trigger<T, W> trigger,
		TypeSerializer<W> windowSerializer) throws Exception {
	this.trigger = trigger;
	this.windowSerializer = windowSerializer;

	// we only ever use one key, other tests make sure that windows work across different
	// keys
	DummyEnvironment dummyEnv = new DummyEnvironment("test", 1, 0);
	MemoryStateBackend backend = new MemoryStateBackend();

	@SuppressWarnings("unchecked")
	HeapKeyedStateBackend<Integer> stateBackend = (HeapKeyedStateBackend<Integer>) backend.createKeyedStateBackend(
		dummyEnv,
		new JobID(),
		"test_op",
		IntSerializer.INSTANCE,
		1,
		new KeyGroupRange(0, 0),
		new KvStateRegistry().createTaskRegistry(new JobID(), new JobVertexID()),
		TtlTimeProvider.DEFAULT,
		new UnregisteredMetricsGroup(),
		Collections.emptyList(),
		new CloseableRegistry());
	this.stateBackend = stateBackend;

	this.stateBackend.setCurrentKey(KEY);

	this.internalTimerService = new TestInternalTimerService<>(new KeyContext() {
		@Override
		public void setCurrentKey(Object key) {
			// ignore
		}

		@Override
		public Object getCurrentKey() {
			return KEY;
		}
	});
}
 
Example #28
Source File: StateBackendITCase.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public <K> AbstractKeyedStateBackend<K> createKeyedStateBackend(
	Environment env,
	JobID jobID,
	String operatorIdentifier,
	TypeSerializer<K> keySerializer,
	int numberOfKeyGroups,
	KeyGroupRange keyGroupRange,
	TaskKvStateRegistry kvStateRegistry,
	TtlTimeProvider ttlTimeProvider,
	MetricGroup metricGroup,
	@Nonnull Collection<KeyedStateHandle> stateHandles,
	CloseableRegistry cancelStreamRegistry) throws IOException {
	throw new SuccessException();
}
 
Example #29
Source File: CheckpointSettingsSerializableTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public <K> AbstractKeyedStateBackend<K> createKeyedStateBackend(
	Environment env,
	JobID jobID,
	String operatorIdentifier,
	TypeSerializer<K> keySerializer,
	int numberOfKeyGroups,
	KeyGroupRange keyGroupRange,
	TaskKvStateRegistry kvStateRegistry,
	TtlTimeProvider ttlTimeProvider,
	MetricGroup metricGroup,
	@Nonnull Collection<KeyedStateHandle> stateHandles,
	CloseableRegistry cancelStreamRegistry) throws Exception {
	throw new UnsupportedOperationException();
}
 
Example #30
Source File: KVStateRequestSerializerRocksDBTest.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
/**
 * Tests list serialization and deserialization match.
 *
 * @see KvStateRequestSerializerTest#testListSerialization()
 * KvStateRequestSerializerTest#testListSerialization() using the heap state back-end
 * test
 */
@Test
public void testListSerialization() throws Exception {
	final long key = 0L;

	// objects for RocksDB state list serialisation
	DBOptions dbOptions = PredefinedOptions.DEFAULT.createDBOptions();
	dbOptions.setCreateIfMissing(true);
	ExecutionConfig executionConfig = new ExecutionConfig();
	final RocksDBKeyedStateBackend<Long> longHeapKeyedStateBackend =
		new RocksDBKeyedStateBackendBuilder<>(
			"no-op",
			ClassLoader.getSystemClassLoader(),
			temporaryFolder.getRoot(),
			dbOptions,
			stateName -> PredefinedOptions.DEFAULT.createColumnOptions(),
			mock(TaskKvStateRegistry.class),
			LongSerializer.INSTANCE,
			1,
			new KeyGroupRange(0, 0),
			executionConfig,
			TestLocalRecoveryConfig.disabled(),
			RocksDBStateBackend.PriorityQueueStateType.HEAP,
			TtlTimeProvider.DEFAULT,
			new UnregisteredMetricsGroup(),
			Collections.emptyList(),
			AbstractStateBackend.getCompressionDecorator(executionConfig),
			new CloseableRegistry()
		).build();
	longHeapKeyedStateBackend.setCurrentKey(key);

	final InternalListState<Long, VoidNamespace, Long> listState = longHeapKeyedStateBackend.createInternalState(VoidNamespaceSerializer.INSTANCE,
			new ListStateDescriptor<>("test", LongSerializer.INSTANCE));

	KvStateRequestSerializerTest.testListSerialization(key, listState);
	longHeapKeyedStateBackend.dispose();
}