xl: Delete older data-dir when replacing an existing version-id (#16176)

This commit is contained in:
Anis Elleuch 2022-12-06 22:43:18 +01:00 committed by GitHub
parent 932d2c3c62
commit 1bae32dc96
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -2329,12 +2329,18 @@ func (s *xlStorage) RenameData(ctx context.Context, srcVolume, srcPath string, f
} }
} }
var oldDstDataPath string var oldDstDataPath, reqVID string
if fi.VersionID == "" { if fi.VersionID == "" {
// return the latest "null" versionId info reqVID = nullVersionID
ofi, err := xlMeta.ToFileInfo(dstVolume, dstPath, nullVersionID) } else {
reqVID = fi.VersionID
}
// Replace the data of null version or any other existing version-id
ofi, err := xlMeta.ToFileInfo(dstVolume, dstPath, reqVID)
if err == nil && !ofi.Deleted { if err == nil && !ofi.Deleted {
if xlMeta.SharedDataDirCountStr(nullVersionID, ofi.DataDir) == 0 { if xlMeta.SharedDataDirCountStr(reqVID, ofi.DataDir) == 0 {
// Purge the destination path as we are not preserving anything // Purge the destination path as we are not preserving anything
// versioned object was not requested. // versioned object was not requested.
oldDstDataPath = pathJoin(dstVolumeDir, dstPath, ofi.DataDir) oldDstDataPath = pathJoin(dstVolumeDir, dstPath, ofi.DataDir)
@ -2343,22 +2349,23 @@ func (s *xlStorage) RenameData(ctx context.Context, srcVolume, srcPath string, f
// avoid setting oldDstDataPath at that point. // avoid setting oldDstDataPath at that point.
if oldDstDataPath == dstDataPath { if oldDstDataPath == dstDataPath {
oldDstDataPath = "" oldDstDataPath = ""
} } else {
xlMeta.data.remove(nullVersionID, ofi.DataDir) xlMeta.data.remove(reqVID, ofi.DataDir)
} }
} }
}
// Empty fi.VersionID indicates that versioning is either // Empty fi.VersionID indicates that versioning is either
// suspended or disabled on this bucket. RenameData will replace // suspended or disabled on this bucket. RenameData will replace
// the 'null' version. We add a free-version to track its tiered // the 'null' version. We add a free-version to track its tiered
// content for asynchronous deletion. // content for asynchronous deletion.
if !fi.IsRestoreObjReq() { if fi.VersionID == "" && !fi.IsRestoreObjReq() {
// Note: Restore object request reuses PutObject/Multipart // Note: Restore object request reuses PutObject/Multipart
// upload to copy back its data from the remote tier. This // upload to copy back its data from the remote tier. This
// doesn't replace the existing version, so we don't need to add // doesn't replace the existing version, so we don't need to add
// a free-version. // a free-version.
xlMeta.AddFreeVersion(fi) xlMeta.AddFreeVersion(fi)
} }
}
// indicates if RenameData() is called by healing. // indicates if RenameData() is called by healing.
// healing doesn't preserve the dataDir as 'legacy' // healing doesn't preserve the dataDir as 'legacy'