Github user arunmahadevan commented on a diff in the pull request:
https://github.com/apache/storm/pull/2218#discussion_r130274003
--- Diff:
storm-client/src/jvm/org/apache/storm/windowing/WindowManager.java ---
@@ -111,14 +125,86 @@ public void add(Event<T> windowEvent) {
LOG.debug("Got watermark event with ts {}",
windowEvent.getTimestamp());
}
track(windowEvent);
- compactWindow();
+ if (!stateful) {
+ compactWindow();
+ }
}
/**
* The callback invoked by the trigger policy.
*/
@Override
public boolean onTrigger() {
+ return stateful ? doOnTriggerStateful() : doOnTrigger();
+ }
+
+ private static class IteratorStatus {
+ private boolean valid = true;
+
+ void invalidate() {
+ valid = false;
+ }
+
+ boolean isValid() {
+ return valid;
+ }
+ }
+
+ private static<T> Iterator<T> expiringIterator(Iterator<T> inner,
IteratorStatus status) {
+ return new Iterator<T>() {
+ @Override
+ public boolean hasNext() {
+ if (status.isValid()) {
+ return inner.hasNext();
+ }
+ throw new IllegalStateException("Stale iterator");
+ }
+
+ @Override
+ public T next() {
+ if (status.isValid()) {
+ return inner.next();
+ }
+ throw new IllegalStateException("Stale iterator");
+ }
+ };
+ }
+
+ private boolean doOnTriggerStateful() {
+ Supplier<Iterator<T>> scanEventsStateful =
this::scanEventsStateful;
+ Iterator<T> it = scanEventsStateful.get();
+ boolean hasEvents = it.hasNext();
+ if (hasEvents) {
+ final IteratorStatus status = new IteratorStatus();
+ LOG.debug("invoking windowLifecycleListener onActivation with
iterator");
+ // reuse the retrieved iterator
+ Supplier<Iterator<T>> wrapper = new Supplier<Iterator<T>>() {
+ Iterator<T> initial = it;
+ @Override
+ public Iterator<T> get() {
+ if (status.isValid()) {
--- End diff --
The iterator is invalidated after returning from the activation callback.
Basically bolts are not supposed to hold a reference to the iterator obtained
via `Window.getIter` after it returns from `execute` (say to iterate the values
later). The window events can expire and some internal state is cleared so its
not feasible and not very meaningful to do this.
---
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 [email protected] or file a JIRA ticket
with INFRA.
---