// NodeSuits checks if node can perform backup
NodeSuits checks if node can perform backup
// NodeSuits checks if node can perform backup
func NodeSuits(bcp pbm.BackupCmd, node *pbm.Node) (bool, error) {
	im, err := node.GetIsMaster()
	if err != nil {
		return false, errors.Wrap(err, "get isMaster data for node")
	}
	if im.IsStandalone() {
		return false, errors.New("mongod node can not be used to fetch a consistent backup because it has no oplog. Please restart it as a primary in a single-node replicaset to make it compatible with PBM's backup method using the oplog")
	}
	 but no need to wait if this is the only node (the single-node replica set).
	 TODO ? there is still a chance that the lock gonna be stolen from the healthy secondary node
	 TODO ? (due tmp network issues node got the command later than the primary, but it's maybe for the good that the node with the faulty network doesn't start the backup)
	if im.IsMaster && im.Me == im.Primary && len(im.Hosts) > 1 {
		time.Sleep(pbm.WaitActionStart * 9 / 10)
	}
	status, err := node.Status()
	if err != nil {
		return false, errors.Wrap(err, "get node status")
	}
	replLag, err := node.ReplicationLag()
	if err != nil {
		return false, errors.Wrap(err, "get node replication lag")
	}
	return replLag < maxReplicationLagTimeSec && status.Health == pbm.NodeHealthUp &&
			(status.State == pbm.NodeStatePrimary || status.State == pbm.NodeStateSecondary),
		nil
}
func NodeSuits ( bcp pbm . BackupCmd , node * pbm . Node ) ( bool , error ) { im , err := node . GetIsMaster ( ) if err != nil { return false , errors . Wrap ( err , " " ) } if im . IsStandalone ( ) { return false , errors . New ( " " ) } if im . IsMaster && im . Me == im . Primary && len ( im . Hosts ) > 1 { time . Sleep ( pbm . WaitActionStart * 9 / 10 ) } status , err := node . Status ( ) if err != nil { return false , errors . Wrap ( err , " " ) } replLag , err := node . ReplicationLag ( ) if err != nil { return false , errors . Wrap ( err , " " ) } return replLag < maxReplicationLagTimeSec && status . Health == pbm . NodeHealthUp && ( status . State == pbm . NodeStatePrimary || status . State == pbm . NodeStateSecondary ) , nil }
NodeSuits checks if node can perform backup
NodeSuits checks if node can perform backup
// for the cases when no secondary was good enough for backup or there are no secondaries alive // wait for 90% of WaitBackupStart and then try to acquire a lock. // by that time healthy secondaries should have already acquired a lock. // // but no need to wait if this is the only node (the single-node replica set). // // TODO ? there is still a chance that the lock gonna be stolen from the healthy secondary node // TODO ? (due tmp network issues node got the command later than the primary, but it's maybe for the good that the node with the faulty network doesn't start the backup)