diff --git a/go/vt/vtctl/reparentutil/emergency_reparenter_test.go b/go/vt/vtctl/reparentutil/emergency_reparenter_test.go index 63d3d8af325..a3d6f1550c0 100644 --- a/go/vt/vtctl/reparentutil/emergency_reparenter_test.go +++ b/go/vt/vtctl/reparentutil/emergency_reparenter_test.go @@ -2872,7 +2872,7 @@ func TestEmergencyReparenter_findMostAdvanced(t *testing.T) { validCandidates: map[string]replication.Position{ "zone1-0000000100": positionMostAdvanced, "zone1-0000000101": positionIntermediate1, - "zone1-0000000102": positionIntermediate2, + "zone1-0000000102": positionMostAdvanced, }, tabletMap: map[string]*topo.TabletInfo{ "zone1-0000000100": { diff --git a/go/vt/vtctl/reparentutil/reparent_sorter.go b/go/vt/vtctl/reparentutil/reparent_sorter.go index 16eb006179b..35ab99f8233 100644 --- a/go/vt/vtctl/reparentutil/reparent_sorter.go +++ b/go/vt/vtctl/reparentutil/reparent_sorter.go @@ -74,14 +74,6 @@ func (rs *reparentSorter) Less(i, j int) bool { return true } - // We want tablets which are currently running a backup to always be at the end of the list, so that's the first thing we check - if !rs.backupRunning[topoproto.TabletAliasString(rs.tablets[i].Alias)] && rs.backupRunning[topoproto.TabletAliasString(rs.tablets[j].Alias)] { - return true - } - if rs.backupRunning[topoproto.TabletAliasString(rs.tablets[i].Alias)] && !rs.backupRunning[topoproto.TabletAliasString(rs.tablets[j].Alias)] { - return false - } - if !rs.positions[i].AtLeast(rs.positions[j]) { // [i] does not have all GTIDs that [j] does return false @@ -96,6 +88,14 @@ func (rs *reparentSorter) Less(i, j int) bool { jPromotionRule := PromotionRule(rs.durability, rs.tablets[j]) iPromotionRule := PromotionRule(rs.durability, rs.tablets[i]) + // We want tablets which are currently running a backup to always be at the end of the list, so that's the first thing we check + if !rs.backupRunning[topoproto.TabletAliasString(rs.tablets[i].Alias)] && rs.backupRunning[topoproto.TabletAliasString(rs.tablets[j].Alias)] { + return true + } + if rs.backupRunning[topoproto.TabletAliasString(rs.tablets[i].Alias)] && !rs.backupRunning[topoproto.TabletAliasString(rs.tablets[j].Alias)] { + return false + } + // If the promotion rules are different then we want to sort by the promotion rules. if len(rs.innodbBufferPool) != 0 && jPromotionRule == iPromotionRule { if rs.innodbBufferPool[i] > rs.innodbBufferPool[j] {