예제 #1
0
// incCmd adds one to the value of c.key in the env and writes
// it to the db. If c.key isn't in the db, writes 1.
func incCmd(c *cmd, txn *client.Txn, t *testing.T) *roachpb.Error {
	r, pErr := txn.Inc(c.getKey(), 1)
	if pErr != nil {
		return pErr
	}
	c.env[c.key] = r.ValueInt()
	c.debug = fmt.Sprintf("[%d]", r.ValueInt())
	return nil
}
예제 #2
0
// sumCmd sums the values of all keys != c.key read during the transaction and
// writes the result to the db.
func sumCmd(c *cmd, txn *client.Txn, t *testing.T) *roachpb.Error {
	sum := int64(0)
	for k, v := range c.env {
		if k != c.key {
			sum += v
		}
	}
	r, pErr := txn.Inc(c.getKey(), sum)
	c.debug = fmt.Sprintf("[%d ts=%d]", sum, r.Timestamp())
	return pErr
}