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

storage: avoid allocations for range-local key generation #13455

Merged

Conversation

petermattis
Copy link
Collaborator

@petermattis petermattis commented Feb 7, 2017

Reorganized the range-local key generation code to utilize a new
RangeIDPrefixBuf abstraction. Use this new functionality in
replicaStateKeys to avoid allocations when loading and saving
range-local data.

This removes 2.2% of allocations in a write-only workload.


This change is Reviewable

@petermattis
Copy link
Collaborator Author

Review status: 0 of 15 files reviewed at latest revision, 2 unresolved discussions.


pkg/storage/replica_state.go, line 38 at r1 (raw file):

//
// Note that this struct is not safe for concurrent use. It is usually
// protected by Replica.raftMu or a goroutine local variable is used.

The concurrency issue isn't a big deal in practice as we only call the methods on replicaStateKeys while holding Replica.raftMu.


pkg/storage/replica_state.go, line 39 at r1 (raw file):

// Note that this struct is not safe for concurrent use. It is usually
// protected by Replica.raftMu or a goroutine local variable is used.
type replicaStateKeys struct {

I'm not fond of this type name. Suggestions?


Comments from Reviewable

@petermattis petermattis force-pushed the pmattis/replica-state-keys branch 2 times, most recently from c8344ea to e70865f Compare February 7, 2017 17:38
@petermattis
Copy link
Collaborator Author

Crap. Data races. Hold off on looking at this.

@petermattis
Copy link
Collaborator Author

Fixed the race. replica_raftstorage.go:snapshot() is called without Replica.raftMu held and this can't use the new Replica.state functionality.

RFAL.

@bdarnell
Copy link
Contributor

bdarnell commented Feb 8, 2017

:lgtm:, although this seems like a fairly big change for a 2% reduction in allocations.


Reviewed 12 of 15 files at r1, 3 of 3 files at r2.
Review status: all files reviewed at latest revision, 3 unresolved discussions, some commit checks failed.


pkg/storage/replica_raftstorage.go, line 358 at r2 (raw file):

// snapshot creates an OutgoingSnapshot containing a rocksdb snapshot for the
// given range. Note that snapshot() is called without Replica.raftMu held.

It's called without even having access to a Replica (and in fact this is the whole reason it's a static function instead of a method, to guarantee that it depends only on the engine.Reader)


pkg/storage/replica_state.go, line 39 at r1 (raw file):

Previously, petermattis (Peter Mattis) wrote…

I'm not fond of this type name. Suggestions?

replicaStateLoader?


Comments from Reviewable

@petermattis
Copy link
Collaborator Author

seems like a fairly big change

Well, large parts of it are fairly mechanical.


Review status: all files reviewed at latest revision, 3 unresolved discussions, some commit checks failed.


pkg/storage/replica_raftstorage.go, line 358 at r2 (raw file):

Previously, bdarnell (Ben Darnell) wrote…

It's called without even having access to a Replica (and in fact this is the whole reason it's a static function instead of a method, to guarantee that it depends only on the engine.Reader)

Well, we could pass the Replica now. The only caller is Replica.GetSnapshot. The comment is meant to indicate that we shouldn't.


pkg/storage/replica_state.go, line 39 at r1 (raw file):

Previously, bdarnell (Ben Darnell) wrote…

replicaStateLoader?

Ok. I'll change in a bit.


Comments from Reviewable

Reorganized the range-local key generation code to utilize a new
RangeIDPrefixBuf abstraction. Use this new functionality in
replicaStateLoader to avoid allocations when loading and saving
range-local data.

This removes 2.2% of allocations in a write-only workload.
@petermattis petermattis merged commit 04f2ead into cockroachdb:master Feb 9, 2017
@petermattis petermattis deleted the pmattis/replica-state-keys branch February 9, 2017 02:12
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.

2 participants