mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2025-11-24 16:53:14 +08:00
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:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user