mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2024-01-19 02:48:24 +00:00
parent
221105eea3
commit
6230eb28a6
|
@ -14,6 +14,7 @@ import (
|
||||||
"github.com/chrislusf/raft"
|
"github.com/chrislusf/raft"
|
||||||
"github.com/chrislusf/seaweedfs/weed/glog"
|
"github.com/chrislusf/seaweedfs/weed/glog"
|
||||||
"github.com/chrislusf/seaweedfs/weed/topology"
|
"github.com/chrislusf/seaweedfs/weed/topology"
|
||||||
|
"github.com/chrislusf/seaweedfs/weed/util"
|
||||||
"github.com/gorilla/mux"
|
"github.com/gorilla/mux"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -71,6 +72,7 @@ func NewRaftServer(r *mux.Router, peers []string, httpAddr string, dataDir strin
|
||||||
for _, peer := range s.peers {
|
for _, peer := range s.peers {
|
||||||
s.raftServer.AddPeer(peer, "http://"+peer)
|
s.raftServer.AddPeer(peer, "http://"+peer)
|
||||||
}
|
}
|
||||||
|
rand.Seed(util.HashBytesToInt64([]byte(httpAddr)))
|
||||||
time.Sleep(time.Duration(1000+rand.Int31n(3000)) * time.Millisecond)
|
time.Sleep(time.Duration(1000+rand.Int31n(3000)) * time.Millisecond)
|
||||||
if s.raftServer.IsLogEmpty() {
|
if s.raftServer.IsLogEmpty() {
|
||||||
// Initialize the server by joining itself.
|
// Initialize the server by joining itself.
|
||||||
|
|
9
weed/util/randomizer.go
Normal file
9
weed/util/randomizer.go
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
package util
|
||||||
|
|
||||||
|
import "hash/fnv"
|
||||||
|
|
||||||
|
func HashBytesToInt64(x []byte) int64 {
|
||||||
|
hash := fnv.New64()
|
||||||
|
hash.Write(x)
|
||||||
|
return int64(hash.Sum64())
|
||||||
|
}
|
Loading…
Reference in a new issue