From 2552b4ce25a9fdb41ff07fa69f2ccf485fea83ac 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/discoverygateway.go | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/go/vt/vtgate/discoverygateway.go b/go/vt/vtgate/discoverygateway.go index 474ec99d35f..5cb17bbe6fb 100644 --- a/go/vt/vtgate/discoverygateway.go +++ b/go/vt/vtgate/discoverygateway.go @@ -39,20 +39,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") - 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 - - tabletFilters flagutil.StringListValue + 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 ( @@ -282,6 +282,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")