From ee05280721d3a57a942777eea56ab9e339ab1a40 Mon Sep 17 00:00:00 2001 From: Anis Elleuch Date: Wed, 16 Oct 2019 19:57:52 +0100 Subject: [PATCH] fs: Remove stale background append temporary file (#8404) Background append creates a temporary file which appends uploaded parts as long as they are available, but when a client stops the upload, the temporary file is not removed by any way. This commit removes the temporary file when the server does its regular removing stale multipart uploads. --- cmd/fs-v1-multipart.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/cmd/fs-v1-multipart.go b/cmd/fs-v1-multipart.go index 1a893db0c..96148bc28 100644 --- a/cmd/fs-v1-multipart.go +++ b/cmd/fs-v1-multipart.go @@ -777,6 +777,12 @@ func (fs *FSObjects) cleanupStaleMultipartUploads(ctx context.Context, cleanupIn if err != nil { continue } + + // Remove the trailing slash separator + for i := range uploadIDs { + uploadIDs[i] = strings.TrimSuffix(uploadIDs[i], SlashSeparator) + } + for _, uploadID := range uploadIDs { fi, err := fsStatDir(ctx, pathJoin(fs.fsPath, minioMetaMultipartBucket, entry, uploadID)) if err != nil { @@ -787,6 +793,15 @@ func (fs *FSObjects) cleanupStaleMultipartUploads(ctx context.Context, cleanupIn // It is safe to ignore any directory not empty error (in case there were multiple uploadIDs on the same object) fsRemoveDir(ctx, pathJoin(fs.fsPath, minioMetaMultipartBucket, entry)) + // Remove uploadID from the append file map and its corresponding temporary file + fs.appendFileMapMu.Lock() + bgAppend, ok := fs.appendFileMap[uploadID] + if ok { + err := fsRemoveFile(ctx, bgAppend.filePath) + logger.LogIf(ctx, err) + delete(fs.appendFileMap, uploadID) + } + fs.appendFileMapMu.Unlock() } } }