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

rangefeed: improve assertions #118265

Merged
merged 2 commits into from
Feb 1, 2024
Merged

Conversation

erikgrinaker
Copy link
Contributor

rangefeed: use log.Fatal instead of panic

This will include the log tags from the context, aiding with debugging. Involves a bunch of context plumbing, and removing some assertion tests.

A couple of panics were left in, where it didn't appear natural to plumb through a context.

rangefeed: use pointer receiver in MVCCLogicalOp assertion

String() is only implemented for a pointer receiver, so the formatting breaks otherwise.

Epic: none
Release note: None

@erikgrinaker erikgrinaker self-assigned this Jan 24, 2024
@erikgrinaker erikgrinaker requested a review from a team January 24, 2024 11:10
@cockroach-teamcity
Copy link
Member

This change is Reviewable

This will include the log tags from the context, aiding with debugging.
Involves a bunch of context plumbing, and removing some assertion tests.

A couple of panics were left in, where it didn't appear natural to plumb
through a context.

Epic: none
Release note: None
`String()` is only implemented for a pointer receiver, so the formatting
breaks otherwise.

Epic: none
Release note: None
Copy link
Member

@nvanbenschoten nvanbenschoten left a comment

Choose a reason for hiding this comment

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

Reviewed 7 of 7 files at r1.
Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @erikgrinaker)


pkg/kv/kvserver/rangefeed/resolved_timestamp.go line 300 at r2 (raw file):

		op := op
		err := errors.AssertionFailedf(
			"resolved timestamp %s equal to or above timestamp of operation %v", rts.resolvedTS, &op)

Was this actually causing the op param to move to the heap when not on the assertion path? I'd think it would only do so if we were passing &op like we were doing in #118413.

Here's a test showing that on master:

➜ git rev-parse HEAD
f71b21dbd904e1a6a7ccd1f767db769c48476e2a
➜ pwd
/Users/nathan/Go/src/github.com/cockroachdb/cockroach/pkg/kv/kvserver/rangefeed

➜ fgrep 'equal to or above timestamp of operation' resolved_timestamp.go
			"resolved timestamp %s equal to or above timestamp of operation %v", rts.resolvedTS, op)
➜ go build -gcflags='-m' 2>&1 | grep 'heap' | grep 'resolved_timestamp.go:29'
./resolved_timestamp.go:296:76: rts.resolvedTS escapes to heap
./resolved_timestamp.go:296:89: op escapes to heap

➜ fgrep 'equal to or above timestamp of operation' resolved_timestamp.go
			"resolved timestamp %s equal to or above timestamp of operation %v", rts.resolvedTS, &op)
➜ go build -gcflags='-m' 2>&1 | grep 'heap' | grep 'resolved_timestamp.go:29'
./resolved_timestamp.go:292:23: moved to heap: op
./resolved_timestamp.go:296:76: rts.resolvedTS escapes to heap

pkg/kv/kvserver/rangefeed/registry_test.go line 512 at r1 (raw file):

}

func TestRegistryPublishAssertsPopulatedInformation(t *testing.T) {

Would it be worth testing for log.Fatal instead of losing this test coverage?

Copy link
Contributor Author

@erikgrinaker erikgrinaker 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 (waiting on @nvanbenschoten)


pkg/kv/kvserver/rangefeed/resolved_timestamp.go line 300 at r2 (raw file):

Previously, nvanbenschoten (Nathan VanBenschoten) wrote…

Was this actually causing the op param to move to the heap when not on the assertion path? I'd think it would only do so if we were passing &op like we were doing in #118413.

Here's a test showing that on master:

➜ git rev-parse HEAD
f71b21dbd904e1a6a7ccd1f767db769c48476e2a
➜ pwd
/Users/nathan/Go/src/github.com/cockroachdb/cockroach/pkg/kv/kvserver/rangefeed

➜ fgrep 'equal to or above timestamp of operation' resolved_timestamp.go
			"resolved timestamp %s equal to or above timestamp of operation %v", rts.resolvedTS, op)
➜ go build -gcflags='-m' 2>&1 | grep 'heap' | grep 'resolved_timestamp.go:29'
./resolved_timestamp.go:296:76: rts.resolvedTS escapes to heap
./resolved_timestamp.go:296:89: op escapes to heap

➜ fgrep 'equal to or above timestamp of operation' resolved_timestamp.go
			"resolved timestamp %s equal to or above timestamp of operation %v", rts.resolvedTS, &op)
➜ go build -gcflags='-m' 2>&1 | grep 'heap' | grep 'resolved_timestamp.go:29'
./resolved_timestamp.go:292:23: moved to heap: op
./resolved_timestamp.go:296:76: rts.resolvedTS escapes to heap

Yeah, looks like op would always escape to the heap here. I think printf arguments generally always do, there's some analysis of why here: golang/go#8618 (comment)


pkg/kv/kvserver/rangefeed/registry_test.go line 512 at r1 (raw file):

Previously, nvanbenschoten (Nathan VanBenschoten) wrote…

Would it be worth testing for log.Fatal instead of losing this test coverage?

I'm kind of ambivalent towards testing assertions. It's sort of like adding tests for tests -- occasionally useful, but generally not worth the cost.

I see that we have log.SetExitFunc() to override the fatal, so I can port these over if you feel like it's worthwhile.

Copy link
Member

@nvanbenschoten nvanbenschoten 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 (waiting on @erikgrinaker)


pkg/kv/kvserver/rangefeed/resolved_timestamp.go line 300 at r2 (raw file):

Previously, erikgrinaker (Erik Grinaker) wrote…

Yeah, looks like op would always escape to the heap here. I think printf arguments generally always do, there's some analysis of why here: golang/go#8618 (comment)

Discussed on Slack. For now, we'll just go with the following until we can bottom out on understanding this better:

err := errors.AssertionFailedf("resolved timestamp %s equal to or above timestamp of operation %s", rts.resolvedTS, op.String())

Copy link
Contributor Author

@erikgrinaker erikgrinaker 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 (waiting on @nvanbenschoten)


pkg/kv/kvserver/rangefeed/resolved_timestamp.go line 300 at r2 (raw file):

Previously, nvanbenschoten (Nathan VanBenschoten) wrote…

Discussed on Slack. For now, we'll just go with the following until we can bottom out on understanding this better:

err := errors.AssertionFailedf("resolved timestamp %s equal to or above timestamp of operation %s", rts.resolvedTS, op.String())

Ran a benchmark for the happy path:

  • op: does not allocate.
  • &op: allocates.
  • op := op; &op: does not allocate.

Copy link
Contributor Author

@erikgrinaker erikgrinaker 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 (waiting on @nvanbenschoten)


pkg/kv/kvserver/rangefeed/resolved_timestamp.go line 300 at r2 (raw file):

Previously, erikgrinaker (Erik Grinaker) wrote…

Ran a benchmark for the happy path:

  • op: does not allocate.
  • &op: allocates.
  • op := op; &op: does not allocate.

Of course, op.String() does allocate, lol.

op := op; &op it is then.

Copy link
Member

@nvanbenschoten nvanbenschoten 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 1 of 1 files at r2, all commit messages.
Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (waiting on @erikgrinaker)

@erikgrinaker
Copy link
Contributor Author

TFTR!

bors r+

@craig
Copy link
Contributor

craig bot commented Feb 1, 2024

Build succeeded:

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