Skip to content

Commit

Permalink
Backport of upstream vitessio#16997 (#565)
Browse files Browse the repository at this point in the history
Signed-off-by: Eduardo J. Ortega U. <[email protected]>
  • Loading branch information
ejortegau authored Nov 26, 2024
1 parent 65cd79e commit f75d407
Show file tree
Hide file tree
Showing 18 changed files with 927 additions and 432 deletions.
191 changes: 106 additions & 85 deletions go/vt/proto/replicationdata/replicationdata.pb.go

Large diffs are not rendered by default.

68 changes: 68 additions & 0 deletions go/vt/proto/replicationdata/replicationdata_vtproto.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

581 changes: 301 additions & 280 deletions go/vt/proto/tabletmanagerdata/tabletmanagerdata.pb.go

Large diffs are not rendered by default.

66 changes: 66 additions & 0 deletions go/vt/proto/tabletmanagerdata/tabletmanagerdata_vtproto.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions go/vt/vtctl/grpcvtctldserver/testutil/test_tmclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,8 @@ type TabletManagerClient struct {
EventJitter time.Duration
ErrorAfter time.Duration
}
// Backing Up - keyed by tablet alias.
TabletsBackupState map[string]bool
// keyed by tablet alias.
ChangeTabletTypeResult map[string]error
// keyed by tablet alias.
Expand Down Expand Up @@ -864,6 +866,9 @@ func (fake *TabletManagerClient) ReplicationStatus(ctx context.Context, tablet *
}

if result, ok := fake.ReplicationStatusResults[key]; ok {
if _, ok = fake.TabletsBackupState[key]; ok {
result.Position.BackupRunning = fake.TabletsBackupState[key]
}
return result.Position, result.Error
}

Expand Down
25 changes: 20 additions & 5 deletions go/vt/vtctl/reparentutil/emergency_reparenter.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,8 @@ func (erp *EmergencyReparenter) reparentShardLocked(ctx context.Context, ev *eve
// 2. Remove the tablets with the Must_not promote rule
// 3. Remove cross-cell tablets if PreventCrossCellPromotion is specified
// Our final primary candidate MUST belong to this list of valid candidates
validCandidateTablets, err = erp.filterValidCandidates(validCandidateTablets, stoppedReplicationSnapshot.reachableTablets, prevPrimary, opts)
validCandidateTablets, err = erp.filterValidCandidates(validCandidateTablets,
stoppedReplicationSnapshot.reachableTablets, stoppedReplicationSnapshot.tabletsBackupState, prevPrimary, opts)
if err != nil {
return err
}
Expand Down Expand Up @@ -722,9 +723,12 @@ func (erp *EmergencyReparenter) promoteNewPrimary(
return nil
}

// filterValidCandidates filters valid tablets, keeping only the ones which can successfully be promoted without any constraint failures and can make forward progress on being promoted
func (erp *EmergencyReparenter) filterValidCandidates(validTablets []*topodatapb.Tablet, tabletsReachable []*topodatapb.Tablet, prevPrimary *topodatapb.Tablet, opts EmergencyReparentOptions) ([]*topodatapb.Tablet, error) {
// filterValidCandidates filters valid tablets, keeping only the ones which can successfully be promoted without any
// constraint failures and can make forward progress on being promoted. It will filter out candidates taking backups
// if possible.
func (erp *EmergencyReparenter) filterValidCandidates(validTablets []*topodatapb.Tablet, tabletsReachable []*topodatapb.Tablet, tabletsBackupState map[string]bool, prevPrimary *topodatapb.Tablet, opts EmergencyReparentOptions) ([]*topodatapb.Tablet, error) {
var restrictedValidTablets []*topodatapb.Tablet
var notPreferredValidTablets []*topodatapb.Tablet
for _, tablet := range validTablets {
tabletAliasStr := topoproto.TabletAliasString(tablet.Alias)
// Remove tablets which have MustNot promote rule since they must never be promoted
Expand All @@ -751,7 +755,18 @@ func (erp *EmergencyReparenter) filterValidCandidates(validTablets []*topodatapb
}
continue
}
restrictedValidTablets = append(restrictedValidTablets, tablet)
// Put candidates that are running a backup in a separate list
backingUp, ok := tabletsBackupState[tabletAliasStr]
if ok && backingUp {
erp.logger.Infof("Setting %s in list of valid candidates taking a backup", tabletAliasStr)
notPreferredValidTablets = append(notPreferredValidTablets, tablet)
} else {
restrictedValidTablets = append(restrictedValidTablets, tablet)
}
}
if len(restrictedValidTablets) > 0 {
return restrictedValidTablets, nil
}
return restrictedValidTablets, nil

return notPreferredValidTablets, nil
}
Loading

0 comments on commit f75d407

Please sign in to comment.