Exemple #1
0
// FilterRDS installs a transaction buffer datastore filter in the context.
func FilterRDS(c context.Context) context.Context {
	// TODO(riannucci): allow the specification of the set of roots to limit this
	// transaction to, transitively.
	return ds.AddRawFilters(c, func(c context.Context, rds ds.RawInterface) ds.RawInterface {
		if par, _ := c.Value(dsTxnBufParent).(*txnBufState); par != nil {
			haveLock, _ := c.Value(dsTxnBufHaveLock).(bool)
			return &dsTxnBuf{c, par, haveLock}
		}
		return &dsBuf{rds}
	})
}
Exemple #2
0
// AlwaysFilterRDS installs a caching RawDatastore filter in the context.
//
// Unlike FilterRDS it doesn't check GlobalConfig via IsGloballyEnabled call,
// assuming caller already knows whether filter should be applied or not.
func AlwaysFilterRDS(c context.Context, shardsForKey func(*ds.Key) int) context.Context {
	return ds.AddRawFilters(c, func(c context.Context, ds ds.RawInterface) ds.RawInterface {
		i := info.Get(c)

		sc := &supportContext{
			i.AppID(),
			i.GetNamespace(),
			c,
			mc.Get(c),
			mathrand.Get(c),
			shardsForKey,
		}

		v := c.Value(dsTxnCacheKey)
		if v == nil {
			return &dsCache{ds, sc}
		}
		return &dsTxnCache{ds, v.(*dsTxnState), sc}
	})
}
Exemple #3
0
// FilterRDS installs a counter datastore filter in the context.
func FilterRDS(c context.Context) (context.Context, *DSCounter) {
	state := &DSCounter{}
	return ds.AddRawFilters(c, func(ic context.Context, ds ds.RawInterface) ds.RawInterface {
		return &dsCounter{state, ds}
	}), state
}
Exemple #4
0
// FilterRDS installs a featureBreaker datastore filter in the context.
func FilterRDS(c context.Context, defaultError error) (context.Context, FeatureBreaker) {
	state := newState(defaultError)
	return ds.AddRawFilters(c, func(ic context.Context, RawDatastore ds.RawInterface) ds.RawInterface {
		return &dsState{state, RawDatastore}
	}), state
}