org.apache.flink.streaming.runtime.tasks.ProcessingTimeService Java Examples

The following examples show how to use org.apache.flink.streaming.runtime.tasks.ProcessingTimeService. 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: InternalTimerServiceImpl.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
InternalTimerServiceImpl(
	KeyGroupRange localKeyGroupRange,
	KeyContext keyContext,
	ProcessingTimeService processingTimeService,
	KeyGroupedInternalPriorityQueue<TimerHeapInternalTimer<K, N>> processingTimeTimersQueue,
	KeyGroupedInternalPriorityQueue<TimerHeapInternalTimer<K, N>> eventTimeTimersQueue) {

	this.keyContext = checkNotNull(keyContext);
	this.processingTimeService = checkNotNull(processingTimeService);
	this.localKeyGroupRange = checkNotNull(localKeyGroupRange);
	this.processingTimeTimersQueue = checkNotNull(processingTimeTimersQueue);
	this.eventTimeTimersQueue = checkNotNull(eventTimeTimersQueue);

	// find the starting index of the local key-group range
	int startIdx = Integer.MAX_VALUE;
	for (Integer keyGroupIdx : localKeyGroupRange) {
		startIdx = Math.min(keyGroupIdx, startIdx);
	}
	this.localKeyGroupRangeStartIdx = startIdx;
}
 
Example #2
Source File: InternalTimerServiceImplTest.java    From flink with Apache License 2.0 6 votes vote down vote up
private static <K, N> InternalTimerServiceImpl<K, N> createInternalTimerService(
	KeyGroupRange keyGroupsList,
	KeyContext keyContext,
	ProcessingTimeService processingTimeService,
	TypeSerializer<K> keySerializer,
	TypeSerializer<N> namespaceSerializer,
	PriorityQueueSetFactory priorityQueueSetFactory) {

	TimerSerializer<K, N> timerSerializer = new TimerSerializer<>(keySerializer, namespaceSerializer);

	return new InternalTimerServiceImpl<>(
		keyGroupsList,
		keyContext,
		processingTimeService,
		createTimerQueue("__test_processing_timers", timerSerializer, priorityQueueSetFactory),
		createTimerQueue("__test_event_timers", timerSerializer, priorityQueueSetFactory));
}
 
Example #3
Source File: TestingSourceOperator.java    From flink with Apache License 2.0 6 votes vote down vote up
public TestingSourceOperator(
		SourceReader<T, MockSourceSplit> reader,
		WatermarkStrategy<T> watermarkStrategy,
		ProcessingTimeService timeService,
		OperatorEventGateway eventGateway,
		int subtaskIndex,
		int parallelism) {

	super(
		(context) -> reader,
		eventGateway,
		new MockSourceSplitSerializer(),
		watermarkStrategy,
		timeService);

	this.subtaskIndex = subtaskIndex;
	this.parallelism = parallelism;
	this.metrics = UnregisteredMetricGroups.createUnregisteredOperatorMetricGroup();
}
 
Example #4
Source File: StreamSourceContexts.java    From flink with Apache License 2.0 6 votes vote down vote up
private AutomaticWatermarkContext(
		final Output<StreamRecord<T>> output,
		final long watermarkInterval,
		final ProcessingTimeService timeService,
		final Object checkpointLock,
		final StreamStatusMaintainer streamStatusMaintainer,
		final long idleTimeout) {

	super(timeService, checkpointLock, streamStatusMaintainer, idleTimeout);

	this.output = Preconditions.checkNotNull(output, "The output cannot be null.");

	Preconditions.checkArgument(watermarkInterval >= 1L, "The watermark interval cannot be smaller than 1 ms.");
	this.watermarkInterval = watermarkInterval;

	this.reuse = new StreamRecord<>(null);

	this.lastRecordTime = Long.MIN_VALUE;

	long now = this.timeService.getCurrentProcessingTime();
	this.nextWatermarkTimer = this.timeService.registerTimer(now + watermarkInterval,
		new WatermarkEmittingTask(this.timeService, checkpointLock, output));
}
 
