@@ -69,12 +69,7 @@ func ElectNewPrimary(
69
69
shardInfo * topo.ShardInfo ,
70
70
tabletMap map [string ]* topo.TabletInfo ,
71
71
innodbBufferPoolData map [string ]int ,
72
- newPrimaryAlias * topodatapb.TabletAlias ,
73
- avoidPrimaryAlias * topodatapb.TabletAlias ,
74
- waitReplicasTimeout time.Duration ,
75
- tolerableReplLag time.Duration ,
76
- durability Durabler ,
77
- allowCrossCellPromotion bool ,
72
+ opts * PlannedReparentOptions ,
78
73
// (TODO:@ajm188) it's a little gross we need to pass this, maybe embed in the context?
79
74
logger logutil.Logger ,
80
75
) (* topodatapb.TabletAlias , error ) {
@@ -99,16 +94,16 @@ func ElectNewPrimary(
99
94
reasonsToInvalidate := strings.Builder {}
100
95
for _ , tablet := range tabletMap {
101
96
switch {
102
- case newPrimaryAlias != nil :
97
+ case opts . NewPrimaryAlias != nil :
103
98
// If newPrimaryAlias is provided, then that is the only valid tablet, even if it is not of type replica or in a different cell.
104
- if ! topoproto .TabletAliasEqual (tablet .Alias , newPrimaryAlias ) {
99
+ if ! topoproto .TabletAliasEqual (tablet .Alias , opts . NewPrimaryAlias ) {
105
100
reasonsToInvalidate .WriteString (fmt .Sprintf ("\n %v does not match the new primary alias provided" , topoproto .TabletAliasString (tablet .Alias )))
106
101
continue
107
102
}
108
- case ! allowCrossCellPromotion && primaryCell != "" && tablet .Alias .Cell != primaryCell :
103
+ case ! opts . AllowCrossCellPromotion && primaryCell != "" && tablet .Alias .Cell != primaryCell :
109
104
reasonsToInvalidate .WriteString (fmt .Sprintf ("\n %v is not in the same cell as the previous primary" , topoproto .TabletAliasString (tablet .Alias )))
110
105
continue
111
- case avoidPrimaryAlias != nil && topoproto .TabletAliasEqual (tablet .Alias , avoidPrimaryAlias ):
106
+ case opts . AvoidPrimaryAlias != nil && topoproto .TabletAliasEqual (tablet .Alias , opts . AvoidPrimaryAlias ):
112
107
reasonsToInvalidate .WriteString (fmt .Sprintf ("\n %v matches the primary alias to avoid" , topoproto .TabletAliasString (tablet .Alias )))
113
108
continue
114
109
case tablet .Tablet .Type != topodatapb .TabletType_REPLICA :
@@ -123,18 +118,18 @@ func ElectNewPrimary(
123
118
// then we don't need to find the position of the said tablet for sorting.
124
119
// We can just return the tablet quickly.
125
120
// This check isn't required, but it saves us an RPC call that is otherwise unnecessary.
126
- if len (candidates ) == 1 && tolerableReplLag == 0 {
121
+ if len (candidates ) == 1 && opts . TolerableReplLag == 0 {
127
122
return candidates [0 ].Alias , nil
128
123
}
129
124
130
125
for _ , tablet := range candidates {
131
126
tb := tablet
132
127
errorGroup .Go (func () error {
133
128
// find and store the positions for the tablet
134
- pos , replLag , err := findPositionAndLagForTablet (groupCtx , tb , logger , tmc , waitReplicasTimeout )
129
+ pos , replLag , err := findPositionAndLagForTablet (groupCtx , tb , logger , tmc , opts . WaitReplicasTimeout )
135
130
mu .Lock ()
136
131
defer mu .Unlock ()
137
- if err == nil && (tolerableReplLag == 0 || tolerableReplLag >= replLag ) {
132
+ if err == nil && (opts . TolerableReplLag == 0 || opts . TolerableReplLag >= replLag ) {
138
133
validTablets = append (validTablets , tb )
139
134
tabletPositions = append (tabletPositions , pos )
140
135
innodbBufferPool = append (innodbBufferPool , innodbBufferPoolData [topoproto .TabletAliasString (tb .Alias )])
@@ -156,7 +151,7 @@ func ElectNewPrimary(
156
151
}
157
152
158
153
// sort the tablets for finding the best primary
159
- err = sortTabletsForReparent (validTablets , tabletPositions , innodbBufferPool , durability )
154
+ err = sortTabletsForReparent (validTablets , tabletPositions , innodbBufferPool , opts . durability )
160
155
if err != nil {
161
156
return nil , err
162
157
}
0 commit comments