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: Write HardState atomically with committing splits #20704

Merged
merged 1 commit into from
Dec 16, 2017

Conversation

bdarnell
Copy link
Contributor

Prior to this change, an ill-timed crash (between applying the raft
command and calling splitPostApply) would leave the replica in a
persistently broken state (no HardState).

Found via jepsen.

Fixes #20629
Fixes #20494

Release note (bugfix): Fixed a replica corruption that could occur if
a process crashed in the middle of a range split.

@bdarnell bdarnell requested a review from a team December 13, 2017 22:30
@cockroach-teamcity
Copy link
Member

This change is Reviewable

@bdarnell bdarnell requested a review from tbg December 13, 2017 22:30
@bdarnell bdarnell force-pushed the split-hardstate-atomic branch from ed14866 to 8496576 Compare December 13, 2017 23:32
@nvanbenschoten
Copy link
Member

Review status: 0 of 2 files reviewed at latest revision, 4 unresolved discussions, all commit checks successful.


pkg/storage/replica.go, line 4615 at r1 (raw file):

			// on each replica (votes may have already been cast on the
			// uninitialized replica). Transform the write batch to add the
			// updated HardState.

Consider linking to the issue here.


pkg/storage/replica.go, line 4616 at r1 (raw file):

			// uninitialized replica). Transform the write batch to add the
			// updated HardState.
			tmpBatch := r.store.engine.NewBatch()

Would using NewWriteOnlyBatch make a difference here?


pkg/storage/replica.go, line 4617 at r1 (raw file):

			// updated HardState.
			tmpBatch := r.store.engine.NewBatch()
			if err := tmpBatch.ApplyBatchRepr(writeBatch.Data, false); err != nil {

Is there any performance concern with this BatchRepr copy? This is only done on splits, so probably not.


pkg/storage/store.go, line 1801 at r1 (raw file):

}

// splitPreApply is called when the raft command is applied. Any

Is there a reason why these functions are in store.go instead of with the other pre and post apply functions in replica_proposal.go?


Comments from Reviewable

Prior to this change, an ill-timed crash (between applying the raft
command and calling splitPostApply) would leave the replica in a
persistently broken state (no HardState).

Found via jepsen.

Fixes cockroachdb#20629
Fixes cockroachdb#20494

Release note (bugfix): Fixed a replica corruption that could occur if
a process crashed in the middle of a range split.
@bdarnell bdarnell force-pushed the split-hardstate-atomic branch from 8496576 to e2b0f7b Compare December 14, 2017 18:20
@bdarnell
Copy link
Contributor Author

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


pkg/storage/replica.go, line 4615 at r1 (raw file):

Previously, nvanbenschoten (Nathan VanBenschoten) wrote…

Consider linking to the issue here.

Done


pkg/storage/replica.go, line 4616 at r1 (raw file):

Previously, nvanbenschoten (Nathan VanBenschoten) wrote…

Would using NewWriteOnlyBatch make a difference here?

Perhaps, but that means encoding knowledge-at-a-distance that splitPreApply doesn't need to read anything else that may have been written in the batch.


pkg/storage/replica.go, line 4617 at r1 (raw file):

Previously, nvanbenschoten (Nathan VanBenschoten) wrote…

Is there any performance concern with this BatchRepr copy? This is only done on splits, so probably not.

Yeah, splits are uncommon enough (and small enough) that I'm not concerned. Added a comment.


pkg/storage/store.go, line 1801 at r1 (raw file):

Previously, nvanbenschoten (Nathan VanBenschoten) wrote…

Is there a reason why these functions are in store.go instead of with the other pre and post apply functions in replica_proposal.go?

Historical reasons (and adjacency with Store.SplitRange, from which splitPostApply was extracted). I figure we'll gather all the split-related code into one place as a part of #18779.


Comments from Reviewable

@nvanbenschoten
Copy link
Member

:lgtm:


Review status: 0 of 2 files reviewed at latest revision, all discussions resolved, all commit checks successful.


Comments from Reviewable

@tbg
Copy link
Member

tbg commented Dec 15, 2017

:lgtm:


Reviewed 1 of 2 files at r1, 1 of 1 files at r2.
Review status: all files reviewed at latest revision, 1 unresolved discussion, all commit checks successful.


pkg/storage/replica.go, line 33 at r2 (raw file):

	"github.com/google/btree"
	"github.com/kr/pretty"
	opentracing "github.com/opentracing/opentracing-go"

I remember having that problem back when I used vim.


Comments from Reviewable

@bdarnell bdarnell merged commit cc2fd80 into cockroachdb:master Dec 16, 2017
@bdarnell bdarnell deleted the split-hardstate-atomic branch December 16, 2017 01:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants