refacotr: move signal handling and pprof to grace package

This commit is contained in:
wuyuxiang
2020-04-28 14:10:23 +08:00
parent 2a7957b4ca
commit 6850d28d6b
13 changed files with 26 additions and 29 deletions

View File

@@ -14,6 +14,7 @@ import (
"sync"
"time"
"github.com/chrislusf/seaweedfs/weed/util/grace"
"google.golang.org/grpc"
"github.com/chrislusf/seaweedfs/weed/operation"
@@ -134,7 +135,7 @@ func runCopy(cmd *Command, args []string) bool {
copy.ttlSec = int32(ttl.Minutes()) * 60
if *cmdCopy.IsDebug {
util.SetupProfiling("filer.copy.cpu.pprof", "filer.copy.mem.pprof")
grace.SetupProfiling("filer.copy.cpu.pprof", "filer.copy.mem.pprof")
}
fileCopyTaskChan := make(chan FileCopyTask, *copy.concurrenctFiles)

View File

@@ -8,6 +8,7 @@ import (
"strings"
"github.com/chrislusf/raft/protobuf"
"github.com/chrislusf/seaweedfs/weed/util/grace"
"github.com/gorilla/mux"
"google.golang.org/grpc/reflection"
@@ -82,7 +83,7 @@ func runMaster(cmd *Command, args []string) bool {
util.LoadConfiguration("master", false)
runtime.GOMAXPROCS(runtime.NumCPU())
util.SetupProfiling(*masterCpuProfile, *masterMemProfile)
grace.SetupProfiling(*masterCpuProfile, *masterMemProfile)
if err := util.TestFolderWritable(*m.metaFolder); err != nil {
glog.Fatalf("Check Meta Folder (-mdir) Writable %s : %s", *m.metaFolder, err)

View File

@@ -19,13 +19,14 @@ import (
"github.com/chrislusf/seaweedfs/weed/pb/filer_pb"
"github.com/chrislusf/seaweedfs/weed/security"
"github.com/chrislusf/seaweedfs/weed/util"
"github.com/chrislusf/seaweedfs/weed/util/grace"
"github.com/seaweedfs/fuse"
"github.com/seaweedfs/fuse/fs"
)
func runMount(cmd *Command, args []string) bool {
util.SetupProfiling(*mountCpuProfile, *mountMemProfile)
grace.SetupProfiling(*mountCpuProfile, *mountMemProfile)
umask, umaskErr := strconv.ParseUint(*mountOptions.umaskString, 8, 64)
if umaskErr != nil {
@@ -144,7 +145,7 @@ func RunMount(option *MountOptions, umask os.FileMode) bool {
}
defer fuse.Unmount(dir)
util.OnInterrupt(func() {
grace.OnInterrupt(func() {
fuse.Unmount(dir)
c.Close()
})

View File

@@ -6,6 +6,7 @@ import (
"strconv"
"time"
"github.com/chrislusf/seaweedfs/weed/util/grace"
"google.golang.org/grpc/reflection"
"github.com/chrislusf/seaweedfs/weed/glog"
@@ -57,7 +58,7 @@ func runMsgBroker(cmd *Command, args []string) bool {
func (msgBrokerOpt *QueueOptions) startQueueServer() bool {
util.SetupProfiling(*messageBrokerStandaloneOptions.cpuprofile, *messageBrokerStandaloneOptions.memprofile)
grace.SetupProfiling(*messageBrokerStandaloneOptions.cpuprofile, *messageBrokerStandaloneOptions.memprofile)
filerGrpcAddress, err := pb.ParseFilerGrpcAddress(*msgBrokerOpt.filer)
if err != nil {

View File

@@ -10,6 +10,7 @@ import (
"strings"
"time"
"github.com/chrislusf/seaweedfs/weed/util/grace"
"github.com/spf13/viper"
"google.golang.org/grpc"
@@ -93,7 +94,7 @@ func runVolume(cmd *Command, args []string) bool {
util.LoadConfiguration("security", false)
runtime.GOMAXPROCS(runtime.NumCPU())
util.SetupProfiling(*v.cpuProfile, *v.memProfile)
grace.SetupProfiling(*v.cpuProfile, *v.memProfile)
v.startVolumeServer(*volumeFolders, *maxVolumeCounts, *volumeWhiteListOption)
@@ -183,7 +184,7 @@ func (v VolumeServerOptions) startVolumeServer(volumeFolders, maxVolumeCounts, v
clusterHttpServer := v.startClusterHttpService(volumeMux)
stopChain := make(chan struct{})
util.OnInterrupt(func() {
grace.OnInterrupt(func() {
fmt.Println("volume server has be killed")
var startTime time.Time