// UpdateTicketPoolData updates the ticket pool cache with the latest data fetched.
// This is a thread-safe way to update ticket pool cache data. TryLock helps avoid
// stacking calls to update the cache.
186519
func UpdateTicketPoolData(interval dbtypes.TimeBasedGrouping, timeGraph *dbtypes.PoolTicketsData,
	priceGraph *dbtypes.PoolTicketsData, donutcharts *dbtypes.PoolTicketsData, height int64) {
	ticketPoolGraphsCache.Lock()
	defer ticketPoolGraphsCache.Unlock()

	ticketPoolGraphsCache.Height[interval] = height
	ticketPoolGraphsCache.TimeGraphCache[interval] = timeGraph
	ticketPoolGraphsCache.PriceGraphCache[interval] = priceGraph
	ticketPoolGraphsCache.DonutGraphCache[interval] = donutcharts
}
669770
func (observer *Observer) UpdateAllStats() {
	queues, err := observer.GetAllQueues()
	if err != nil {
		log.Fatalf("ERROR FETCHING QUEUES %s", err.Error())
	}

	for _, queue := range queues {
		observer.UpdateQueueStats(queue)
	}
}
869642
func (pgb *ChainDB) TicketsByPrice(maturityBlock int64) (*dbtypes.PoolTicketsData, error) {
	ctx, cancel := context.WithTimeout(pgb.ctx, pgb.queryTimeout)
	defer cancel()
	ptd, err := retrieveTicketByPrice(ctx, pgb.db, maturityBlock)
	return ptd, pgb.replaceCancelError(err)
}
370816
func (s *DescribeMatchmakingOutput) SetTicketList(v []*MatchmakingTicket) *DescribeMatchmakingOutput {
	s.TicketList = v
	return s
}
782205
func (h *Handler) updateCache(request *Request) (*cacheEntry, error) {

	updateAddr := request.Addr()
	log.Trace("feed cache update", "topic", request.Topic.Hex(), "updateaddr", updateAddr, "epoch time", request.Epoch.Time, "epoch level", request.Epoch.Level)

	feedUpdate := h.get(&request.Feed)
	if feedUpdate == nil {
		feedUpdate = &cacheEntry{}
		h.set(&request.Feed, feedUpdate)
	}

	// update our rsrcs entry map
	feedUpdate.lastKey = updateAddr
	feedUpdate.Update = request.Update
	feedUpdate.Reader = bytes.NewReader(feedUpdate.data)
	return feedUpdate, nil
}
941065
func (c *Client) UpdatePool(pname, provider string, attrs map[string]interface{}) error {
	if c.BestAPIVersion() < 5 {
		return errors.New("updating storage pools is not supported by this version of Juju")
	}
	var results params.ErrorResults
	args := params.StoragePoolArgs{
		Pools: []params.StoragePool{{
			Name:     pname,
			Provider: provider,
			Attrs:    attrs,
		}},
	}
	if err := c.facade.FacadeCall("UpdatePool", args, &results); err != nil {
		return errors.Trace(err)
	}
	return results.OneError()
}
612514
func (tp *TicketPool) AdvanceToTip() (int64, error) {
	tp.mtx.Lock()
	defer tp.mtx.Unlock()
	err := tp.advanceTo(tp.tip)
	return tp.cursor - 1, err
}
1165687
func (f *Facade) UpdateHost(ctx datastore.Context, entity *host.Host) error {
	defer ctx.Metrics().Stop(ctx.Metrics().Start("Facade.UpdateHost"))
	alog := f.auditLogger.Message(ctx, "Updating Host").Entity(entity).Action(audit.Update)
	glog.V(2).Infof("Facade.UpdateHost: %+v", entity)
	if err := f.DFSLock(ctx).LockWithTimeout("update host", userLockTimeout); err != nil {
		glog.Warningf("Cannot update host: %s", err)
		return alog.Error(err)
	}
	defer f.DFSLock(ctx).Unlock()

	// validate the host exists
	foundhost, err := f.GetHost(ctx, entity.ID)
	if err != nil {
		return alog.Error(err)
	} else if foundhost == nil {
		return alog.Error(fmt.Errorf("host does not exist: %s", entity.ID))
	}

	// validate the pool exists
	if pool, err := f.GetResourcePool(ctx, entity.PoolID); err != nil {
		return alog.Error(err)
	} else if pool == nil {
		return alog.Error(fmt.Errorf("pool does not exist: %s", entity.PoolID))
	}

	ec := newEventCtx()
	defer f.afterEvent(afterHostAdd, ec, entity, err)

	if err = f.beforeEvent(beforeHostAdd, ec, entity); err != nil {
		return alog.Error(err)
	}

	// Preserve the NAT IP. Delegates won't know their own.
	entity.NatIP = foundhost.NatIP

	entity.UpdatedAt = time.Now()
	if err = f.hostStore.Put(ctx, host.HostKey(entity.ID), entity); err != nil {
		return alog.Error(err)
	}

	err = f.zzk.UpdateHost(entity)

	f.poolCache.SetDirty()

	return alog.Error(err)
}
325271
func UpdateTabletReplicationData(ctx context.Context, ts *Server, tablet *topodatapb.Tablet) error {
	return UpdateShardReplicationRecord(ctx, ts, tablet.Keyspace, tablet.Shard, tablet.Alias)
}
1129432
func (c *MempoolDataCache) GetTicketPriceCountTime(feeAvgLength int) *apitypes.PriceCountTime {
	c.mtx.RLock()
	defer c.mtx.RUnlock()

	numFees := len(c.allFees)
	if numFees < feeAvgLength {
		feeAvgLength = numFees
	}
	var feeAvg float64
	for i := 0; i < feeAvgLength; i++ {
		feeAvg += c.allFees[numFees-i-1]
	}
	feeAvg /= float64(feeAvgLength)

	return &apitypes.PriceCountTime{
		Price: c.stakeDiff + feeAvg,
		Count: numFees,
		Time:  dbtypes.NewTimeDef(c.timestamp),
	}
}
1154107
func (c *Client) UpdateEvent(e contract.Event) (err error) {
	conn := c.Pool.Get()
	defer conn.Close()

	id := e.ID

	o, err := eventByID(conn, id)
	if err != nil {
		if err == redis.ErrNil {
			return db.ErrNotFound
		}
		return err
	}

	e.Modified = db.MakeTimestamp()
	err = mergo.Merge(&e, o)
	if err != nil {
		return err
	}

	err = deleteEvent(conn, id)
	if err != nil {
		return err
	}

	_, err = addEvent(conn, e)
	return err
}
683571
func (s *MatchmakingTicket) SetTicketId(v string) *MatchmakingTicket {
	s.TicketId = &v
	return s
}
600385
func (p *MempoolMonitor) Refresh() (*StakeData, []exptypes.MempoolTx, *exptypes.MempoolInfo, error) {
	// Collect mempool data (currently ticket fees)
	log.Trace("Gathering new mempool data.")
	stakeData, txs, addrOuts, txnsStore, err := p.collector.Collect()
	if err != nil {
		log.Errorf("mempool data collection failed: %v", err.Error())
		// stakeData is nil when err != nil
		return nil, nil, nil, err
	}

	log.Debugf("%d addresses in mempool pertaining to %d transactions",
		len(addrOuts), len(txnsStore))

	// Pre-sort the txs so other consumers will not have to do it.
	sort.Sort(exptypes.MPTxsByTime(txs))
	inventory := ParseTxns(txs, p.params, &stakeData.LatestBlock)

	// Reset the counter for tickets since last report.
	p.mtx.Lock()
	newTickets := p.mpoolInfo.NumTicketsSinceStatsReport
	p.mpoolInfo.NumTicketsSinceStatsReport = 0

	// Reset the timer and ticket counter.
	p.mpoolInfo.CurrentHeight = uint32(stakeData.LatestBlock.Height)
	p.mpoolInfo.LastCollectTime = stakeData.Time
	p.mpoolInfo.NumTicketPurchasesInMempool = stakeData.Ticketfees.FeeInfoMempool.Number

	// Store the current best block info.
	p.lastBlock = stakeData.LatestBlock
	if p.inventory != nil {
		inventory.Ident = p.inventory.ID() + 1
	}
	p.inventory = inventory
	p.txnsStore = txnsStore
	p.mtx.Unlock()

	p.addrMap.mtx.Lock()
	p.addrMap.store = addrOuts
	p.addrMap.mtx.Unlock()

	// Insert new ticket counter into stakeData structure.
	stakeData.NewTickets = uint32(newTickets)

	return stakeData, txs, inventory, err
}
1241210
func (pgb *ChainDB) TicketsByInputCount() (*dbtypes.PoolTicketsData, error) {
	ctx, cancel := context.WithTimeout(pgb.ctx, pgb.queryTimeout)
	defer cancel()
	ptd, err := retrieveTicketsGroupedByType(ctx, pgb.db)
	return ptd, pgb.replaceCancelError(err)
}
1132149
func restUpdatePool(w *rest.ResponseWriter, r *rest.Request, ctx *requestContext) {
	poolID, err := url.QueryUnescape(r.PathParam("poolId"))
	if err != nil {
		restBadRequest(w, err)
		return
	} else if len(poolID) == 0 {
		restBadRequest(w, fmt.Errorf("poolID must be specified for PUT"))
		return
	}

	var payload pool.ResourcePool
	err = r.DecodeJsonPayload(&payload)
	if err != nil {
		glog.V(1).Info("Could not decode pool payload: ", err)
		restBadRequest(w, err)
		return
	}

	facade := ctx.getFacade()
	err = facade.UpdateResourcePool(ctx.getDatastoreContext(), &payload)
	if err != nil {
		glog.Error("Unable to update pool: ", err)
		restServerError(w, err)
		return
	}
	glog.V(1).Info("Updated pool ", poolID)
	w.WriteJson(&simpleResponse{"Updated resource pool", poolLinks(poolID)})
}
938798
func (pgb *ChainDB) PoolStatusForTicket(txid string) (dbtypes.TicketSpendType, dbtypes.TicketPoolStatus, error) {
	ctx, cancel := context.WithTimeout(pgb.ctx, pgb.queryTimeout)
	defer cancel()
	_, spendType, poolStatus, err := RetrieveTicketStatusByHash(ctx, pgb.db, txid)
	return spendType, poolStatus, pgb.replaceCancelError(err)
}
1017441
func (tp *TicketPool) currentPool() ([]chainhash.Hash, int64) {
	poolSize := len(tp.pool)
	// allocate space for all the ticket hashes, but use append to avoid the
	// slice initialization having to zero initialize all of the arrays.
	pool := make([]chainhash.Hash, 0, poolSize)
	for h := range tp.pool {
		pool = append(pool, h)
	}
	return pool, tp.cursor
}