etcd: use v2 machines prefix

release-2.0
Xiang Li 2014-07-07 10:25:18 -07:00 committed by Yicheng Qin
parent a88f077348
commit 5e486dd912
3 changed files with 13 additions and 8 deletions

View File

@ -19,9 +19,10 @@ const (
defaultTickDuration = time.Millisecond * 100
nodePrefix = "/cfg/nodes"
v2machineKVPrefix = "/_etcd/machines"
v2Prefix = "/v2/keys"
raftPrefix = "/raft"
v2Prefix = "/v2/keys"
)
type Server struct {
@ -179,7 +180,7 @@ func (s *Server) apply(ents []raft.Entry) {
}
log.Printf("Add Node %x %v\n", cfg.NodeId, cfg.Addr)
s.nodes[cfg.Addr] = true
p := path.Join(nodePrefix, fmt.Sprint(cfg.NodeId))
p := path.Join(v2machineKVPrefix, fmt.Sprint(cfg.NodeId))
s.Store.Set(p, false, cfg.Addr, store.Permanent)
default:
panic("unimplemented")

View File

@ -5,6 +5,8 @@ import (
"net/http/httptest"
"testing"
"time"
"github.com/coreos/etcd/config"
)
func TestMultipleNodes(t *testing.T) {
@ -30,7 +32,9 @@ func buildCluster(number int) ([]*Server, []*httptest.Server) {
var seed string
for i := range es {
es[i] = New(i, "", []string{seed})
c := config.New()
c.Peers = []string{seed}
es[i] = New(c, i)
es[i].SetTick(time.Millisecond * 5)
hs[i] = httptest.NewServer(es[i])
es[i].pubAddr = hs[i].URL
@ -41,7 +45,7 @@ func buildCluster(number int) ([]*Server, []*httptest.Server) {
} else {
// wait for the previous configuration change to be committed
// or this configuration request might be dropped
w, err := es[0].Watch(nodePrefix, true, false, uint64(i))
w, err := es[0].Watch(v2machineKVPrefix, true, false, uint64(i))
if err != nil {
panic(err)
}
@ -56,12 +60,12 @@ func waitCluster(t *testing.T, es []*Server) {
n := len(es)
for i, e := range es {
for k := 1; k < n+1; k++ {
w, err := e.Watch(nodePrefix, true, false, uint64(k))
w, err := e.Watch(v2machineKVPrefix, true, false, uint64(k))
if err != nil {
panic(err)
}
v := <-w.EventChan
ww := fmt.Sprintf("%s/%d", nodePrefix, k-1)
ww := fmt.Sprintf("%s/%d", v2machineKVPrefix, k-1)
if v.Node.Key != ww {
t.Errorf("#%d path = %v, want %v", i, v.Node.Key, w)
}

View File

@ -99,7 +99,7 @@ func (t *transporter) fetchAddr(seedurl string, id int) error {
return fmt.Errorf("cannot parse the url of the given seed")
}
u.Path = path.Join(v2Prefix, nodePrefix, fmt.Sprint(id))
u.Path = path.Join(v2Prefix, v2machineKVPrefix, fmt.Sprint(id))
resp, err := t.client.Get(u.String())
if err != nil {
return fmt.Errorf("cannot reach %v", u)