Skip to content
This repository was archived by the owner on Nov 11, 2022. It is now read-only.

Commit 3a33f87

Browse files
authored
Merge pull request #498 from scwhittle/fix_late_counter
Increase counters in LateDroppingDoFnRunner once, even with many iterations
2 parents 40ff148 + 9b96b97 commit 3a33f87

File tree

2 files changed

+21
-9
lines changed

2 files changed

+21
-9
lines changed

sdk/src/main/java/com/google/cloud/dataflow/sdk/util/LateDataDroppingDoFnRunner.java

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -112,20 +112,30 @@ public WindowedValue<InputT> apply(BoundedWindow window) {
112112
});
113113
}});
114114

115+
Iterable<WindowedValue<InputT>> concatElements = Iterables.concat(windowsExpandedElements);
116+
117+
// Bump the counter separately since we don't want multiple iterations to
118+
// increase it multiple times.
119+
for (WindowedValue<InputT> input : concatElements) {
120+
BoundedWindow window = Iterables.getOnlyElement(input.getWindows());
121+
if (canDropDueToExpiredWindow(window)) {
122+
// The element is too late for this window.
123+
droppedDueToLateness.addValue(1L);
124+
WindowTracing.debug(
125+
"ReduceFnRunner.processElement: Dropping element at {} for key:{}; window:{} "
126+
+ "since too far behind inputWatermark:{}; outputWatermark:{}",
127+
input.getTimestamp(), key, window, timerInternals.currentInputWatermarkTime(),
128+
timerInternals.currentOutputWatermarkTime());
129+
}
130+
}
131+
115132
Iterable<WindowedValue<InputT>> nonLateElements = Iterables.filter(
116-
Iterables.concat(windowsExpandedElements),
133+
concatElements,
117134
new Predicate<WindowedValue<InputT>>() {
118135
@Override
119136
public boolean apply(WindowedValue<InputT> input) {
120137
BoundedWindow window = Iterables.getOnlyElement(input.getWindows());
121138
if (canDropDueToExpiredWindow(window)) {
122-
// The element is too late for this window.
123-
droppedDueToLateness.addValue(1L);
124-
WindowTracing.debug(
125-
"ReduceFnRunner.processElement: Dropping element at {} for key:{}; window:{} "
126-
+ "since too far behind inputWatermark:{}; outputWatermark:{}",
127-
input.getTimestamp(), key, window, timerInternals.currentInputWatermarkTime(),
128-
timerInternals.currentOutputWatermarkTime());
129139
return false;
130140
} else {
131141
return true;

sdk/src/test/java/com/google/cloud/dataflow/sdk/util/LateDataDroppingDoFnRunnerTest.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,9 @@ public void testLateDataFilter() throws Exception {
7777
createDatum(18, 18L));
7878
assertThat(expected, containsInAnyOrder(Iterables.toArray(actual, WindowedValue.class)));
7979
assertEquals(1, droppedDueToLateness.sum);
80+
// Ensure that reiterating returns the same results and doesn't increment the counter again.
81+
assertThat(expected, containsInAnyOrder(Iterables.toArray(actual, WindowedValue.class)));
82+
assertEquals(1, droppedDueToLateness.sum);
8083
}
8184

8285
private <T> WindowedValue<T> createDatum(T element, long timestampMillis) {
@@ -112,4 +115,3 @@ public String getName() {
112115
}
113116
}
114117
}
115-

0 commit comments

Comments
 (0)