Skip to content

Commit

Permalink
reorder tablet checks in vtgate tablet gateway
Browse files Browse the repository at this point in the history
Signed-off-by: austenLacy <[email protected]>
  • Loading branch information
austenLacy committed Oct 16, 2023
1 parent 8575b17 commit 804c014
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
2 changes: 1 addition & 1 deletion go/vt/vtgate/buffer/buffer.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ const (
type RetryDoneFunc context.CancelFunc

const (
ClusterEventReshardingInProgress = "current keyspace is being resharded"
ClusterEventReshardingInProgress = "current keyspace is potentially being resharded"
ClusterEventReparentInProgress = "primary is not serving, there may be a reparent operation in progress"
ClusterEventMoveTables = "disallowed due to rule"
)
Expand Down
12 changes: 7 additions & 5 deletions go/vt/vtgate/tabletgateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -283,22 +283,24 @@ func (gw *TabletGateway) withRetry(ctx context.Context, target *querypb.Target,
// if we have a keyspace event watcher, check if the reason why our primary is not available is that it's currently being resharded
// or if a reparent operation is in progress.
if kev := gw.kev; kev != nil {
if kev.TargetIsBeingResharded(ctx, target) {
log.V(2).Infof("current keyspace is being resharded, retrying: %s: %s", target.Keyspace, debug.Stack())
err = vterrors.Errorf(vtrpcpb.Code_CLUSTER_EVENT, buffer.ClusterEventReshardingInProgress)
continue
}
primary, notServing := kev.PrimaryIsNotServing(ctx, target)
if notServing {
err = vterrors.Errorf(vtrpcpb.Code_CLUSTER_EVENT, buffer.ClusterEventReparentInProgress)
continue
}

// if primary is serving, but we initially found no tablet, we're in an inconsistent state
// we then retry the entire loop
if primary != nil {
err = vterrors.Errorf(vtrpcpb.Code_UNAVAILABLE, "inconsistent state detected, primary is serving but initially found no available tablet")
continue
}

if kev.TargetIsBeingResharded(ctx, target) {
log.V(2).Infof("current keyspace is potentally being resharded, retrying: %s: %s", target.Keyspace, debug.Stack())
err = vterrors.Errorf(vtrpcpb.Code_CLUSTER_EVENT, buffer.ClusterEventReshardingInProgress)
continue
}
}

// fail fast if there is no tablet
Expand Down

0 comments on commit 804c014

Please sign in to comment.