Skip to content
This repository has been archived by the owner on Dec 16, 2022. It is now read-only.

Commit

Permalink
add a hack to enable routing to RDONLY tablets for REPLICA queries
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Demmer <mdemmer@slack-corp.com>
  • Loading branch information
demmer authored and setassociative committed Mar 4, 2021
1 parent 7a8d85f commit f8a19a5
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions go/vt/vtgate/discoverygateway.go
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
package vtgate

import (
"flag"
"fmt"
"math/rand"
"sort"
Expand All @@ -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"
Expand Down Expand Up @@ -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")
Expand Down

0 comments on commit f8a19a5

Please sign in to comment.