Example #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
}
Example #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
}
Example #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
}
Example #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
}
Example #5
0
func (w *writer) Run() error {
	toRun := func(c *connection) error {
		return c.client.BatchMutate(w.writers, cassandra.ConsistencyLevel(w.consistencyLevel))
	}
	if w.usedCounters {
		return w.pool.runWithRetries(toRun, 1)
	}
	return w.pool.run(toRun)
}
Example #6
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)
}