Skip to content

storage/engine: optionalize + document MVCCGet#33213

Merged
craig[bot] merged 3 commits intocockroachdb:masterfrom
benesch:mvccget
Dec 18, 2018
Merged

storage/engine: optionalize + document MVCCGet#33213
craig[bot] merged 3 commits intocockroachdb:masterfrom
benesch:mvccget

Conversation

@benesch
Copy link
Copy Markdown
Contributor

@benesch benesch commented Dec 17, 2018

No description provided.

@benesch benesch requested review from a team and petermattis December 17, 2018 23:27
@cockroach-teamcity
Copy link
Copy Markdown
Member

This change is Reviewable

Copy link
Copy Markdown
Collaborator

@petermattis petermattis left a comment

Choose a reason for hiding this comment

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

:lgtm: modulo small comment about the extra allocation caused by transforming the pointer to a slice.

Reviewed 34 of 34 files at r1.
Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained


pkg/storage/batcheval/cmd_get.go, line 47 at r2 (raw file):

	var intents []roachpb.Intent
	if intent != nil {
		intents = append(intents, *intent)

This results in an extra allocation as we allocated once to return the *intent and again here to create the backing array for the slice. Is this worth worry about? Probably not.


pkg/storage/engine/engine.go, line 107 at r1 (raw file):

	// MVCCGet is the internal implementation of the family of package-level
	// MVCCGet functions. The notable difference is that key/value pairs are
	// returned raw, as a buffer of varint-prefixed slices, alternating from key

This doesn't look accurate. Iterator.MVCCGet has the same interface as the package-level MVCCGet.


pkg/storage/engine/mvcc.go, line 681 at r1 (raw file):

// ...
// keyA_Timestamp_0 : value of version_0
// keyB : MVCCMetadata of keyB

Is there a documentation comment elsewhere about the MVCC key structure? Seems a shame to remove this if this is the only comment describing the structure.


pkg/storage/engine/rocksdb.go, line 2257 at r1 (raw file):

	state := C.MVCCGet(
		r.iter, goToCSlice(key), goToCTimestamp(timestamp),
		goToCTxn(opts.Txn), C.bool(!opts.Inconsistent), C.bool(opts.Tombstones),

I wonder if you should go the extra mile and change the libroach MVCCGet function parameter from consistent to inconsistent. It will be a bit confusing in the future to stumble across that polarity change.

Copy link
Copy Markdown
Contributor Author

@benesch benesch 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)


pkg/storage/batcheval/cmd_get.go, line 47 at r2 (raw file):

Previously, petermattis (Peter Mattis) wrote…

This results in an extra allocation as we allocated once to return the *intent and again here to create the backing array for the slice. Is this worth worry about? Probably not.

Yeah, I figured it was safe because nothing perf-sensitive uses the Get API AFAIK. (E.g., result.FromIntents allocates again to construct the result.)


pkg/storage/engine/engine.go, line 107 at r1 (raw file):

Previously, petermattis (Peter Mattis) wrote…

This doesn't look accurate. Iterator.MVCCGet has the same interface as the package-level MVCCGet.

Oops, thanks for the fact check. Done.


pkg/storage/engine/mvcc.go, line 681 at r1 (raw file):

Previously, petermattis (Peter Mattis) wrote…

Is there a documentation comment elsewhere about the MVCC key structure? Seems a shame to remove this if this is the only comment describing the structure.

Good point. Not that I can find. I've moved the diagram to the doc.go in this package.


pkg/storage/engine/rocksdb.go, line 2257 at r1 (raw file):

Previously, petermattis (Peter Mattis) wrote…

I wonder if you should go the extra mile and change the libroach MVCCGet function parameter from consistent to inconsistent. It will be a bit confusing in the future to stumble across that polarity change.

Yeah, I'd been thinking about that. Done. Thanks for the push.

@benesch benesch force-pushed the mvccget branch 2 times, most recently from 43e5ace to 0ed047e Compare December 18, 2018 05:27
Copy link
Copy Markdown
Collaborator

@petermattis petermattis left a comment

Choose a reason for hiding this comment

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

:shipit:

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (and 1 stale)


pkg/storage/batcheval/cmd_get.go, line 47 at r2 (raw file):

Previously, benesch (Nikhil Benesch) wrote…

Yeah, I figured it was safe because nothing perf-sensitive uses the Get API AFAIK. (E.g., result.FromIntents allocates again to construct the result.)

Yeah, I'm ok with this.

For symmetry with 4678a31, which extracted an MVCCScanOptions struct.

Also take the opportunity to update the documentation for MVCCGet.

Release note: None
MVCCGet can only return zero or one intents. This is more naturally
represented by a pointer than a slice. Adjust the return value
accordingly so that callers do not need to check for MVCCGet returning
multiple intents, which is obviously nonsense.

Release note: None
For consistency with the Go signature, which uses inconsistent instead
of consistent.

Release note: None
@benesch
Copy link
Copy Markdown
Contributor Author

benesch commented Dec 18, 2018

TFTR!

bors r=petermattis

craig bot pushed a commit that referenced this pull request Dec 18, 2018
33213: storage/engine: optionalize + document MVCCGet r=petermattis a=benesch



Co-authored-by: Nikhil Benesch <nikhil.benesch@gmail.com>
@craig
Copy link
Copy Markdown
Contributor

craig bot commented Dec 18, 2018

Build succeeded

@craig craig bot merged commit ba01a38 into cockroachdb:master Dec 18, 2018
@benesch benesch deleted the mvccget branch June 21, 2019 22:00
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