fix tikv listing due to expired entries (#7115)

* fix tikv listing due to expired entries

When there are many entries with empty fileName values (which can happen after TTL cleanup), the continue statements prevent the loop counter from incrementing, creating an infinite loop.

* address comments

* Update weed/filer/tikv/tikv_store.go

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* address comments

Update weed/filer/tikv/tikv_store.go

Co-Authored-By: Copilot <175728472+Copilot@users.noreply.github.com>

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
Chris LuandCopilot authored and GitHub committed 2025-08-08 12:38:55 -07:00
1 parent fae416586b
commit 3ac2a2e22d
1 file changed
+21 -5
+21 -5
View File
@@ -228,19 +228,31 @@ func (store *TikvStore) ListDirectoryPrefixedEntries(ctx context.Context, dirPat
return err
}
defer iter.Close()
for i := int64(0); i < limit && iter.Valid(); i++ {
i := int64(0)
for iter.Valid() {
key := iter.Key()
if !bytes.HasPrefix(key, directoryPrefix) {
break
}
fileName := getNameFromKey(key)
if fileName == "" || fileName == startFileName && !includeStartFile {
if fileName == "" {
if err := iter.Next(); err != nil {
break
} else {
continue
}
continue
}
if fileName == startFileName && !includeStartFile {
if err := iter.Next(); err != nil {
break
}
continue
}
// Check limit only before processing valid entries
if limit > 0 && i >= limit {
break
}
lastFileName = fileName
entry := &filer.Entry{
FullPath: util.NewFullPath(string(dirPath), fileName),
@@ -252,11 +264,15 @@ func (store *TikvStore) ListDirectoryPrefixedEntries(ctx context.Context, dirPat
glog.V(0).InfofCtx(ctx, "list %s : %v", entry.FullPath, err)
break
}
// Only increment counter after successful processing
i++
if err := iter.Next(); !eachEntryFunc(entry) || err != nil {
break
}
}
return nil
return err
})
if err != nil {
return lastFileName, fmt.Errorf("prefix list %s : %v", dirPath, err)