-
Notifications
You must be signed in to change notification settings - Fork 546
[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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
fluss-common/src/main/java/org/apache/fluss/exception/DiskWriteLockedException.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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)); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
94 changes: 94 additions & 0 deletions
94
fluss-server/src/main/java/org/apache/fluss/server/storage/DiskUsageCollector.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,94 @@ | ||
| /* | ||
| * 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, or whose {@link FileStore} | ||
| * throws during {@code getTotalSpace}/{@code getUsableSpace}) 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) { | ||
| try { | ||
| FileStore fs = Files.getFileStore(dir.toPath()); | ||
| if (counted.add(fs)) { | ||
| long total = fs.getTotalSpace(); | ||
| if (total <= 0L) { | ||
| continue; | ||
| } | ||
| double ratio = (double) (total - fs.getUsableSpace()) / total; | ||
| if (ratio > maxRatio) { | ||
| maxRatio = ratio; | ||
| } | ||
| } | ||
| } catch (IOException e) { | ||
| LOG.warn("Failed to stat FileStore for data directory {}; skipping.", dir, e); | ||
| failures++; | ||
| } | ||
| } | ||
| if (failures > 0 && failures == dataDirs.size()) { | ||
| throw new IOException("All " + failures + " data directories failed FileStore lookup."); | ||
| } | ||
| return maxRatio; | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.