Skip to content

Commit

Permalink
cmd: shutdown object storage before service exits (#4716)
Browse files Browse the repository at this point in the history
  • Loading branch information
SandyXSD authored Apr 17, 2024
1 parent 953d37e commit 2acedf6
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 5 deletions.
4 changes: 3 additions & 1 deletion cmd/gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ package cmd
import (
"context"
"errors"
"github.com/juicedata/juicefs/pkg/utils"
_ "net/http/pprof"
"os"
"os/signal"
Expand All @@ -33,6 +32,8 @@ import (
"github.com/juicedata/juicefs/pkg/chunk"
"github.com/juicedata/juicefs/pkg/fs"
"github.com/juicedata/juicefs/pkg/meta"
"github.com/juicedata/juicefs/pkg/object"
"github.com/juicedata/juicefs/pkg/utils"
"github.com/juicedata/juicefs/pkg/vfs"

jfsgateway "github.com/juicedata/juicefs/pkg/gateway"
Expand Down Expand Up @@ -247,6 +248,7 @@ func initForSvc(c *cli.Context, mp string, metaUrl string) (*vfs.Config, *fs.Fil
if err := metaCli.CloseSession(); err != nil {
logger.Fatalf("close session failed: %s", err)
}
object.Shutdown(blob)
os.Exit(0)
}()
vfsConf := getVfsConf(c, metaConf, format, chunkConf)
Expand Down
9 changes: 7 additions & 2 deletions cmd/mount.go
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,10 @@ type storageHolder struct {
fmt meta.Format
}

func (h *storageHolder) Shutdown() {
object.Shutdown(h.ObjectStorage)
}

func NewReloadableStorage(format *meta.Format, cli meta.Meta, patch func(*meta.Format)) (object.ObjectStorage, error) {
if patch != nil {
patch(format)
Expand Down Expand Up @@ -597,7 +601,7 @@ func mount(c *cli.Context) error {
if err = metaCli.Shutdown(); err != nil {
logger.Errorf("[pid=%d] meta shutdown: %s", os.Getpid(), err)
}
object.Shutdown(blob.(*storageHolder).ObjectStorage)
object.Shutdown(blob)
var foreground bool
if runtime.GOOS == "windows" || !c.Bool("background") || os.Getenv("JFS_FOREGROUND") != "" {
foreground = true
Expand Down Expand Up @@ -640,14 +644,15 @@ func mount(c *cli.Context) error {
store.UpdateLimit(fmt.UploadLimit, fmt.DownloadLimit)
})
v := vfs.NewVFS(vfsConf, metaCli, store, registerer, registry)
installHandler(mp, v)
installHandler(mp, v, blob)
v.UpdateFormat = updateFormat(c)
initBackgroundTasks(c, vfsConf, metaConf, metaCli, blob, registerer, registry)
mountMain(v, c)
if err := v.FlushAll(""); err != nil {
logger.Errorf("flush all delayed data: %s", err)
}
err = metaCli.CloseSession()
object.Shutdown(blob)
logger.Infof("The juicefs mount process exit successfully, mountpoint: %s", metaConf.MountPoint)
return err
}
4 changes: 3 additions & 1 deletion cmd/mount_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import (
"github.com/juicedata/godaemon"
"github.com/juicedata/juicefs/pkg/fuse"
"github.com/juicedata/juicefs/pkg/meta"
"github.com/juicedata/juicefs/pkg/object"
"github.com/juicedata/juicefs/pkg/utils"
"github.com/juicedata/juicefs/pkg/vfs"
"github.com/urfave/cli/v2"
Expand Down Expand Up @@ -619,7 +620,7 @@ func adjustOOMKiller(score int) {
}
}

func installHandler(mp string, v *vfs.VFS) {
func installHandler(mp string, v *vfs.VFS, blob object.ObjectStorage) {
// Go will catch all the signals
signal.Ignore(syscall.SIGPIPE)
signalChan := make(chan os.Signal, 10)
Expand All @@ -636,6 +637,7 @@ func installHandler(mp string, v *vfs.VFS) {
if err != nil {
logger.Fatalf("flush buffered data failed: %s", err)
}
object.Shutdown(blob)
logger.Warnf("exit with code 1")
os.Exit(1)
} else {
Expand Down
3 changes: 2 additions & 1 deletion cmd/mount_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package cmd

import (
"github.com/juicedata/juicefs/pkg/meta"
"github.com/juicedata/juicefs/pkg/object"
"github.com/juicedata/juicefs/pkg/vfs"
"github.com/juicedata/juicefs/pkg/winfsp"
"github.com/urfave/cli/v2"
Expand Down Expand Up @@ -68,4 +69,4 @@ func setFuseOption(c *cli.Context, format *meta.Format, vfsConf *vfs.Config) {}

func launchMount(mp string, conf *vfs.Config) error { return nil }

func installHandler(mp string, v *vfs.VFS) {}
func installHandler(mp string, v *vfs.VFS, blob object.ObjectStorage) {}

0 comments on commit 2acedf6

Please sign in to comment.