Example #5
Source File: StreamSourceContexts.java    From flink with Apache License 2.0 6 votes vote down vote up
private AutomaticWatermarkContext(
		final Output<StreamRecord<T>> output,
		final long watermarkInterval,
		final ProcessingTimeService timeService,
		final Object checkpointLock,
		final StreamStatusMaintainer streamStatusMaintainer,
		final long idleTimeout) {

	super(timeService, checkpointLock, streamStatusMaintainer, idleTimeout);

	this.output = Preconditions.checkNotNull(output, "The output cannot be null.");

	Preconditions.checkArgument(watermarkInterval >= 1L, "The watermark interval cannot be smaller than 1 ms.");
	this.watermarkInterval = watermarkInterval;

	this.reuse = new StreamRecord<>(null);

	this.lastRecordTime = Long.MIN_VALUE;

	long now = this.timeService.getCurrentProcessingTime();
	this.nextWatermarkTimer = this.timeService.registerTimer(now + watermarkInterval,
		new WatermarkEmittingTask(this.timeService, checkpointLock, output));
}
 
Example #6
Source File: StreamSourceContexts.java    From flink with Apache License 2.0 6 votes vote down vote up
/**
 * Create a watermark context.
 *
 * @param timeService the time service to schedule idleness detection tasks
 * @param checkpointLock the checkpoint lock
 * @param streamStatusMaintainer the stream status maintainer to toggle and retrieve current status
 * @param idleTimeout (-1 if idleness checking is disabled)
 */
public WatermarkContext(
		final ProcessingTimeService timeService,
		final Object checkpointLock,
		final StreamStatusMaintainer streamStatusMaintainer,
		final long idleTimeout) {

	this.timeService = Preconditions.checkNotNull(timeService, "Time Service cannot be null.");
	this.checkpointLock = Preconditions.checkNotNull(checkpointLock, "Checkpoint Lock cannot be null.");
	this.streamStatusMaintainer = Preconditions.checkNotNull(streamStatusMaintainer, "Stream Status Maintainer cannot be null.");

	if (idleTimeout != -1) {
		Preconditions.checkArgument(idleTimeout >= 1, "The idle timeout cannot be smaller than 1 ms.");
	}
	this.idleTimeout = idleTimeout;

	scheduleNextIdleDetectionTask();
}
 
Example #7
Source File: AbstractFetcherTest.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
TestFetcher(
		SourceContext<T> sourceContext,
		Map<KafkaTopicPartition, Long> assignedPartitionsWithStartOffsets,
		SerializedValue<AssignerWithPeriodicWatermarks<T>> watermarksPeriodic,
		SerializedValue<AssignerWithPunctuatedWatermarks<T>> watermarksPunctuated,
		ProcessingTimeService processingTimeProvider,
		long autoWatermarkInterval) throws Exception {

	this(
		sourceContext,
		assignedPartitionsWithStartOffsets,
		watermarksPeriodic,
		watermarksPunctuated,
		processingTimeProvider,
		autoWatermarkInterval,
		null,
		null);
}
 
Example #8
Source File: AbstractFetcherTest.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
TestFetcher(
		SourceContext<T> sourceContext,
		Map<KafkaTopicPartition, Long> assignedPartitionsWithStartOffsets,
		SerializedValue<AssignerWithPeriodicWatermarks<T>> watermarksPeriodic,
		SerializedValue<AssignerWithPunctuatedWatermarks<T>> watermarksPunctuated,
		ProcessingTimeService processingTimeProvider,
		long autoWatermarkInterval,
		OneShotLatch fetchLoopWaitLatch,
		OneShotLatch stateIterationBlockLatch) throws Exception {

	super(
		sourceContext,
		assignedPartitionsWithStartOffsets,
		watermarksPeriodic,
		watermarksPunctuated,
		processingTimeProvider,
		autoWatermarkInterval,
		TestFetcher.class.getClassLoader(),
		new UnregisteredMetricsGroup(),
		false);

	this.fetchLoopWaitLatch = fetchLoopWaitLatch;
	this.stateIterationBlockLatch = stateIterationBlockLatch;
}
 
Example #9
Source File: AsyncWaitOperator.java    From flink with Apache License 2.0 6 votes vote down vote up
public AsyncWaitOperator(
		@Nonnull AsyncFunction<IN, OUT> asyncFunction,
		long timeout,
		int capacity,
		@Nonnull AsyncDataStream.OutputMode outputMode,
		@Nonnull ProcessingTimeService processingTimeService,
		@Nonnull MailboxExecutor mailboxExecutor) {
	super(asyncFunction);

	setChainingStrategy(ChainingStrategy.ALWAYS);

	Preconditions.checkArgument(capacity > 0, "The number of concurrent async operation should be greater than 0.");
	this.capacity = capacity;

	this.outputMode = Preconditions.checkNotNull(outputMode, "outputMode");

	this.timeout = timeout;

	this.processingTimeService = Preconditions.checkNotNull(processingTimeService);

	this.mailboxExecutor = mailboxExecutor;
}
 
