Example #1
0
// TestRangeGossipConfigWithMultipleKeyPrefixes verifies that multiple
// key prefixes for a config are gossipped.
func TestRangeGossipConfigWithMultipleKeyPrefixes(t *testing.T) {
	e := createTestEngine(t)
	mvcc := engine.NewMVCC(e)
	// Add a permission for a new key prefix.
	db1Perm := proto.PermConfig{
		Read:  []string{"spencer", "foo", "bar", "baz"},
		Write: []string{"spencer"},
	}
	key := engine.MakeKey(engine.KeyConfigPermissionPrefix, engine.Key("/db1"))
	if err := mvcc.PutProto(key, proto.MinTimestamp, nil, &db1Perm); err != nil {
		t.Fatal(err)
	}
	r, g := createTestRange(e, t)
	defer r.Stop()

	info, err := g.GetInfo(gossip.KeyConfigPermission)
	if err != nil {
		t.Fatal(err)
	}
	configMap := info.(PrefixConfigMap)
	expConfigs := []*PrefixConfig{
		&PrefixConfig{engine.KeyMin, nil, &testDefaultPermConfig},
		&PrefixConfig{engine.Key("/db1"), nil, &db1Perm},
		&PrefixConfig{engine.Key("/db2"), engine.KeyMin, &testDefaultPermConfig},
	}
	if !reflect.DeepEqual([]*PrefixConfig(configMap), expConfigs) {
		t.Errorf("expected gossiped configs to be equal %s vs %s", configMap, expConfigs)
	}
}
Example #2
0
// createTestEngine creates an in-memory engine and initializes some
// default configuration settings.
func createTestEngine(t *testing.T) engine.Engine {
	e := engine.NewInMem(proto.Attributes{Attrs: []string{"dc1", "mem"}}, 1<<20)
	mvcc := engine.NewMVCC(e)
	if err := mvcc.PutProto(engine.KeyConfigAccountingPrefix, proto.MinTimestamp, nil, &testDefaultAcctConfig); err != nil {
		t.Fatal(err)
	}
	if err := mvcc.PutProto(engine.KeyConfigPermissionPrefix, proto.MinTimestamp, nil, &testDefaultPermConfig); err != nil {
		t.Fatal(err)
	}
	if err := mvcc.PutProto(engine.KeyConfigZonePrefix, proto.MinTimestamp, nil, &testDefaultZoneConfig); err != nil {
		t.Fatal(err)
	}
	return e
}
Example #3
0
// NewRange initializes the range using the given metadata. The range will have
// no knowledge of a possible store that contains it and thus all rebalancing
// operations will fail. Use NewRangeFromStore() instead to create ranges
// contained within a store.
func NewRange(meta *proto.RangeMetadata, clock *hlc.Clock, eng engine.Engine,
	allocator *allocator, gossip *gossip.Gossip, rm RangeManager) *Range {
	r := &Range{
		Meta:      meta,
		mvcc:      engine.NewMVCC(eng),
		engine:    eng,
		allocator: allocator,
		gossip:    gossip,
		raft:      make(chan *Cmd, 10), // TODO(spencer): remove
		rm:        rm,
		closer:    make(chan struct{}),
		readQ:     NewReadQueue(),
		tsCache:   NewTimestampCache(clock),
		respCache: NewResponseCache(meta.RangeID, eng),
	}
	return r
}