Skip to content

Commit

Permalink
Merge pull request #5978 from planetscale/ds-rm-gateway
Browse files Browse the repository at this point in the history
Cleanup: remove Gateway interface
  • Loading branch information
sougou authored Mar 27, 2020
2 parents 79210c6 + 698519d commit e522127
Show file tree
Hide file tree
Showing 17 changed files with 123 additions and 260 deletions.
3 changes: 1 addition & 2 deletions go/cmd/vtgate/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
"vitess.io/vitess/go/vt/srvtopo"
_ "vitess.io/vitess/go/vt/status"
"vitess.io/vitess/go/vt/vtgate"
"vitess.io/vitess/go/vt/vtgate/gateway"
)

// For use by plugins which wish to avoid racing when registering status page parts.
Expand All @@ -39,7 +38,7 @@ func addStatusParts(vtg *vtgate.VTGate) {
servenv.AddStatusPart("Topology Cache", srvtopo.TopoTemplate, func() interface{} {
return resilientServer.CacheStatus()
})
servenv.AddStatusPart("Gateway Status", gateway.StatusTemplate, func() interface{} {
servenv.AddStatusPart("Gateway Status", vtgate.StatusTemplate, func() interface{} {
return vtg.GetGatewayCacheStatus()
})
servenv.AddStatusPart("Health Check Cache", discovery.HealthCheckTemplate, func() interface{} {
Expand Down
4 changes: 1 addition & 3 deletions go/vt/vtexplain/vtexplain_vtgate.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ import (
"vitess.io/vitess/go/vt/srvtopo"
"vitess.io/vitess/go/vt/vtgate"
"vitess.io/vitess/go/vt/vtgate/engine"
"vitess.io/vitess/go/vt/vtgate/gateway"

"vitess.io/vitess/go/vt/vttablet/queryservice"

topodatapb "vitess.io/vitess/go/vt/proto/topodata"
Expand Down Expand Up @@ -74,7 +72,7 @@ func initVtgateExecutor(vSchemaStr string, opts *Options) error {

func newFakeResolver(opts *Options, hc discovery.HealthCheck, serv srvtopo.Server, cell string) *vtgate.Resolver {
ctx := context.Background()
gw := gateway.GetCreator()(ctx, hc, serv, cell, 3)
gw := vtgate.NewTabletGateway(ctx, hc, serv, cell, 3)
gw.WaitForTablets(ctx, []topodatapb.TabletType{topodatapb.TabletType_REPLICA})

txMode := vtgatepb.TransactionMode_MULTI
Expand Down
122 changes: 0 additions & 122 deletions go/vt/vtgate/gateway/gateway.go

This file was deleted.

40 changes: 0 additions & 40 deletions go/vt/vtgate/gateway/shard_error.go

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ limitations under the License.
// - the error type returned: it's not a TabletError any more, but a ShardError.
// We still check the error code is correct though which is really all we care
// about.
package gatewaytest
package vtgate

import (
"testing"
Expand All @@ -32,7 +32,6 @@ import (
"vitess.io/vitess/go/vt/grpcclient"
"vitess.io/vitess/go/vt/topo"
"vitess.io/vitess/go/vt/topo/memorytopo"
"vitess.io/vitess/go/vt/vtgate/gateway"
"vitess.io/vitess/go/vt/vttablet/queryservice"
"vitess.io/vitess/go/vt/vttablet/tabletconn"
"vitess.io/vitess/go/vt/vttablet/tabletconntest"
Expand Down Expand Up @@ -80,24 +79,24 @@ func CreateFakeServers(t *testing.T) (*tabletconntest.FakeQueryService, *topo.Se
// gatewayAdapter implements the TabletConn interface, but sends the
// queries to the Gateway.
type gatewayAdapter struct {
gateway.Gateway
*tabletGateway
}

// Close should be overridden to make sure we don't close the underlying Gateway.
func (ga gatewayAdapter) Close(ctx context.Context) error {
func (ga *gatewayAdapter) Close(ctx context.Context) error {
return nil
}

// TestSuite executes a set of tests on the provided gateway. The provided
// gateway needs to be configured with one established connection for
// tabletconntest.TestTarget.{Keyspace, Shard, TabletType} to the
// provided tabletconntest.FakeQueryService.
func TestSuite(t *testing.T, name string, g gateway.Gateway, f *tabletconntest.FakeQueryService) {
func TestSuite(t *testing.T, name string, g *tabletGateway, f *tabletconntest.FakeQueryService) {

protocolName := "gateway-test-" + name

tabletconn.RegisterDialer(protocolName, func(tablet *topodatapb.Tablet, failFast grpcclient.FailFast) (queryservice.QueryService, error) {
return &gatewayAdapter{Gateway: g}, nil
return &gatewayAdapter{tabletGateway: g}, nil
})

tabletconntest.TestSuite(t, protocolName, &topodatapb.Tablet{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,19 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package gatewaytest
package vtgate

import (
"flag"
"golang.org/x/net/context"
"net"
"testing"
"time"

"golang.org/x/net/context"

"google.golang.org/grpc"

"vitess.io/vitess/go/vt/discovery"
"vitess.io/vitess/go/vt/srvtopo"
"vitess.io/vitess/go/vt/vtgate/gateway"
"vitess.io/vitess/go/vt/vttablet/grpcqueryservice"
"vitess.io/vitess/go/vt/vttablet/tabletconntest"

Expand All @@ -42,7 +40,6 @@ import (
// connection from the gateway to the fake tablet.
func TestGRPCDiscovery(t *testing.T) {
flag.Set("tablet_protocol", "grpc")
flag.Set("gateway_implementation", "discoverygateway")

// Fake services for the tablet, topo server.
service, ts, cell := CreateFakeServers(t)
Expand All @@ -66,7 +63,7 @@ func TestGRPCDiscovery(t *testing.T) {
// Wait for the right tablets to be present.
hc := discovery.NewHealthCheck(10*time.Second, 2*time.Minute)
rs := srvtopo.NewResilientServer(ts, "TestGRPCDiscovery")
dg := gateway.GetCreator()(context.Background(), hc, rs, cell, 2)
dg := NewTabletGateway(context.Background(), hc, rs, cell, 2)
hc.AddTablet(&topodatapb.Tablet{
Alias: &topodatapb.TabletAlias{
Cell: cell,
Expand All @@ -80,7 +77,7 @@ func TestGRPCDiscovery(t *testing.T) {
"grpc": int32(port),
},
}, "test_tablet")
err = gateway.WaitForTablets(dg, []topodatapb.TabletType{tabletconntest.TestTarget.TabletType})
err = WaitForTablets(dg, []topodatapb.TabletType{tabletconntest.TestTarget.TabletType})
if err != nil {
t.Fatalf("WaitForTablets failed: %v", err)
}
Expand Down
8 changes: 3 additions & 5 deletions go/vt/vtgate/resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,11 @@ import (
"golang.org/x/net/context"
"vitess.io/vitess/go/sqltypes"
"vitess.io/vitess/go/vt/key"
"vitess.io/vitess/go/vt/srvtopo"
"vitess.io/vitess/go/vt/vterrors"
"vitess.io/vitess/go/vt/vtgate/gateway"

querypb "vitess.io/vitess/go/vt/proto/query"
topodatapb "vitess.io/vitess/go/vt/proto/topodata"
vtrpcpb "vitess.io/vitess/go/vt/proto/vtrpc"
"vitess.io/vitess/go/vt/srvtopo"
"vitess.io/vitess/go/vt/vterrors"
)

// Resolver is the layer to resolve KeyspaceIds and KeyRanges
Expand Down Expand Up @@ -163,6 +161,6 @@ func (res *Resolver) MessageStream(ctx context.Context, keyspace string, shard s
}

// GetGatewayCacheStatus returns a displayable version of the Gateway cache.
func (res *Resolver) GetGatewayCacheStatus() gateway.TabletCacheStatusList {
func (res *Resolver) GetGatewayCacheStatus() TabletCacheStatusList {
return res.scatterConn.GetGatewayCacheStatus()
}
14 changes: 6 additions & 8 deletions go/vt/vtgate/scatter_conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,13 @@ import (
"vitess.io/vitess/go/stats"
"vitess.io/vitess/go/vt/concurrency"
"vitess.io/vitess/go/vt/discovery"
"vitess.io/vitess/go/vt/srvtopo"
"vitess.io/vitess/go/vt/topo/topoproto"
"vitess.io/vitess/go/vt/vterrors"
"vitess.io/vitess/go/vt/vtgate/gateway"

querypb "vitess.io/vitess/go/vt/proto/query"
topodatapb "vitess.io/vitess/go/vt/proto/topodata"
vtgatepb "vitess.io/vitess/go/vt/proto/vtgate"
vtrpcpb "vitess.io/vitess/go/vt/proto/vtrpc"
"vitess.io/vitess/go/vt/srvtopo"
"vitess.io/vitess/go/vt/topo/topoproto"
"vitess.io/vitess/go/vt/vterrors"
)

var (
Expand All @@ -49,7 +47,7 @@ type ScatterConn struct {
timings *stats.MultiTimings
tabletCallErrorCount *stats.CountersWithMultiLabels
txConn *TxConn
gateway gateway.Gateway
gateway *tabletGateway
healthCheck discovery.HealthCheck
}

Expand All @@ -71,7 +69,7 @@ type shardActionFunc func(rs *srvtopo.ResolvedShard, i int) error
type shardActionTransactionFunc func(rs *srvtopo.ResolvedShard, i int, shouldBegin bool, transactionID int64) (int64, error)

// NewScatterConn creates a new ScatterConn.
func NewScatterConn(statsName string, txConn *TxConn, gw gateway.Gateway, hc discovery.HealthCheck) *ScatterConn {
func NewScatterConn(statsName string, txConn *TxConn, gw *tabletGateway, hc discovery.HealthCheck) *ScatterConn {
tabletCallErrorCountStatsName := ""
if statsName != "" {
tabletCallErrorCountStatsName = statsName + "ErrorCount"
Expand Down Expand Up @@ -417,7 +415,7 @@ func (stc *ScatterConn) Close() error {
}

// GetGatewayCacheStatus returns a displayable version of the Gateway cache.
func (stc *ScatterConn) GetGatewayCacheStatus() gateway.TabletCacheStatusList {
func (stc *ScatterConn) GetGatewayCacheStatus() TabletCacheStatusList {
return stc.gateway.CacheStatus()
}

Expand Down
8 changes: 3 additions & 5 deletions go/vt/vtgate/scatter_conn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,12 @@ import (
"vitess.io/vitess/go/sqltypes"
"vitess.io/vitess/go/vt/discovery"
"vitess.io/vitess/go/vt/key"
"vitess.io/vitess/go/vt/srvtopo"
"vitess.io/vitess/go/vt/vterrors"
"vitess.io/vitess/go/vt/vtgate/gateway"

querypb "vitess.io/vitess/go/vt/proto/query"
topodatapb "vitess.io/vitess/go/vt/proto/topodata"
vtgatepb "vitess.io/vitess/go/vt/proto/vtgate"
vtrpcpb "vitess.io/vitess/go/vt/proto/vtrpc"
"vitess.io/vitess/go/vt/srvtopo"
"vitess.io/vitess/go/vt/vterrors"
)

// This file uses the sandbox_test framework.
Expand Down Expand Up @@ -654,7 +652,7 @@ func newTestScatterConn(hc discovery.HealthCheck, serv srvtopo.Server, cell stri
// The topo.Server is used to start watching the cells described
// in '-cells_to_watch' command line parameter, which is
// empty by default. So it's unused in this test, set to nil.
gw := gateway.GetCreator()(context.Background(), hc, serv, cell, 3)
gw := NewTabletGateway(context.Background(), hc, serv, cell, 3)
tc := NewTxConn(gw, vtgatepb.TransactionMode_TWOPC)
return NewScatterConn("", tc, gw, hc)
}
2 changes: 1 addition & 1 deletion go/vt/vtgate/gateway/status.go → go/vt/vtgate/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package gateway
package vtgate

import (
"fmt"
Expand Down
Loading

0 comments on commit e522127

Please sign in to comment.