Example #10
Source File: InternalTimerServiceImpl.java    From flink with Apache License 2.0 6 votes vote down vote up
InternalTimerServiceImpl(
	KeyGroupRange localKeyGroupRange,
	KeyContext keyContext,
	ProcessingTimeService processingTimeService,
	KeyGroupedInternalPriorityQueue<TimerHeapInternalTimer<K, N>> processingTimeTimersQueue,
	KeyGroupedInternalPriorityQueue<TimerHeapInternalTimer<K, N>> eventTimeTimersQueue) {

	this.keyContext = checkNotNull(keyContext);
	this.processingTimeService = checkNotNull(processingTimeService);
	this.localKeyGroupRange = checkNotNull(localKeyGroupRange);
	this.processingTimeTimersQueue = checkNotNull(processingTimeTimersQueue);
	this.eventTimeTimersQueue = checkNotNull(eventTimeTimersQueue);

	// find the starting index of the local key-group range
	int startIdx = Integer.MAX_VALUE;
	for (Integer keyGroupIdx : localKeyGroupRange) {
		startIdx = Math.min(keyGroupIdx, startIdx);
	}
	this.localKeyGroupRangeStartIdx = startIdx;
}
 
Example #11
Source File: StreamSourceContexts.java    From flink with Apache License 2.0 6 votes vote down vote up
/**
 * Create a watermark context.
 *
 * @param timeService the time service to schedule idleness detection tasks
 * @param checkpointLock the checkpoint lock
 * @param streamStatusMaintainer the stream status maintainer to toggle and retrieve current status
 * @param idleTimeout (-1 if idleness checking is disabled)
 */
public WatermarkContext(
		final ProcessingTimeService timeService,
		final Object checkpointLock,
		final StreamStatusMaintainer streamStatusMaintainer,
		final long idleTimeout) {

	this.timeService = Preconditions.checkNotNull(timeService, "Time Service cannot be null.");
	this.checkpointLock = Preconditions.checkNotNull(checkpointLock, "Checkpoint Lock cannot be null.");
	this.streamStatusMaintainer = Preconditions.checkNotNull(streamStatusMaintainer, "Stream Status Maintainer cannot be null.");

	if (idleTimeout != -1) {
		Preconditions.checkArgument(idleTimeout >= 1, "The idle timeout cannot be smaller than 1 ms.");
	}
	this.idleTimeout = idleTimeout;

	scheduleNextIdleDetectionTask();
}
 
Example #12
Source File: StreamSourceContexts.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
private AutomaticWatermarkContext(
		final Output<StreamRecord<T>> output,
		final long watermarkInterval,
		final ProcessingTimeService timeService,
		final Object checkpointLock,
		final StreamStatusMaintainer streamStatusMaintainer,
		final long idleTimeout) {

	super(timeService, checkpointLock, streamStatusMaintainer, idleTimeout);

	this.output = Preconditions.checkNotNull(output, "The output cannot be null.");

	Preconditions.checkArgument(watermarkInterval >= 1L, "The watermark interval cannot be smaller than 1 ms.");
	this.watermarkInterval = watermarkInterval;

	this.reuse = new StreamRecord<>(null);

	this.lastRecordTime = Long.MIN_VALUE;

	long now = this.timeService.getCurrentProcessingTime();
	this.nextWatermarkTimer = this.timeService.registerTimer(now + watermarkInterval,
		new WatermarkEmittingTask(this.timeService, checkpointLock, output));
}
 
Example #13
Source File: InternalTimerServiceImplTest.java    From flink with Apache License 2.0 6 votes vote down vote up
private static InternalTimerServiceImpl<Integer, String> createAndStartInternalTimerService(
		Triggerable<Integer, String> triggerable,
		KeyContext keyContext,
		ProcessingTimeService processingTimeService,
		KeyGroupRange keyGroupList,
		PriorityQueueSetFactory priorityQueueSetFactory) {
	InternalTimerServiceImpl<Integer, String> service = createInternalTimerService(
		keyGroupList,
		keyContext,
		processingTimeService,
		IntSerializer.INSTANCE,
		StringSerializer.INSTANCE,
		priorityQueueSetFactory);

	service.startTimerService(IntSerializer.INSTANCE, StringSerializer.INSTANCE, triggerable);
	return service;
}
 
