Ejemplo n.º 1
0
func newQuasarDB(c *quasarConfig) *quasarDB {
	var err error
	q := &quasarDB{
		addr:           c.addr,
		mdStore:        c.mdStore,
		maxConnections: 200,
	}
	log.Noticef("Connecting to Quasar at %v...", q.addr.String())
	q.packetpool = sync.Pool{
		New: func() interface{} {
			seg := capn.NewBuffer(nil)
			req := qsr.NewRootRequest(seg)
			req.SetEchoTag(0)
			ins := qsr.NewCmdInsertValues(seg)
			ins.SetSync(false)
			return quasarReading{
				seg: seg,
				req: &req,
				ins: &ins,
			}
		},
	}
	q.bufferpool = sync.Pool{
		New: func() interface{} {
			return bytes.NewBuffer(make([]byte, 0, 200)) // 200 byte buffer
		},
	}
	if q.connpool, err = NewConnectionPool(q.getConnection, q.maxConnections); err != nil {
		log.Fatal(err)
	}
	return q
}
Ejemplo n.º 2
0
//TODO: fix?
func (q *quasarDB) WindowData(uuids []common.UUID, pointWidth, start, end uint64) ([]common.StatisticalNumbersResponse, error) {
	var ret = make([]common.StatisticalNumbersResponse, len(uuids))
	conn := q.connpool.Get()
	defer q.connpool.Put(conn)
	for i, uu := range uuids {
		seg := capn.NewBuffer(nil)
		req := qsr.NewRootRequest(seg)
		query := qsr.NewCmdQueryStatisticalValues(seg)
		uuid, _ := uuid.FromString(string(uu))
		query.SetUuid(uuid.Bytes())
		query.SetStartTime(int64(start))
		query.SetEndTime(int64(end))
		query.SetPointWidth(uint8(pointWidth))
		req.SetQueryStatisticalValues(query)
		_, err := seg.WriteTo(conn) // here, ignoring # bytes written
		if err != nil {
			return ret, err
		}
		sr, err := q.receiveStats(conn)
		if err != nil {
			return ret, err
		}
		sr.UUID = uu
		ret[i] = sr
	}
	return ret, nil
}
Ejemplo n.º 3
0
func (quasar *quasarDB) queryNearestValue(uuids []common.UUID, start uint64, backwards bool) ([]common.SmapNumbersResponse, error) {
	var ret = make([]common.SmapNumbersResponse, len(uuids))
	conn := quasar.connpool.Get()
	defer quasar.connpool.Put(conn)
	for i, uu := range uuids {
		seg := capn.NewBuffer(nil)
		req := qsr.NewRootRequest(seg)
		qnv := qsr.NewCmdQueryNearestValue(seg)
		qnv.SetBackward(backwards)
		uuid, _ := uuid.FromString(string(uu))
		qnv.SetUuid(uuid.Bytes())
		qnv.SetTime(int64(start))
		req.SetQueryNearestValue(qnv)
		_, err := seg.WriteTo(conn) // here, ignoring # bytes written
		if err != nil {
			return ret, err
		}
		sr, err := quasar.receive(conn)
		if err != nil {
			return ret, err
		}
		sr.UUID = uu
		ret[i] = sr
	}
	return ret, nil
}
Ejemplo n.º 4
0
func (q *quasarDB) DeleteData(uuids []common.UUID, start, end uint64) error {
	conn := q.connpool.Get()
	defer q.connpool.Put(conn)
	for _, uu := range uuids {
		seg := capn.NewBuffer(nil)
		req := qsr.NewRootRequest(seg)
		del := qsr.NewCmdDeleteValues(seg)
		uuid, _ := uuid.FromString(string(uu))
		del.SetUuid(uuid.Bytes())
		del.SetStartTime(int64(start))
		del.SetEndTime(int64(end))
		req.SetDeleteValues(del)
		_, err := seg.WriteTo(conn) // here, ignoring # bytes written
		if err != nil {
			return err
		}
		_, err = q.receive(conn)
		if err != nil {
			return err
		}
	}
	return nil
}