chore: [cache-dir-size-fix] Part 4: Implement the fix for dir-size in file-cache#4417
Conversation
|
/gemini summary |
|
/gemini review |
Summary of ChangesThis pull request is the fourth part of a series aimed at fixing directory size calculation within the file cache. It integrates new components for precise disk utilization tracking and introduces a shared locking mechanism for cache directories. These changes enhance the file cache's ability to manage disk space effectively and ensure thread-safe operations, particularly in scenarios involving sparse files and parallel downloads. Highlights
Changelog
Activity
|
There was a problem hiding this comment.
Code Review
This pull request implements the logic for more accurate file cache size calculation by introducing a diskSizeCalculator. The changes involve plumbing this new component and a sharedDirLocker through several layers of the cache and downloader packages. The overall approach seems correct, but I've found a critical issue with the error handling in the new NewCacheHandler function, which uses panic instead of returning errors. This could lead to application crashes and should be addressed.
| if jobManager != nil { | ||
| if err := jobManager.SetSharedDirLocker(sharedDirLocker); err != nil { | ||
| // TODO: Instead of panicking, return an error from NewCacheHandler and handle it in the caller. | ||
| panic(fmt.Errorf("failed to set shared directory locker for job manager: %w", err)) | ||
| } | ||
| } | ||
| if diskSizeCalculator != nil { | ||
| if err := diskSizeCalculator.SetSharedDirLocker(sharedDirLocker); err != nil { | ||
| // TODO: Instead of panicking, return an error from NewCacheHandler and handle it in the caller. | ||
| panic(fmt.Errorf("failed to set shared directory locker for disk size calculator: %w", err)) | ||
| } | ||
| } |
There was a problem hiding this comment.
Using panic for recoverable errors, such as a dependency being set more than once, is dangerous as it can crash the entire gcsfuse process. The TODO comments correctly identify that these errors should be returned to the caller for graceful handling.
I recommend refactoring NewCacheHandler to return an error, for example:
func NewCacheHandler(...) (*CacheHandler, error)
Then, you can replace the panic calls with return nil, fmt.Errorf(...). This change can be propagated up to createFileCacheHandler in internal/fs/fs.go, which already returns an error and can handle this failure condition.
b0703f9 to
1b337ac
Compare
a114ba0 to
6ee30f0
Compare
1b337ac to
19b157e
Compare
6ee30f0 to
c32efd1
Compare
19b157e to
8296b90
Compare
c32efd1 to
039676b
Compare
8296b90 to
8ca046f
Compare
039676b to
fa4ad93
Compare
8ca046f to
95670d6
Compare
fa4ad93 to
f1c7923
Compare
95670d6 to
14c98fc
Compare
f1c7923 to
ff4b534
Compare
Description
Link to the issue in case of a bug fix.
b/477828938
Testing details
Any backward incompatible change? If so, please explain.