(vr *VoteRecord)
| 184 | } |
| 185 | |
| 186 | func (p *proxy) doProxyElection(vr *VoteRecord) { |
| 187 | var ( |
| 188 | err error |
| 189 | curPrimary = vr.Smap.Primary |
| 190 | timeout = cmn.Timeout.CplaneOperation() / 2 |
| 191 | ) |
| 192 | // 1. ping current primary (not using apc.QparamAskPrimary as it might be transitioning) |
| 193 | for i := 0; i < 2; i++ { |
| 194 | if i > 0 { |
| 195 | runtime.Gosched() |
| 196 | } |
| 197 | smap := p.owner.smap.get() |
| 198 | if smap.version() > vr.Smap.version() { |
| 199 | glog.Warningf("%s: %s updated from %s, moving back to idle", p, smap, vr.Smap) |
| 200 | return |
| 201 | } |
| 202 | _, _, err = p.Health(curPrimary, timeout, nil /*ask primary*/) |
| 203 | if err == nil { |
| 204 | break |
| 205 | } |
| 206 | timeout = cmn.Timeout.CplaneOperation() |
| 207 | } |
| 208 | if err == nil { |
| 209 | // move back to idle |
| 210 | query := url.Values{apc.QparamAskPrimary: []string{"true"}} |
| 211 | _, _, err = p.Health(curPrimary, timeout, query /*ask primary*/) |
| 212 | if err == nil { |
| 213 | glog.Infof("%s: current primary %s is up, moving back to idle", p, curPrimary) |
| 214 | } else { |
| 215 | glog.Errorf("%s: current primary(?) %s responds but does not consider itself primary", |
| 216 | p.si, curPrimary) |
| 217 | } |
| 218 | return |
| 219 | } |
| 220 | glog.Infof("%s: primary %s is confirmed down: %v", p, curPrimary, err) |
| 221 | |
| 222 | // 2. election phase 1 |
| 223 | glog.Info("Moving to election state phase 1 (prepare)") |
| 224 | elected, votingErrors := p.electAmongProxies(vr) |
| 225 | if !elected { |
| 226 | glog.Errorf("Election phase 1 (prepare) failed: primary remains %s, moving back to idle", curPrimary) |
| 227 | return |
| 228 | } |
| 229 | |
| 230 | // 3. election phase 2 |
| 231 | glog.Info("Moving to election state phase 2 (commit)") |
| 232 | confirmationErrors := p.confirmElectionVictory(vr) |
| 233 | for sid := range confirmationErrors { |
| 234 | if !votingErrors.Contains(sid) { |
| 235 | glog.Errorf("Error confirming the election: %s was healthy when voting", sid) |
| 236 | } |
| 237 | } |
| 238 | |
| 239 | // 4. become! |
| 240 | glog.Infof("%s: moving (self) to primary state", p.si) |
| 241 | p.becomeNewPrimary(vr.Primary /*proxyIDToRemove*/) |
| 242 | } |
| 243 |
no test coverage detected