Proxy/gateway that is, potentially, the leader of the cluster. It waits a configured time for other nodes to join, discovers cluster-wide metadata, and resolve remaining conflicts.
(loadedSmap *smapX, config *cmn.Config, ntargets int)
| 195 | // It waits a configured time for other nodes to join, |
| 196 | // discovers cluster-wide metadata, and resolve remaining conflicts. |
| 197 | func (p *proxy) primaryStartup(loadedSmap *smapX, config *cmn.Config, ntargets int) { |
| 198 | var ( |
| 199 | smap = newSmap() |
| 200 | uuid, created string |
| 201 | haveJoins bool |
| 202 | ) |
| 203 | |
| 204 | // 1: init Smap to accept reg-s |
| 205 | p.owner.smap.Lock() |
| 206 | si := p.si.Clone() |
| 207 | smap.Primary = si |
| 208 | smap.addProxy(si) |
| 209 | if loadedSmap != nil { |
| 210 | smap.UUID = loadedSmap.UUID |
| 211 | } |
| 212 | p.owner.smap.put(smap) |
| 213 | p.owner.smap.Unlock() |
| 214 | |
| 215 | p.markNodeStarted() |
| 216 | |
| 217 | if !daemon.cli.primary.skipStartup { |
| 218 | maxVerSmap := p.acceptRegistrations(smap, loadedSmap, config, ntargets) |
| 219 | if maxVerSmap != nil { |
| 220 | if _, err := maxVerSmap.IsDuplicate(p.si); err != nil { |
| 221 | cos.ExitLogf("FATAL: %v", err) |
| 222 | } |
| 223 | maxVerSmap.Pmap[p.si.ID()] = p.si |
| 224 | p.owner.smap.put(maxVerSmap) |
| 225 | glog.Infof("%s: change-of-mind #1: registering with %s(%s)", |
| 226 | p.si, maxVerSmap.Primary.ID(), maxVerSmap.Primary.URL(cmn.NetIntraControl)) |
| 227 | if err := p.secondaryStartup(maxVerSmap); err != nil { |
| 228 | cos.ExitLogf("FATAL: %v", err) |
| 229 | } |
| 230 | return |
| 231 | } |
| 232 | } |
| 233 | |
| 234 | smap = p.owner.smap.get() |
| 235 | haveJoins = smap.CountTargets() > 0 || smap.CountProxies() > 1 |
| 236 | |
| 237 | // 2: merging local => boot |
| 238 | if haveJoins { |
| 239 | var ( |
| 240 | before, after cluMeta |
| 241 | added int |
| 242 | ) |
| 243 | p.owner.smap.Lock() |
| 244 | clone := p.owner.smap.get().clone() |
| 245 | if loadedSmap != nil { |
| 246 | added, _ = clone.merge(loadedSmap, true /*override (IP, port) duplicates*/) |
| 247 | clone = loadedSmap |
| 248 | if added > 0 { |
| 249 | clone.Version = clone.Version + int64(added) + 1 |
| 250 | } |
| 251 | } |
| 252 | // NOTE: use regpool to try to upgrade all the four revs: Smap, BMD, RMD, and global Config |
| 253 | before.Smap, before.BMD, before.RMD, before.EtlMD = clone, p.owner.bmd.get(), p.owner.rmd.get(), p.owner.etl.get() |
| 254 | before.Config, _ = p.owner.config.get() |
no test coverage detected