diff --git a/go/cmd/l2vtgate/main.go b/go/cmd/l2vtgate/main.go index 2404c1256b8..dd082656c8e 100644 --- a/go/cmd/l2vtgate/main.go +++ b/go/cmd/l2vtgate/main.go @@ -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" @@ -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() { @@ -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() @@ -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) diff --git a/go/cmd/l2vtgate/status.go b/go/cmd/l2vtgate/status.go index cc1325f3151..194e77a42ad 100644 --- a/go/cmd/l2vtgate/status.go +++ b/go/cmd/l2vtgate/status.go @@ -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" ) @@ -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() diff --git a/go/cmd/vtcombo/main.go b/go/cmd/vtcombo/main.go index e411f773043..43729f70d83 100644 --- a/go/cmd/vtcombo/main.go +++ b/go/cmd/vtcombo/main.go @@ -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" @@ -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, @@ -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) diff --git a/go/cmd/vtgate/status.go b/go/cmd/vtgate/status.go index 8c4e52f3b6c..bc7b6ce7fdc 100644 --- a/go/cmd/vtgate/status.go +++ b/go/cmd/vtgate/status.go @@ -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" @@ -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() diff --git a/go/cmd/vtgate/vtgate.go b/go/cmd/vtgate/vtgate.go index bcfd3dd0b41..3c2d9c33260 100644 --- a/go/cmd/vtgate/vtgate.go +++ b/go/cmd/vtgate/vtgate.go @@ -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" @@ -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() @@ -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() @@ -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) diff --git a/go/vt/discovery/tablet_stats_cache_wait.go b/go/vt/discovery/tablet_stats_cache_wait.go index 21951da0e4d..8589a89e3be 100644 --- a/go/vt/discovery/tablet_stats_cache_wait.go +++ b/go/vt/discovery/tablet_stats_cache_wait.go @@ -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" ) @@ -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 @@ -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 diff --git a/go/vt/discovery/tablet_stats_cache_wait_test.go b/go/vt/discovery/tablet_stats_cache_wait_test.go index ece0af3a188..2bf6db0b089 100644 --- a/go/vt/discovery/tablet_stats_cache_wait_test.go +++ b/go/vt/discovery/tablet_stats_cache_wait_test.go @@ -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" @@ -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) } @@ -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) } @@ -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) } diff --git a/go/vt/vtgate/resilient_srv_topo_server.go b/go/vt/srvtopo/resilient_server.go similarity index 82% rename from go/vt/vtgate/resilient_srv_topo_server.go rename to go/vt/srvtopo/resilient_server.go index fbf4daa6574..6dcd81e92ed 100644 --- a/go/vt/vtgate/resilient_srv_topo_server.go +++ b/go/vt/srvtopo/resilient_server.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package vtgate +package srvtopo import ( "flag" @@ -31,11 +31,11 @@ import ( "github.com/youtube/vitess/go/vt/topo" topodatapb "github.com/youtube/vitess/go/vt/proto/topodata" + vschemapb "github.com/youtube/vitess/go/vt/proto/vschema" ) var ( srvTopoCacheTTL = flag.Duration("srv_topo_cache_ttl", 1*time.Second, "how long to use cached entries for topology") - srvTopoTimeout = flag.Duration("srv_topo_timeout", 2*time.Second, "topo server timeout") ) const ( @@ -44,7 +44,7 @@ const ( errorCategory = "error" // TopoTemplate is the HTML to use to display the - // ResilientSrvTopoServerCacheStatus object + // ResilientServerCacheStatus object TopoTemplate = `