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: Ensure that raft methods use a consistent view of the data #6187

Merged
merged 3 commits into from
Apr 21, 2016

Conversation

bdarnell
Copy link
Contributor

Replica.Snapshot() takes a rocksdb snapshot and intends to use that
snapshot exclusively. However, it calls into other methods on the
Replica which may make their own independent accesses to
r.store.Engine() or return in-memory data. This could result in
an inconsistent view of the world and panics as in #5857.

To ensure that this can't happen, this commit moves the implementation
of Snapshot() from a method of Replica to a static function, so it
doesn't have access to anything but its rocksdb snapshot. All methods
called by snapshot() are also moved to static functions.

Fixes #5857.


This change is Reviewable

Replica.Snapshot() takes a rocksdb snapshot and intends to use that
snapshot exclusively. However, it calls into other methods on the
Replica which may make their own independent accesses to
r.store.Engine() or return in-memory data. This could result in
an inconsistent view of the world and panics as in cockroachdb#5857.

To ensure that this can't happen, this commit moves the implementation
of Snapshot() from a method of Replica to a static function, so it
doesn't have access to anything but its rocksdb snapshot. All methods
called by snapshot() are also moved to static functions.

Fixes cockroachdb#5857.
This was unnecessary as we just want the latest version of the
descriptor regardless of timestamp.
This ensures that all raft.Storage methods see a consistent view of the
DB, avoiding potential issues like the panic in cockroachdb#5857.
@tbg
Copy link
Member

tbg commented Apr 21, 2016

LGTM. Short-lived engine snapshots are cheap, correct? Not that there's much of an alternative (except in isolated cases, and it'd be brittle).

@bdarnell
Copy link
Contributor Author

The docs say short-lived snapshots are cheap but I haven't measured. I think internally rocksdb is doing something very close to creating a snapshot on any read. The major cost here is two extra crossings of the cgo boundary.

We might be able to get by without the snapshot if we rely on the fact that we only ever make changes on the processRaft goroutine. That's why I thought this was safe before, but I must be missing some concurrent access somewhere (and we want to improve parallelism in this code regardless).

@tbg
Copy link
Member

tbg commented Apr 21, 2016

Ok, was just curious. We'll see it when it shows up.

On Thu, Apr 21, 2016 at 11:06 AM Ben Darnell [email protected]
wrote:

The docs say short-lived snapshots are cheap but I haven't measured. I
think internally rocksdb is doing something very close to creating a
snapshot on any read. The major cost here is two extra crossings of the cgo
boundary.

We might be able to get by without the snapshot if we rely on the fact
that we only ever make changes on the processRaft goroutine. That's why I
thought this was safe before, but I must be missing some concurrent access
somewhere (and we want to improve parallelism in this code regardless).


You are receiving this because you commented.

Reply to this email directly or view it on GitHub
#6187 (comment)

-- Tobias

@bdarnell bdarnell merged commit c01b9b9 into cockroachdb:master Apr 21, 2016
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