From 8a274169da744144a902f4e746df85f1bdfb8945 Mon Sep 17 00:00:00 2001 From: Klaus Post Date: Tue, 8 Mar 2022 09:04:20 -0800 Subject: [PATCH] heal: Fix first entry on dangling (#14495) Instead of the first, the last entry was returned pointerizing the range value. --- cmd/erasure-healing_test.go | 20 +++++++++++++++----- cmd/metacache-entries.go | 4 ++-- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/cmd/erasure-healing_test.go b/cmd/erasure-healing_test.go index 9a80e1567..a8a5848e4 100644 --- a/cmd/erasure-healing_test.go +++ b/cmd/erasure-healing_test.go @@ -382,6 +382,13 @@ func TestHealingDanglingObject(t *testing.T) { copy(disks, newDisks) objLayer.(*erasureServerPools).serverPools[0].erasureDisksMu.Unlock() } + getDisk := func(n int) StorageAPI { + objLayer.(*erasureServerPools).serverPools[0].erasureDisksMu.Lock() + disk := disks[n] + objLayer.(*erasureServerPools).serverPools[0].erasureDisksMu.Unlock() + return disk + } + // Remove 4 disks. setDisks(nil, nil, nil, nil) @@ -440,8 +447,8 @@ func TestHealingDanglingObject(t *testing.T) { } setDisks(orgDisks[:4]...) - - fileInfoPreHeal, err = disks[0].ReadVersion(context.Background(), bucket, object, "", false) + disk := getDisk(0) + fileInfoPreHeal, err = disk.ReadVersion(context.Background(), bucket, object, "", false) if err != nil { t.Fatal(err) } @@ -458,7 +465,8 @@ func TestHealingDanglingObject(t *testing.T) { t.Fatal(err) } - fileInfoPostHeal, err = disks[0].ReadVersion(context.Background(), bucket, object, "", false) + disk = getDisk(0) + fileInfoPostHeal, err = disk.ReadVersion(context.Background(), bucket, object, "", false) if err != nil { t.Fatal(err) } @@ -488,7 +496,8 @@ func TestHealingDanglingObject(t *testing.T) { setDisks(orgDisks[:4]...) - fileInfoPreHeal, err = disks[0].ReadVersion(context.Background(), bucket, object, "", false) + disk = getDisk(0) + fileInfoPreHeal, err = disk.ReadVersion(context.Background(), bucket, object, "", false) if err != nil { t.Fatal(err) } @@ -505,7 +514,8 @@ func TestHealingDanglingObject(t *testing.T) { t.Fatal(err) } - fileInfoPostHeal, err = disks[0].ReadVersion(context.Background(), bucket, object, "", false) + disk = getDisk(0) + fileInfoPostHeal, err = disk.ReadVersion(context.Background(), bucket, object, "", false) if err != nil { t.Fatal(err) } diff --git a/cmd/metacache-entries.go b/cmd/metacache-entries.go index 4d091bef1..30cd0fef0 100644 --- a/cmd/metacache-entries.go +++ b/cmd/metacache-entries.go @@ -389,11 +389,11 @@ func (m metaCacheEntries) resolve(r *metadataResolutionParams) (selected *metaCa // firstFound returns the first found and the number of set entries. func (m metaCacheEntries) firstFound() (first *metaCacheEntry, n int) { - for _, entry := range m { + for i, entry := range m { if entry.name != "" { n++ if first == nil { - first = &entry + first = &m[i] } } }