Skip to content
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
14 changes: 10 additions & 4 deletions go/cmd/vtctld/actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,16 @@ import (
"net/url"
"strings"

"golang.org/x/net/context"

"github.com/youtube/vitess/go/acl"
"github.com/youtube/vitess/go/vt/logutil"
"github.com/youtube/vitess/go/vt/tabletmanager/actionnode"
"github.com/youtube/vitess/go/vt/tabletmanager/tmclient"
"github.com/youtube/vitess/go/vt/topo"
"github.com/youtube/vitess/go/vt/wrangler"
"golang.org/x/net/context"

pb "github.com/youtube/vitess/go/vt/proto/topodata"
)

var (
Expand Down Expand Up @@ -42,7 +45,7 @@ type actionKeyspaceMethod func(ctx context.Context, wr *wrangler.Wrangler, keysp

type actionShardMethod func(ctx context.Context, wr *wrangler.Wrangler, keyspace, shard string, r *http.Request) (output string, err error)

type actionTabletMethod func(ctx context.Context, wr *wrangler.Wrangler, tabletAlias topo.TabletAlias, r *http.Request) (output string, err error)
type actionTabletMethod func(ctx context.Context, wr *wrangler.Wrangler, tabletAlias *pb.TabletAlias, r *http.Request) (output string, err error)

type actionTabletRecord struct {
role string
Expand Down Expand Up @@ -137,8 +140,11 @@ func (ar *ActionRepository) ApplyShardAction(ctx context.Context, actionName, ke
}

// ApplyTabletAction applies the provided action to the tablet.
func (ar *ActionRepository) ApplyTabletAction(ctx context.Context, actionName string, tabletAlias topo.TabletAlias, r *http.Request) *ActionResult {
result := &ActionResult{Name: actionName, Parameters: tabletAlias.String()}
func (ar *ActionRepository) ApplyTabletAction(ctx context.Context, actionName string, tabletAlias *pb.TabletAlias, r *http.Request) *ActionResult {
result := &ActionResult{
Name: actionName,
Parameters: topo.TabletAliasString(tabletAlias),
}

action, ok := ar.tabletActions[actionName]
if !ok {
Expand Down
7 changes: 6 additions & 1 deletion go/cmd/vtctld/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,8 +219,13 @@ func initAPI(ctx context.Context, ts topo.Server, actions *ActionRepository) {
return ts.GetSrvTabletTypesPerShard(ctx, parts[0], parts[1], parts[2])
}

tabletType, err := topo.ParseTabletType(parts[3])
if err != nil {
return nil, fmt.Errorf("invalid tablet type %v: %v", parts[3], err)
}

// Get the endpoints object for a specific type.
ep, _, err := ts.GetEndPoints(ctx, parts[0], parts[1], parts[2], topo.TabletType(parts[3]))
ep, _, err := ts.GetEndPoints(ctx, parts[0], parts[1], parts[2], tabletType)
return ep, err
})

Expand Down
50 changes: 22 additions & 28 deletions go/cmd/vtctld/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (

"golang.org/x/net/context"

"github.com/youtube/vitess/go/vt/key"
"github.com/youtube/vitess/go/vt/logutil"
"github.com/youtube/vitess/go/vt/topo"
"github.com/youtube/vitess/go/vt/topotools"
Expand Down Expand Up @@ -52,21 +51,21 @@ func TestAPI(t *testing.T) {
KeyRange: &pb.KeyRange{Start: []byte{0x80}, End: nil},
})

topo.CreateTablet(ctx, ts, &topo.Tablet{
Alias: topo.TabletAlias{Cell: "cell1", Uid: 100},
topo.CreateTablet(ctx, ts, &pb.Tablet{
Alias: &pb.TabletAlias{Cell: "cell1", Uid: 100},
Keyspace: "ks1",
Shard: "-80",
Type: topo.TYPE_REPLICA,
KeyRange: key.KeyRange{Start: "", End: "\x80"},
Portmap: map[string]int{"vt": 100},
Type: pb.TabletType_REPLICA,
KeyRange: &pb.KeyRange{Start: nil, End: []byte{0x80}},
PortMap: map[string]int32{"vt": 100},
})
topo.CreateTablet(ctx, ts, &topo.Tablet{
Alias: topo.TabletAlias{Cell: "cell2", Uid: 200},
topo.CreateTablet(ctx, ts, &pb.Tablet{
Alias: &pb.TabletAlias{Cell: "cell2", Uid: 200},
Keyspace: "ks1",
Shard: "-80",
Type: topo.TYPE_REPLICA,
KeyRange: key.KeyRange{Start: "", End: "\x80"},
Portmap: map[string]int{"vt": 200},
Type: pb.TabletType_REPLICA,
KeyRange: &pb.KeyRange{Start: nil, End: []byte{0x80}},
PortMap: map[string]int32{"vt": 200},
})
topotools.RebuildShard(ctx, logutil.NewConsoleLogger(), ts, "ks1", "-80", cells, 10*time.Second)

Expand All @@ -80,7 +79,7 @@ func TestAPI(t *testing.T) {
return "TestShardAction Result", nil
})
actionRepo.RegisterTabletAction("TestTabletAction", "",
func(ctx context.Context, wr *wrangler.Wrangler, tabletAlias topo.TabletAlias, r *http.Request) (string, error) {
func(ctx context.Context, wr *wrangler.Wrangler, tabletAlias *pb.TabletAlias, r *http.Request) (string, error) {
return "TestTabletAction Result", nil
})

Expand Down Expand Up @@ -118,27 +117,22 @@ func TestAPI(t *testing.T) {

// Tablets
{"GET", "tablets/?shard=ks1%2F-80", `[
{"Cell":"cell1","Uid":100},
{"Cell":"cell2","Uid":200}
{"cell":"cell1","uid":100},
{"cell":"cell2","uid":200}
]`},
{"GET", "tablets/?cell=cell1", `[
{"Cell":"cell1","Uid":100}
{"cell":"cell1","uid":100}
]`},
{"GET", "tablets/?shard=ks1%2F-80&cell=cell2", `[
{"Cell":"cell2","Uid":200}
{"cell":"cell2","uid":200}
]`},
{"GET", "tablets/cell1-100", `{
"Alias": {"Cell": "cell1", "Uid": 100},
"Hostname": "",
"IPAddr": "",
"Portmap": {"vt": 100},
"Tags": null,
"Health": null,
"Keyspace": "ks1",
"Shard": "-80",
"Type": "replica",
"DbNameOverride": "",
"KeyRange": {"Start": "", "End": "80"}
"alias": {"cell": "cell1", "uid": 100},
"port_map": {"vt": 100},
"keyspace": "ks1",
"shard": "-80",
"key_range": {"end": "gA=="},
"type": 3
}`},
{"POST", "tablets/cell1-100?action=TestTabletAction", `{
"Name": "TestTabletAction",
Expand All @@ -148,7 +142,7 @@ func TestAPI(t *testing.T) {
}`},

// EndPoints
{"GET", "endpoints/cell1/ks1/-80/", `["replica"]`},
{"GET", "endpoints/cell1/ks1/-80/", `[3]`},
{"GET", "endpoints/cell1/ks1/-80/replica", `{
"entries": [{
"uid": 100,
Expand Down
12 changes: 9 additions & 3 deletions go/cmd/vtctld/explorer.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import (
log "github.com/golang/glog"
"github.com/youtube/vitess/go/cmd/vtctld/proto"
"github.com/youtube/vitess/go/vt/topo"

pb "github.com/youtube/vitess/go/vt/proto/topodata"
)

// Explorer allows exploring a topology server.
Expand Down Expand Up @@ -41,11 +43,11 @@ type Explorer interface {
// GetShardTypePath returns an explorer path that will contain
// information about the named tablet type in the named shard
// in the named keyspace in the serving graph for cell.
GetSrvTypePath(cell, keyspace, shard string, tabletType topo.TabletType) string
GetSrvTypePath(cell, keyspace, shard string, tabletType pb.TabletType) string

// GetTabletPath returns an explorer path that will contain
// information about the tablet named by alias.
GetTabletPath(alias topo.TabletAlias) string
GetTabletPath(alias *pb.TabletAlias) string

// GetReplicationSlaves returns an explorer path that contains
// replication slaves for the named cell, keyspace, and shard.
Expand Down Expand Up @@ -132,7 +134,11 @@ func handleExplorerRedirect(r *http.Request) (string, error) {
if keyspace == "" || shard == "" || cell == "" || tabletType == "" {
return "", errors.New("keyspace, shard, cell, and tablet_type are required for this redirect")
}
return explorer.GetSrvTypePath(cell, keyspace, shard, topo.TabletType(tabletType)), nil
tt, err := topo.ParseTabletType(tabletType)
if err != nil {
return "", fmt.Errorf("cannot parse tablet type %v: %v", tabletType, err)
}
return explorer.GetSrvTypePath(cell, keyspace, shard, tt), nil
case "tablet":
alias := r.FormValue("alias")
if alias == "" {
Expand Down
16 changes: 9 additions & 7 deletions go/cmd/vtctld/plugin_zktopo.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import (
"github.com/youtube/vitess/go/vt/topo"
"github.com/youtube/vitess/go/vt/zktopo"
"github.com/youtube/vitess/go/zk"

pb "github.com/youtube/vitess/go/vt/proto/topodata"
)

func init() {
Expand Down Expand Up @@ -63,13 +65,13 @@ func (ex ZkExplorer) GetSrvShardPath(cell, keyspace, shard string) string {
}

// GetSrvTypePath is part of the Explorer interface
func (ex ZkExplorer) GetSrvTypePath(cell, keyspace, shard string, tabletType topo.TabletType) string {
return path.Join("/zk", cell, "/vt/ns", keyspace, shard, string(tabletType))
func (ex ZkExplorer) GetSrvTypePath(cell, keyspace, shard string, tabletType pb.TabletType) string {
return path.Join("/zk", cell, "/vt/ns", keyspace, shard, strings.ToLower(tabletType.String()))
}

// GetTabletPath is part of the Explorer interface
func (ex ZkExplorer) GetTabletPath(alias topo.TabletAlias) string {
return path.Join("/zk", alias.Cell, "vt/tablets", alias.TabletUIDStr())
func (ex ZkExplorer) GetTabletPath(alias *pb.TabletAlias) string {
return path.Join("/zk", alias.Cell, "vt/tablets", topo.TabletAliasUIDStr(alias))
}

// GetReplicationSlaves is part of the Explorer interface
Expand Down Expand Up @@ -126,14 +128,14 @@ func (ex ZkExplorer) HandlePath(actionRepo proto.ActionRepository, zkPath string
}

func (ex ZkExplorer) addTabletLinks(data string, result *ZkResult) {
t := &topo.Tablet{}
t := &pb.Tablet{}
err := json.Unmarshal([]byte(data), t)
if err != nil {
return
}

if port, ok := t.Portmap["vt"]; ok {
result.Links["status"] = template.URL(fmt.Sprintf("http://%v/debug/status", netutil.JoinHostPort(t.Hostname, int32(port))))
if port, ok := t.PortMap["vt"]; ok {
result.Links["status"] = template.URL(fmt.Sprintf("http://%v/debug/status", netutil.JoinHostPort(t.Hostname, port)))
}
}

Expand Down
16 changes: 8 additions & 8 deletions go/cmd/vtctld/tablet_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func (th *tabletHealth) lastAccessed() time.Time {
return th.accessed
}

func (th *tabletHealth) stream(ctx context.Context, ts topo.Server, tabletAlias topo.TabletAlias) (err error) {
func (th *tabletHealth) stream(ctx context.Context, ts topo.Server, tabletAlias *pbt.TabletAlias) (err error) {
defer func() {
th.mu.Lock()
th.err = err
Expand Down Expand Up @@ -129,24 +129,24 @@ type tabletHealthCache struct {
ts topo.Server

mu sync.Mutex
tabletMap map[topo.TabletAlias]*tabletHealth
tabletMap map[pbt.TabletAlias]*tabletHealth
}

func newTabletHealthCache(ts topo.Server) *tabletHealthCache {
return &tabletHealthCache{
ts: ts,
tabletMap: make(map[topo.TabletAlias]*tabletHealth),
tabletMap: make(map[pbt.TabletAlias]*tabletHealth),
}
}

func (thc *tabletHealthCache) Get(ctx context.Context, tabletAlias topo.TabletAlias) (*pb.StreamHealthResponse, error) {
func (thc *tabletHealthCache) Get(ctx context.Context, tabletAlias *pbt.TabletAlias) (*pb.StreamHealthResponse, error) {
thc.mu.Lock()

th, ok := thc.tabletMap[tabletAlias]
th, ok := thc.tabletMap[*tabletAlias]
if !ok {
// No existing stream, so start one.
th = newTabletHealth()
thc.tabletMap[tabletAlias] = th
thc.tabletMap[*tabletAlias] = th

go func() {
log.Infof("starting health stream for tablet %v", tabletAlias)
Expand All @@ -161,8 +161,8 @@ func (thc *tabletHealthCache) Get(ctx context.Context, tabletAlias topo.TabletAl
return th.lastResult(ctx)
}

func (thc *tabletHealthCache) delete(tabletAlias topo.TabletAlias) {
func (thc *tabletHealthCache) delete(tabletAlias *pbt.TabletAlias) {
thc.mu.Lock()
delete(thc.tabletMap, tabletAlias)
delete(thc.tabletMap, *tabletAlias)
thc.mu.Unlock()
}
4 changes: 2 additions & 2 deletions go/cmd/vtctld/tablet_data_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ import (
"github.com/youtube/vitess/go/vt/tabletmanager/tmclient"
"github.com/youtube/vitess/go/vt/tabletserver/grpcqueryservice"
"github.com/youtube/vitess/go/vt/tabletserver/queryservice"
"github.com/youtube/vitess/go/vt/topo"
"github.com/youtube/vitess/go/vt/wrangler"
"github.com/youtube/vitess/go/vt/wrangler/testlib"
"github.com/youtube/vitess/go/vt/zktopo"

pb "github.com/youtube/vitess/go/vt/proto/query"
pbt "github.com/youtube/vitess/go/vt/proto/topodata"
)

// streamHealthSQLQuery is a local QueryService implementation to support the tests
Expand Down Expand Up @@ -80,7 +80,7 @@ func TestTabletData(t *testing.T) {
ts := zktopo.NewTestServer(t, []string{"cell1", "cell2"})
wr := wrangler.New(logutil.NewConsoleLogger(), ts, tmclient.NewTabletManagerClient(), time.Second)

tablet1 := testlib.NewFakeTablet(t, wr, "cell1", 0, topo.TYPE_MASTER, testlib.TabletKeyspaceShard(t, "ks", "-80"))
tablet1 := testlib.NewFakeTablet(t, wr, "cell1", 0, pbt.TabletType_MASTER, testlib.TabletKeyspaceShard(t, "ks", "-80"))
tablet1.StartActionLoop(t, wr)
defer tablet1.StopActionLoop(t)
shsq := newStreamHealthSQLQuery(t)
Expand Down
4 changes: 3 additions & 1 deletion go/cmd/vtctld/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import (

"github.com/youtube/vitess/go/vt/topo"
"github.com/youtube/vitess/go/vt/topotools"

pb "github.com/youtube/vitess/go/vt/proto/topodata"
)

// FHtmlize writes data to w as debug HTML (using definition lists).
Expand Down Expand Up @@ -127,7 +129,7 @@ var FuncMap = template.FuncMap{
}
return template.HTML(link(shard.Name, explorer.GetSrvShardPath(cell, keyspace, shard.Name)))
},
"tablet": func(alias topo.TabletAlias, shortname string) template.HTML {
"tablet": func(alias *pb.TabletAlias, shortname string) template.HTML {
if explorer == nil {
return template.HTML(shortname)
}
Expand Down
6 changes: 3 additions & 3 deletions go/cmd/vtctld/topo_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ type CellShardTablets struct {
ShardName string

// TabletAliases is the array os tablet aliases
TabletAliases []topo.TabletAlias
TabletAliases []*pb.TabletAlias
}

// Reset is part of the VersionedObject interface
Expand All @@ -365,10 +365,10 @@ func newCellShardTabletsCache(ts topo.Server) *VersionedObjectCacheMap {
Cell: parts[0],
KeyspaceName: parts[1],
ShardName: parts[2],
TabletAliases: make([]topo.TabletAlias, len(sr.Nodes)),
TabletAliases: make([]*pb.TabletAlias, len(sr.Nodes)),
}
for i, node := range sr.Nodes {
result.TabletAliases[i] = topo.ProtoToTabletAlias(node.TabletAlias)
result.TabletAliases[i] = node.TabletAlias
}
return result, nil
})
Expand Down
7 changes: 3 additions & 4 deletions go/cmd/vtctld/topo_data_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"testing"
"time"

"github.com/youtube/vitess/go/vt/topo"
"github.com/youtube/vitess/go/vt/zktopo"
"golang.org/x/net/context"

Expand Down Expand Up @@ -325,12 +324,12 @@ func TestCellShardTabletsCache(t *testing.T) {
Cell: "cell1",
KeyspaceName: "ks1",
ShardName: "s1",
TabletAliases: []topo.TabletAlias{
topo.TabletAlias{
TabletAliases: []*pb.TabletAlias{
&pb.TabletAlias{
Cell: "cell1",
Uid: 12,
},
topo.TabletAlias{
&pb.TabletAlias{
Cell: "cell1",
Uid: 13,
},
Expand Down
Loading