示例#1
0
// writeMutation ensures that this transaction can support the given key/value
// mutation.
//
//   if getOnly is true, don't record the actual mutation data, just ensure that
//	   the key is in an included entity group (or add an empty entry for that
//	   group).
//
//   if !getOnly && data == nil, this counts as a deletion instead of a Put.
//
// Returns an error if this key causes the transaction to cross too many entity
// groups.
func (td *txnDataStoreData) writeMutation(getOnly bool, key ds.Key, data ds.PropertyMap) error {
	rk := string(keyBytes(dskey.Root(key)))

	td.Lock()
	defer td.Unlock()

	if _, ok := td.muts[rk]; !ok {
		limit := 1
		if td.isXG {
			limit = xgEGLimit
		}
		if len(td.muts)+1 > limit {
			msg := "cross-group transaction need to be explicitly specified (xg=True)"
			if td.isXG {
				msg = "operating on too many entity groups in a single transaction"
			}
			return errors.New(msg)
		}
		td.muts[rk] = []txnMutation{}
	}
	if !getOnly {
		td.muts[rk] = append(td.muts[rk], txnMutation{key, data})
	}

	return nil
}
示例#2
0
func testGetMeta(c context.Context, k dsS.Key) int64 {
	ds := dsS.Get(c)
	mg := &MetaGroup{Parent: dskey.Root(k)}
	if err := ds.Get(mg); err != nil {
		panic(err)
	}
	return mg.Version
}
示例#3
0
// GetEntityGroupVersion returns the entity group version for the entity group
// containing root. If the entity group doesn't exist, this function will return
// zero and a nil error.
func GetEntityGroupVersion(c context.Context, root dstore.Key) (int64, error) {
	ds := dstore.Get(c)
	egm := &EntityGroupMeta{Parent: dskey.Root(root)}
	err := ds.Get(egm)
	ret := egm.Version
	if err == dstore.ErrNoSuchEntity {
		// this is OK for callers. The version of the entity group is effectively 0
		// in this case.
		err = nil
	}
	return ret, err
}
示例#4
0
func groupIDsKey(key ds.Key) []byte {
	return keyBytes(dskey.New("", "", "__entity_group_ids__", "", 1, dskey.Root(key)))
}