SeaweedFS is a distributed storage system for object storage (S3), file systems, Iceberg table buckets, and Lance vector buckets, designed to handle billions of files with O(1) disk access and effortless horizontal scaling.
Go blob-storagecloud-drivedistributed-file-systemdistributed-storageerasure-codingfusehadoop-hdfshdfskuberneteslancelancedbobject-storageposixs3s3-storageseaweedfstiered-file-systemvector-search
avoid int bigger than math.MaxInt32
Chris Lu0a856241fe2a
diff --git a/weed/filer/filer_search.go b/weed/filer/filer_search.goindex 2e0336da8d..112df79842 100644--- a/weed/filer/filer_search.go+++ b/weed/filer/filer_search.go@@ -23,15 +23,15 @@ func splitPattern(pattern string) (prefix string, restPattern string) {// For now, prefix and namePattern are mutually exclusivefunc (f *Filer) ListDirectoryEntries(ctx context.Context, p util.FullPath, startFileName string, inclusive bool, limit int64, prefix string, namePattern string, namePatternExclude string) (entries []*Entry, hasMore bool, err error) {+ if limit > math.MaxInt32-1 {+ limit = math.MaxInt32 - 1+ }+_, err = f.StreamListDirectoryEntries(ctx, p, startFileName, inclusive, limit+1, prefix, namePattern, namePatternExclude, func(entry *Entry) bool {entries = append(entries, entry)return true})- if limit == math.MaxInt64 {- limit = math.MaxInt64 - 1- }-hasMore = int64(len(entries)) >= limit+1if hasMore {entries = entries[:limit]diff --git a/weed/filer/filerstore_translate_path.go b/weed/filer/filerstore_translate_path.goindex 00bf82ed49..55a8bc9291 100644--- a/weed/filer/filerstore_translate_path.go+++ b/weed/filer/filerstore_translate_path.go@@ -3,6 +3,7 @@ package filerimport ("context""github.com/chrislusf/seaweedfs/weed/util"+ "math""strings")@@ -120,6 +121,10 @@ func (t *FilerStorePathTranlator) ListDirectoryPrefixedEntries(ctx context.ContenewFullPath := t.translatePath(dirPath)+ if limit > math.MaxInt32-1 {+ limit = math.MaxInt32 - 1+ }+return t.actualStore.ListDirectoryPrefixedEntries(ctx, newFullPath, startFileName, includeStartFile, limit, prefix, func(entry *Entry) bool {entry.FullPath = dirPath[:len(t.storeRoot)-1] + entry.FullPathreturn eachEntryFunc(entry)diff --git a/weed/filer/filerstore_wrapper.go b/weed/filer/filerstore_wrapper.goindex 2470f340c9..4ded40fb16 100644--- a/weed/filer/filerstore_wrapper.go+++ b/weed/filer/filerstore_wrapper.go@@ -4,6 +4,7 @@ import ("context""github.com/chrislusf/seaweedfs/weed/glog""github.com/viant/ptrie"+ "math""strings""time"@@ -248,6 +249,9 @@ func (fsw *FilerStoreWrapper) ListDirectoryPrefixedEntries(ctx context.Context,defer func() {stats.FilerStoreHistogram.WithLabelValues(actualStore.GetName(), "prefixList").Observe(time.Since(start).Seconds())}()+ if limit > math.MaxInt32-1 {+ limit = math.MaxInt32 - 1+ }glog.V(4).Infof("ListDirectoryPrefixedEntries %s from %s prefix %s limit %d", dirPath, startFileName, prefix, limit)lastFileName, err = actualStore.ListDirectoryPrefixedEntries(ctx, dirPath, startFileName, includeStartFile, limit, prefix, eachEntryFunc)if err == ErrUnsupportedListDirectoryPrefixed {diff --git a/weed/pb/filer_pb/filer_client.go b/weed/pb/filer_pb/filer_client.goindex 6a74e3c4c2..719039d884 100644--- a/weed/pb/filer_pb/filer_client.go+++ b/weed/pb/filer_pb/filer_client.go@@ -101,9 +101,13 @@ func SeaweedList(client SeaweedFilerClient, parentDirectoryPath, prefix string,func doSeaweedList(client SeaweedFilerClient, fullDirPath util.FullPath, prefix string, fn EachEntryFunciton, startFrom string, inclusive bool, limit uint32) (err error) {// Redundancy limit to make it correctly judge whether it is the last file.redLimit := limit- if limit != math.MaxInt32 && limit != 0 {++ if limit < math.MaxInt32 && limit != 0 {redLimit = limit + 1}+ if redLimit > math.MaxInt32 {+ redLimit = math.MaxInt32+ }request := &ListEntriesRequest{Directory: string(fullDirPath),Prefix: prefix,