Ejemplo n.º 1
0
func (r *reader) IndexedGet(rang *IndexedRange) ([]*Row, error) {
	if r.cf == "" {
		return nil, errors.New("No column family specified")
	}

	if !r.setWhere {
		return nil, errors.New("At least one Where call must be made")
	}

	if rang == nil || rang.Count <= 0 {
		return make([]*Row, 0), nil
	}

	ic := r.buildIndexClause(rang)
	cp := r.buildColumnParent()
	sp := r.buildPredicate()

	var ret thrift.TList
	err := r.pool.run(func(c *connection) *transactionError {
		var ire *cassandra.InvalidRequestException
		var ue *cassandra.UnavailableException
		var te *cassandra.TimedOutException
		var err error
		ret, ire, ue, te, err = c.client.GetIndexedSlices(
			cp, ic, sp, cassandra.ConsistencyLevel(r.consistencyLevel))
		return &transactionError{ire, ue, te, err}
	})

	if err != nil {
		return nil, err
	}

	return rowsFromTListKeySlice(ret), nil
}
Ejemplo n.º 2
0
func (r *reader) RangeGet(rang *Range) ([]*Row, error) {
	if r.cf == "" {
		return nil, errors.New("No column family specified")
	}

	if rang == nil || rang.Count <= 0 {
		return make([]*Row, 0), nil
	}

	kr := r.buildKeyRange(rang)
	cp := r.buildColumnParent()
	sp := r.buildPredicate()

	var ret thrift.TList
	err := r.pool.run(func(c *connection) *transactionError {
		var ire *cassandra.InvalidRequestException
		var ue *cassandra.UnavailableException
		var te *cassandra.TimedOutException
		var err error
		ret, ire, ue, te, err = c.client.GetRangeSlices(
			cp, sp, kr, cassandra.ConsistencyLevel(r.consistencyLevel))
		return &transactionError{ire, ue, te, err}
	})

	if err != nil {
		return nil, err
	}

	return rowsFromTListKeySlice(ret), nil
}
Ejemplo n.º 3
0
func (r *reader) MultiCount(keys [][]byte) ([]*RowColumnCount, error) {
	if r.cf == "" {
		return nil, errors.New("No column family specified")
	}

	if len(keys) <= 0 {
		return make([]*RowColumnCount, 0), nil
	}

	cp := r.buildColumnParent()
	sp := r.buildPredicate()
	tk := r.buildMultiKeys(keys)

	var ret thrift.TMap
	err := r.pool.run(func(c *connection) *transactionError {
		var ire *cassandra.InvalidRequestException
		var ue *cassandra.UnavailableException
		var te *cassandra.TimedOutException
		var err error
		ret, ire, ue, te, err = c.client.MultigetCount(
			tk, cp, sp, cassandra.ConsistencyLevel(r.consistencyLevel))
		return &transactionError{ire, ue, te, err}
	})

	if err != nil {
		return nil, err
	}

	return rowsColumnCountFromTMap(ret), nil
}
Ejemplo n.º 4
0
func (r *reader) Count(key []byte) (int, error) {
	if r.cf == "" {
		return 0, errors.New("No column family specified")
	}

	cp := r.buildColumnParent()
	sp := r.buildPredicate()

	var ret int32
	err := r.pool.run(func(c *connection) *transactionError {
		var ire *cassandra.InvalidRequestException
		var ue *cassandra.UnavailableException
		var te *cassandra.TimedOutException
		var err error
		ret, ire, ue, te, err = c.client.GetCount(
			key, cp, sp, cassandra.ConsistencyLevel(r.consistencyLevel))
		return &transactionError{ire, ue, te, err}
	})

	if err != nil {
		return 0, err
	}

	return int(ret), nil
}
Ejemplo n.º 5
0
func (r *reader) SuperGet(key []byte) (*SuperRow, error) {
	if r.cf == "" {
		return nil, errors.New("No column family specified")
	}

	cp := r.buildColumnParent()
	sp := r.buildPredicate()
	var ret thrift.TMap
	var keys thrift.TList = thrift.NewTList(thrift.BINARY, 0) // size appears to be ignored in the thrift lib
	keys.Push(key)
	err := r.pool.run(func(c *connection) (*cassandra.InvalidRequestException, *cassandra.UnavailableException, *cassandra.TimedOutException, error) {
		var ire *cassandra.InvalidRequestException
		var ue *cassandra.UnavailableException
		var te *cassandra.TimedOutException
		var err error

		ret, ire, ue, te, err = c.client.MultigetSlice(keys, cp, sp, cassandra.ConsistencyLevel(r.consistencyLevel))
		return ire, ue, te, err
	})

	if err != nil {
		return nil, err
	}

	return rowFromTMapColumns(key, ret), nil
}
Ejemplo n.º 6
0
func (w *writer) Run() error {
	return w.pool.run(func(c *connection) (*cassandra.InvalidRequestException, *cassandra.UnavailableException, *cassandra.TimedOutException, error) {
		var ire *cassandra.InvalidRequestException
		var ue *cassandra.UnavailableException
		var te *cassandra.TimedOutException
		var err error
		ire, ue, te, err = c.client.BatchMutate(w.writers, cassandra.ConsistencyLevel(w.consistencyLevel))
		return ire, ue, te, err
	})
}
Ejemplo n.º 7
0
func (w *writer) Run() error {
	toRun := func(c *connection) *transactionError {
		ire, ue, te, err := c.client.BatchMutate(
			w.writers, cassandra.ConsistencyLevel(w.consistencyLevel))
		return &transactionError{ire, ue, te, err}
	}
	if w.usedCounters {
		return w.pool.runWithRetries(toRun, 1)
	}
	return w.pool.run(toRun)
}
Ejemplo n.º 8
0
func (r *reader) Get(key []byte) (*Row, error) {
	if r.cf == "" {
		return nil, errors.New("No column family specified")
	}

	cp := r.buildColumnParent()
	sp := r.buildPredicate()

	var ret thrift.TList
	err := r.pool.run(func(c *connection) (*cassandra.InvalidRequestException, *cassandra.UnavailableException, *cassandra.TimedOutException, error) {
		var ire *cassandra.InvalidRequestException
		var ue *cassandra.UnavailableException
		var te *cassandra.TimedOutException
		var err error
		ret, ire, ue, te, err = c.client.GetSlice(key, cp, sp, cassandra.ConsistencyLevel(r.consistencyLevel))
		return ire, ue, te, err
	})

	if err != nil {
		return nil, err
	}

	return rowFromTListColumns(key, ret), nil
}