Example #14
Source File: StreamingFileSinkHelper.java    From flink with Apache License 2.0 6 votes vote down vote up
public StreamingFileSinkHelper(
		Buckets<IN, ?> buckets,
		boolean isRestored,
		OperatorStateStore stateStore,
		ProcessingTimeService procTimeService,
		long bucketCheckInterval) throws Exception {
	this.bucketCheckInterval = bucketCheckInterval;
	this.buckets = buckets;
	this.bucketStates = stateStore.getListState(BUCKET_STATE_DESC);
	this.maxPartCountersState = stateStore.getUnionListState(MAX_PART_COUNTER_STATE_DESC);
	this.procTimeService = procTimeService;

	if (isRestored) {
		buckets.initializeState(bucketStates, maxPartCountersState);
	}

	long currentProcessingTime = procTimeService.getCurrentProcessingTime();
	procTimeService.registerTimer(currentProcessingTime + bucketCheckInterval, this);
}
 
Example #15
Source File: StreamSourceContexts.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
/**
 * Create a watermark context.
 *
 * @param timeService the time service to schedule idleness detection tasks
 * @param checkpointLock the checkpoint lock
 * @param streamStatusMaintainer the stream status maintainer to toggle and retrieve current status
 * @param idleTimeout (-1 if idleness checking is disabled)
 */
public WatermarkContext(
		final ProcessingTimeService timeService,
		final Object checkpointLock,
		final StreamStatusMaintainer streamStatusMaintainer,
		final long idleTimeout) {

	this.timeService = Preconditions.checkNotNull(timeService, "Time Service cannot be null.");
	this.checkpointLock = Preconditions.checkNotNull(checkpointLock, "Checkpoint Lock cannot be null.");
	this.streamStatusMaintainer = Preconditions.checkNotNull(streamStatusMaintainer, "Stream Status Maintainer cannot be null.");

	if (idleTimeout != -1) {
		Preconditions.checkArgument(idleTimeout >= 1, "The idle timeout cannot be smaller than 1 ms.");
	}
	this.idleTimeout = idleTimeout;

	scheduleNextIdleDetectionTask();
}
 
Example #16
Source File: AbstractFetcherTest.java    From flink with Apache License 2.0 6 votes vote down vote up
TestFetcher(
		SourceContext<T> sourceContext,
		Map<KafkaTopicPartition, Long> assignedPartitionsWithStartOffsets,
		SerializedValue<WatermarkStrategy<T>> watermarkStrategy,
		ProcessingTimeService processingTimeProvider,
		long autoWatermarkInterval,
		OneShotLatch fetchLoopWaitLatch,
		OneShotLatch stateIterationBlockLatch) throws Exception {

	super(
		sourceContext,
		assignedPartitionsWithStartOffsets,
		watermarkStrategy,
		processingTimeProvider,
		autoWatermarkInterval,
		TestFetcher.class.getClassLoader(),
		new UnregisteredMetricsGroup(),
		false);

	this.fetchLoopWaitLatch = fetchLoopWaitLatch;
	this.stateIterationBlockLatch = stateIterationBlockLatch;
}
 
Example #17
Source File: AbstractFetcherTest.java    From flink with Apache License 2.0 6 votes vote down vote up
TestFetcher(
		SourceContext<T> sourceContext,
		Map<KafkaTopicPartition, Long> assignedPartitionsWithStartOffsets,
		SerializedValue<WatermarkStrategy<T>> watermarkStrategy,
		ProcessingTimeService processingTimeProvider,
		long autoWatermarkInterval) throws Exception {

	this(
		sourceContext,
		assignedPartitionsWithStartOffsets,
		watermarkStrategy,
		processingTimeProvider,
		autoWatermarkInterval,
		null,
		null);
}
 
