-
Notifications
You must be signed in to change notification settings - Fork 3.9k
CASSANDRA-21134: Direct I/O for background SSTable writes #4815
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
Open
samueldlightfoot
wants to merge
3
commits into
apache:cassandra-6.0
Choose a base branch
from
samueldlightfoot:CASSANDRA-21134-direct-compaction-writes
base: cassandra-6.0
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
ca8ef09
CASSANDRA-21134: Direct I/O for background SSTable writes
samueldlightfoot 313c56c
CASSANDRA-21134: Address review feedback for background write Direct I/O
samueldlightfoot ef73b09
CASSANDRA-21134: Enable background-write Direct I/O in cassandra_late…
samueldlightfoot 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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -224,6 +224,8 @@ public class DatabaseDescriptor | |
|
|
||
| private static DiskAccessMode compactionReadDiskAccessMode; | ||
|
|
||
| private static DiskAccessMode backgroundWriteDiskAccessMode; | ||
|
|
||
| private static AbstractCryptoProvider cryptoProvider; | ||
| private static IAuthenticator authenticator; | ||
| private static IAuthorizer authorizer; | ||
|
|
@@ -897,6 +899,10 @@ else if (conf.repair_session_space.toMebibytes() > (int) (Runtime.getRuntime().m | |
| if (conf.hints_directory.equals(conf.saved_caches_directory)) | ||
| throw new ConfigurationException("saved_caches_directory must not be the same as the hints_directory", false); | ||
|
|
||
| initializeBackgroundWriteDiskAccessMode(); | ||
| if (backgroundWriteDiskAccessMode != conf.background_write_disk_access_mode) | ||
| logger.info("background_write_disk_access_mode resolved to: {}", backgroundWriteDiskAccessMode); | ||
|
|
||
| if (conf.memtable_flush_writers == 0) | ||
| { | ||
| conf.memtable_flush_writers = conf.data_file_directories.length == 1 ? 2 : 1; | ||
|
|
@@ -3406,6 +3412,84 @@ public static void initializeCommitLogDiskAccessMode() | |
| commitLogWriteDiskAccessMode = accessModeDirectIoPair.left; | ||
| } | ||
|
|
||
| public static DiskAccessMode getBackgroundWriteDiskAccessMode() | ||
| { | ||
| return backgroundWriteDiskAccessMode; | ||
| } | ||
|
|
||
| @VisibleForTesting | ||
| public static void setBackgroundWriteDiskAccessMode(DiskAccessMode diskAccessMode) | ||
| { | ||
| backgroundWriteDiskAccessMode = diskAccessMode; | ||
| conf.background_write_disk_access_mode = diskAccessMode; | ||
| } | ||
|
|
||
| public static DataStorageSpec.IntKibibytesBound getDirectWriteBufferSize() | ||
| { | ||
| return conf.direct_write_buffer_size; | ||
| } | ||
|
|
||
| @VisibleForTesting | ||
| public static void initializeBackgroundWriteDiskAccessMode() | ||
| { | ||
| DiskAccessMode providedMode = conf.background_write_disk_access_mode; | ||
|
|
||
| if (providedMode == DiskAccessMode.auto) | ||
| { | ||
| providedMode = DiskAccessMode.standard; | ||
|
Contributor
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. Auto seems pretty unconditional here so the check above to log that it changed doesn't seem to mean much? I guess it clarifies that It's fine just something I noted. |
||
| } | ||
|
|
||
| if (providedMode == DiskAccessMode.direct) | ||
| { | ||
| // DataStorageSpec already rejects negatives at parse time; zero is the remaining | ||
| // nonsense value. The writer's Math.max would silently coerce it to minRequiredSize, | ||
| // which masks a likely operator mistake — fail fast instead. | ||
| if (conf.direct_write_buffer_size.toBytes() <= 0) | ||
| throw new ConfigurationException("direct_write_buffer_size must be > 0 when background_write_disk_access_mode is 'direct'. " + | ||
| "Got: " + conf.direct_write_buffer_size, false); | ||
|
|
||
| if (!toolInitialized) | ||
| { | ||
| List<String> unsupportedLocations = new ArrayList<>(); | ||
|
|
||
| for (String dataDir : conf.data_file_directories) | ||
| { | ||
| try | ||
| { | ||
| File dataDirFile = new File(dataDir); | ||
| PathUtils.createDirectoriesIfNotExists(dataDirFile.toPath()); | ||
|
|
||
| if (!FileUtils.isDirectIOSupported(dataDirFile)) | ||
| { | ||
| unsupportedLocations.add(dataDir); | ||
| } | ||
| } | ||
| catch (RuntimeException e) | ||
| { | ||
| logger.warn("Unable to determine Direct IO support for data directory {}: {}", dataDir, e.getMessage()); | ||
| unsupportedLocations.add(dataDir + " (check failed: " + e.getMessage() + ")"); | ||
| } | ||
| } | ||
|
|
||
| if (!unsupportedLocations.isEmpty()) | ||
| { | ||
| throw new ConfigurationException( | ||
| String.format("background_write_disk_access_mode is set to 'direct', but the following data directories " + | ||
| "do not support Direct I/O: %s. Either change background_write_disk_access_mode to 'standard' " + | ||
| "in cassandra.yaml, or ensure all data directories are on filesystems that support Direct I/O.", | ||
| unsupportedLocations), false); | ||
| } | ||
| } | ||
| } | ||
| else if (providedMode != DiskAccessMode.standard) | ||
| { | ||
| throw new ConfigurationException("Unsupported disk access mode for background_write_disk_access_mode " + | ||
| "(options: standard/direct/auto): " + providedMode, false); | ||
| } | ||
|
|
||
| backgroundWriteDiskAccessMode = providedMode; | ||
| } | ||
|
|
||
| public static String getSavedCachesLocation() | ||
| { | ||
| return conf.saved_caches_directory; | ||
|
|
||
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,49 @@ | ||
| /* | ||
| * 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.cassandra.io; | ||
|
|
||
| /** | ||
| * Classifies an operation's eligibility for a direct-IO (O_DIRECT) data path, encoding both | ||
| * the answer and the rationale class. Consumers maintain their own per-operation classification | ||
| * and apply this alongside their own gates (e.g. compression, configuration mode); | ||
| * {@link #SUPPORTED} is necessary but not sufficient. | ||
| */ | ||
| public enum DirectIoSupport | ||
| { | ||
| /** | ||
| * Eligible for the direct-IO data path. | ||
| * */ | ||
| SUPPORTED, | ||
|
|
||
| /** | ||
| * The direct-IO path is mechanically incompatible with this operation. Removing this | ||
| * exclusion requires code changes, not policy. | ||
| */ | ||
| UNSUPPORTED_CORRECTNESS, | ||
|
|
||
| /** | ||
| * Direct IO would work but is deliberately disabled for performance or cache-residency | ||
| * reasons. Removing this exclusion requires re-evaluating the policy, not code changes. | ||
| */ | ||
| UNSUPPORTED_POLICY; | ||
|
|
||
| public boolean isSupported() | ||
| { | ||
| return this == SUPPORTED; | ||
| } | ||
| } |
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.
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.
You don't really need to prefix with Note:. It's not really information bearing.