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

Vtgate refactors. #3539

Merged
merged 7 commits into from
Jan 11, 2018
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
8 changes: 4 additions & 4 deletions go/cmd/l2vtgate/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ import (
"github.com/youtube/vitess/go/exit"
"github.com/youtube/vitess/go/vt/discovery"
"github.com/youtube/vitess/go/vt/servenv"
"github.com/youtube/vitess/go/vt/srvtopo"
"github.com/youtube/vitess/go/vt/topo"
"github.com/youtube/vitess/go/vt/topo/topoproto"
"github.com/youtube/vitess/go/vt/vtgate"
"github.com/youtube/vitess/go/vt/vtgate/l2vtgate"

topodatapb "github.com/youtube/vitess/go/vt/proto/topodata"
Expand All @@ -44,7 +44,7 @@ var (
tabletTypesToWait = flag.String("tablet_types_to_wait", "", "wait till connected for specified tablet types during Gateway initialization")
)

var resilientSrvTopoServer *vtgate.ResilientSrvTopoServer
var resilientServer *srvtopo.ResilientServer
var healthCheck discovery.HealthCheck

func init() {
Expand All @@ -66,7 +66,7 @@ func main() {
ts := topo.Open()
defer ts.Close()

resilientSrvTopoServer = vtgate.NewResilientSrvTopoServer(ts, "ResilientSrvTopoServer")
resilientServer = srvtopo.NewResilientServer(ts, "ResilientSrvTopoServer")

healthCheck = discovery.NewHealthCheck(*healthCheckRetryDelay, *healthCheckTimeout)
healthCheck.RegisterStats()
Expand All @@ -82,7 +82,7 @@ func main() {
tabletTypes = append(tabletTypes, tt)
}
}
l2vtg := l2vtgate.Init(healthCheck, ts, resilientSrvTopoServer, "VttabletCall", *cell, *retryCount, tabletTypes)
l2vtg := l2vtgate.Init(healthCheck, ts, resilientServer, "VttabletCall", *cell, *retryCount, tabletTypes)

servenv.OnRun(func() {
addStatusParts(l2vtg)
Expand Down
6 changes: 3 additions & 3 deletions go/cmd/l2vtgate/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ package main
import (
"github.com/youtube/vitess/go/vt/discovery"
"github.com/youtube/vitess/go/vt/servenv"
"github.com/youtube/vitess/go/vt/srvtopo"
_ "github.com/youtube/vitess/go/vt/status"
"github.com/youtube/vitess/go/vt/vtgate"
"github.com/youtube/vitess/go/vt/vtgate/gateway"
"github.com/youtube/vitess/go/vt/vtgate/l2vtgate"
)
Expand All @@ -29,8 +29,8 @@ import (
var onStatusRegistered func()

func addStatusParts(l2vtgate *l2vtgate.L2VTGate) {
servenv.AddStatusPart("Topology Cache", vtgate.TopoTemplate, func() interface{} {
return resilientSrvTopoServer.CacheStatus()
servenv.AddStatusPart("Topology Cache", srvtopo.TopoTemplate, func() interface{} {
return resilientServer.CacheStatus()
})
servenv.AddStatusPart("Gateway Status", gateway.StatusTemplate, func() interface{} {
return l2vtgate.GetGatewayCacheStatus()
Expand Down
5 changes: 3 additions & 2 deletions go/cmd/vtcombo/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import (
"github.com/youtube/vitess/go/vt/discovery"
"github.com/youtube/vitess/go/vt/mysqlctl"
"github.com/youtube/vitess/go/vt/servenv"
"github.com/youtube/vitess/go/vt/srvtopo"
"github.com/youtube/vitess/go/vt/topo"
"github.com/youtube/vitess/go/vt/topo/memorytopo"
"github.com/youtube/vitess/go/vt/vtctld"
Expand Down Expand Up @@ -126,7 +127,7 @@ func main() {
}

// vtgate configuration and init
resilientSrvTopoServer := vtgate.NewResilientSrvTopoServer(ts, "ResilientSrvTopoServer")
resilientServer := srvtopo.NewResilientServer(ts, "ResilientSrvTopoServer")
healthCheck := discovery.NewHealthCheck(1*time.Millisecond /*retryDelay*/, 1*time.Hour /*healthCheckTimeout*/)
tabletTypesToWait := []topodatapb.TabletType{
topodatapb.TabletType_MASTER,
Expand All @@ -137,7 +138,7 @@ func main() {
vtgate.QueryLogHandler = "/debug/vtgate/querylog"
vtgate.QueryLogzHandler = "/debug/vtgate/querylogz"
vtgate.QueryzHandler = "/debug/vtgate/queryz"
vtgate.Init(context.Background(), healthCheck, ts, resilientSrvTopoServer, tpb.Cells[0], 2 /*retryCount*/, tabletTypesToWait)
vtgate.Init(context.Background(), healthCheck, ts, resilientServer, tpb.Cells[0], 2 /*retryCount*/, tabletTypesToWait)

// vtctld configuration and init
vtctld.InitVtctld(ts)
Expand Down
5 changes: 3 additions & 2 deletions go/cmd/vtgate/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package main
import (
"github.com/youtube/vitess/go/vt/discovery"
"github.com/youtube/vitess/go/vt/servenv"
"github.com/youtube/vitess/go/vt/srvtopo"
_ "github.com/youtube/vitess/go/vt/status"
"github.com/youtube/vitess/go/vt/vtgate"
"github.com/youtube/vitess/go/vt/vtgate/gateway"
Expand All @@ -34,8 +35,8 @@ func addStatusParts(vtg *vtgate.VTGate) {
servenv.AddStatusPart("VSchema", vtgate.VSchemaTemplate, func() interface{} {
return vtg.VSchemaStats()
})
servenv.AddStatusPart("Topology Cache", vtgate.TopoTemplate, func() interface{} {
return resilientSrvTopoServer.CacheStatus()
servenv.AddStatusPart("Topology Cache", srvtopo.TopoTemplate, func() interface{} {
return resilientServer.CacheStatus()
})
servenv.AddStatusPart("Gateway Status", gateway.StatusTemplate, func() interface{} {
return vtg.GetGatewayCacheStatus()
Expand Down
7 changes: 4 additions & 3 deletions go/cmd/vtgate/vtgate.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (
"github.com/youtube/vitess/go/exit"
"github.com/youtube/vitess/go/vt/discovery"
"github.com/youtube/vitess/go/vt/servenv"
"github.com/youtube/vitess/go/vt/srvtopo"
"github.com/youtube/vitess/go/vt/topo"
"github.com/youtube/vitess/go/vt/topo/topoproto"
"github.com/youtube/vitess/go/vt/vtgate"
Expand All @@ -45,7 +46,7 @@ var (
tabletTypesToWait = flag.String("tablet_types_to_wait", "", "wait till connected for specified tablet types during Gateway initialization")
)

var resilientSrvTopoServer *vtgate.ResilientSrvTopoServer
var resilientServer *srvtopo.ResilientServer
var healthCheck discovery.HealthCheck

var initFakeZK func()
Expand All @@ -72,7 +73,7 @@ func main() {
ts := topo.Open()
defer ts.Close()

resilientSrvTopoServer = vtgate.NewResilientSrvTopoServer(ts, "ResilientSrvTopoServer")
resilientServer = srvtopo.NewResilientServer(ts, "ResilientSrvTopoServer")

healthCheck = discovery.NewHealthCheck(*healthCheckRetryDelay, *healthCheckTimeout)
healthCheck.RegisterStats()
Expand All @@ -89,7 +90,7 @@ func main() {
}
}

vtg := vtgate.Init(context.Background(), healthCheck, ts, resilientSrvTopoServer, *cell, *retryCount, tabletTypes)
vtg := vtgate.Init(context.Background(), healthCheck, ts, resilientServer, *cell, *retryCount, tabletTypes)

servenv.OnRun(func() {
addStatusParts(vtg)
Expand Down
6 changes: 3 additions & 3 deletions go/vt/discovery/tablet_stats_cache_wait.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
"golang.org/x/net/context"

"github.com/youtube/vitess/go/vt/concurrency"
"github.com/youtube/vitess/go/vt/topo"
"github.com/youtube/vitess/go/vt/srvtopo"

topodatapb "github.com/youtube/vitess/go/vt/proto/topodata"
)
Expand Down Expand Up @@ -66,7 +66,7 @@ func (tc *TabletStatsCache) WaitForAnyTablet(ctx context.Context, cell, keyspace
// WaitForAllServingTablets waits for at least one healthy serving tablet in
// the given cell for all keyspaces / shards before returning.
// It will return ctx.Err() if the context is canceled.
func (tc *TabletStatsCache) WaitForAllServingTablets(ctx context.Context, ts topo.SrvTopoServer, cell string, types []topodatapb.TabletType) error {
func (tc *TabletStatsCache) WaitForAllServingTablets(ctx context.Context, ts srvtopo.Server, cell string, types []topodatapb.TabletType) error {
keyspaceShards, err := findAllKeyspaceShards(ctx, ts, cell)
if err != nil {
return err
Expand All @@ -76,7 +76,7 @@ func (tc *TabletStatsCache) WaitForAllServingTablets(ctx context.Context, ts top
}

// findAllKeyspaceShards goes through all serving shards in the topology
func findAllKeyspaceShards(ctx context.Context, ts topo.SrvTopoServer, cell string) (map[keyspaceShard]bool, error) {
func findAllKeyspaceShards(ctx context.Context, ts srvtopo.Server, cell string) (map[keyspaceShard]bool, error) {
ksNames, err := ts.GetSrvKeyspaceNames(ctx, cell)
if err != nil {
return nil, err
Expand Down
10 changes: 7 additions & 3 deletions go/vt/discovery/tablet_stats_cache_wait_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,14 @@ limitations under the License.
package discovery

import (
"flag"
"reflect"
"testing"
"time"

"golang.org/x/net/context"

"github.com/youtube/vitess/go/vt/srvtopo"
"github.com/youtube/vitess/go/vt/topo"
"github.com/youtube/vitess/go/vt/topo/memorytopo"

Expand All @@ -33,9 +35,11 @@ import (
func TestFindAllKeyspaceShards(t *testing.T) {
ctx := context.Background()
ts := memorytopo.NewServer("cell1", "cell2")
flag.Set("srv_topo_cache_ttl", "0s") // No caching values
rs := srvtopo.NewResilientServer(ts, "TestFindAllKeyspaceShards")

// no keyspace / shards
ks, err := findAllKeyspaceShards(ctx, ts, "cell1")
ks, err := findAllKeyspaceShards(ctx, rs, "cell1")
if err != nil {
t.Errorf("unexpected error: %v", err)
}
Expand All @@ -60,7 +64,7 @@ func TestFindAllKeyspaceShards(t *testing.T) {
}

// get it
ks, err = findAllKeyspaceShards(ctx, ts, "cell1")
ks, err = findAllKeyspaceShards(ctx, rs, "cell1")
if err != nil {
t.Errorf("unexpected error: %v", err)
}
Expand Down Expand Up @@ -98,7 +102,7 @@ func TestFindAllKeyspaceShards(t *testing.T) {
}

// get it
ks, err = findAllKeyspaceShards(ctx, ts, "cell1")
ks, err = findAllKeyspaceShards(ctx, rs, "cell1")
if err != nil {
t.Errorf("unexpected error: %v", err)
}
Expand Down
Loading