Skip to content

SeaweedFS is a distributed storage system for object storage (S3), file systems, Iceberg table buckets, and Lance vector buckets, designed to handle billions of files with O(1) disk access and effortless horizontal scaling.

randomize raft server startup

Chris Lu75d63db60d16
diff --git a/weed/command/benchmark.go b/weed/command/benchmark.go
index 4ba00dc983..8b65c86637 100644
--- a/weed/command/benchmark.go
+++ b/weed/command/benchmark.go
@@ -2,6 +2,7 @@ package command
import (
"bufio"
+ "context"
"fmt"
"io"
"math"
@@ -19,7 +20,6 @@ import (
"github.com/chrislusf/seaweedfs/weed/security"
"github.com/chrislusf/seaweedfs/weed/util"
"github.com/chrislusf/seaweedfs/weed/wdclient"
- "context"
)
type BenchmarkOptions struct {
diff --git a/weed/command/master.go b/weed/command/master.go
index ac5902b60d..34f467bd2c 100644
--- a/weed/command/master.go
+++ b/weed/command/master.go
@@ -132,7 +132,7 @@ func checkPeers(masterIp string, masterPort int, peers string) (masterAddress st
if !hasSelf {
peerCount += 1
}
- if peerCount %2 == 0 {
+ if peerCount%2 == 0 {
glog.Fatalf("Only odd number of masters are supported!")
}
return
diff --git a/weed/server/filer_ui/templates.go b/weed/server/filer_ui/templates.go
index e53d5caa7e..c2d69156e6 100644
--- a/weed/server/filer_ui/templates.go
+++ b/weed/server/filer_ui/templates.go
@@ -1,8 +1,8 @@
package master_ui
import (
- "html/template"
"github.com/dustin/go-humanize"
+ "html/template"
)
var funcMap = template.FuncMap{
diff --git a/weed/server/raft_server.go b/weed/server/raft_server.go
index e2a091e83b..01ca41aac1 100644
--- a/weed/server/raft_server.go
+++ b/weed/server/raft_server.go
@@ -3,6 +3,7 @@ package weed_server
import (
"encoding/json"
"io/ioutil"
+ "math/rand"
"os"
"path"
"reflect"
@@ -68,7 +69,7 @@ func NewRaftServer(r *mux.Router, peers []string, httpAddr string, dataDir strin
for _, peer := range s.peers {
s.raftServer.AddPeer(peer, "http://"+peer)
}
- time.Sleep(2 * time.Second)
+ time.Sleep(time.Duration(1000+rand.Int31n(3000)) * time.Millisecond)
if s.raftServer.IsLogEmpty() {
// Initialize the server by joining itself.
glog.V(0).Infoln("Initializing new cluster")
diff --git a/weed/storage/types/needle_id_128bit.go b/weed/storage/types/needle_id_128bit.go
index 8f1c50a295..3af0b72856 100644
--- a/weed/storage/types/needle_id_128bit.go
+++ b/weed/storage/types/needle_id_128bit.go
@@ -7,7 +7,7 @@ import (
)
const (
- NeedleIdSize = 16
+ NeedleIdSize = 16
NeedleIdEmpty = ""
)
diff --git a/weed/storage/types/needle_id_type.go b/weed/storage/types/needle_id_type.go
index 78a493b943..efb22190d6 100644
--- a/weed/storage/types/needle_id_type.go
+++ b/weed/storage/types/needle_id_type.go
@@ -11,7 +11,7 @@ import (
type NeedleId uint64
const (
- NeedleIdSize = 8
+ NeedleIdSize = 8
NeedleIdEmpty = 0
)