Nit: use time.Durations instead of constants in seconds. (#7438)
Nit: use `time.Durations` instead of constants in seconds. Makes for slightly more readable code.
This commit is contained in:
@@ -258,7 +258,7 @@ func (v VolumeServerOptions) startVolumeServer(volumeFolders, maxVolumeCounts, v
|
|||||||
v.folders, v.folderMaxLimits, minFreeSpaces, diskTypes,
|
v.folders, v.folderMaxLimits, minFreeSpaces, diskTypes,
|
||||||
*v.idxFolder,
|
*v.idxFolder,
|
||||||
volumeNeedleMapKind,
|
volumeNeedleMapKind,
|
||||||
v.masters, constants.VolumePulseSeconds, *v.dataCenter, *v.rack,
|
v.masters, constants.VolumePulsePeriod, *v.dataCenter, *v.rack,
|
||||||
v.whiteList,
|
v.whiteList,
|
||||||
*v.fixJpgOrientation, *v.readMode,
|
*v.fixJpgOrientation, *v.readMode,
|
||||||
*v.compactionMBPerSecond,
|
*v.compactionMBPerSecond,
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
package constants
|
package constants
|
||||||
|
|
||||||
|
import "time"
|
||||||
|
|
||||||
const (
|
const (
|
||||||
VolumePulseSeconds = 5
|
VolumePulsePeriod = 5 * time.Second
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -68,7 +68,7 @@ func (vs *VolumeServer) heartbeat() {
|
|||||||
master = newLeader
|
master = newLeader
|
||||||
}
|
}
|
||||||
vs.store.MasterAddress = master
|
vs.store.MasterAddress = master
|
||||||
newLeader, err = vs.doHeartbeatWithRetry(master, grpcDialOption, time.Duration(vs.pulseSeconds)*time.Second, duplicateRetryCount)
|
newLeader, err = vs.doHeartbeatWithRetry(master, grpcDialOption, vs.pulsePeriod, duplicateRetryCount)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
glog.V(0).Infof("heartbeat to %s error: %v", master, err)
|
glog.V(0).Infof("heartbeat to %s error: %v", master, err)
|
||||||
|
|
||||||
@@ -81,7 +81,7 @@ func (vs *VolumeServer) heartbeat() {
|
|||||||
} else {
|
} else {
|
||||||
// Regular error, reset duplicate retry count
|
// Regular error, reset duplicate retry count
|
||||||
duplicateRetryCount = 0
|
duplicateRetryCount = 0
|
||||||
time.Sleep(time.Duration(vs.pulseSeconds) * time.Second)
|
time.Sleep(vs.pulsePeriod)
|
||||||
}
|
}
|
||||||
|
|
||||||
newLeader = ""
|
newLeader = ""
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ type VolumeServer struct {
|
|||||||
SeedMasterNodes []pb.ServerAddress
|
SeedMasterNodes []pb.ServerAddress
|
||||||
whiteList []string
|
whiteList []string
|
||||||
currentMaster pb.ServerAddress
|
currentMaster pb.ServerAddress
|
||||||
pulseSeconds int
|
pulsePeriod time.Duration
|
||||||
dataCenter string
|
dataCenter string
|
||||||
rack string
|
rack string
|
||||||
store *storage.Store
|
store *storage.Store
|
||||||
@@ -59,7 +59,7 @@ func NewVolumeServer(adminMux, publicMux *http.ServeMux, ip string,
|
|||||||
folders []string, maxCounts []int32, minFreeSpaces []util.MinFreeSpace, diskTypes []types.DiskType,
|
folders []string, maxCounts []int32, minFreeSpaces []util.MinFreeSpace, diskTypes []types.DiskType,
|
||||||
idxFolder string,
|
idxFolder string,
|
||||||
needleMapKind storage.NeedleMapKind,
|
needleMapKind storage.NeedleMapKind,
|
||||||
masterNodes []pb.ServerAddress, pulseSeconds int,
|
masterNodes []pb.ServerAddress, pulsePeriod time.Duration,
|
||||||
dataCenter string, rack string,
|
dataCenter string, rack string,
|
||||||
whiteList []string,
|
whiteList []string,
|
||||||
fixJpgOrientation bool,
|
fixJpgOrientation bool,
|
||||||
@@ -86,7 +86,7 @@ func NewVolumeServer(adminMux, publicMux *http.ServeMux, ip string,
|
|||||||
readExpiresAfterSec := v.GetInt("jwt.signing.read.expires_after_seconds")
|
readExpiresAfterSec := v.GetInt("jwt.signing.read.expires_after_seconds")
|
||||||
|
|
||||||
vs := &VolumeServer{
|
vs := &VolumeServer{
|
||||||
pulseSeconds: pulseSeconds,
|
pulsePeriod: pulsePeriod,
|
||||||
dataCenter: dataCenter,
|
dataCenter: dataCenter,
|
||||||
rack: rack,
|
rack: rack,
|
||||||
needleMapKind: needleMapKind,
|
needleMapKind: needleMapKind,
|
||||||
|
|||||||
@@ -88,7 +88,8 @@ func (c *commandVolumeCheckDisk) eqVolumeFileCount(a, b *VolumeReplica) (bool, b
|
|||||||
return fileCountA == fileCountB, fileDeletedCountA == fileDeletedCountB
|
return fileCountA == fileCountB, fileDeletedCountA == fileDeletedCountB
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *commandVolumeCheckDisk) shouldSkipVolume(a, b *VolumeReplica, pulseTimeAtSecond int64, syncDeletions, verbose bool) bool {
|
func (c *commandVolumeCheckDisk) shouldSkipVolume(a, b *VolumeReplica, pulseTime time.Time, syncDeletions, verbose bool) bool {
|
||||||
|
pulseTimeAtSecond := pulseTime.Unix()
|
||||||
doSyncDeletedCount := false
|
doSyncDeletedCount := false
|
||||||
if syncDeletions && a.info.DeleteCount != b.info.DeleteCount {
|
if syncDeletions && a.info.DeleteCount != b.info.DeleteCount {
|
||||||
doSyncDeletedCount = true
|
doSyncDeletedCount = true
|
||||||
@@ -135,7 +136,7 @@ func (c *commandVolumeCheckDisk) Do(args []string, commandEnv *CommandEnv, write
|
|||||||
c.writer = writer
|
c.writer = writer
|
||||||
|
|
||||||
// collect topology information
|
// collect topology information
|
||||||
pulseTimeAtSecond := time.Now().Unix() - constants.VolumePulseSeconds*2
|
pulseTime := time.Now().Add(-constants.VolumePulsePeriod * 2)
|
||||||
topologyInfo, _, err := collectTopologyInfo(commandEnv, 0)
|
topologyInfo, _, err := collectTopologyInfo(commandEnv, 0)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -162,7 +163,7 @@ func (c *commandVolumeCheckDisk) Do(args []string, commandEnv *CommandEnv, write
|
|||||||
})
|
})
|
||||||
for len(writableReplicas) >= 2 {
|
for len(writableReplicas) >= 2 {
|
||||||
a, b := writableReplicas[0], writableReplicas[1]
|
a, b := writableReplicas[0], writableReplicas[1]
|
||||||
if !*slowMode && c.shouldSkipVolume(a, b, pulseTimeAtSecond, *syncDeletions, *verbose) {
|
if !*slowMode && c.shouldSkipVolume(a, b, pulseTime, *syncDeletions, *verbose) {
|
||||||
// always choose the larger volume to be the source
|
// always choose the larger volume to be the source
|
||||||
writableReplicas = append(replicas[:1], writableReplicas[2:]...)
|
writableReplicas = append(replicas[:1], writableReplicas[2:]...)
|
||||||
continue
|
continue
|
||||||
|
|||||||
@@ -1,9 +1,11 @@
|
|||||||
package shell
|
package shell
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/seaweedfs/seaweedfs/weed/pb/master_pb"
|
|
||||||
"os"
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/seaweedfs/seaweedfs/weed/pb/master_pb"
|
||||||
)
|
)
|
||||||
|
|
||||||
type testCommandVolumeCheckDisk struct {
|
type testCommandVolumeCheckDisk struct {
|
||||||
@@ -65,7 +67,8 @@ func TestShouldSkipVolume(t *testing.T) {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
for num, tt := range tests {
|
for num, tt := range tests {
|
||||||
if isShould := cmdVolumeCheckDisk.shouldSkipVolume(&tt.a, &tt.b, tt.pulseTimeAtSecond, true, true); isShould != tt.shouldSkipVolume {
|
pulseTime := time.Unix(tt.pulseTimeAtSecond, 0)
|
||||||
|
if isShould := cmdVolumeCheckDisk.shouldSkipVolume(&tt.a, &tt.b, pulseTime, true, true); isShould != tt.shouldSkipVolume {
|
||||||
t.Fatalf("result of should skip volume is unexpected for %d test", num)
|
t.Fatalf("result of should skip volume is unexpected for %d test", num)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -152,9 +152,9 @@ func (vg *VolumeGrowth) findAndGrow(grpcDialOption grpc.DialOption, topo *Topolo
|
|||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
for !topo.LastLeaderChangeTime.Add(constants.VolumePulseSeconds * 2).Before(time.Now()) {
|
for !topo.LastLeaderChangeTime.Add(constants.VolumePulsePeriod * 2).Before(time.Now()) {
|
||||||
glog.V(0).Infof("wait for volume servers to join back")
|
glog.V(0).Infof("wait for volume servers to join back")
|
||||||
time.Sleep(constants.VolumePulseSeconds / 2)
|
time.Sleep(constants.VolumePulsePeriod / 2)
|
||||||
}
|
}
|
||||||
vid, raftErr := topo.NextVolumeId()
|
vid, raftErr := topo.NextVolumeId()
|
||||||
if raftErr != nil {
|
if raftErr != nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user