Beispiel #1
0
func (p *Backend) Query(param specs.RrdQuery,
	resp *specs.RrdResp) (err error) {
	var (
		e    *cacheEntry
		rrds []*specs.RRDData
		ret  []*specs.RRDData
	)

	statInc(ST_RPC_SERV_QUERY, 1)

	e, err = p.queryGetCacheEntry(&param, resp)
	if err != nil {
		return err
	}

	rrds, ret, err = p.queryGetData(&param, resp, e)
	if err != nil {
		statInc(ST_RPC_SERV_QUERY_ITEM, len(resp.Vs))
		return err
	}

	ret = queryPruneCache(ret, e, param.Start, param.End)

	ret = queryMergeData(rrds, ret, param.Start, param.End, int64(e.e.step))

	resp.Vs = queryPruneRet(ret, param.Start, param.End, int64(e.e.step))

	statInc(ST_RPC_SERV_QUERY_ITEM, len(resp.Vs))
	return nil
}
Beispiel #2
0
func (p *Backend) queryGetData(param *specs.RrdQuery, resp *specs.RrdResp,
	e *cacheEntry) (rrds, caches []*specs.RRDData, err error) {

	flag := atomic.LoadUint32(&e.flag)
	caches, _ = e._getData(uint32(e.e.commitId), uint32(e.e.dataId))

	if !p.Migrate.Disabled && flag&RRD_F_MISS != 0 {
		node, _ := p.storageMigrateConsistent.Get(param.Id())
		done := make(chan error, 1)
		res := &specs.RrdRespCsum{}
		p.storageNetTaskCh[node] <- &netTask{
			Method: NET_TASK_M_QUERY,
			Done:   done,
			Args:   param,
			Reply:  res,
		}
		<-done
		// fetch data from remote
		rrds = res.Values
	} else {
		// read data from local rrd file
		rrds, _ = p.taskRrdFetch(e.hashkey(), param.ConsolFun,
			param.Start, param.End, int(e.e.step))
	}

	// larger than rra1point range, skip merge
	now := p.timeNow()
	if param.Start < now-now%int64(e.e.step)-RRA1PointCnt*int64(e.e.step) {
		resp.Vs = rrds
		return nil, nil, errors.New("skip merge")
	}

	// no cached caches, do not merge
	if len(caches) < 1 {
		resp.Vs = rrds
		return nil, nil, errors.New("no caches")
	}
	return rrds, caches, nil
}
Beispiel #3
0
func (p *Backend) queryGetCacheEntry(param *specs.RrdQuery,
	resp *specs.RrdResp) (*cacheEntry, error) {
	// form empty response
	resp.Vs = []*specs.RRDData{}
	resp.Host = param.Host
	resp.Name = param.Name

	e := p.cache.get(param.Csum())
	if e == nil {
		return nil, specs.ErrNoent
	}

	resp.Type = e.typ()
	resp.Step = int(e.e.step)

	param.Start = param.Start - param.Start%int64(resp.Step)
	param.End = param.End - param.End%int64(resp.Step) + int64(resp.Step)
	if param.End-param.Start-int64(resp.Step) < 1 {
		return nil, specs.ErrParam
	}
	return e, nil
}