Skip to content

Commit

Permalink
cli: added --locality
Browse files Browse the repository at this point in the history
  • Loading branch information
d4l3k committed Aug 30, 2016
1 parent 8b8376f commit 9b41a2d
Show file tree
Hide file tree
Showing 18 changed files with 1,932 additions and 89 deletions.
31 changes: 21 additions & 10 deletions cli/cliflags/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,29 @@ var (
Attrs = FlagInfo{
Name: "attrs",
Description: `
An ordered, colon-separated list of node attributes. Attributes are
arbitrary strings specifying topography or machine
capabilities. Topography might include datacenter designation
(e.g. "us-west-1a", "us-west-1b", "us-east-1c"). Machine capabilities
might include specialized hardware or number of cores (e.g. "gpu",
"x16c"). The relative geographic proximity of two nodes is inferred
from the common prefix of the attributes list, so topographic
attributes should be specified first and in the same order for all
nodes. For example:
An ordered, colon-separated list of node attributes. Attributes are arbitrary
strings specifying machine capabilities. Machine capabilities might include
specialized hardware or number of cores (e.g. "gpu", "x16c"). For example:
<PRE>
--attrs=us-west-1b:gpu`,
--attrs=x16c:gpu`,
}

Locality = FlagInfo{
Name: "locality",
Description: `
Not fully implemented. https://github.com/cockroachdb/cockroach/issues/4868
An ordered, comma-separated list of key-value pairs that describe the topography
of the machine. Topography might include country, datacenter or rack
designations. Data is automatically replicated to maximize diversities of each
tier. The order of tiers is used to determine the priority of the diversity. The
tiers and order must be the same on all nodes. For example:
<PRE>
--locality=country=us,region=us-west,datacenter=us-west-1b,rack=12
--locality=country=ca,region=ca-east,datacenter=ca-east-2,rack=4
--locality=planet=earth,province=manitoba,colo=secondary,power=3`,
}

ZoneConfig = FlagInfo{
Expand Down
1 change: 1 addition & 0 deletions cli/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,7 @@ func init() {
stringFlag(f, &httpPort, cliflags.ServerHTTPPort, base.DefaultHTTPPort)
stringFlag(f, &httpAddr, cliflags.ServerHTTPAddr, "")
stringFlag(f, &serverCtx.Attrs, cliflags.Attrs, serverCtx.Attrs)
varFlag(f, &serverCtx.Locality, cliflags.Locality)

varFlag(f, &serverCtx.Stores, cliflags.Store)
durationFlag(f, &serverCtx.RaftTickInterval, cliflags.RaftTickInterval, base.DefaultRaftTickInterval)
Expand Down
64 changes: 32 additions & 32 deletions config/config.pb.go

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

2 changes: 1 addition & 1 deletion config/config.proto
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ syntax = "proto2";
package cockroach.config;
option go_package = "config";

import "cockroach/roachpb/metadata.proto";
import "cockroach/roachpb/data.proto";
import "cockroach/roachpb/metadata.proto";
import weak "gogoproto/gogo.proto";

// GCPolicy defines garbage collection policies which apply to MVCC
Expand Down
2 changes: 2 additions & 0 deletions roachpb/api.pb.go

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

54 changes: 54 additions & 0 deletions roachpb/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package roachpb

import (
"fmt"
"sort"
"strconv"
"strings"
Expand Down Expand Up @@ -200,3 +201,56 @@ func (s StoreDescriptor) CombinedAttrs() *Attributes {
a = append(a, s.Attrs.Attrs...)
return &Attributes{Attrs: a}
}

// String returns a string representation of the Tier.
func (t Tier) String() string {
return fmt.Sprintf("%s=%s", t.Key, t.Value)
}

// FromString parses the string representation into the Tier.
func (t *Tier) FromString(tier string) error {
parts := strings.Split(tier, "=")
if len(parts) != 2 || len(parts[0]) == 0 || len(parts[1]) == 0 {
return errors.Errorf("tier must be in the form \"key=value\" not %q", tier)
}
t.Key = parts[0]
t.Value = parts[1]
return nil
}

// String returns a string representation of all the Tiers. This is part
// of pflag's value interface.
func (l Locality) String() string {
tiers := make([]string, len(l.Tiers))
for i, tier := range l.Tiers {
tiers[i] = tier.String()
}
return strings.Join(tiers, ",")
}

// Type returns the underlying type in string form. This is part of pflag's
// value interface.
func (Locality) Type() string {
return "Locality"
}

// Set sets the value of the Locality. It is the important part of
// pflag's value interface.
func (l *Locality) Set(value string) error {
if len(l.Tiers) > 0 {
return errors.New("can't set locality more than once")
}
if len(value) == 0 {
return errors.New("can't have empty locality")
}

tiersStr := strings.Split(value, ",")
tiers := make([]Tier, len(tiersStr))
for i, tier := range tiersStr {
if err := tiers[i].FromString(tier); err != nil {
return err
}
}
l.Tiers = tiers
return nil
}
Loading

0 comments on commit 9b41a2d

Please sign in to comment.