flink-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From soniclavier <...@git.apache.org>
Subject [GitHub] flink pull request #2736: [FLINK-4174] Enhance evictor functionality
Date Thu, 03 Nov 2016 23:09:51 GMT
Github user soniclavier commented on a diff in the pull request:

    https://github.com/apache/flink/pull/2736#discussion_r86462637
  
    --- Diff: flink-streaming-java/src/main/java/org/apache/flink/streaming/runtime/operators/windowing/EvictingWindowOperator.java
---
    @@ -273,32 +284,93 @@ public void onProcessingTime(InternalTimer<K, W> timer) throws
Exception {
     			return;
     		}
     
    -		TriggerResult triggerResult = context.onProcessingTime(timer.getTimestamp());
    -		if (triggerResult.isFire()) {
    -			fire(context.window, contents);
    -		}
    +				TriggerResult triggerResult = context.onProcessingTime(timer.getTimestamp());
    +				if (triggerResult.isFire()) {
    +					fire(context.window, contents, windowState);
    +				}
     
     		if (triggerResult.isPurge() || (!windowAssigner.isEventTime() && isCleanupTime(context.window,
timer.getTimestamp()))) {
     			cleanup(context.window, windowState, mergingWindows);
     		}
     	}
     
    -	private void fire(W window, Iterable<StreamRecord<IN>> contents) throws
Exception {
    +	private void fire(W window, Iterable<StreamRecord<IN>> contents, ListState<StreamRecord<IN>>
windowState) throws Exception {
     		timestampedCollector.setAbsoluteTimestamp(window.maxTimestamp());
     
     		// Work around type system restrictions...
    -		int toEvict = evictor.evict((Iterable) contents, Iterables.size(contents), context.window);
    -
    -		FluentIterable<IN> projectedContents = FluentIterable
    +		FluentIterable<TimestampedValue<IN>> recordsWithTimestamp = FluentIterable
     			.from(contents)
    -			.skip(toEvict)
    -			.transform(new Function<StreamRecord<IN>, IN>() {
    +			.transform(new Function<StreamRecord<IN>, TimestampedValue<IN>>()
{
    +				@Override
    +				public TimestampedValue<IN> apply(StreamRecord<IN> input) {
    +					return new TimestampedValue<>(input.getValue(), input.getTimestamp());
    +				}
    +			});
    +		evictorContext.evictBefore(recordsWithTimestamp, Iterables.size(recordsWithTimestamp));
    +
    +		FluentIterable<IN> projectedContents = recordsWithTimestamp
    +			.transform(new Function<TimestampedValue<IN>, IN>() {
     				@Override
    -				public IN apply(StreamRecord<IN> input) {
    +				public IN apply(TimestampedValue<IN> input) {
     					return input.getValue();
     				}
     			});
    +
     		userFunction.apply(context.key, context.window, projectedContents, timestampedCollector);
    +		evictorContext.evictAfter(recordsWithTimestamp, Iterables.size(recordsWithTimestamp));
    +
    +
    +		//work around to fix FLINK-4369, remove the evicted elements from the windowState.
    +		//this is inefficient, but there is no other way to remove elements from ListState,
which is an AppendingState.
    +		windowState.clear();
    +		for(TimestampedValue<IN> record : recordsWithTimestamp) {
    +			if (record.getTimestamp() < 0) {
    --- End diff --
    
    Regarding the copy method: Are you asking me to add a copy method in the TimestampedValue
that will return a corresponding StreamRecord, something like this:
    
    ```java
    /**
     * Creates a {@link StreamRecord} from this TimestampedValue.
     */
    public StreamRecord<T> getStreamRecord() {
    	StreamRecord<T> streamRecord = new StreamRecord<>(value);
    	if (hasTimestamp) {
    		streamRecord.setTimestamp(timestamp);
    	}
    	return streamRecord;
    }
    ```


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

Mime
View raw message