mirror of
https://github.com/minio/minio.git
synced 2025-01-26 22:23:15 -05:00
fix: reduce an extra readdir() attempted on non-legacy setups (#11301)
to verify moving content and preserving legacy content, we have way to detect the objects through readdir() this path is not necessary for most common cases on newer setups, avoid readdir() to save multiple system calls. also fix the CheckFile behavior for most common use case i.e without legacy format.
This commit is contained in:
parent
e0055609bb
commit
b5049d541f
@ -1808,16 +1808,18 @@ func (s *xlStorage) CheckFile(ctx context.Context, volume string, path string) e
|
|||||||
|
|
||||||
st, _ := os.Lstat(filePath)
|
st, _ := os.Lstat(filePath)
|
||||||
if st == nil {
|
if st == nil {
|
||||||
if s.formatLegacy {
|
if !s.formatLegacy {
|
||||||
filePathOld := pathJoin(volumeDir, p, xlStorageFormatFileV1)
|
return errPathNotFound
|
||||||
if err := checkPathLength(filePathOld); err != nil {
|
}
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
st, _ = os.Lstat(filePathOld)
|
filePathOld := pathJoin(volumeDir, p, xlStorageFormatFileV1)
|
||||||
if st == nil {
|
if err := checkPathLength(filePathOld); err != nil {
|
||||||
return errPathNotFound
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
st, _ = os.Lstat(filePathOld)
|
||||||
|
if st == nil {
|
||||||
|
return errPathNotFound
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2110,18 +2112,24 @@ func (s *xlStorage) RenameData(ctx context.Context, srcVolume, srcPath, dataDir,
|
|||||||
// It is possible that some drives may not have `xl.meta` file
|
// It is possible that some drives may not have `xl.meta` file
|
||||||
// in such scenarios verify if atleast `part.1` files exist
|
// in such scenarios verify if atleast `part.1` files exist
|
||||||
// to verify for legacy version.
|
// to verify for legacy version.
|
||||||
currentDataPath := pathJoin(dstVolumeDir, dstPath)
|
if s.formatLegacy {
|
||||||
entries, err := readDirN(currentDataPath, 1)
|
// We only need this code if we are moving
|
||||||
if err != nil && err != errFileNotFound {
|
// from `xl.json` to `xl.meta`, we can avoid
|
||||||
return osErrToFileErr(err)
|
// one extra readdir operation here for all
|
||||||
}
|
// new deployments.
|
||||||
for _, entry := range entries {
|
currentDataPath := pathJoin(dstVolumeDir, dstPath)
|
||||||
if entry == xlStorageFormatFile || strings.HasSuffix(entry, slashSeparator) {
|
entries, err := readDirN(currentDataPath, 1)
|
||||||
continue
|
if err != nil && err != errFileNotFound {
|
||||||
|
return osErrToFileErr(err)
|
||||||
}
|
}
|
||||||
if strings.HasPrefix(entry, "part.") {
|
for _, entry := range entries {
|
||||||
legacyPreserved = true
|
if entry == xlStorageFormatFile || strings.HasSuffix(entry, slashSeparator) {
|
||||||
break
|
continue
|
||||||
|
}
|
||||||
|
if strings.HasPrefix(entry, "part.") {
|
||||||
|
legacyPreserved = true
|
||||||
|
break
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1719,7 +1719,7 @@ func TestXLStorageCheckFile(t *testing.T) {
|
|||||||
|
|
||||||
for i, testCase := range testCases {
|
for i, testCase := range testCases {
|
||||||
if err := xlStorage.CheckFile(context.Background(), testCase.srcVol, testCase.srcPath); err != testCase.expectedErr {
|
if err := xlStorage.CheckFile(context.Background(), testCase.srcVol, testCase.srcPath); err != testCase.expectedErr {
|
||||||
t.Fatalf("TestXLStorage case %d: Expected: \"%s\", got: \"%s\"", i+1, testCase.expectedErr, err)
|
t.Errorf("TestXLStorage case %d: Expected: \"%s\", got: \"%s\"", i+1, testCase.expectedErr, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user