Example #18
Source File: InternalTimerServiceImplTest.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
private static <K, N> InternalTimerServiceImpl<K, N> createInternalTimerService(
	KeyGroupRange keyGroupsList,
	KeyContext keyContext,
	ProcessingTimeService processingTimeService,
	TypeSerializer<K> keySerializer,
	TypeSerializer<N> namespaceSerializer,
	PriorityQueueSetFactory priorityQueueSetFactory) {

	TimerSerializer<K, N> timerSerializer = new TimerSerializer<>(keySerializer, namespaceSerializer);

	return new InternalTimerServiceImpl<>(
		keyGroupsList,
		keyContext,
		processingTimeService,
		createTimerQueue("__test_processing_timers", timerSerializer, priorityQueueSetFactory),
		createTimerQueue("__test_event_timers", timerSerializer, priorityQueueSetFactory));
}
 
Example #19
Source File: SourceOperatorFactory.java    From flink with Apache License 2.0 6 votes vote down vote up
/**
 * This is a utility method to conjure up a "SplitT" generics variable binding so that we can
 * construct the SourceOperator without resorting to "all raw types".
 * That way, this methods puts all "type non-safety" in one place and allows to maintain as much
 * generics safety in the main code as possible.
 */
@SuppressWarnings("unchecked")
private static <T, SplitT extends SourceSplit> SourceOperator<T, SplitT> instantiateSourceOperator(
		Function<SourceReaderContext, SourceReader<T, ?>> readerFactory,
		OperatorEventGateway eventGateway,
		SimpleVersionedSerializer<?> splitSerializer,
		WatermarkStrategy<T> watermarkStrategy,
		ProcessingTimeService timeService) {

	// jumping through generics hoops: cast the generics away to then cast them back more strictly typed
	final Function<SourceReaderContext, SourceReader<T, SplitT>> typedReaderFactory =
			(Function<SourceReaderContext, SourceReader<T, SplitT>>) (Function<?, ?>) readerFactory;

	final SimpleVersionedSerializer<SplitT> typedSplitSerializer = (SimpleVersionedSerializer<SplitT>) splitSerializer;

	return new SourceOperator<>(
			typedReaderFactory,
			eventGateway,
			typedSplitSerializer,
			watermarkStrategy,
			timeService);
}
 
Example #20
Source File: ExecutableStageDoFnOperator.java    From beam with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("FutureReturnValueIgnored")
private void finishBundleCallback() {
  minEventTimeTimerTimestampInLastBundle = minEventTimeTimerTimestampInCurrentBundle;
  minEventTimeTimerTimestampInCurrentBundle = Long.MAX_VALUE;
  try {
    if (!closed
        && minEventTimeTimerTimestampInLastBundle < Long.MAX_VALUE
        && minEventTimeTimerTimestampInLastBundle <= getEffectiveInputWatermark()) {
      ProcessingTimeService processingTimeService = getProcessingTimeService();
      // We are scheduling a timer for advancing the watermark, to not delay finishing the bundle
      // and temporarily release the checkpoint lock. Otherwise, we could potentially loop when a
      // timer keeps scheduling a timer for the same timestamp.
      processingTimeService.registerTimer(
          processingTimeService.getCurrentProcessingTime(),
          ts -> processWatermark1(new Watermark(getEffectiveInputWatermark())));
    } else {
      processWatermark1(new Watermark(getEffectiveInputWatermark()));
    }
  } catch (Exception e) {
    throw new RuntimeException(
        "Failed to progress watermark to " + getEffectiveInputWatermark(), e);
  }
}
 
Example #21
Source File: FlinkKafkaConsumerBaseTest.java    From flink with Apache License 2.0 6 votes vote down vote up
protected TestingFetcher(
		SourceFunction.SourceContext<T> sourceContext,
		Map<KafkaTopicPartition, Long> seedPartitionsWithInitialOffsets,
		SerializedValue<WatermarkStrategy<T>> watermarkStrategy,
		ProcessingTimeService processingTimeProvider,
		long autoWatermarkInterval,
		ClassLoader userCodeClassLoader,
		MetricGroup consumerMetricGroup,
		boolean useMetrics) throws Exception {
	super(
			sourceContext,
			seedPartitionsWithInitialOffsets,
			watermarkStrategy,
			processingTimeProvider,
			autoWatermarkInterval,
			userCodeClassLoader,
			consumerMetricGroup,
			useMetrics);
}
 
