// refreshState is the main implementation of RefreshState, but split out so
// that we can make internal calls to it from methods that are already holding
// the s.mu lock.
320489
func (s *State) refreshState() error {
	payload, err := s.Client.Get()
	if err != nil {
		return err
	}

	// no remote state is OK
	if payload == nil {
		s.readState = nil
		s.lineage = ""
		s.serial = 0
		return nil
	}

	stateFile, err := statefile.Read(bytes.NewReader(payload.Data))
	if err != nil {
		return err
	}

	s.lineage = stateFile.Lineage
	s.serial = stateFile.Serial
	s.state = stateFile.State
	s.readState = s.state.DeepCopy() // our states must be separate instances so we can track changes
	return nil
}
147440
func (mig *modelMigration) Refresh() error {
	// Only the status document is updated. The modelMigDoc is static
	// after creation.
	statusColl, closer := mig.st.db().GetCollection(migrationsStatusC)
	defer closer()
	var statusDoc modelMigStatusDoc
	err := statusColl.FindId(mig.doc.Id).One(&statusDoc)
	if err == mgo.ErrNotFound {
		return errors.NotFoundf("migration status")
	} else if err != nil {
		return errors.Annotate(err, "migration status lookup failed")
	}

	mig.statusDoc = statusDoc
	return nil
}
1228061
func (b *Backend) PurgeState(taskUUID string) error {
	conn := b.open()
	defer conn.Close()

	_, err := conn.Do("DEL", taskUUID)
	if err != nil {
		return err
	}

	return nil
}
42886
func (s *storeImpl) updateDesiredState(serviceID string, desiredState int, updatedAt time.Time) error {
	// Validate desired state
	if err := validation.IntIn(desiredState, int(SVCRun), int(SVCStop), int(SVCPause)); err != nil {
		plog.WithFields(log.Fields{
			"serviceID":    serviceID,
			"desiredState": desiredState,
		}).Debug("Invalid Desired State")
		return err
	}

	plog.WithFields(log.Fields{
		"serviceID":    serviceID,
		"desiredState": desiredState,
		"updatedAt":    updatedAt,
	}).Debug("Saving desired state in cache")

	s.serviceCacheLock.Lock()
	defer s.serviceCacheLock.Unlock()
	var cacheEntry volatileService

	cacheEntry, ok := s.serviceCache[serviceID]
	if !ok {
		cacheEntry = volatileService{
			ID:           serviceID,
			DesiredState: desiredState,
			UpdatedAt:    updatedAt,
		}
	} else {
		cacheEntry.DesiredState = desiredState
		cacheEntry.UpdatedAt = updatedAt
	}

	s.serviceCache[serviceID] = cacheEntry

	return nil
}
604697
func (client *Client) ResetState() error {
	resp, err := http.Post(client.endpoint+"/reset", "text/plain", bytes.NewReader([]byte{}))
	if err != nil {
		return err
	}

	return checkError(resp, http.StatusNoContent, "ResetState")
}
651078
func (c *InstanceCache) withState(ctx context.Context, now time.Time, f func(*messages.InstanceCache)) {
	state := &messages.InstanceCache{}

	start := clock.Now(ctx)
	defer func() {
		totalTime := clock.Since(ctx, start)
		if totalTime > 2*time.Second {
			logging.Warningf(
				ctx, "cipd: instance cache state update took %s (%d entries)",
				totalTime, len(state.Entries))
		}
	}()

	c.stateLock.Lock()
	defer c.stateLock.Unlock()

	c.readState(ctx, state, now)
	f(state)
	if err := c.saveState(ctx, state); err != nil {
		logging.Warningf(ctx, "cipd: could not save instance cache - %s", err)
	}
}
1279002
func (w *WalletState) RefreshAll(mctx libkb.MetaContext, reason string) error {
	_, err := w.refreshGroup.Do("RefreshAll", func() (interface{}, error) {
		doErr := w.refreshAll(mctx, reason)
		return nil, doErr
	})
	return err
}
595663
func WithState(c context.Context, s State) context.Context {
	return context.WithValue(c, stateContextKey(0), s)
}
227678
func (i *RefreshableInstance) Refresh(ctx context.ProviderCallContext) error {
	instances, err := i.Env.Instances(ctx, []instance.Id{i.Id()})
	if err != nil {
		return errors.Trace(err)
	}
	i.Instance = instances[0]
	return nil
}
188559
func (d *Downloader) syncState(root common.Hash) *stateSync {
	s := newStateSync(d, root)
	select {
	case d.stateSyncStart <- s:
	case <-d.quitCh:
		s.err = errCancelStateFetch
		close(s.done)
	}
	return s
}
408648
func (c *upgradeContext) APIState() api.Connection {
	if c.api == nil {
		panic("API not available from this context")
	}
	return c.api
}
840793
func (c *ConnReq) updateState(state ConnState) {
	c.stateMtx.Lock()
	c.state = state
	c.stateMtx.Unlock()
}
1224110
func (agent *ActionAgent) RefreshState(ctx context.Context) error {
	if err := agent.lock(ctx); err != nil {
		return err
	}
	defer agent.unlock()

	return agent.refreshTablet(ctx, "RefreshState")
}
105601
func (s *IPSet) Refresh(entries []string) error {
	tempName := s.Name + "-temp"
	err := s.createHashSet(tempName)
	if err != nil {
		return err
	}
	for _, entry := range entries {
		out, err := exec.Command(ipsetPath, "add", tempName, entry, "-exist").CombinedOutput()
		if err != nil {
			log.Errorf("error adding entry %s to set %s: %v (%s)", entry, tempName, err, out)
		}
	}
	err = Swap(tempName, s.Name)
	if err != nil {
		return err
	}
	err = destroyIPSet(tempName)
	if err != nil {
		return err
	}
	return nil
}
269083
func (h *healthcheckManager) healthState(n *healthcheck.Notification) error {
	log.V(1).Infof("Received healthcheck notification: %v", n)

	h.lock.RLock()
	enabled := h.enabled
	h.lock.RUnlock()

	if !enabled {
		log.Warningf("Healthcheck manager is disabled; ignoring healthcheck notification %v", n)
		return nil
	}

	h.engine.syncServer.notify(&SyncNote{Type: SNTHealthcheck, Healthcheck: n})

	return h.queueHealthState(n)
}
1140082
func (s *IndexService) Refresh(refresh string) *IndexService {
	s.refresh = refresh
	return s
}
1348650
func (h *handshake) resetState() {
	b := make([]byte, 4)
	if _, err := rand.Read(b); err != nil {
		panic(err)
	}

	h.state = handshakeSynSent
	h.flags = header.TCPFlagSyn
	h.ackNum = 0
	h.mss = 0
	h.iss = seqnum.Value(uint32(b[0]) | uint32(b[1])<<8 | uint32(b[2])<<16 | uint32(b[3])<<24)
}