@@ -1150,15 +1150,15 @@ public Cancellable schedule(final Instant startTime, final long interval, final
1150
1150
switch (type ) {
1151
1151
case STREAM_TIME :
1152
1152
// align punctuation to 0L, punctuate as soon as we have data
1153
- return schedule (0L , interval , type , punctuator );
1153
+ return schedule (0L , interval , type , punctuator , false );
1154
1154
case WALL_CLOCK_TIME :
1155
1155
// align punctuation to now, punctuate after interval has elapsed
1156
- return schedule (time .milliseconds () + interval , interval , type , punctuator );
1156
+ return schedule (time .milliseconds () + interval , interval , type , punctuator , false );
1157
1157
default :
1158
1158
throw new IllegalArgumentException ("Unrecognized PunctuationType: " + type );
1159
1159
}
1160
1160
}
1161
- return schedule (startTime .toEpochMilli (), interval , type , punctuator );
1161
+ return schedule (startTime .toEpochMilli (), interval , type , punctuator , true );
1162
1162
}
1163
1163
1164
1164
/**
@@ -1169,12 +1169,12 @@ public Cancellable schedule(final Instant startTime, final long interval, final
1169
1169
* @param type the punctuation type
1170
1170
* @throws IllegalStateException if the current node is not null
1171
1171
*/
1172
- private Cancellable schedule (final long startTime , final long interval , final PunctuationType type , final Punctuator punctuator ) {
1172
+ private Cancellable schedule (final long startTime , final long interval , final PunctuationType type , final Punctuator punctuator , final boolean anchored ) {
1173
1173
if (processorContext .currentNode () == null ) {
1174
1174
throw new IllegalStateException (String .format ("%sCurrent node is null" , logPrefix ));
1175
1175
}
1176
1176
1177
- final PunctuationSchedule schedule = new PunctuationSchedule ( processorContext . currentNode (), startTime , interval , punctuator );
1177
+ final PunctuationSchedule schedule = getInitialSchedule ( startTime , interval , type , punctuator , anchored );
1178
1178
1179
1179
switch (type ) {
1180
1180
case STREAM_TIME :
@@ -1189,6 +1189,15 @@ private Cancellable schedule(final long startTime, final long interval, final Pu
1189
1189
}
1190
1190
}
1191
1191
1192
+ // For anchored schedule, we want to have all punctuations to happen only on times based on combinations of startTime and interval
1193
+ // This method ensures that the first anchored punctuation is not fired prematurely due to startTime < now
1194
+ private PunctuationSchedule getInitialSchedule (final long startTime , final long interval , final PunctuationType type , final Punctuator punctuator , final boolean anchored ) {
1195
+ final PunctuationSchedule originalSchedule = new PunctuationSchedule (processorContext .currentNode (), startTime , interval , punctuator );
1196
+ final long now = (type == PunctuationType .WALL_CLOCK_TIME ) ? time .milliseconds () : streamTime ();
1197
+
1198
+ return (anchored && startTime < now ) ? originalSchedule .next (now ) : originalSchedule ;
1199
+ }
1200
+
1192
1201
/**
1193
1202
* Possibly trigger registered stream-time punctuation functions if
1194
1203
* current partition group timestamp has reached the defined stamp
0 commit comments