Skip to content
Open
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 @@ -86,14 +86,9 @@ public void open(org.apache.flink.api.common.functions.OpenContext openContext)
}
audit = new AuditLogger();
int parallelism = getRuntimeContext().getTaskInfo().getNumberOfParallelSubtasks();
int subtaskIndex = getRuntimeContext().getTaskInfo().getIndexOfThisSubtask();
// Distribute the configured rate as base + 1 extra for the first `remainder` subtasks.
// Flink does not provide a cross-JVM limiter here, so this is a best-effort job-level
// target. Each subtask gets at least 1/s; if parallelism exceeds the configured rate, the
// effective aggregate can exceed the target by that floor.
// Each worker owns its limiter; fractional rates preserve the best-effort job-level target.
remoteFsOpRateLimiter =
RateLimiter.create(
perSubtaskRate(remoteFsOpRateLimitPerSecond, parallelism, subtaskIndex));
RateLimiter.create(perSubtaskRate(remoteFsOpRateLimitPerSecond, parallelism));
}

@Override
Expand Down Expand Up @@ -241,11 +236,8 @@ private SafeDeleter createSafeDeleter(FileSystem fs, boolean dryRun) {
return new SafeDeleter(fs, dryRun, audit, remoteFsOpRateLimiter);
}

private static double perSubtaskRate(long totalRate, int parallelism, int subtaskIndex) {
long base = totalRate / parallelism;
long remainder = totalRate % parallelism;
long quota = base + (subtaskIndex < remainder ? 1L : 0L);
return Math.max(1.0, (double) quota);
static double perSubtaskRate(long totalRate, int parallelism) {
return ((double) totalRate) / parallelism;
}

private static final class DirVisit {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.fluss.flink.action.orphan.job;

import org.junit.jupiter.api.Test;

import static org.assertj.core.api.Assertions.assertThat;

/** Tests for scan filesystem rate allocation. */
class ScanAndCleanFunctionTest {
@Test
void splitsNonDivisibleRateAcrossSubtasks() {
assertThat(ScanAndCleanFunction.perSubtaskRate(100, 16)).isEqualTo(6.25);
}

@Test
void doesNotRaiseRateWhenParallelismExceedsLimit() {
assertThat(ScanAndCleanFunction.perSubtaskRate(3, 8)).isEqualTo(0.375);
}

@Test
void preservesRateWithOneSubtask() {
assertThat(ScanAndCleanFunction.perSubtaskRate(100, 1)).isEqualTo(100);
}
}
Loading