docs and cluster ID change based on name

This commit is contained in:
Barak Michener 2014-10-21 14:41:52 -04:00
parent ad0b7b7dbb
commit 1347e3952f
2 changed files with 11 additions and 1 deletions

View File

@ -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.

View File

@ -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])
}