Skip to content

Commit

Permalink
Merge #38465
Browse files Browse the repository at this point in the history
38465: roachpb: Change RangeDescriptor.StickyBit and ReplicaDescriptor.Type to nullable r=jeffrey-xiao a=jeffrey-xiao

On a mixed version cluster, only having #38302 does not guarantee backwards compatibility for non-nullable fields in RangeDescriptor. Suppose the replicas of a range are of mixed version and the current
leaseholder of the range is on newest version. If the leaseholder splits that range and writes to the non-nullable fields in RangeDescriptor and the leaseholder transfers to a node on an older version without #38302, then all CPuts would fail on that node.

We must guarantee that #38302 is on all nodes before making the fields in RangeDescriptor non-nullable.

Fixes #36983.
Fixes #38471.

Release note: None

Co-authored-by: Jeffrey Xiao <[email protected]>
  • Loading branch information
craig[bot] and jeffrey-xiao committed Jun 26, 2019
2 parents d56d70f + 692a4fa commit 8c9a74f
Show file tree
Hide file tree
Showing 16 changed files with 257 additions and 176 deletions.
6 changes: 6 additions & 0 deletions c-deps/libroach/protos/roachpb/metadata.pb.cc

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions c-deps/libroach/protos/roachpb/metadata.pb.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions pkg/kv/split_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ func TestRangeSplitsStickyBit(t *testing.T) {
if err != nil {
t.Fatal(err)
}
if (desc.StickyBit == hlc.Timestamp{}) {
if (desc.GetStickyBit() == hlc.Timestamp{}) {
t.Fatal("Sticky bit not set after splitting")
}

Expand All @@ -304,7 +304,7 @@ func TestRangeSplitsStickyBit(t *testing.T) {
if err != nil {
t.Fatal(err)
}
if (desc.StickyBit == hlc.Timestamp{}) {
if (desc.GetStickyBit() == hlc.Timestamp{}) {
t.Fatal("Sticky bit not set after splitting")
}
}
19 changes: 18 additions & 1 deletion pkg/roachpb/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"strconv"
"strings"

"github.com/cockroachdb/cockroach/pkg/util/hlc"
"github.com/cockroachdb/cockroach/pkg/util/humanizeutil"
"github.com/gogo/protobuf/proto"
"github.com/pkg/errors"
Expand Down Expand Up @@ -197,6 +198,14 @@ func (r *RangeDescriptor) IncrementGeneration() {
r.Generation = proto.Int64(r.GetGeneration() + 1)
}

// GetStickyBit returns the sticky bit of this RangeDescriptor.
func (r RangeDescriptor) GetStickyBit() hlc.Timestamp {
if r.StickyBit == nil {
return hlc.Timestamp{}
}
return *r.StickyBit
}

// Validate performs some basic validation of the contents of a range descriptor.
func (r RangeDescriptor) Validate() error {
if r.NextReplicaID == 0 {
Expand Down Expand Up @@ -257,7 +266,7 @@ func (r ReplicaDescriptor) String() string {
} else {
fmt.Fprintf(&buf, "%d", r.ReplicaID)
}
if r.Type == ReplicaType_LEARNER {
if r.GetType() == ReplicaType_LEARNER {
buf.WriteString("LEARNER")
}
return buf.String()
Expand All @@ -277,6 +286,14 @@ func (r ReplicaDescriptor) Validate() error {
return nil
}

// GetType returns the type of this ReplicaDescriptor.
func (r ReplicaDescriptor) GetType() ReplicaType {
if r.Type == nil {
return ReplicaType_VOTER
}
return *r.Type
}

// PercentilesFromData derives percentiles from a slice of data points.
// Sorts the input data if it isn't already sorted.
func PercentilesFromData(data []float64) Percentiles {
Expand Down
Loading

0 comments on commit 8c9a74f

Please sign in to comment.