fix: record extral skippedEntry for listObject (#21484)

This commit is contained in:
jiuker 2025-08-01 23:53:35 +08:00 committed by GitHub
parent e3d183b6a4
commit 71f293d9ab
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 47 additions and 1 deletions

View File

@ -225,7 +225,10 @@ func (o *listPathOptions) gatherResults(ctx context.Context, in <-chan metaCache
continue continue
} }
if yes := o.shouldSkip(ctx, entry); yes { if yes := o.shouldSkip(ctx, entry); yes {
results.lastSkippedEntry = entry.name // when we have not enough results, record the skipped entry
if o.Limit > 0 && results.len() < o.Limit {
results.lastSkippedEntry = entry.name
}
continue continue
} }
if o.Limit > 0 && results.len() >= o.Limit { if o.Limit > 0 && results.len() >= o.Limit {

View File

@ -20,10 +20,13 @@ package cmd
import ( import (
"bytes" "bytes"
"context" "context"
"fmt"
"io" "io"
"math/rand" "math/rand"
"strconv" "strconv"
"strings"
"testing" "testing"
"time"
"github.com/dustin/go-humanize" "github.com/dustin/go-humanize"
"github.com/minio/minio/internal/kms" "github.com/minio/minio/internal/kms"
@ -432,6 +435,46 @@ func testPaging(obj ObjectLayer, instanceType string, t TestErrHandler) {
t.Errorf("%s: Expected the object name to be `%s`, but instead found `%s`", instanceType, "newPrefix2", result.Objects[0].Name) t.Errorf("%s: Expected the object name to be `%s`, but instead found `%s`", instanceType, "newPrefix2", result.Objects[0].Name)
} }
} }
// check paging works.
ag := []string{"a", "b", "c", "d", "e", "f", "g"}
checkObjCount := make(map[string]int)
for i := 0; i < 7; i++ {
dirName := strings.Repeat(ag[i], 3)
key := fmt.Sprintf("testPrefix/%s/obj%s", dirName, dirName)
checkObjCount[key]++
_, err = obj.PutObject(context.Background(), "bucket", key, mustGetPutObjReader(t, bytes.NewBufferString(uploadContent), int64(len(uploadContent)), "", ""), opts)
if err != nil {
t.Fatalf("%s: <ERROR> %s", instanceType, err)
}
}
{
ctx, cancel := context.WithTimeout(context.Background(), time.Second*5)
defer cancel()
token := ""
for ctx.Err() == nil {
result, err := obj.ListObjectsV2(ctx, "bucket", "testPrefix", token, "", 2, false, "")
if err != nil {
t.Fatalf("%s: <ERROR> %s", instanceType, err)
}
token = result.NextContinuationToken
if len(result.Objects) == 0 {
break
}
for _, obj := range result.Objects {
checkObjCount[obj.Name]--
}
if token == "" {
break
}
}
for key, value := range checkObjCount {
if value != 0 {
t.Errorf("%s: Expected value of objects to be %d, instead found to be %d", instanceType, 0, value)
}
delete(checkObjCount, key)
}
}
} }
// Wrapper for calling testObjectOverwriteWorks for both Erasure and FS. // Wrapper for calling testObjectOverwriteWorks for both Erasure and FS.