You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@flink.apache.org by "prashantbh (via GitHub)" <gi...@apache.org> on 2025/04/11 09:45:52 UTC

[PR] [FLINK-37655][runtime] Convert WindowStagger into an interface for ea… [flink]

prashantbh opened a new pull request, #26441:
URL: https://github.com/apache/flink/pull/26441

   …sy extensibility
   
   <!--
   *Thank you very much for contributing to Apache Flink - we are happy that you want to help us improve Flink. To help the community review your contribution in the best possible way, please go through the checklist below, which will get the contribution into a shape in which it can be best reviewed.*
   
   *Please understand that we do not do this to make contributions to Flink a hassle. In order to uphold a high standard of quality for code contributions, while at the same time managing a large number of contributions, we need contributors to prepare the contributions well, and give reviewers enough contextual information for the review. Please also understand that contributions that do not follow this guide will take longer to review and thus typically be picked up with lower priority by the community.*
   
   ## Contribution Checklist
   
     - Make sure that the pull request corresponds to a [JIRA issue](https://issues.apache.org/jira/projects/FLINK/issues). Exceptions are made for typos in JavaDoc or documentation files, which need no JIRA issue.
     
     - Name the pull request in the form "[FLINK-XXXX] [component] Title of the pull request", where *FLINK-XXXX* should be replaced by the actual issue number. Skip *component* if you are unsure about which is the best component.
     Typo fixes that have no associated JIRA issue should be named following this pattern: `[hotfix] [docs] Fix typo in event time introduction` or `[hotfix] [javadocs] Expand JavaDoc for PuncuatedWatermarkGenerator`.
   
     - Fill out the template below to describe the changes contributed by the pull request. That will give reviewers the context they need to do the review.
     
     - Make sure that the change passes the automated tests, i.e., `mvn clean verify` passes. You can set up Azure Pipelines CI to do that following [this guide](https://cwiki.apache.org/confluence/display/FLINK/Azure+Pipelines#AzurePipelines-Tutorial:SettingupAzurePipelinesforaforkoftheFlinkrepository).
   
     - Each pull request should address only one issue, not mix up code from multiple issues.
     
     - Each commit in the pull request has a meaningful commit message (including the JIRA id)
   
     - Once all items of the checklist are addressed, remove the above text and this checklist, leaving only the filled out template below.
   
   
   **(The sections below can be removed for hotfixes of typos)**
   -->
   
   ## What is the purpose of the change
   To provide users the flexibility to implement custom window staggering behaviours beyond the standard options (ALIGNED, RANDOM, NATURAL), this PR convert the WindowStagger enum into an interface. The current enum structure restricts extension because enums are final. By adopting an interface, we allow users to define and plug in their own staggering strategies, catering to more diverse use cases. The original enum constants will be provided as default implementations of this new interface.
   
   ## Brief change log
   
   Converts WindowStagger into an interface from ENUM. 
   
   ## Verifying this change
   
   This change is a trivial rework, since existing ENUM constants are retained as standard implementation, all the existing test will work as it is.
   
   ## Does this pull request potentially affect one of the following parts:
   
     - Dependencies (does it add or upgrade a dependency): No
     - The public API, i.e., is any changed class annotated with `@Public(Evolving)`: No
   
   ## Documentation
   
     - Does this pull request introduce a new feature?
     - If yes, how is the feature documented? (not applicable / docs / JavaDocs / not documented)
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [FLINK-37655][runtime] Convert WindowStagger into an interface [flink]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #26441:
URL: https://github.com/apache/flink/pull/26441#issuecomment-4385867052

   This PR is being marked as stale since it has not had any activity in the last 90 days. 
   If you would like to keep this PR alive, please leave a comment asking for a review. 
   If the PR has merge conflicts, update it with the latest from the base branch.
   
   If you are having difficulty finding a reviewer, please reach out to the 
   community, contact details can be found here: https://flink.apache.org/what-is-flink/community/
   
   If this PR is no longer valid or desired, please feel free to close it. 
   If no activity occurs in the next 30 days, it will be automatically closed.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [FLINK-37655][runtime] Convert WindowStagger into an interface [flink]

Posted by "prashantbh (via GitHub)" <gi...@apache.org>.
prashantbh commented on code in PR #26441:
URL: https://github.com/apache/flink/pull/26441#discussion_r2039503996


##########
flink-runtime/src/main/java/org/apache/flink/streaming/api/windowing/assigners/WindowStagger.java:
##########
@@ -21,43 +21,81 @@
 import org.apache.flink.annotation.PublicEvolving;
 import org.apache.flink.streaming.api.windowing.windows.TimeWindow;
 
+import java.io.Serializable;
 import java.util.concurrent.ThreadLocalRandom;
 
-/** A {@code WindowStagger} staggers offset in runtime for each window assignment. */
+/**
+ * Interface for defining how window assignments should be staggered to distribute load over time.
+ * Implementations determine the offset applied during window assignment.
+ */
 @PublicEvolving
-public enum WindowStagger {
-    /** Default mode, all panes fire at the same time across all partitions. */
-    ALIGNED {
-        @Override
-        public long getStaggerOffset(final long currentProcessingTime, final long size) {
-            return 0L;
-        }
-    },
+public interface WindowStagger extends Serializable {
+
+    /**
+     * Calculates the stagger offset for a window assignment based on the current processing time
+     * and the window size.
+     *
+     * @param currentProcessingTime The current processing time.
+     * @param size The size of the window.
+     * @return The calculated stagger offset in milliseconds.
+     */
+    long getStaggerOffset(final long currentProcessingTime, final long size);
+
+    // Pre-defined Staggering Strategies
+    /** Default mode: No staggering, all panes fire at the same time across all partitions. */
+    WindowStagger ALIGNED =
+            new WindowStagger() {
+                private static final long serialVersionUID = 1L;
+
+                @Override
+                public long getStaggerOffset(final long currentProcessingTime, final long size) {
+                    return 0L;
+                }
+
+                @Override
+                public String toString() {
+                    return "ALIGNED";
+                }
+            };
 
     /**
      * Stagger offset is sampled from uniform distribution U(0, WindowSize) when first event
      * ingested in the partitioned operator.
      */
-    RANDOM {
-        @Override
-        public long getStaggerOffset(final long currentProcessingTime, final long size) {
-            return (long) (ThreadLocalRandom.current().nextDouble() * size);
-        }
-    },
+    WindowStagger RANDOM =
+            new WindowStagger() {
+                private static final long serialVersionUID = 1L;
+
+                @Override
+                public long getStaggerOffset(final long currentProcessingTime, final long size) {
+                    return (long) (ThreadLocalRandom.current().nextDouble() * size);
+                }
+
+                @Override
+                public String toString() {
+                    return "RANDOM";
+                }
+            };
 
     /**
      * When the first event is received in the window operator, take the difference between the
      * start of the window and current procesing time as the offset. This way, windows are staggered
      * based on when each parallel operator receives the first event.
      */
-    NATURAL {
-        @Override
-        public long getStaggerOffset(final long currentProcessingTime, final long size) {
-            final long currentProcessingWindowStart =
-                    TimeWindow.getWindowStartWithOffset(currentProcessingTime, 0, size);
-            return Math.max(0, currentProcessingTime - currentProcessingWindowStart);
-        }
-    };
-
-    public abstract long getStaggerOffset(final long currentProcessingTime, final long size);
+    WindowStagger NATURAL =
+            new WindowStagger() {
+                private static final long serialVersionUID = 1L; // Add serialVersionUID
+
+                @Override
+                public long getStaggerOffset(final long currentProcessingTime, final long size) {
+                    final long currentProcessingWindowStart =
+                            TimeWindow.getWindowStartWithOffset(currentProcessingTime, 0, size);
+                    return Math.max(0, currentProcessingTime - currentProcessingWindowStart);
+                }
+
+                @Override
+                public String toString() {
+                    return "NATURAL"; // Optional: for better readability

Review Comment:
   I will remove this.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [FLINK-37655][runtime] Convert WindowStagger into an interface [flink]

Posted by "flinkbot (via GitHub)" <gi...@apache.org>.
flinkbot commented on PR #26441:
URL: https://github.com/apache/flink/pull/26441#issuecomment-2796411490

   <!--
   Meta data
   {
     "version" : 1,
     "metaDataEntries" : [ {
       "hash" : "c3c4894e2208dfe9adda8fd23044041a2079e153",
       "status" : "UNKNOWN",
       "url" : "TBD",
       "triggerID" : "c3c4894e2208dfe9adda8fd23044041a2079e153",
       "triggerType" : "PUSH"
     } ]
   }-->
   ## CI report:
   
   * c3c4894e2208dfe9adda8fd23044041a2079e153 UNKNOWN
   
   <details>
   <summary>Bot commands</summary>
     The @flinkbot bot supports the following commands:
   
    - `@flinkbot run azure` re-run the last Azure build
   </details>


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [FLINK-37655][runtime] Convert WindowStagger into an interface [flink]

Posted by "prashantbh (via GitHub)" <gi...@apache.org>.
prashantbh commented on PR #26441:
URL: https://github.com/apache/flink/pull/26441#issuecomment-2796875876

   > I have some questions:
   > 
   > * I assume this means the user will need to recompile their programs to pick up the interface version.
   > * I am inclined to leave this as an enum, until there is a need to extend it. Otherwise we are creating an extension point that may never be used.
   
   This change affects only new Flink versions and isn’t backported. So, if you upgrade, you'll need to recompile any programs that use it—but since you're already updating Flink, that's expected, unless you are changing Flink version at runtime.
   
   We're switching from an enum to an interface to give us a flexible extension point for future needs without breaking backward compatibility. For example, we’re working on a custom WindowAssigner (a variant of `TumblingEventTimeWindows` with our own `WindowStagger` logic), and with this change, we only need to provide our custom `WindowStagger` rather than re-implementing the whole assigner.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [FLINK-37655][runtime] Convert WindowStagger into an interface [flink]

Posted by "prashantbh (via GitHub)" <gi...@apache.org>.
prashantbh commented on PR #26441:
URL: https://github.com/apache/flink/pull/26441#issuecomment-2796820453

   @flinkbot run azure


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [FLINK-37655][runtime] Convert WindowStagger into an interface [flink]

Posted by "davidradl (via GitHub)" <gi...@apache.org>.
davidradl commented on code in PR #26441:
URL: https://github.com/apache/flink/pull/26441#discussion_r2039502534


##########
flink-runtime/src/main/java/org/apache/flink/streaming/api/windowing/assigners/WindowStagger.java:
##########
@@ -21,43 +21,81 @@
 import org.apache.flink.annotation.PublicEvolving;
 import org.apache.flink.streaming.api.windowing.windows.TimeWindow;
 
+import java.io.Serializable;
 import java.util.concurrent.ThreadLocalRandom;
 
-/** A {@code WindowStagger} staggers offset in runtime for each window assignment. */
+/**
+ * Interface for defining how window assignments should be staggered to distribute load over time.
+ * Implementations determine the offset applied during window assignment.
+ */
 @PublicEvolving
-public enum WindowStagger {
-    /** Default mode, all panes fire at the same time across all partitions. */
-    ALIGNED {
-        @Override
-        public long getStaggerOffset(final long currentProcessingTime, final long size) {
-            return 0L;
-        }
-    },
+public interface WindowStagger extends Serializable {
+
+    /**
+     * Calculates the stagger offset for a window assignment based on the current processing time
+     * and the window size.
+     *
+     * @param currentProcessingTime The current processing time.
+     * @param size The size of the window.
+     * @return The calculated stagger offset in milliseconds.
+     */
+    long getStaggerOffset(final long currentProcessingTime, final long size);
+
+    // Pre-defined Staggering Strategies
+    /** Default mode: No staggering, all panes fire at the same time across all partitions. */
+    WindowStagger ALIGNED =
+            new WindowStagger() {
+                private static final long serialVersionUID = 1L;
+
+                @Override
+                public long getStaggerOffset(final long currentProcessingTime, final long size) {
+                    return 0L;
+                }
+
+                @Override
+                public String toString() {
+                    return "ALIGNED";
+                }
+            };
 
     /**
      * Stagger offset is sampled from uniform distribution U(0, WindowSize) when first event
      * ingested in the partitioned operator.
      */
-    RANDOM {
-        @Override
-        public long getStaggerOffset(final long currentProcessingTime, final long size) {
-            return (long) (ThreadLocalRandom.current().nextDouble() * size);
-        }
-    },
+    WindowStagger RANDOM =
+            new WindowStagger() {
+                private static final long serialVersionUID = 1L;
+
+                @Override
+                public long getStaggerOffset(final long currentProcessingTime, final long size) {
+                    return (long) (ThreadLocalRandom.current().nextDouble() * size);
+                }
+
+                @Override
+                public String toString() {
+                    return "RANDOM";
+                }
+            };
 
     /**
      * When the first event is received in the window operator, take the difference between the
      * start of the window and current procesing time as the offset. This way, windows are staggered
      * based on when each parallel operator receives the first event.
      */
-    NATURAL {
-        @Override
-        public long getStaggerOffset(final long currentProcessingTime, final long size) {
-            final long currentProcessingWindowStart =
-                    TimeWindow.getWindowStartWithOffset(currentProcessingTime, 0, size);
-            return Math.max(0, currentProcessingTime - currentProcessingWindowStart);
-        }
-    };
-
-    public abstract long getStaggerOffset(final long currentProcessingTime, final long size);
+    WindowStagger NATURAL =
+            new WindowStagger() {
+                private static final long serialVersionUID = 1L; // Add serialVersionUID
+
+                @Override
+                public long getStaggerOffset(final long currentProcessingTime, final long size) {
+                    final long currentProcessingWindowStart =
+                            TimeWindow.getWindowStartWithOffset(currentProcessingTime, 0, size);
+                    return Math.max(0, currentProcessingTime - currentProcessingWindowStart);
+                }
+
+                @Override
+                public String toString() {
+                    return "NATURAL"; // Optional: for better readability

Review Comment:
   nit: why does this toString have a comment but this others do not?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [FLINK-37655][runtime] Convert WindowStagger into an interface [flink]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #26441:
URL: https://github.com/apache/flink/pull/26441#issuecomment-4629319596

   This PR has been closed since it has not had any activity in 120 days. 
   If you feel like this was a mistake, or you would like to continue working on it, 
   please feel free to re-open the PR and ask for a review.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [FLINK-37655][runtime] Convert WindowStagger into an interface [flink]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] closed pull request #26441: [FLINK-37655][runtime] Convert WindowStagger into an interface
URL: https://github.com/apache/flink/pull/26441


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org