Optimize ReadDirPlus for large directory listings#4631
Optimize ReadDirPlus for large directory listings#4631wadhwanisimran442-cloud wants to merge 9 commits intoGoogleCloudPlatform:masterfrom
Conversation
|
Hey there and thank you for opening this pull request! 👋🏼 We require pull request titles to follow the Conventional Commits specification and it looks like your proposed title needs to be adjusted. Details: |
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request introduces performance optimizations for directory listings in large buckets by implementing a streaming mechanism for ReadDirPlus. By moving away from loading entire directory contents into memory, the file system can now handle significantly larger directories without hitting memory constraints. The changes include refactoring the directory handle to support pagination, decoupling it from the core file system logic, and ensuring robust handling of inode lookups during the streaming process. Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. Footnotes
|
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
There was a problem hiding this comment.
Code Review
This pull request introduces a streaming implementation for ReadDirPlus to improve performance and memory efficiency when listing large directories. It also includes refactoring to break direct dependencies between the directory handle and the file system, along with minor bug fixes in temporary file handling and configuration mapping. However, the new ReadDirPlus implementation currently ignores local unsynced entries, which is a regression from the previous buffered logic. Additionally, there is redundant type assertion logic in the root inode initialization and a change in error handling strategy during directory listing that could lead to silent failures.
| // TODO(b/233580853): Add any remaining localEntries if applicable after exhausting GCS entries. | ||
| // This requires careful sorting and merging. |
There was a problem hiding this comment.
The new streaming implementation of ReadDirPlus currently ignores localEntries (files created locally but not yet synced to GCS). This is a regression in functionality compared to the previous buffered implementation, which merged local entries into the listing. This means that newly created or modified files that haven't been flushed will be missing from ReadDirPlus results, leading to inconsistencies in directory listings (e.g., ls might show a file that ls -l misses).
| if _, ok := root.(inode.BucketOwnedDirInode); ok { | ||
| // Attempt to dynamic cast to BucketOwnedDirInode | ||
| if boDi, ok := root.(inode.BucketOwnedDirInode); ok { | ||
| if boDi.Bucket().BucketType().Hierarchical { | ||
| fs.folderInodes[root.Name()] = root | ||
| } else { | ||
| fs.implicitDirInodes[root.Name()] = root | ||
| } | ||
| } else { | ||
| // Fallback for BaseDirInode which doesn't have Bucket() | ||
| fs.implicitDirInodes[root.Name()] = root | ||
| } | ||
| } else { | ||
| fs.implicitDirInodes[root.Name()] = root | ||
| } |
There was a problem hiding this comment.
The type assertion for root as inode.BucketOwnedDirInode is performed twice consecutively. The outer if check at line 299 makes the inner check at line 301 redundant. Additionally, the else block at line 307 is unreachable because if the outer check passes, the inner one will also pass. The logic can be simplified by combining these checks.
if boDi, ok := root.(inode.BucketOwnedDirInode); ok {
if boDi.Bucket().BucketType().Hierarchical {
fs.folderInodes[root.Name()] = root
} else {
fs.implicitDirInodes[root.Name()] = root
}
} else {
fs.implicitDirInodes[root.Name()] = root
}| if err != nil { | ||
| logger.Warnf("ReadDirPlus: Failed to convert core to DirentPlus for %s: %v", name, err) | ||
| continue | ||
| } |
There was a problem hiding this comment.
In the new ReadDirPlus implementation, errors encountered during coreToDirentPlus are logged as warnings and the entry is skipped. The previous implementation in fs.go would return the error immediately, failing the ReadDirPlus operation. Swallowing these errors might lead to incomplete directory listings without the caller knowing that an error occurred. It is generally better to propagate the error to the VFS layer unless skipping the entry is the intended behavior for specific, recoverable errors.
d478280 to
5ce8b73
Compare
Please ensure your PR title follows the format:
Example:
feat(api): add user login endpointAvailable types:
feat: A new featurefix: A bug fixdocs: Documentation only changesstyle: Changes that do not affect the meaning of the code (white-space, formatting, missing semi-colons, etc)refactor: A code change that neither fixes a bug nor adds a featureperf: A code change that improves performancetest: Adding missing tests or correcting existing testsbuild: Changes that affect the build system or external dependencies (example scopes: gulp, broccoli, npm)ci: Changes to our CI configuration files and scripts (example scopes: Travis, Circle, BrowserStack, SauceLabs)chore: Other changes that don't modify src or test filesrevert: Reverts a previous commitDescription
Link to the issue in case of a bug fix.
Testing details
Any backward incompatible change? If so, please explain.