Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Also clean up expired tmp dirs #5366

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions pkg/gateway/gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"net/http"
"os"
"path"
"path/filepath"
"sort"
"strconv"
"strings"
Expand Down Expand Up @@ -1172,6 +1173,7 @@ func (n *jfsObjects) cleanup() {
if errno != 0 {
continue
}
deleted := 0
entries, _ := f.ReaddirPlus(mctx, 0)
for _, entry := range entries {
if _, err := uuid.Parse(string(entry.Name)); err != nil {
Expand All @@ -1183,11 +1185,42 @@ func (n *jfsObjects) cleanup() {
logger.Errorf("failed to delete expired temporary files path: %s,", p)
} else {
logger.Infof("delete expired temporary files path: %s, mtime: %s", p, time.Unix(entry.Attr.Mtime, 0).Format(time.RFC3339))
deleted += 1
}
}
}
f.Close(mctx)
if deleted == len(entries) { // try to clean up to .sys if all files are deleted
dir = strings.TrimRight(dir, "/")
for {
if errno := n.rmEmptyDir(mctx, dir); errno != 0 {
break
}
dir = filepath.Dir(dir)
if !strings.HasPrefix(dir, metaBucket) {
break
}
}
}
}
}
}

func (n *jfsObjects) rmEmptyDir(ctx meta.Context, dir string) syscall.Errno {
f, errno := n.fs.Open(ctx, dir, 0)
if errno != 0 { // reopen to avoid reading from dir cache
logger.Warnf("Failed to open %s: %v", dir, errno)
return errno
}
defer f.Close(ctx)
if entries, errno := f.ReaddirPlus(ctx, 0); errno == 0 && len(entries) == 0 {
if errno = n.fs.Delete(ctx, dir); errno != 0 {
logger.Warnf("Failed to delete empty %s: %v", dir, errno)
return errno
}
return 0
}
return syscall.ENOTEMPTY
}

type jfsFLock struct {
Expand Down
Loading