// computeChanges computes the changes that need to be made to the platforms in the database.
558415
func (t *PlatformsTable) computeChanges(c context.Context, platforms []*config.Platform) {
	cfgs := make(map[string]*Platform, len(platforms))
	for _, cfg := range platforms {
		cfgs[cfg.Name] = &Platform{
			Platform: config.Platform{
				Name:         cfg.Name,
				Description:  cfg.Description,
				Manufacturer: cfg.Manufacturer,
			},
		}
	}

	for _, p := range t.current {
		if cfg, ok := cfgs[p.Name]; ok {
			// Platform found in the config.
			if t.needsUpdate(p, cfg) {
				// Platform doesn't match the config.
				cfg.Id = p.Id
				t.updates = append(t.updates, cfg)
			}
			// Record that the platform config has been seen.
			delete(cfgs, cfg.Name)
		} else {
			// Platform not found in the config.
			t.removals = append(t.removals, p)
		}
	}

	// Platforms remaining in the map are present in the config but not the database.
	// Iterate deterministically over the slice to determine which platforms need to be added.
	for _, cfg := range platforms {
		if p, ok := cfgs[cfg.Name]; ok {
			t.additions = append(t.additions, p)
		}
	}
}
372178
func (am *AutogitManager) BatchChanges(
	ctx context.Context, _ []libkbfs.NodeChange,
	affectedNodeIDs []libkbfs.NodeID) {
	nodes, repoNodeIDs := am.getNodesToInvalidate(affectedNodeIDs)
	go am.clearInvalidatedBrowsers(repoNodeIDs)
	for _, node := range nodes {
		node := node
		go func() {
			ctx := libkbfs.CtxWithRandomIDReplayable(
				context.Background(), ctxAutogitIDKey, ctxAutogitOpID, am.log)
			am.config.KBFSOps().InvalidateNodeAndChildren(ctx, node)
		}()
	}
}
996570
func (n *Node) handleChanges(changes []Change) {
	n.disseminator.AdjustMaxPropagations()
	for _, change := range changes {
		n.disseminator.RecordChange(change)

		switch change.Status {
		case Alive:
			n.stateTransitions.Cancel(change)

		case Suspect:
			n.stateTransitions.ScheduleSuspectToFaulty(change)

		case Faulty:
			n.stateTransitions.ScheduleFaultyToTombstone(change)

		case Leave:
			// XXX: should this also reap?
			n.stateTransitions.Cancel(change)

		case Tombstone:
			n.stateTransitions.ScheduleTombstoneToEvict(change)
		}
	}
}
1190429
func (dr *DiffReport) ComputeQPS() {
	if dr.processedRows > 0 {
		dr.processingQPS = int(time.Duration(dr.processedRows) * time.Second / time.Since(dr.startingTime))
	}
}
988642
func (f *Folder) BatchChanges(
	ctx context.Context, changes []libkbfs.NodeChange, _ []libkbfs.NodeID) {
	f.fs.queueNotification(func() {})
}
1299625
func (vi *ValidatorImpl) computeUpdateResult(updatedConfig map[string]comparable) map[string]comparable {
	newConfigMap := make(map[string]comparable)
	for key, value := range vi.configMap {
		newConfigMap[key] = value
	}

	for key, value := range updatedConfig {
		newConfigMap[key] = value
	}
	return newConfigMap
}
717557
func (t *IPsTable) computeChanges(c context.Context, vlans []*config.VLAN) error {
	cfgs := make(map[common.IPv4]*IP, len(vlans))
	for _, vlan := range vlans {
		ipv4, length, err := common.IPv4Range(vlan.CidrBlock)
		if err != nil {
			return errors.Annotate(err, "failed to determine start address and range for CIDR block %q", vlan.CidrBlock).Err()
		}
		// TODO(smut): Mark the first address as the network address and the last address as the broadcast address.
		for i := int64(0); i < length; i++ {
			cfgs[ipv4] = &IP{
				IPv4:   ipv4,
				VLANId: vlan.Id,
			}
			ipv4 += 1
		}
	}

	for _, ip := range t.current {
		if cfg, ok := cfgs[ip.IPv4]; ok {
			// IP address found in the config.
			if t.needsUpdate(ip, cfg) {
				// IP address doesn't match the config.
				cfg.Id = ip.Id
				t.updates = append(t.updates, cfg)
			}
			// Record that the IP address config has been seen.
			delete(cfgs, cfg.IPv4)
		} else {
			// IP address not found in the config.
			t.removals = append(t.removals, ip)
		}
	}

	// IP addresses remaining in the map are present in the config but not the database.
	// Iterate deterministically over the slices to determine which IP addresses need to be added.
	for _, vlan := range vlans {
		ipv4, length, err := common.IPv4Range(vlan.CidrBlock)
		if err != nil {
			return errors.Annotate(err, "failed to determine start address and range for CIDR block %q", vlan.CidrBlock).Err()
		}
		for i := int64(0); i < length; i++ {
			if ip, ok := cfgs[ipv4]; ok {
				t.additions = append(t.additions, ip)
			}
			ipv4 += 1
		}
	}
	return nil
}
399263
func (l *State) SyncChanges() error {
	l.Lock()
	defer l.Unlock()

	// We will do node-level info syncing at the end, since it will get
	// updated by a service or check sync anyway, given how the register
	// API works.

	// Sync the services
	// (logging happens in the helper methods)
	for id, s := range l.services {
		var err error
		switch {
		case s.Deleted:
			err = l.deleteService(id)
		case !s.InSync:
			err = l.syncService(id)
		default:
			l.logger.Printf("[DEBUG] agent: Service %q in sync", id)
		}
		if err != nil {
			return err
		}
	}

	// Sync the checks
	// (logging happens in the helper methods)
	for id, c := range l.checks {
		var err error
		switch {
		case c.Deleted:
			err = l.deleteCheck(id)
		case !c.InSync:
			if c.DeferCheck != nil {
				c.DeferCheck.Stop()
				c.DeferCheck = nil
			}
			err = l.syncCheck(id)
		default:
			l.logger.Printf("[DEBUG] agent: Check %q in sync", id)
		}
		if err != nil {
			return err
		}
	}

	// Now sync the node level info if we need to, and didn't do any of
	// the other sync operations.
	if l.nodeInfoInSync {
		l.logger.Printf("[DEBUG] agent: Node info in sync")
		return nil
	}
	return l.syncNodeInfo()
}
413881
func (a *Application) ChangeScale(scaleChange int) (int, error) {
	newScale := a.doc.DesiredScale + scaleChange
	if newScale < 0 {
		return a.doc.DesiredScale, errors.NotValidf("cannot remove more units than currently exist")
	}
	buildTxn := func(attempt int) ([]txn.Op, error) {
		if attempt > 0 {
			alive, err := isAlive(a.st, applicationsC, a.doc.DocID)
			if err != nil {
				return nil, errors.Trace(err)
			} else if !alive {
				return nil, applicationNotAliveErr
			}
			if err := a.Refresh(); err != nil {
				return nil, errors.Trace(err)
			}
			newScale = a.doc.DesiredScale + scaleChange
			if newScale < 0 {
				return nil, errors.NotValidf("cannot remove more units than currently exist")
			}
		}
		return []txn.Op{{
			C:  applicationsC,
			Id: a.doc.DocID,
			Assert: bson.D{{"life", Alive},
				{"charmurl", a.doc.CharmURL},
				{"unitcount", a.doc.UnitCount},
				{"scale", a.doc.DesiredScale}},
			Update: bson.D{{"$set", bson.D{{"scale", newScale}}}},
		}}, nil
	}
	if err := a.st.db().Run(buildTxn); err != nil {
		return a.doc.DesiredScale, errors.Errorf("cannot set scale for application %q to %v: %v", a, newScale, onAbort(err, applicationNotAliveErr))
	}
	a.doc.DesiredScale = newScale
	return newScale, nil
}
1166130
func (d diffResult) Changed() bool {
	return len(d.added) > 0 || len(d.removed) > 0 || len(d.modified) > 0
}
1320769
func (_ *AttachISO) CheckChanges(a, e, changes *AttachISO) error {
	glog.Info("AttachISO.CheckChanges invoked!")
	return nil
}
273127
func (d *Driver) Changes(id, parent string) ([]archive.Change, error) {
	return d.naiveDiff.Changes(id, parent)
}
468314
func (n *ng) parseChange(response *etcd.Response) (interface{}, error) {
	// Order parsers from the most to the least frequently used.
	matchers := []MatcherFn{
		n.parseBackendServerChange,
		n.parseBackendChange,
		n.parseFrontendMiddlewareChange,
		n.parseFrontendChange,
		n.parseHostChange,
		n.parseListenerChange,
	}
	for _, matcher := range matchers {
		a, err := matcher(response)
		if a != nil || err != nil {
			return a, err
		}
	}
	return nil, nil
}
1146298
func ComputeLogs(c context.Context, oldCheckout, newCheckout Checkout, history HistoryFunc) (Logs, error) {
	var resultMu sync.Mutex
	result := make(Logs)
	err := parallel.WorkPool(8, func(ch chan<- func() error) {
		for repo, revision := range newCheckout {
			repo := repo
			newRev := revision
			oldRev, ok := oldCheckout[repo]
			if !ok {
				continue
			}
			host, project, _ := gitiles.ParseRepoURL(repo)
			ch <- func() error {
				log, err := history(c, host, project, oldRev, newRev)
				if err != nil {
					return err
				}
				if len(log) <= 1 {
					return nil
				}
				resultMu.Lock()
				result[repo] = log[:len(log)-1]
				resultMu.Unlock()
				return nil
			}
		}
	})
	return result, err
}
36729
func NewChangeBytes(key string, value []byte, rev int64, changeType datasync.Op) *Change {
	return &Change{
		changeType: changeType,
		KeyVal:     &KeyValBytes{key, value, rev},
	}
}
911981
func (api *RemoteRelationsAPI) ConsumeRemoteRelationChanges(
	changes params.RemoteRelationsChanges,
) (params.ErrorResults, error) {
	results := params.ErrorResults{
		Results: make([]params.ErrorResult, len(changes.Changes)),
	}
	for i, change := range changes.Changes {
		relationTag, err := api.st.GetRemoteEntity(change.RelationToken)
		if err != nil {
			if errors.IsNotFound(err) {
				continue
			}
			results.Results[i].Error = common.ServerError(err)
			continue
		}
		if err := commoncrossmodel.PublishRelationChange(api.st, relationTag, change); err != nil {
			results.Results[i].Error = common.ServerError(err)
			continue
		}
	}
	return results, nil
}
1355044
func (g *Git) HasStagedChanges(ctx context.Context) bool {
	st, err := g.wt.Status()
	if err != nil {
		out.Error(ctx, "Error: Unable to get status: %s", err)
		return false
	}
	return !st.IsClean()
}