Example #22
Source File: AbstractFetcherTest.java    From flink with Apache License 2.0 6 votes vote down vote up
TestFetcher(
		SourceContext<T> sourceContext,
		Map<KafkaTopicPartition, Long> assignedPartitionsWithStartOffsets,
		SerializedValue<AssignerWithPeriodicWatermarks<T>> watermarksPeriodic,
		SerializedValue<AssignerWithPunctuatedWatermarks<T>> watermarksPunctuated,
		ProcessingTimeService processingTimeProvider,
		long autoWatermarkInterval,
		OneShotLatch fetchLoopWaitLatch,
		OneShotLatch stateIterationBlockLatch) throws Exception {

	super(
		sourceContext,
		assignedPartitionsWithStartOffsets,
		watermarksPeriodic,
		watermarksPunctuated,
		processingTimeProvider,
		autoWatermarkInterval,
		TestFetcher.class.getClassLoader(),
		new UnregisteredMetricsGroup(),
		false);

	this.fetchLoopWaitLatch = fetchLoopWaitLatch;
	this.stateIterationBlockLatch = stateIterationBlockLatch;
}
 
Example #23
Source File: PartitionCommitTrigger.java    From flink with Apache License 2.0 6 votes vote down vote up
static PartitionCommitTrigger create(
		boolean isRestored,
		OperatorStateStore stateStore,
		Configuration conf,
		ClassLoader cl,
		List<String> partitionKeys,
		ProcessingTimeService procTimeService) throws Exception {
	String trigger = conf.get(SINK_PARTITION_COMMIT_TRIGGER);
	switch (trigger) {
		case PARTITION_TIME:
			return new PartitionTimeCommitTigger(
					isRestored, stateStore, conf, cl, partitionKeys);
		case PROCESS_TIME:
			return new ProcTimeCommitTigger(
					isRestored, stateStore, conf, procTimeService);
		default:
			throw new UnsupportedOperationException(
					"Unsupported partition commit trigger: " + trigger);
	}
}
 
Example #24
Source File: InternalTimerServiceImplTest.java    From flink with Apache License 2.0 6 votes vote down vote up
private static <K, N> InternalTimerServiceImpl<K, N> createInternalTimerService(
	KeyGroupRange keyGroupsList,
	KeyContext keyContext,
	ProcessingTimeService processingTimeService,
	TypeSerializer<K> keySerializer,
	TypeSerializer<N> namespaceSerializer,
	PriorityQueueSetFactory priorityQueueSetFactory) {

	TimerSerializer<K, N> timerSerializer = new TimerSerializer<>(keySerializer, namespaceSerializer);

	return new InternalTimerServiceImpl<>(
		keyGroupsList,
		keyContext,
		processingTimeService,
		createTimerQueue("__test_processing_timers", timerSerializer, priorityQueueSetFactory),
		createTimerQueue("__test_event_timers", timerSerializer, priorityQueueSetFactory));
}
 
Example #25
Source File: InternalTimerServiceImpl.java    From flink with Apache License 2.0 6 votes vote down vote up
InternalTimerServiceImpl(
	KeyGroupRange localKeyGroupRange,
	KeyContext keyContext,
	ProcessingTimeService processingTimeService,
	KeyGroupedInternalPriorityQueue<TimerHeapInternalTimer<K, N>> processingTimeTimersQueue,
	KeyGroupedInternalPriorityQueue<TimerHeapInternalTimer<K, N>> eventTimeTimersQueue) {

	this.keyContext = checkNotNull(keyContext);
	this.processingTimeService = checkNotNull(processingTimeService);
	this.localKeyGroupRange = checkNotNull(localKeyGroupRange);
	this.processingTimeTimersQueue = checkNotNull(processingTimeTimersQueue);
	this.eventTimeTimersQueue = checkNotNull(eventTimeTimersQueue);

	// find the starting index of the local key-group range
	int startIdx = Integer.MAX_VALUE;
	for (Integer keyGroupIdx : localKeyGroupRange) {
		startIdx = Math.min(keyGroupIdx, startIdx);
	}
	this.localKeyGroupRangeStartIdx = startIdx;
}
 
