From 71f293d9ab301d7bf63b36ed7f125028d703a434 Mon Sep 17 00:00:00 2001 From: jiuker <2818723467@qq.com> Date: Fri, 1 Aug 2025 23:53:35 +0800 Subject: [PATCH] fix: record extral skippedEntry for listObject (#21484) --- cmd/metacache-set.go | 5 ++++- cmd/object_api_suite_test.go | 43 ++++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 1 deletion(-) diff --git a/cmd/metacache-set.go b/cmd/metacache-set.go index 6feabbea4..0f0786e4a 100644 --- a/cmd/metacache-set.go +++ b/cmd/metacache-set.go @@ -225,7 +225,10 @@ func (o *listPathOptions) gatherResults(ctx context.Context, in <-chan metaCache continue } 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 } if o.Limit > 0 && results.len() >= o.Limit { diff --git a/cmd/object_api_suite_test.go b/cmd/object_api_suite_test.go index a6e1093ee..3fed8c437 100644 --- a/cmd/object_api_suite_test.go +++ b/cmd/object_api_suite_test.go @@ -20,10 +20,13 @@ package cmd import ( "bytes" "context" + "fmt" "io" "math/rand" "strconv" + "strings" "testing" + "time" "github.com/dustin/go-humanize" "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) } } + + // 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: %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: %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.