Skip to content

requestbatcher,intentresolver: add timeout in requestbatcher and adopt#36845

Merged
craig[bot] merged 2 commits intocockroachdb:masterfrom
ajwerner:ajwerner/add-timeout-to-request-batcher
Apr 16, 2019
Merged

requestbatcher,intentresolver: add timeout in requestbatcher and adopt#36845
craig[bot] merged 2 commits intocockroachdb:masterfrom
ajwerner:ajwerner/add-timeout-to-request-batcher

Conversation

@ajwerner
Copy link
Copy Markdown
Contributor

This PR adds a configuration option for a timeout for batch request sends in
the request batcher and adopts this option in the intent resolver. Prior to
the introduction of batching in #34803 intent resolution was performed with a
maximum timeout of 30s. This PR uses that same constant and additionally
applies it to batches of requests to gc transaction records.

Informs #36806.

Release note: None

@ajwerner ajwerner requested a review from a team April 15, 2019 17:14
@cockroach-teamcity
Copy link
Copy Markdown
Member

This change is Reviewable

@ajwerner
Copy link
Copy Markdown
Contributor Author

Before #34803 we used to also respect client provided timeouts via the context passed to the intent resolver if it was shorter than the package default. We could add logic to do that still but I wasn't sure what the right policy would be. It seems like if the code were to give any consideration to client provided timeouts the two options would be to respect the earliest timeout of any request sent in the batch or the latest. The earliest worries me as it's probably not a good idea to cancel a whole batch for a single request due perhaps to a timeout from processing the gc queue. Taking the latest client provided timeout seems fine but I don't have a compelling argument to justify the complexity.

@ajwerner ajwerner force-pushed the ajwerner/add-timeout-to-request-batcher branch 2 times, most recently from 501ca42 to 8de9061 Compare April 15, 2019 19:36
@ajwerner
Copy link
Copy Markdown
Contributor Author

Added another commit which changes the behavior of contextutil.RunWithTimeout so that it returns a TimeoutError if the timeout is exceeded even if the returned error does not have context.DeadlineExceeded as its Cause. See the commit message for more details.

Copy link
Copy Markdown
Contributor

@nvb nvb left a comment

Choose a reason for hiding this comment

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

:lgtm:

Reviewed 2 of 2 files at r1, 3 of 3 files at r2.
Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (waiting on @ajwerner)


pkg/internal/client/requestbatcher/batcher.go, line 272 at r2 (raw file):

		defer b.sendDone(ba)
		var resp *roachpb.BatchResponse
		var pErr *roachpb.Error

Are we getting anything out of capturing pErr? If not then I'd tighten its scope both for clarity and to ensure that it doesn't escape.


pkg/util/contextutil/context_test.go, line 83 at r1 (raw file):

	notContextDeadlineExceeded := errors.New(context.DeadlineExceeded.Error())
	err := RunWithTimeout(ctx, "foo", 1, func(ctx context.Context) error {
		time.Sleep(10 * time.Millisecond)

This looks flaky. Can't we wait on the context cancelation like: <-ctx.Done()?

@nvb
Copy link
Copy Markdown
Contributor

nvb commented Apr 15, 2019

The earliest worries me as it's probably not a good idea to cancel a whole batch for a single request due perhaps to a timeout from processing the gc queue. Taking the latest client provided timeout seems fine but I don't have a compelling argument to justify the complexity.

I agree that it's not worth the complexity. What you have here looks fine.

Andrew Werner added 2 commits April 15, 2019 21:30
Before this commit, if the context were to have expired but the returned
errors did not have a Cause of context.DeadlineExceeded, RunWithTimeout
would not return a TimeoutError.

It is perhaps surprising that the returned TimeoutError does not have
context.DeadlineExceeded as its Cause but it seemed preferable to
retain the potentially more meaningful error as the Cause.
This PR adds a configuration option for a timeout for batch request sends in
the request batcher and adopts this option in the intent resolver. Prior to
the introduction of batching in cockroachdb#34803 intent resolution was performed with a
maximum timeout of 30s. This PR uses that same constant and additionally
applies it to batches of requests to gc transaction records.

Informs cockroachdb#36806.

Release note: None
@ajwerner ajwerner force-pushed the ajwerner/add-timeout-to-request-batcher branch from 8de9061 to be3414d Compare April 16, 2019 01:33
Copy link
Copy Markdown
Contributor Author

@ajwerner ajwerner left a comment

Choose a reason for hiding this comment

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

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (and 1 stale) (waiting on @nvanbenschoten)


pkg/internal/client/requestbatcher/batcher.go, line 272 at r2 (raw file):

Previously, nvanbenschoten (Nathan VanBenschoten) wrote…

Are we getting anything out of capturing pErr? If not then I'd tighten its scope both for clarity and to ensure that it doesn't escape.

Done.


pkg/util/contextutil/context_test.go, line 83 at r1 (raw file):

Previously, nvanbenschoten (Nathan VanBenschoten) wrote…

This looks flaky. Can't we wait on the context cancelation like: <-ctx.Done()?

Done.

@ajwerner
Copy link
Copy Markdown
Contributor Author

bors r+

craig bot pushed a commit that referenced this pull request Apr 16, 2019
36845: requestbatcher,intentresolver: add timeout in requestbatcher and adopt r=ajwerner a=ajwerner

This PR adds a configuration option for a timeout for batch request sends in
the request batcher and adopts this option in the intent resolver. Prior to
the introduction of batching in #34803 intent resolution was performed with a
maximum timeout of 30s. This PR uses that same constant and additionally
applies it to batches of requests to gc transaction records.

Informs #36806.

Release note: None

Co-authored-by: Andrew Werner <ajwerner@cockroachlabs.com>
@craig
Copy link
Copy Markdown
Contributor

craig bot commented Apr 16, 2019

Build succeeded

@craig craig bot merged commit be3414d into cockroachdb:master Apr 16, 2019
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.

3 participants