From aed84eef2b0e16a5ce4750db93e83faf31a89100 Mon Sep 17 00:00:00 2001 From: Michael Demmer Date: Thu, 5 Mar 2020 11:42:27 -0800 Subject: [PATCH] add a hack to enable routing to RDONLY tablets for REPLICA queries Signed-off-by: Michael Demmer --- go/vt/vtgate/gateway/discoverygateway.go | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/go/vt/vtgate/gateway/discoverygateway.go b/go/vt/vtgate/gateway/discoverygateway.go index e8f2240ee40..31e0c1d4300 100644 --- a/go/vt/vtgate/gateway/discoverygateway.go +++ b/go/vt/vtgate/gateway/discoverygateway.go @@ -38,18 +38,20 @@ import ( "vitess.io/vitess/go/vt/vttablet/queryservice" querypb "vitess.io/vitess/go/vt/proto/query" + "vitess.io/vitess/go/vt/proto/topodata" topodatapb "vitess.io/vitess/go/vt/proto/topodata" vtrpcpb "vitess.io/vitess/go/vt/proto/vtrpc" "vitess.io/vitess/go/vt/topo/topoproto" ) var ( - cellsToWatch = flag.String("cells_to_watch", "", "comma-separated list of cells for watching tablets") - tabletFilters flagutil.StringListValue - refreshInterval = flag.Duration("tablet_refresh_interval", 1*time.Minute, "tablet refresh interval") - refreshKnownTablets = flag.Bool("tablet_refresh_known_tablets", true, "tablet refresh reloads the tablet address/port map from topo in case it changes") - topoReadConcurrency = flag.Int("topo_read_concurrency", 32, "concurrent topo reads") - allowedTabletTypes []topodatapb.TabletType + cellsToWatch = flag.String("cells_to_watch", "", "comma-separated list of cells for watching tablets") + tabletFilters flagutil.StringListValue + refreshInterval = flag.Duration("tablet_refresh_interval", 1*time.Minute, "tablet refresh interval") + refreshKnownTablets = flag.Bool("tablet_refresh_known_tablets", true, "tablet refresh reloads the tablet address/port map from topo in case it changes") + topoReadConcurrency = flag.Int("topo_read_concurrency", 32, "concurrent topo reads") + allowedTabletTypes []topodatapb.TabletType + routeReplicaToRdonly = flag.Bool("gateway_route_replica_to_rdonly", false, "route REPLICA queries to RDONLY tablets as well as REPLICA tablets") ) const ( @@ -275,6 +277,12 @@ func (dg *discoveryGateway) withRetry(ctx context.Context, target *querypb.Targe } tablets := dg.tsc.GetHealthyTabletStats(target.Keyspace, target.Shard, target.TabletType) + + // temporary hack to enable REPLICA type queries to address both REPLICA tablets and RDONLY tablets + if *routeReplicaToRdonly && target.TabletType == topodata.TabletType_REPLICA { + tablets = append(tablets, dg.tsc.GetHealthyTabletStats(target.Keyspace, target.Shard, topodata.TabletType_RDONLY)...) + } + if len(tablets) == 0 { // fail fast if there is no tablet err = vterrors.New(vtrpcpb.Code_UNAVAILABLE, "no valid tablet")