-
Notifications
You must be signed in to change notification settings - Fork 635
HDDS-16326. Cache the container chunks directory instead of stat-ing it on every chunk operation #11151
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
Draft
rich7420
wants to merge
3
commits into
apache:master
Choose a base branch
from
rich7420:HDDS-16326
base: master
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.
Draft
HDDS-16326. Cache the container chunks directory instead of stat-ing it on every chunk operation #11151
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
db567eb
HDDS-16326. Cache the container chunks directory instead of stat-ing …
rich7420 e68e3b0
HDDS-16326. Validate the chunks directory on writes, cache only on reads
rich7420 349ce2d
HDDS-16326. Memoize the read-path chunks directory on ContainerData
rich7420 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -32,6 +32,7 @@ | |
| import com.google.common.annotations.VisibleForTesting; | ||
| import com.google.common.collect.Lists; | ||
| import jakarta.annotation.Nullable; | ||
| import java.io.File; | ||
| import java.io.IOException; | ||
| import java.nio.charset.Charset; | ||
| import java.nio.charset.StandardCharsets; | ||
|
|
@@ -47,6 +48,7 @@ | |
| import org.apache.hadoop.hdds.protocol.datanode.proto.ContainerProtos.ContainerDataProto; | ||
| import org.apache.hadoop.hdds.protocol.datanode.proto.ContainerProtos.ContainerType; | ||
| import org.apache.hadoop.hdds.protocol.proto.StorageContainerDatanodeProtocolProtos.ContainerReplicaProto; | ||
| import org.apache.hadoop.hdds.scm.container.common.helpers.StorageContainerException; | ||
| import org.apache.hadoop.ozone.container.common.helpers.ContainerUtils; | ||
| import org.apache.hadoop.ozone.container.common.volume.HddsVolume; | ||
| import org.apache.ratis.util.Preconditions; | ||
|
|
@@ -77,6 +79,10 @@ public abstract class ContainerData { | |
| // Path to Physical file system where chunks are stored. | ||
| private String chunksPath; | ||
|
|
||
| // Chunks directory resolved and validated once from chunksPath, cached to | ||
| // avoid re-stat-ing it on every chunk operation. Not serialized. | ||
| private transient volatile File chunksDirFile; | ||
|
|
||
| // State of the Container | ||
| private ContainerDataProto.State state; | ||
|
|
||
|
|
@@ -263,6 +269,26 @@ public String getChunksPath() { | |
| */ | ||
| public void setChunksPath(String chunkPath) { | ||
| this.chunksPath = chunkPath; | ||
| this.chunksDirFile = null; | ||
| } | ||
|
|
||
| /** | ||
| * Read-path accessor for the chunks directory. Resolves and validates it once | ||
| * via {@link ContainerUtils#getChunkDir(ContainerData)}, then returns the | ||
| * cached result on later calls to skip the per-read stat. Writes and other | ||
| * callers use {@code ContainerUtils.getChunkDir} directly, so a missing | ||
| * directory still surfaces as a storage failure on every operation. | ||
| * | ||
| * @return the resolved chunks directory | ||
| * @throws StorageContainerException if the chunks directory cannot be resolved | ||
| */ | ||
| public File getChunksDirForRead() throws StorageContainerException { | ||
|
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. Should this getter be |
||
| File dir = chunksDirFile; | ||
| if (dir == null) { | ||
| dir = ContainerUtils.getChunkDir(this); | ||
| chunksDirFile = dir; | ||
| } | ||
| return dir; | ||
| } | ||
|
|
||
| /** | ||
|
|
||
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,8 +224,10 @@ public ChunkBufferToByteString readChunk(Container container, BlockID blockID, | |
| HddsVolume volume = containerData.getVolume(); | ||
|
|
||
| // In version1, we verify checksum if it is available and return data | ||
| // of the chunk file. | ||
| File finalChunkFile = getChunkFile(kvContainer, blockID, info); | ||
| // of the chunk file. Reads use the cached chunks directory to skip the | ||
| // per-read stat; writes keep validating so a missing directory is detected. | ||
| File finalChunkFile = FILE_PER_CHUNK.getChunkFile( | ||
| containerData.getChunksDirForRead(), blockID, info.getChunkName()); | ||
|
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. Should we still validate the directory at this path to preserve the previous error and logging behavior? |
||
|
|
||
| List<File> possibleFiles = new ArrayList<>(); | ||
| possibleFiles.add(finalChunkFile); | ||
|
|
||
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
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.
nit: Could this Javadoc stay about what the method does? It now describes what callers rely on, and the same note appears in other files.