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

roachpb: Change RangeDescriptor.StickyBit and ReplicaDescriptor.Type to nullable #38465

Merged
merged 2 commits into from
Jun 27, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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