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

sync -- client cleanup #1680

Merged
merged 20 commits into from
Jul 7, 2023
Merged

sync -- client cleanup #1680

merged 20 commits into from
Jul 7, 2023

Conversation

danlaine
Copy link

@danlaine danlaine commented Jul 3, 2023

Why this should be merged

Cleanup

How this works

Comments, nits and other small changes to improve readability and make the code easier to understand.

How this was tested

Existing UT.

@danlaine danlaine added cleanup Code quality improvement merkledb labels Jul 3, 2023
@danlaine danlaine self-assigned this Jul 3, 2023
x/sync/client.go Outdated Show resolved Hide resolved
lastErr = err
time.Sleep(failedRequestSleepInterval)
Copy link
Author

Choose a reason for hiding this comment

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

Removed to avoid sleeping. It's not the end of the world to wait 10 ms to wake up in the event of context cancellation, but still seems like good practice to not sleep.

// or [ctx] is canceled.
// Returns the peer's NodeID and response.
// It's safe to call this method multiple times concurrently.
func (c *client) get(ctx context.Context, request []byte) (ids.NodeID, []byte, error) {
Copy link
Author

Choose a reason for hiding this comment

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

In other places like this we return the node ID first so I did that here too

func (c *networkClient) AppRequestFailed(_ context.Context, nodeID ids.NodeID, requestID uint32) error {
// Always returns nil because the engine considers errors
// returned from this function as fatal.
func (c *networkClient) AppRequestFailed(
Copy link
Author

Choose a reason for hiding this comment

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

I don't think it's necessary to rewrite the semantics of AppRequestFailed here

if err := c.activeRequests.Acquire(ctx, 1); err != nil {
return nil, ErrAcquiringSemaphore
}
defer c.activeRequests.Release(1)
Copy link
Author

Choose a reason for hiding this comment

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

Moved releases for this semaphore to be in the two places we acquire from it

Comment on lines +247 to +248
handler := newResponseHandler()
c.outstandingRequestHandlers[requestID] = handler
Copy link
Author

Choose a reason for hiding this comment

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

can wait to register this until we've successfully sent the request

@danlaine danlaine marked this pull request as ready for review July 3, 2023 16:25
x/sync/client.go Outdated
// Return error at top of loop.
// Don't do it here to avoid duplicate code.
case <-time.After(failedRequestSleepInterval):
// TODO should we randomize this?
Copy link
Contributor

Choose a reason for hiding this comment

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

What benefit would randomization have?
We could consider adding exponential backoff.

Copy link
Author

Choose a reason for hiding this comment

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

Just trying to prevent retry storms. I'll add exponential backoff in a follow up PR.

Copy link
Author

Choose a reason for hiding this comment

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

x/sync/client.go Outdated Show resolved Hide resolved
x/sync/client.go Outdated Show resolved Hide resolved
@danlaine danlaine merged commit 524afaa into dev Jul 7, 2023
13 checks passed
@danlaine danlaine deleted the sync-refactor-client branch July 7, 2023 18:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cleanup Code quality improvement merkledb
Projects
No open projects
Archived in project
Development

Successfully merging this pull request may close these issues.

3 participants