Skip to content

Commit f75d407

Browse files
authored
Backport of upstream vitessio#16997 (#565)
Signed-off-by: Eduardo J. Ortega U. <5791035+ejortegau@users.noreply.github.com>
1 parent 65cd79e commit f75d407

File tree

18 files changed

+927
-432
lines changed

18 files changed

+927
-432
lines changed

go/vt/proto/replicationdata/replicationdata.pb.go

Lines changed: 106 additions & 85 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

go/vt/proto/replicationdata/replicationdata_vtproto.pb.go

Lines changed: 68 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

go/vt/proto/tabletmanagerdata/tabletmanagerdata.pb.go

Lines changed: 301 additions & 280 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

go/vt/proto/tabletmanagerdata/tabletmanagerdata_vtproto.pb.go

Lines changed: 66 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

go/vt/vtctl/grpcvtctldserver/testutil/test_tmclient.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,8 @@ type TabletManagerClient struct {
184184
EventJitter time.Duration
185185
ErrorAfter time.Duration
186186
}
187+
// Backing Up - keyed by tablet alias.
188+
TabletsBackupState map[string]bool
187189
// keyed by tablet alias.
188190
ChangeTabletTypeResult map[string]error
189191
// keyed by tablet alias.
@@ -864,6 +866,9 @@ func (fake *TabletManagerClient) ReplicationStatus(ctx context.Context, tablet *
864866
}
865867

866868
if result, ok := fake.ReplicationStatusResults[key]; ok {
869+
if _, ok = fake.TabletsBackupState[key]; ok {
870+
result.Position.BackupRunning = fake.TabletsBackupState[key]
871+
}
867872
return result.Position, result.Error
868873
}
869874

go/vt/vtctl/reparentutil/emergency_reparenter.go

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,8 @@ func (erp *EmergencyReparenter) reparentShardLocked(ctx context.Context, ev *eve
246246
// 2. Remove the tablets with the Must_not promote rule
247247
// 3. Remove cross-cell tablets if PreventCrossCellPromotion is specified
248248
// Our final primary candidate MUST belong to this list of valid candidates
249-
validCandidateTablets, err = erp.filterValidCandidates(validCandidateTablets, stoppedReplicationSnapshot.reachableTablets, prevPrimary, opts)
249+
validCandidateTablets, err = erp.filterValidCandidates(validCandidateTablets,
250+
stoppedReplicationSnapshot.reachableTablets, stoppedReplicationSnapshot.tabletsBackupState, prevPrimary, opts)
250251
if err != nil {
251252
return err
252253
}
@@ -722,9 +723,12 @@ func (erp *EmergencyReparenter) promoteNewPrimary(
722723
return nil
723724
}
724725

725-
// 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
726-
func (erp *EmergencyReparenter) filterValidCandidates(validTablets []*topodatapb.Tablet, tabletsReachable []*topodatapb.Tablet, prevPrimary *topodatapb.Tablet, opts EmergencyReparentOptions) ([]*topodatapb.Tablet, error) {
726+
// filterValidCandidates filters valid tablets, keeping only the ones which can successfully be promoted without any
727+
// constraint failures and can make forward progress on being promoted. It will filter out candidates taking backups
728+
// if possible.
729+
func (erp *EmergencyReparenter) filterValidCandidates(validTablets []*topodatapb.Tablet, tabletsReachable []*topodatapb.Tablet, tabletsBackupState map[string]bool, prevPrimary *topodatapb.Tablet, opts EmergencyReparentOptions) ([]*topodatapb.Tablet, error) {
727730
var restrictedValidTablets []*topodatapb.Tablet
731+
var notPreferredValidTablets []*topodatapb.Tablet
728732
for _, tablet := range validTablets {
729733
tabletAliasStr := topoproto.TabletAliasString(tablet.Alias)
730734
// Remove tablets which have MustNot promote rule since they must never be promoted
@@ -751,7 +755,18 @@ func (erp *EmergencyReparenter) filterValidCandidates(validTablets []*topodatapb
751755
}
752756
continue
753757
}
754-
restrictedValidTablets = append(restrictedValidTablets, tablet)
758+
// Put candidates that are running a backup in a separate list
759+
backingUp, ok := tabletsBackupState[tabletAliasStr]
760+
if ok && backingUp {
761+
erp.logger.Infof("Setting %s in list of valid candidates taking a backup", tabletAliasStr)
762+
notPreferredValidTablets = append(notPreferredValidTablets, tablet)
763+
} else {
764+
restrictedValidTablets = append(restrictedValidTablets, tablet)
765+
}
766+
}
767+
if len(restrictedValidTablets) > 0 {
768+
return restrictedValidTablets, nil
755769
}
756-
return restrictedValidTablets, nil
770+
771+
return notPreferredValidTablets, nil
757772
}

0 commit comments

Comments
 (0)