Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import java.util.UUID;
import javax.annotation.Nullable;
import org.apache.flink.annotation.Internal;
import org.apache.flink.annotation.VisibleForTesting;
import org.apache.flink.api.common.ExecutionConfig;
import org.apache.flink.api.common.eventtime.TimestampAssigner;
import org.apache.flink.api.common.eventtime.TimestampAssignerSupplier;
Expand Down Expand Up @@ -378,7 +379,9 @@ private DataStream<TableChange> changeStream(String tableName, TableLoader loade
// Create a monitor source to provide the TableChange stream
MonitorSource source =
new MonitorSource(
loader, RateLimiterStrategy.perSecond(1.0 / rateLimit.getSeconds()), maxReadBack);
loader,
RateLimiterStrategy.perSecond(monitorRatePerSecond(rateLimit.toMillis())),
maxReadBack);
return setSlotSharingGroup(
env.fromSource(
source,
Expand All @@ -395,6 +398,16 @@ private static String nameFor(MaintenanceTaskBuilder<?> streamBuilder, int taskI
return String.format(Locale.ROOT, "%s [%d]", streamBuilder.maintenanceTaskName(), taskIndex);
}

/**
* Monitor poll rate per rate-limit interval, in checks/second. We compute from millis instead
* of seconds, otherwise sub-second intervals could be truncated to 0, yielding an infinite rate
* which busy-loops the source.
*/
@VisibleForTesting
static double monitorRatePerSecond(long rateLimitMillis) {
return 1000.0 / rateLimitMillis;
}

private <T> SingleOutputStreamOperator<T> setSlotSharingGroup(
SingleOutputStreamOperator<T> operator) {
return slotSharingGroup == null ? operator : operator.slotSharingGroup(slotSharingGroup);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,14 @@ void testUidAndSlotSharingGroupForMonitorSource() throws IOException {
checkSlotSharingGroupsAreSet(env, SLOT_SHARING_GROUP);
}

@Test
void testMonitorRatePerSecond() {
// Sub-second rate limits must not yield infinite (unthrottled) monitor rates.
assertThat(TableMaintenance.Builder.monitorRatePerSecond(50)).isEqualTo(20.0);
assertThat(TableMaintenance.Builder.monitorRatePerSecond(100)).isEqualTo(10.0);
assertThat(TableMaintenance.Builder.monitorRatePerSecond(60_000)).isEqualTo(1.0 / 60);
}

/**
* Sends the events though the {@link ManualSource} provided, and waits until the given number of
* records are processed.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import java.util.UUID;
import javax.annotation.Nullable;
import org.apache.flink.annotation.Internal;
import org.apache.flink.annotation.VisibleForTesting;
import org.apache.flink.api.common.ExecutionConfig;
import org.apache.flink.api.common.eventtime.TimestampAssigner;
import org.apache.flink.api.common.eventtime.TimestampAssignerSupplier;
Expand Down Expand Up @@ -378,7 +379,9 @@ private DataStream<TableChange> changeStream(String tableName, TableLoader loade
// Create a monitor source to provide the TableChange stream
MonitorSource source =
new MonitorSource(
loader, RateLimiterStrategy.perSecond(1.0 / rateLimit.getSeconds()), maxReadBack);
loader,
RateLimiterStrategy.perSecond(monitorRatePerSecond(rateLimit.toMillis())),
maxReadBack);
return setSlotSharingGroup(
env.fromSource(
source,
Expand All @@ -395,6 +398,16 @@ private static String nameFor(MaintenanceTaskBuilder<?> streamBuilder, int taskI
return String.format(Locale.ROOT, "%s [%d]", streamBuilder.maintenanceTaskName(), taskIndex);
}

/**
* Monitor poll rate per rate-limit interval, in checks/second. We compute from millis instead
* of seconds, otherwise sub-second intervals could be truncated to 0, yielding an infinite rate
* which busy-loops the source.
*/
@VisibleForTesting
static double monitorRatePerSecond(long rateLimitMillis) {
return 1000.0 / rateLimitMillis;
}

private <T> SingleOutputStreamOperator<T> setSlotSharingGroup(
SingleOutputStreamOperator<T> operator) {
return slotSharingGroup == null ? operator : operator.slotSharingGroup(slotSharingGroup);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,14 @@ void testUidAndSlotSharingGroupForMonitorSource() throws IOException {
checkSlotSharingGroupsAreSet(env, SLOT_SHARING_GROUP);
}

@Test
void testMonitorRatePerSecond() {
// Sub-second rate limits must not yield infinite (unthrottled) monitor rates.
assertThat(TableMaintenance.Builder.monitorRatePerSecond(50)).isEqualTo(20.0);
assertThat(TableMaintenance.Builder.monitorRatePerSecond(100)).isEqualTo(10.0);
assertThat(TableMaintenance.Builder.monitorRatePerSecond(60_000)).isEqualTo(1.0 / 60);
}

/**
* Sends the events though the {@link ManualSource} provided, and waits until the given number of
* records are processed.
Expand Down