From 1347e3952f68370ce8b1b796deeefefc61e51035 Mon Sep 17 00:00:00 2001 From: Barak Michener Date: Tue, 21 Oct 2014 14:41:52 -0400 Subject: [PATCH] docs and cluster ID change based on name --- Documentation/clustering.md | 6 ++++++ etcdserver/cluster.go | 6 +++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/Documentation/clustering.md b/Documentation/clustering.md index 5487bc235..69745c833 100644 --- a/Documentation/clustering.md +++ b/Documentation/clustering.md @@ -167,3 +167,9 @@ Etcd can also do internal server-to-server communication using SSL client certs. To do this just change the `-*-file` flags to `-peer-*-file`. If you are using SSL for server-to-server communication, you must use it on all instances of etcd. + +### Bootstrapping a new cluster by name + +An etcd server is uniquely defined by the peer addresses it listens to. Suppose, however, that you wish to start over, while maintaining the data from the previous cluster -- that is, to pretend that this machine has never joined a cluster before. + +You can use `--initial-cluster-name` to generate a new unique ID for each node, as a shared token that every node understands. Nodes also take this into account for bootstrapping the new cluster ID, so it also provides a way for a machine to listen on the same interfaces, disconnect from one cluster, and join a different cluster. diff --git a/etcdserver/cluster.go b/etcdserver/cluster.go index 0400e7af2..717cefef8 100644 --- a/etcdserver/cluster.go +++ b/etcdserver/cluster.go @@ -106,7 +106,11 @@ func (c *Cluster) GenID(salt []byte) { for i, id := range mIDs { binary.BigEndian.PutUint64(b[8*i:], id) } - hash := sha1.Sum(append(b, salt...)) + if len(c.name) > 0 { + b = append(b, []byte(c.name)...) + } + b = append(b, salt...) + hash := sha1.Sum(b) c.id = binary.BigEndian.Uint64(hash[:8]) }