func replicaAddCall(session mgoSession, members ...replicaset.Member) error { mSession := session.(*mgo.Session) if err := replicaset.Add(mSession, members...); err != nil { return errors.Annotate(err, "cannot resume HA") } return nil }
// ResumeReplication will add all passed members to replicaset. func (st *State) ResumeReplication(members []replicaset.Member) error { return replicaset.Add(st.session, members...) }
// startReplicaSet starts up a replica set with n mongo instances. func startReplicaSet(n int) (_ []*gitjujutesting.MgoInstance, err error) { insts := make([]*gitjujutesting.MgoInstance, 0, n) root, err := newMongoInstance() if err != nil { return nil, err } insts = append(insts, root) defer func() { if err == nil { return } for _, inst := range insts { inst.Destroy() } }() dialInfo := root.DialInfo() dialInfo.Direct = true dialInfo.Timeout = 60 * time.Second session, err := root.DialDirect() if err != nil { return nil, fmt.Errorf("cannot dial root instance: %v", err) } defer session.Close() logger.Infof("dialled root instance") if err := replicaset.Initiate(session, root.Addr(), replicaSetName, nil); err != nil { return nil, fmt.Errorf("cannot initiate replica set: %v", err) } var members []replicaset.Member for i := 1; i < n; i++ { inst, err := newMongoInstance() if err != nil { return nil, err } insts = append(insts, inst) members = append(members, replicaset.Member{ Address: inst.Addr(), Priority: newFloat64(0.1), Id: i + 1, }) } attempt := utils.AttemptStrategy{ Total: 60 * time.Second, Delay: 1 * time.Second, } for a := attempt.Start(); a.Next(); { err := replicaset.Add(session, members...) if err == nil { break } logger.Errorf("cannot add members: %v", err) if !a.HasNext() { return nil, fmt.Errorf("timed out trying to add members") } logger.Errorf("retrying") } return insts, err }