// Attempt tries one time to box audit a Team ID. It does not store any
// persistent state to disk related to the box audit, but it may, e.g., refresh
// the team cache.
973218
func (a *BoxAuditor) Attempt(mctx libkb.MetaContext, teamID keybase1.TeamID, rotateBeforeAudit bool) (attempt keybase1.BoxAuditAttempt) {
	mctx = a.initMctx(mctx)
	defer mctx.TraceTimed(fmt.Sprintf("Attempt(%s, %t)", teamID, rotateBeforeAudit), func() error {
		if attempt.Error != nil {
			return errors.New(*attempt.Error)
		}
		return nil
	})()
	lock := a.locktab.AcquireOnName(mctx.Ctx(), mctx.G(), teamID.String())
	defer lock.Release(mctx.Ctx())
	return a.attemptLocked(mctx, teamID, rotateBeforeAudit, false)
}
1112133
func try_autobuild(p *build.Package) {
	if g_config.Autobuild {
		err := autobuild(p)
		if err != nil && *g_debug {
			log.Printf("Autobuild error: %s\n", err)
		}
	}
}
1227875
func (m *Mutex) TryLock() bool {
	return atomic.CompareAndSwapInt32(m.state, mutexUnlocked, mutexLocked)
}
899610
func (m *Mutex) TryLock() bool {
	v := atomic.LoadInt32(&m.v)
	if v <= 0 {
		return false
	}
	return atomic.CompareAndSwapInt32(&m.v, 1, 0)
}
1105998
func NewAttemptWaiting(numWaiting uint32) *Attempt {
	return &Attempt{
		Data: &Attempt_Data{
			AttemptType: &Attempt_Data_Waiting_{
				&Attempt_Data_Waiting{NumWaiting: numWaiting}}}}
}
947463
func (u *UserCommand) TryRun(cmd string, client auth.ClientI) (match bool, err error) {
	switch cmd {
	case u.userAdd.FullCommand():
		err = u.Add(client)
	case u.userUpdate.FullCommand():
		err = u.Update(client)
	case u.userList.FullCommand():
		err = u.List(client)
	case u.userDelete.FullCommand():
		err = u.Delete(client)
	default:
		return false, nil
	}
	return true, trace.Wrap(err)
}
1306620
func attemptInitiateMongoServer(dialInfo *mgo.DialInfo, memberHostPort string) error {
	session, err := mgo.DialWithInfo(dialInfo)
	if err != nil {
		return errors.Annotatef(err, "cannot dial mongo to initiate replicaset")
	}
	defer session.Close()
	session.SetSocketTimeout(mongo.SocketTimeout)

	return replicaset.Initiate(
		session,
		memberHostPort,
		mongo.ReplicaSetName,
		map[string]string{
			jujuMachineKey: agent.BootstrapMachineId,
		},
	)
}
411840
func (self *Matrix) TryFlushSuccess() {
	if cache.Task.Mode != status.SERVER && cache.Task.SuccessInherit {
		self.history.FlushSuccess(cache.Task.OutType)
	}
}
1047451
func (a *EventCorrelator) AttemptsForSignal(signalInfo *SignalInfo) int {
	a.checkInit()
	if signalInfo == nil {
		return 0
	}
	return a.SignalAttempts[a.signalIdFromInfo(signalInfo)]
}
1045425
func (r *PEXReactor) attemptDisconnects() {
	for _, peer := range r.Switch.Peers().List() {
		if peer.Status().Duration < r.config.SeedDisconnectWaitPeriod {
			continue
		}
		if peer.IsPersistent() {
			continue
		}
		r.Switch.StopPeerGracefully(peer)
	}
}
264644
func (c *StatusCommand) TryRun(cmd string, client auth.ClientI) (match bool, err error) {
	switch cmd {
	case c.status.FullCommand():
		err = c.Status(client)
	default:
		return false, nil
	}
	return true, trace.Wrap(err)
}
864400
func (t token) Check(attempt int, trapdoorKey interface{}) error {

	// This validation, which could be done at Token creation time, is deferred
	// until this point for historical reasons. In particular, this code was
	// extracted from a *leadership* implementation which has a LeadershipCheck
	// method returning a token; if it returned an error as well it would seem
	// to imply that the method implemented a check itself, rather than a check
	// factory.
	//
	// Fixing that would be great but seems out of scope.
	if err := t.secretary.CheckLease(t.leaseKey); err != nil {
		return errors.Annotatef(err, "cannot check lease %q", t.leaseKey.Lease)
	}
	if err := t.secretary.CheckHolder(t.holderName); err != nil {
		return errors.Annotatef(err, "cannot check holder %q", t.holderName)
	}
	return check{
		leaseKey:    t.leaseKey,
		holderName:  t.holderName,
		attempt:     attempt,
		trapdoorKey: trapdoorKey,
		response:    make(chan error),
		stop:        t.stop,
	}.invoke(t.checks)
}
170497
func (a *EventCorrelator) AttemptsForActivity(info *ActivityInfo) int {
	a.checkInit()
	if info == nil || info.ActivityId == "" {
		return 0
	}
	return a.ActivityAttempts[info.ActivityId]
}
400280
func (a *EventCorrelator) AttemptsForChild(info *ChildInfo) int {
	a.checkInit()
	if info == nil || info.WorkflowId == "" {
		return 0
	}
	return a.ChildrenAttempts[info.WorkflowId]
}
1261428
func (a *Attempt) ModifyState(c context.Context, newState dm.Attempt_State) error {
	if a.State == newState {
		return nil
	}
	if err := a.State.Evolve(newState); err != nil {
		return err
	}
	now := clock.Now(c).UTC()
	if now.After(a.Modified) {
		a.Modified = now
	} else {
		// Microsecond is the smallest granularity that datastore can store
		// timestamps, so use that to disambiguate: the goal here is that any
		// modification always increments the modified time, and never decrements
		// it.
		a.Modified = a.Modified.Add(time.Microsecond)
	}
	return nil
}
1111394
func (le *LeaderElector) tryAcquireOrRenew() bool {
	now := metav1.Now()
	leaderElectionRecord := rl.LeaderElectionRecord{
		HolderIdentity:       le.config.Lock.Identity(),
		LeaseDurationSeconds: int(le.config.LeaseDuration / time.Second),
		RenewTime:            now,
		AcquireTime:          now,
	}

	// 1. obtain or create the ElectionRecord
	oldLeaderElectionRecord, err := le.config.Lock.Get()
	if err != nil {
		if !errors.IsNotFound(err) {
			klog.Errorf("error retrieving resource lock %v: %v", le.config.Lock.Describe(), err)
			return false
		}
		if err = le.config.Lock.Create(leaderElectionRecord); err != nil {
			klog.Errorf("error initially creating leader election record: %v", err)
			return false
		}
		le.observedRecord = leaderElectionRecord
		le.observedTime = le.clock.Now()
		return true
	}

	// 2. Record obtained, check the Identity & Time
	if !reflect.DeepEqual(le.observedRecord, *oldLeaderElectionRecord) {
		le.observedRecord = *oldLeaderElectionRecord
		le.observedTime = le.clock.Now()
	}
	if len(oldLeaderElectionRecord.HolderIdentity) > 0 &&
		le.observedTime.Add(le.config.LeaseDuration).After(now.Time) &&
		!le.IsLeader() {
		klog.V(4).Infof("lock is held by %v and has not yet expired", oldLeaderElectionRecord.HolderIdentity)
		return false
	}

	// 3. We're going to try to update. The leaderElectionRecord is set to it's default
	// here. Let's correct it before updating.
	if le.IsLeader() {
		leaderElectionRecord.AcquireTime = oldLeaderElectionRecord.AcquireTime
		leaderElectionRecord.LeaderTransitions = oldLeaderElectionRecord.LeaderTransitions
	} else {
		leaderElectionRecord.LeaderTransitions = oldLeaderElectionRecord.LeaderTransitions + 1
	}

	// update the lock itself
	if err = le.config.Lock.Update(leaderElectionRecord); err != nil {
		klog.Errorf("Failed to update lock: %v", err)
		return false
	}
	le.observedRecord = leaderElectionRecord
	le.observedTime = le.clock.Now()
	return true
}
903154
func AttemptIDFromKey(k *ds.Key) *dm.Attempt_ID {
	if k.Kind() != "Attempt" || k.Parent() != nil {
		panic(fmt.Errorf("invalid Attempt key: %s", k))
	}
	ret := &dm.Attempt_ID{}
	if err := ret.SetDMEncoded(k.StringID()); err != nil {
		panic(fmt.Errorf("invalid Attempt key: %s: %s", k, err))
	}
	return ret
}