-
Notifications
You must be signed in to change notification settings - Fork 544
[server] Add disk-usage write protection to TabletServer #3340
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| /* | ||
| * 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.exception; | ||
|
|
||
| import org.apache.fluss.annotation.PublicEvolving; | ||
|
|
||
| /** | ||
| * Thrown by a tablet server to reject writes when its local data disk usage has reached the | ||
| * configured write-limit ratio. The exception is retriable so that clients can retry once the | ||
| * server frees up enough disk space and resumes accepting writes. | ||
| */ | ||
| @PublicEvolving | ||
| public class DiskWriteLockedException extends RetriableException { | ||
|
|
||
| private static final long serialVersionUID = 1L; | ||
|
|
||
| public DiskWriteLockedException(String message) { | ||
| super(message); | ||
| } | ||
|
|
||
| public DiskWriteLockedException(int serverId, double usageRatio, double limit) { | ||
| super( | ||
| String.format( | ||
| "TabletServer %d has rejected writes because the data disk usage " | ||
| + "reached %.2f%% (limit: %.2f%%). Free up space or scale the cluster.", | ||
| serverId, usageRatio * 100, limit * 100)); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,95 @@ | ||
| /* | ||
| * 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.server.storage; | ||
|
|
||
| import org.apache.fluss.annotation.Internal; | ||
|
|
||
| import org.slf4j.Logger; | ||
| import org.slf4j.LoggerFactory; | ||
|
|
||
| import java.io.File; | ||
| import java.io.IOException; | ||
| import java.nio.file.FileStore; | ||
| import java.nio.file.Files; | ||
| import java.util.Collections; | ||
| import java.util.HashSet; | ||
| import java.util.List; | ||
| import java.util.Set; | ||
|
|
||
| import static org.apache.fluss.utils.Preconditions.checkNotNull; | ||
|
|
||
| /** | ||
| * Collects the local data disk usage ratio for the tablet server. The reported ratio is the | ||
| * <b>maximum</b> usage across all distinct {@link FileStore}s backing the configured data | ||
| * directories. A per-disk maximum (rather than a weighted average over total/used bytes) is used so | ||
| * that a single nearly-full disk cannot be masked by other low-usage disks in a multi-disk | ||
| * deployment: any single disk crossing the limit ratio must trip the write protection, because | ||
| * partitions pinned to that disk would otherwise fail to write. Multiple data directories sharing | ||
| * the same physical {@link FileStore} are still counted only once. | ||
| */ | ||
| @Internal | ||
| public final class DiskUsageCollector { | ||
|
|
||
| private static final Logger LOG = LoggerFactory.getLogger(DiskUsageCollector.class); | ||
|
|
||
| private final List<File> dataDirs; | ||
|
|
||
| public DiskUsageCollector(List<File> dataDirs) { | ||
| checkNotNull(dataDirs, "dataDirs"); | ||
| this.dataDirs = Collections.unmodifiableList(dataDirs); | ||
| } | ||
|
|
||
| /** | ||
| * Collects the current disk usage ratio in the range {@code [0.0, 1.0]}, defined as the maximum | ||
| * usage across all distinct {@link FileStore}s. Returns {@code 0.0} when no data directory is | ||
| * configured or every reachable file store reports a non-positive total space. | ||
| * | ||
| * <p>Individual directories that fail (e.g. deleted at runtime) are skipped with a warning so | ||
| * that one unhealthy directory does not prevent monitoring of the remaining disks. An {@link | ||
| * IOException} is thrown only when <b>all</b> directories fail. | ||
| */ | ||
| public double collect() throws IOException { | ||
| double maxRatio = 0.0; | ||
| Set<FileStore> counted = new HashSet<>(); | ||
| int failures = 0; | ||
| for (File dir : dataDirs) { | ||
| FileStore fs; | ||
| try { | ||
| fs = Files.getFileStore(dir.toPath()); | ||
| } catch (IOException e) { | ||
| LOG.warn("Failed to get FileStore for data directory {}; skipping.", dir, e); | ||
| failures++; | ||
| continue; | ||
| } | ||
| if (counted.add(fs)) { | ||
| long total = fs.getTotalSpace(); | ||
| if (total <= 0L) { | ||
| continue; | ||
| } | ||
| double ratio = (double) (total - fs.getUsableSpace()) / total; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| if (ratio > maxRatio) { | ||
| maxRatio = ratio; | ||
| } | ||
| } | ||
| } | ||
| if (failures > 0 && failures == dataDirs.size()) { | ||
| throw new IOException("All " + failures + " data directories failed FileStore lookup."); | ||
| } | ||
| return maxRatio; | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This key now passes the coordinator allowlist, but the range check still exists only in
LocalDiskManager.validate(), which is registered on TabletServer, not CoordinatorServer. Values like0.0or1.5can therefore be persisted throughAlterConfigsand only fail later when tablet servers try to apply them. The coordinator path should reject invalidserver.data-disk.write-limit-ratioupdates up front.I think we should also validate this on the Coordinator via
org.apache.fluss.server.DynamicConfigManager#registerValidatorby extending aConfigValidator. We should also add an IT case for setting valid and invalidserver.data-disk.write-limit-ratio(maybe nearFlussAdminITCase#testDynamicConfigs()).