Example #26
Source File: PulsarRowFetcher.java    From pulsar-flink with Apache License 2.0 6 votes vote down vote up
public PulsarRowFetcher(
        SourceFunction.SourceContext<Row> sourceContext,
        Map<String, MessageId> seedTopicsWithInitialOffsets,
        SerializedValue<AssignerWithPeriodicWatermarks<Row>> watermarksPeriodic,
        SerializedValue<AssignerWithPunctuatedWatermarks<Row>> watermarksPunctuated,
        ProcessingTimeService processingTimeProvider,
        long autoWatermarkInterval,
        ClassLoader userCodeClassLoader,
        StreamingRuntimeContext runtimeContext,
        ClientConfigurationData clientConf,
        Map<String, Object> readerConf,
        int pollTimeoutMs,
        DeserializationSchema<Row> deserializer,
        PulsarMetadataReader metadataReader) throws Exception {

    super(sourceContext, seedTopicsWithInitialOffsets, watermarksPeriodic, watermarksPunctuated, processingTimeProvider, autoWatermarkInterval, userCodeClassLoader, runtimeContext, clientConf, readerConf, pollTimeoutMs, deserializer, metadataReader);
}
 
Example #27
Source File: AbstractFetcherWatermarksTest.java    From flink with Apache License 2.0 6 votes vote down vote up
TestFetcher(
		SourceContext<T> sourceContext,
		Map<KafkaTopicPartition, Long> assignedPartitionsWithStartOffsets,
		SerializedValue<WatermarkStrategy<T>> watermarkStrategy,
		ProcessingTimeService processingTimeProvider,
		long autoWatermarkInterval) throws Exception {
	super(
			sourceContext,
			assignedPartitionsWithStartOffsets,
			watermarkStrategy,
			processingTimeProvider,
			autoWatermarkInterval,
			TestFetcher.class.getClassLoader(),
			new UnregisteredMetricsGroup(),
			false);
}
 
Example #28
Source File: BoundedStreamTask.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
protected void init() throws Exception {
	Preconditions.checkState(
		operatorChain.getNumberOfOperators() == 1,
		"BoundedStreamTask's should only run a single operator");

	// re-initialize the operator with the correct collector.
	StreamOperatorFactory<OUT> operatorFactory = configuration.getStreamOperatorFactory(getUserCodeClassLoader());
	Tuple2<OP, Optional<ProcessingTimeService>> headOperatorAndTimeService = StreamOperatorFactoryUtil.createOperator(
			operatorFactory,
			this,
			configuration,
			new CollectorWrapper<>(collector),
			operatorChain.getOperatorEventDispatcher());
	headOperator = headOperatorAndTimeService.f0;
	headOperator.initializeState(createStreamTaskStateInitializer());
	headOperator.open();
}
 
Example #29
Source File: FlinkPulsarSourceTest.java    From pulsar-flink with Apache License 2.0 6 votes vote down vote up
public TestingFetcher(
        SourceFunction.SourceContext<T> sourceContext,
        Map<String, MessageId> seedTopicsWithInitialOffsets,
        SerializedValue<AssignerWithPeriodicWatermarks<T>> watermarksPeriodic,
        SerializedValue<AssignerWithPunctuatedWatermarks<T>> watermarksPunctuated,
        ProcessingTimeService processingTimeProvider,
        long autoWatermarkInterval) throws Exception {
    super(
            sourceContext,
            seedTopicsWithInitialOffsets,
            watermarksPeriodic,
            watermarksPunctuated,
            processingTimeProvider,
            autoWatermarkInterval,
            TestingFetcher.class.getClassLoader(),
            null,
            null,
            null,
            0,
            null,
            null);
}
 
Example #30
Source File: SourceOperatorEventTimeTest.java    From flink with Apache License 2.0 6 votes vote down vote up
private static <T> SourceOperator<T, MockSourceSplit> createTestOperator(
		SourceReader<T, MockSourceSplit> reader,
		WatermarkStrategy<T> watermarkStrategy,
		ProcessingTimeService timeService) throws Exception {

	final OperatorStateStore operatorStateStore =
			new MemoryStateBackend().createOperatorStateBackend(
					new MockEnvironmentBuilder().build(),
					"test-operator",
					Collections.emptyList(),
					new CloseableRegistry());

	final StateInitializationContext stateContext = new StateInitializationContextImpl(
		false, operatorStateStore, null, null, null);

	final SourceOperator<T, MockSourceSplit> sourceOperator =
			new TestingSourceOperator<>(reader, watermarkStrategy, timeService);
	sourceOperator.initializeState(stateContext);
	sourceOperator.open();

	return sourceOperator;
}