Skip to content
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

internal/transport: minor cleanup of controlBuffer code #7319

Merged
merged 2 commits into from
Jun 17, 2024

Conversation

easwars
Copy link
Contributor

@easwars easwars commented Jun 11, 2024

This PR makes a few minor cleanups to the controlBuffer code with the aim of making it more readable.

Summary of changes:

  • Rename ch to wakeupCh
    • This channel is used to wake up readers blocked waiting for something to read out of the control buffer, and ch simply isn't descriptive enough, since the scope of this field is reasonable large.
  • Got rid of the err field with a closed boolean
    • The only time when the control buffer returns error is when it is closed and the error value returned in this case is always ErrConnClosing. Using a closed boolean and explicitly returning ErrConnClosing makes this explicit, instead of making the reader wonder what possible error values could be returned.
  • Changed the type of trfChan from atomic.Value to atomic.Pointer
    • The latter is ergonomic to use and we have started using it in a lot of places in our codebase (in newer code).
  • Got rid of the execute method which had a single caller, and change the caller to work with executeAndPut
  • Switched all methods to defer the call to cc.Unlock
    • This eliminates multiple calls to cc.Unlock from each of the return paths
    • Over the years, the Go team has made significant improvements in defer performance. So, it is no longer required that we avoid defer in the hopes for improved performance, but in return having harder to read code.
  • Added comments to all methods of controlBuffer and indented existing comment lines at 80 cols.

RELEASE NOTES: none

@easwars easwars requested a review from arvindbr8 June 11, 2024 19:47
@easwars easwars added the Type: Internal Cleanup Refactors, etc label Jun 11, 2024
@easwars easwars added this to the 1.66 Release milestone Jun 11, 2024
Copy link
Member

@arvindbr8 arvindbr8 left a comment

Choose a reason for hiding this comment

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

Great! thanks so much for looking into this. Hopefully your eyes didnt need bleaching..

Just a few comments. Please let me know when its ready for another review.

internal/transport/controlbuf.go Outdated Show resolved Hide resolved
internal/transport/controlbuf.go Show resolved Hide resolved
internal/transport/controlbuf.go Outdated Show resolved Hide resolved
internal/transport/controlbuf.go Show resolved Hide resolved
@arvindbr8 arvindbr8 assigned easwars and unassigned arvindbr8 Jun 11, 2024
@easwars easwars assigned arvindbr8 and unassigned easwars Jun 11, 2024
Copy link
Member

@arvindbr8 arvindbr8 left a comment

Choose a reason for hiding this comment

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

Thanks!

@arvindbr8 arvindbr8 assigned easwars and unassigned arvindbr8 Jun 11, 2024
@easwars easwars merged commit c04b085 into grpc:master Jun 17, 2024
11 checks passed
@easwars easwars deleted the controlbuf_minor_cleanup branch June 17, 2024 14:41
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 15, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants