diff --git a/go/vt/vtgate/discoverygateway.go b/go/vt/vtgate/discoverygateway.go index bb65952916a..9cc913dc2c3 100644 --- a/go/vt/vtgate/discoverygateway.go +++ b/go/vt/vtgate/discoverygateway.go @@ -17,6 +17,7 @@ limitations under the License. package vtgate import ( + "flag" "fmt" "math/rand" "sort" @@ -40,6 +41,10 @@ import ( vtrpcpb "vitess.io/vitess/go/vt/proto/vtrpc" ) +var ( + routeReplicaToRdonly = flag.Bool("gateway_route_replica_to_rdonly", false, "route REPLICA queries to RDONLY tablets as well as REPLICA tablets") +) + const ( // GatewayImplementationDiscovery defines the string value used as the implementation key for DiscoveryGateway GatewayImplementationDiscovery = "discoverygateway" @@ -286,6 +291,13 @@ 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 + // original commit - https://github.com/tinyspeck/vitess/pull/166/commits/2552b4ce25a9fdb41ff07fa69f2ccf485fea83ac + if *routeReplicaToRdonly && target.TabletType == topodatapb.TabletType_REPLICA { + tablets = append(tablets, dg.tsc.GetHealthyTabletStats(target.Keyspace, target.Shard, topodatapb.TabletType_RDONLY)...) + } + if len(tablets) == 0 { // fail fast if there is no tablet err = vterrors.New(vtrpcpb.Code_UNAVAILABLE, "no valid tablet")