// UpdateFrom updates the cache from resource records in msg.
// TODO consider the cache-flush bit to make records as to be deleted in one second
341378
func (c *Cache) UpdateFrom(msg *dns.Msg) (adds []*Service, rmvs []*Service) {
	answers := allRecords(msg)
	sort.Sort(byType(answers))

loop:
	for _, answer := range answers {
		switch rr := answer.(type) {
		case *dns.PTR:
			ttl := time.Duration(rr.Hdr.Ttl) * time.Second

			var entry *Service
			if e, ok := c.services[rr.Ptr]; !ok {
				if ttl == 0 {
					// Ignore new records with no ttl
					break
				}
				entry = newService(rr.Ptr)
				adds = append(adds, entry)
				c.services[entry.ServiceInstanceName()] = entry
			} else {
				entry = e
			}

			entry.TTL = ttl
			entry.expiration = time.Now().Add(ttl)

		case *dns.SRV:
			ttl := time.Duration(rr.Hdr.Ttl) * time.Second
			var entry *Service
			if e, ok := c.services[rr.Hdr.Name]; !ok {
				if ttl == 0 {
					// Ignore new records with no ttl
					break
				}
				entry = newService(rr.Hdr.Name)
				adds = append(adds, entry)
				c.services[entry.ServiceInstanceName()] = entry
			} else {
				entry = e
			}

			entry.SetHostname(rr.Target)
			entry.TTL = ttl
			entry.expiration = time.Now().Add(ttl)
			entry.Port = int(rr.Port)

		case *dns.A:
			for _, entry := range c.services {
				if entry.Hostname() == rr.Hdr.Name {
					for _, ip := range entry.IPs {
						if ip.Equal(rr.A) {
							continue loop
						}
					}
					entry.IPs = append(entry.IPs, rr.A)
				}
			}

		case *dns.AAAA:
			for _, entry := range c.services {
				if entry.Hostname() == rr.Hdr.Name {
					for _, ip := range entry.IPs {
						if ip.Equal(rr.AAAA) {
							continue loop
						}
					}

					entry.IPs = append(entry.IPs, rr.AAAA)
				}
			}

		case *dns.TXT:
			if entry, ok := c.services[rr.Hdr.Name]; ok {
				text := make(map[string]string)
				for _, txt := range rr.Txt {
					var pairs = strings.Split(txt, " ")
					for _, pair := range pairs {
						elems := strings.SplitN(pair, "=", 2)
						if len(elems) == 2 {
							key := elems[0]
							value := elems[1]

							// Don't override existing keys
							// TODO make txt records case insensitive
							if _, ok := text[key]; !ok {
								text[key] = value
							}

							text[key] = value
						}
					}
				}

				entry.Text = text
				entry.TTL = time.Duration(rr.Hdr.Ttl) * time.Second
				entry.expiration = time.Now().Add(entry.TTL)
			}
		default:
			// ignore
			break
		}
	}

	// TODO remove outdated services regularly
	rmvs = c.removeExpired()

	return
}
346619
func (c *CordonHelper) UpdateIfRequired(desired bool) bool {
	c.desired = desired
	if c.node.Spec.Unschedulable == c.desired {
		return false
	}
	return true
}
197775
func (c *ExpireCache) Update(key interface{}, value interface{}) error {
	c.mutex.Lock()
	defer c.mutex.Unlock()

	record, ok := c.cache[key]
	if !ok {
		return errors.Errorf("ExpoireCache() - No record found for '%+v'", key)
	}
	record.Value = value
	return nil
}
1265070
func (c *cacher) deleteFromCache(id ID) {
	c.lock.Lock()
	defer c.lock.Unlock()

	delete(c.cache, string(id))
}
508743
func (c *Config) UpdateFromFile(path string) error {
	data, err := ioutil.ReadFile(path)
	if err != nil {
		return err
	}

	t := new(tomlConfig)
	t.fromConfig(c)

	_, err = toml.Decode(string(data), t)
	if err != nil {
		return fmt.Errorf("unable to decode configuration %v: %v", path, err)
	}

	t.toConfig(c)
	return nil
}
756951
func (m *Msg) Update(db *sqlx.DB) error {
	q := `UPDATE messages SET needstraining=$1 WHERE id=$2`
	if _, err := db.Exec(q, m.NeedsTraining, m.ID); err != nil {
		return err
	}
	return nil
}
793754
func (s *storeImpl) getUpdatedCacheEntries(since time.Time) []volatileService {
	s.serviceCacheLock.RLock()
	defer s.serviceCacheLock.RUnlock()

	logger := plog.WithFields(log.Fields{
		"since": since,
	})
	logger.Debug("Querying services updated since")

	cacheEntries := []volatileService{}
	for _, cacheEntry := range s.serviceCache {
		if cacheEntry.UpdatedAt.After(since) {
			logger.WithField("serviceid", cacheEntry.ID).Debug("Adding cache entry")
			cacheEntries = append(cacheEntries, cacheEntry)
		}
	}
	logger.WithField("count", len(cacheEntries)).Debug("Returning %d cached entries")
	return cacheEntries
}
1204748
func (resourcequotaStrategy) PrepareForUpdate(ctx context.Context, obj, old runtime.Object) {
	newResourcequota := obj.(*api.ResourceQuota)
	oldResourcequota := old.(*api.ResourceQuota)
	newResourcequota.Status = oldResourcequota.Status
	resourcequotautil.DropDisabledFields(&newResourcequota.Spec, &oldResourcequota.Spec)
}
65892
func (md *RootMetadata) updateFromTlfHandle(newHandle *tlfhandle.Handle) error {
	// TODO: Strengthen check, e.g. make sure every writer/reader
	// in the old handle is also a writer/reader of the new
	// handle.
	valid := true
	newBareHandle, err := newHandle.ToBareHandle()
	if err != nil {
		return err
	}
	switch md.TypeForKeying() {
	case tlf.PrivateKeying:
		// Private-keyed TLFs can move to team keying, but not to
		// public keying.
		valid = newBareHandle.TypeForKeying() != tlf.PublicKeying
	case tlf.PublicKeying:
		// Public-keyed TLFs can move to team keying, but not to
		// private keying.
		valid = newBareHandle.TypeForKeying() != tlf.PrivateKeying
	case tlf.TeamKeying:
		// Team-keyed TLFs must always remain team-keyed.
		valid = newBareHandle.TypeForKeying() == tlf.TeamKeying
	default:
		return fmt.Errorf("Unexpected keying type %s", md.TypeForKeying())
	}
	if !valid {
		return fmt.Errorf(
			"Trying to update rmd with id type=%s, keying type=%s with "+
				"handle of type=%s, keying type=%s",
			md.TlfID().Type(), md.TypeForKeying(),
			newHandle.Type(), newBareHandle.TypeForKeying())
	}

	if newBareHandle.TypeForKeying() == tlf.PrivateKeying {
		md.SetUnresolvedReaders(newHandle.UnresolvedReaders())
	} else {
		md.SetWriters(newHandle.ResolvedWriters())
	}

	md.SetUnresolvedWriters(newHandle.UnresolvedWriters())
	md.SetConflictInfo(newHandle.ConflictInfo())
	md.SetFinalizedInfo(newHandle.FinalizedInfo())

	bareHandle, err := md.bareMd.MakeBareTlfHandle(md.extra)
	if err != nil {
		return err
	}

	if !reflect.DeepEqual(bareHandle, newBareHandle) {
		return fmt.Errorf(
			"bareHandle=%+v != newBareHandle=%+v",
			bareHandle, newBareHandle)
	}

	md.tlfHandle = newHandle
	return nil
}
1177502
func (r *sentReq) update(ev reqPeerEvent) {
	switch ev.event {
	case rpSent:
		r.lastReqQueued = false
		r.lastReqSentTo = ev.peer
	case rpSoftTimeout:
		r.lastReqSentTo = nil
		r.reqSrtoCount++
	case rpHardTimeout:
		r.reqSrtoCount--
	case rpDeliveredValid, rpDeliveredInvalid:
		if ev.peer == r.lastReqSentTo {
			r.lastReqSentTo = nil
		} else {
			r.reqSrtoCount--
		}
	}
}
514178
func (pt *pollingTrackerBase) updateErrorFromResponse() {
	var err error
	if pt.resp.ContentLength != 0 {
		type respErr struct {
			ServiceError *ServiceError `json:"error"`
		}
		re := respErr{}
		defer pt.resp.Body.Close()
		var b []byte
		if b, err = ioutil.ReadAll(pt.resp.Body); err != nil || len(b) == 0 {
			goto Default
		}
		if err = json.Unmarshal(b, &re); err != nil {
			goto Default
		}
		// unmarshalling the error didn't yield anything, try unwrapped error
		if re.ServiceError == nil {
			err = json.Unmarshal(b, &re.ServiceError)
			if err != nil {
				goto Default
			}
		}
		// the unmarshaller will ensure re.ServiceError is non-nil
		// even if there was no content unmarshalled so check the code.
		if re.ServiceError.Code != "" {
			pt.Err = re.ServiceError
			return
		}
	}
Default:
	se := &ServiceError{
		Code:    pt.pollingStatus(),
		Message: "The async operation failed.",
	}
	if err != nil {
		se.InnerError = make(map[string]interface{})
		se.InnerError["unmarshalError"] = err.Error()
	}
	// stick the response body into the error object in hopes
	// it contains something useful to help diagnose the failure.
	if len(pt.rawBody) > 0 {
		se.AdditionalInfo = []map[string]interface{}{
			pt.rawBody,
		}
	}
	pt.Err = se
}
939040
func (f *FastTeamChainLoader) updateCache(m libkb.MetaContext, state *keybase1.FastTeamData) {
	f.storage.Put(m, state)
}
767242
func (h *BindHandle) Update(fullLoad bool) (err error) {
	sql := "select original_sql, bind_sql, default_db, status, create_time, update_time, charset, collation from mysql.bind_info"
	if !fullLoad {
		sql += " where update_time >= \"" + h.lastUpdateTime.String() + "\""
	}

	// No need to acquire the session context lock for ExecRestrictedSQL, it
	// uses another background session.
	rows, _, err := h.sctx.Context.(sqlexec.RestrictedSQLExecutor).ExecRestrictedSQL(nil, sql)
	if err != nil {
		return err
	}

	// Make sure there is only one goroutine writes the cache.
	h.bindInfo.Lock()
	newCache := h.bindInfo.Value.Load().(cache).copy()
	defer func() {
		h.bindInfo.Value.Store(newCache)
		h.bindInfo.Unlock()
	}()

	for _, row := range rows {
		hash, meta, err := h.newBindMeta(newBindRecord(row))
		// Update lastUpdateTime to the newest one.
		if meta.UpdateTime.Compare(h.lastUpdateTime) > 0 {
			h.lastUpdateTime = meta.UpdateTime
		}
		if err != nil {
			logutil.Logger(context.Background()).Error("update bindinfo failed", zap.Error(err))
			continue
		}

		newCache.removeStaleBindMetas(hash, meta)
		if meta.Status == Using {
			newCache[hash] = append(newCache[hash], meta)
		}
	}
	return nil
}
1247781
func Update(id string, params *stripe.SubscriptionScheduleParams) (*stripe.SubscriptionSchedule, error) {
	return getC().Update(id, params)
}
383774
func Update(c *messagebird.Client, id string, contactRequest *Request) (*Contact, error) {
	contact := &Contact{}
	if err := c.Request(contact, http.MethodPatch, path+"/"+id, contactRequest); err != nil {
		return nil, err
	}

	return contact, nil
}
1170836
func (csrStrategy) PrepareForUpdate(ctx context.Context, obj, old runtime.Object) {
	newCSR := obj.(*certificates.CertificateSigningRequest)
	oldCSR := old.(*certificates.CertificateSigningRequest)

	newCSR.Spec = oldCSR.Spec
	newCSR.Status = oldCSR.Status
}
14245
func (s *UDPSession) update() (interval time.Duration) {
	s.mu.Lock()
	waitsnd := s.kcp.WaitSnd()
	interval = time.Duration(s.kcp.flush(false)) * time.Millisecond
	if s.kcp.WaitSnd() < waitsnd {
		s.notifyWriteEvent()
	}
	s.mu.Unlock()
	return
}