Skip to content

fs/remote: Refactor blob code to make it more modular - #1948

Closed
ChengyuZhu6 wants to merge 1 commit into
containerd:mainfrom
ChengyuZhu6:refactor
Closed

ChengyuZhu6 wants to merge 1 commit into
containerd:mainfrom
ChengyuZhu6:refactor

Conversation

@ChengyuZhu6

Copy link
Copy Markdown
Member

This PR refactors the blob handling code to improve code organization. The changes include:

  1. Extract chunk handling logic into separate functions:

    • prepareChunksForRead: Prepare chunks for reading
    • readFromCache: Handle cache reading
    • cacheChunkData: Handle chunk caching
    • handleSharedFetch: Handle shared fetch scenarios
    • copyFetchedChunks: Copy fetched chunks
  2. Improve error handling:

    • Add more descriptive error messages
    • Consistent error wrapping using fmt.Errorf
    • Maintain same error handling behavior
  3. Keep original behavior:

    • Maintain same data flow
    • Keep same concurrency control
    • No additional memory allocations
    • Same caching mechanism
  4. Code organization improvements:

    • Single responsibility functions
    • Clear function names
    • Better code readability
    • Easier to maintain and test

Comment thread fs/remote/blob.go Outdated
Comment thread fs/remote/blob.go Outdated
Comment thread fs/remote/blob.go
@ChengyuZhu6
ChengyuZhu6 force-pushed the refactor branch 2 times, most recently from ba7f88a to e519d34 Compare January 21, 2025 07:23
@ChengyuZhu6

Copy link
Copy Markdown
Member Author

retrigger the ci

@ChengyuZhu6
ChengyuZhu6 requested a review from ktock January 21, 2025 07:56
Comment thread fs/remote/blob.go Outdated
@ChengyuZhu6

Copy link
Copy Markdown
Member Author

just retrigger the ci

Comment thread fs/remote/blob.go Outdated
@ChengyuZhu6
ChengyuZhu6 force-pushed the refactor branch 4 times, most recently from b3a4e9b to 1cac7e0 Compare January 22, 2025 05:49
@ChengyuZhu6
ChengyuZhu6 requested a review from ktock January 22, 2025 05:59
Comment thread fs/remote/blob.go
defer r.Close()
var n int
n, err = r.ReadAt(dest, offset)
if (err == nil || err == io.EOF) && int64(n) == int64(len(dest)) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

assign an explicit error on err == nil but int64(n) != int64(len(dest)) otherwize nil error will returned to the caller in that case.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

This commit refactors the blob handling code to improve code organization.
The changes include:

1. Extract chunk handling logic into separate functions:
   - prepareChunksForRead: Prepare chunks for reading
   - readFromCache: Handle cache reading
   - cacheChunkData: Handle chunk caching
   - handleSharedFetch: Handle shared fetch scenarios
   - copyFetchedChunks: Copy fetched chunks

2. Improve error handling:
   - Add more descriptive error messages
   - Consistent error wrapping using fmt.Errorf
   - Maintain same error handling behavior

3. Keep original behavior:
   - Maintain same data flow
   - Keep same concurrency control
   - No additional memory allocations
   - Same caching mechanism

4. Code organization improvements:
   - Single responsibility functions
   - Clear function names
   - Better code readability
   - Easier to maintain and test

Signed-off-by: ChengyuZhu6 <hudson@cyzhu.com>
@ChengyuZhu6

Copy link
Copy Markdown
Member Author

Just retrigger the ci

@ktock

ktock commented Jan 24, 2025

Copy link
Copy Markdown
Member

Thanks, I'll merge this via #1955.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants