etcdserver: register pre-defined namespaces in store

This commit is contained in:
Yicheng Qin 2015-02-04 16:33:40 -08:00
parent 38038e476a
commit f13c7872d5
3 changed files with 17 additions and 4 deletions

View File

@ -141,7 +141,7 @@ type EtcdServer struct {
// NewServer creates a new EtcdServer from the supplied configuration. The // NewServer creates a new EtcdServer from the supplied configuration. The
// configuration is considered static for the lifetime of the EtcdServer. // configuration is considered static for the lifetime of the EtcdServer.
func NewServer(cfg *ServerConfig) (*EtcdServer, error) { func NewServer(cfg *ServerConfig) (*EtcdServer, error) {
st := store.New() st := store.New(StoreAdminPrefix, StoreKeysPrefix)
var w *wal.WAL var w *wal.WAL
var n raft.Node var n raft.Node
var s *raft.MemoryStorage var s *raft.MemoryStorage

View File

@ -70,16 +70,20 @@ type store struct {
clock clockwork.Clock clock clockwork.Clock
} }
func New() Store { // The given namespaces will be created as initial directories in the returned store.
s := newStore() func New(namespaces ...string) Store {
s := newStore(namespaces...)
s.clock = clockwork.NewRealClock() s.clock = clockwork.NewRealClock()
return s return s
} }
func newStore() *store { func newStore(namespaces ...string) *store {
s := new(store) s := new(store)
s.CurrentVersion = defaultVersion s.CurrentVersion = defaultVersion
s.Root = newDir(s, "/", s.CurrentIndex, nil, "", Permanent) s.Root = newDir(s, "/", s.CurrentIndex, nil, "", Permanent)
for _, namespace := range namespaces {
s.Root.Add(newDir(s, namespace, s.CurrentIndex, s.Root, "", Permanent))
}
s.Stats = newStats() s.Stats = newStats()
s.WatcherHub = newWatchHub(1000) s.WatcherHub = newWatchHub(1000)
s.ttlKeyHeap = newTtlKeyHeap() s.ttlKeyHeap = newTtlKeyHeap()

View File

@ -23,6 +23,15 @@ import (
etcdErr "github.com/coreos/etcd/error" etcdErr "github.com/coreos/etcd/error"
) )
func TestNewStoreWithNamespaces(t *testing.T) {
s := newStore("/0", "/1")
_, err := s.Get("/0", false, false)
assert.Nil(t, err, "")
_, err = s.Get("/1", false, false)
assert.Nil(t, err, "")
}
// Ensure that the store can retrieve an existing value. // Ensure that the store can retrieve an existing value.
func TestStoreGetValue(t *testing.T) { func TestStoreGetValue(t *testing.T) {
s := newStore() s := newStore()