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
separate prefix from namePattern
Chris Lu2c3c2c27d7a9
diff --git a/weed/filer/filer_buckets.go b/weed/filer/filer_buckets.goindex 4d4f4abc30..87ad9e4521 100644--- a/weed/filer/filer_buckets.go+++ b/weed/filer/filer_buckets.go@@ -29,7 +29,7 @@ func (f *Filer) LoadBuckets() {limit := math.MaxInt32- entries, err := f.ListDirectoryEntries(context.Background(), util.FullPath(f.DirBucketsPath), "", false, limit, "")+ entries, err := f.ListDirectoryEntries(context.Background(), util.FullPath(f.DirBucketsPath), "", false, limit, "", "")if err != nil {glog.V(1).Infof("no buckets found: %v", err)diff --git a/weed/filer/filer_delete_entry.go b/weed/filer/filer_delete_entry.goindex da92c4f4b5..0d1fd7e475 100644--- a/weed/filer/filer_delete_entry.go+++ b/weed/filer/filer_delete_entry.go@@ -68,7 +68,7 @@ func (f *Filer) doBatchDeleteFolderMetaAndData(ctx context.Context, entry *EntrylastFileName := ""includeLastFile := falsefor {- entries, err := f.ListDirectoryEntries(ctx, entry.FullPath, lastFileName, includeLastFile, PaginationSize, "")+ entries, err := f.ListDirectoryEntries(ctx, entry.FullPath, lastFileName, includeLastFile, PaginationSize, "", "")if err != nil {glog.Errorf("list folder %s: %v", entry.FullPath, err)return nil, nil, fmt.Errorf("list folder %s: %v", entry.FullPath, err)diff --git a/weed/filer/filer_notify.go b/weed/filer/filer_notify.goindex 40755e6a7b..563e0eb513 100644--- a/weed/filer/filer_notify.go+++ b/weed/filer/filer_notify.go@@ -113,13 +113,13 @@ func (f *Filer) ReadPersistedLogBuffer(startTime time.Time, eachLogEntryFn func(sizeBuf := make([]byte, 4)startTsNs := startTime.UnixNano()- dayEntries, listDayErr := f.ListDirectoryEntries(context.Background(), SystemLogDir, startDate, true, 366, "")+ dayEntries, listDayErr := f.ListDirectoryEntries(context.Background(), SystemLogDir, startDate, true, 366, "", "")if listDayErr != nil {return lastTsNs, fmt.Errorf("fail to list log by day: %v", listDayErr)}for _, dayEntry := range dayEntries {// println("checking day", dayEntry.FullPath)- hourMinuteEntries, listHourMinuteErr := f.ListDirectoryEntries(context.Background(), util.NewFullPath(SystemLogDir, dayEntry.Name()), "", false, 24*60, "")+ hourMinuteEntries, listHourMinuteErr := f.ListDirectoryEntries(context.Background(), util.NewFullPath(SystemLogDir, dayEntry.Name()), "", false, 24*60, "", "")if listHourMinuteErr != nil {return lastTsNs, fmt.Errorf("fail to list log %s by day: %v", dayEntry.Name(), listHourMinuteErr)}diff --git a/weed/filer/filer_search.go b/weed/filer/filer_search.goindex b26959cb08..34358d849d 100644--- a/weed/filer/filer_search.go+++ b/weed/filer/filer_search.go@@ -19,12 +19,16 @@ func splitPattern(pattern string) (prefix string, restPattern string) {return "", restPattern}-func (f *Filer) ListDirectoryEntries(ctx context.Context, p util.FullPath, startFileName string, inclusive bool, limit int, namePattern string) (entries []*Entry, err error) {+// For now, prefix and namePattern are mutually exclusive+func (f *Filer) ListDirectoryEntries(ctx context.Context, p util.FullPath, startFileName string, inclusive bool, limit int, prefix string, namePattern string) (entries []*Entry, err error) {if strings.HasSuffix(string(p), "/") && len(p) > 1 {p = p[0 : len(p)-1]}- prefix, restNamePattern := splitPattern(namePattern)+ prefixInNamePattern, restNamePattern := splitPattern(namePattern)+ if prefixInNamePattern != "" {+ prefix = prefixInNamePattern+ }var missedCount intvar lastFileName stringdiff --git a/weed/filer/leveldb/leveldb_store.go b/weed/filer/leveldb/leveldb_store.goindex b879f3a6ea..1aefbf5d49 100644--- a/weed/filer/leveldb/leveldb_store.go+++ b/weed/filer/leveldb/leveldb_store.go@@ -170,8 +170,12 @@ func (store *LevelDBStore) ListDirectoryEntries(ctx context.Context, fullpath wefunc (store *LevelDBStore) ListDirectoryPrefixedEntries(ctx context.Context, fullpath weed_util.FullPath, startFileName string, inclusive bool, limit int, prefix string) (entries []*filer.Entry, err error) {directoryPrefix := genDirectoryKeyPrefix(fullpath, prefix)+ lastFileStart := directoryPrefix+ if startFileName != "" {+ lastFileStart = genDirectoryKeyPrefix(fullpath, startFileName)+ }- iter := store.db.NewIterator(&leveldb_util.Range{Start: genDirectoryKeyPrefix(fullpath, startFileName)}, nil)+ iter := store.db.NewIterator(&leveldb_util.Range{Start: lastFileStart}, nil)for iter.Next() {key := iter.Key()if !bytes.HasPrefix(key, directoryPrefix) {diff --git a/weed/filer/leveldb/leveldb_store_test.go b/weed/filer/leveldb/leveldb_store_test.goindex c5bfb84743..c85a373329 100644--- a/weed/filer/leveldb/leveldb_store_test.go+++ b/weed/filer/leveldb/leveldb_store_test.go@@ -49,14 +49,14 @@ func TestCreateAndFind(t *testing.T) {}// checking one upper directory- entries, _ := testFiler.ListDirectoryEntries(ctx, util.FullPath("/home/chris/this/is/one"), "", false, 100, "")+ entries, _ := testFiler.ListDirectoryEntries(ctx, util.FullPath("/home/chris/this/is/one"), "", false, 100, "", "")if len(entries) != 1 {t.Errorf("list entries count: %v", len(entries))return}// checking one upper directory- entries, _ = testFiler.ListDirectoryEntries(ctx, util.FullPath("/"), "", false, 100, "")+ entries, _ = testFiler.ListDirectoryEntries(ctx, util.FullPath("/"), "", false, 100, "", "")if len(entries) != 1 {t.Errorf("list entries count: %v", len(entries))return@@ -75,7 +75,7 @@ func TestEmptyRoot(t *testing.T) {ctx := context.Background()// checking one upper directory- entries, err := testFiler.ListDirectoryEntries(ctx, util.FullPath("/"), "", false, 100, "")+ entries, err := testFiler.ListDirectoryEntries(ctx, util.FullPath("/"), "", false, 100, "", "")if err != nil {t.Errorf("list entries: %v", err)returndiff --git a/weed/filer/leveldb2/leveldb2_store.go b/weed/filer/leveldb2/leveldb2_store.goindex 4b41554b9c..ceda64153d 100644--- a/weed/filer/leveldb2/leveldb2_store.go+++ b/weed/filer/leveldb2/leveldb2_store.go@@ -179,7 +179,10 @@ func (store *LevelDB2Store) ListDirectoryEntries(ctx context.Context, fullpath wfunc (store *LevelDB2Store) ListDirectoryPrefixedEntries(ctx context.Context, fullpath weed_util.FullPath, startFileName string, inclusive bool, limit int, prefix string) (entries []*filer.Entry, err error) {directoryPrefix, partitionId := genDirectoryKeyPrefix(fullpath, prefix, store.dbCount)- lastFileStart, _ := genDirectoryKeyPrefix(fullpath, startFileName, store.dbCount)+ lastFileStart := directoryPrefix+ if startFileName != "" {+ lastFileStart, _ = genDirectoryKeyPrefix(fullpath, startFileName, store.dbCount)+ }iter := store.dbs[partitionId].NewIterator(&leveldb_util.Range{Start: lastFileStart}, nil)for iter.Next() {diff --git a/weed/filer/leveldb2/leveldb2_store_test.go b/weed/filer/leveldb2/leveldb2_store_test.goindex 22c0d6052b..a7f5ae95b6 100644--- a/weed/filer/leveldb2/leveldb2_store_test.go+++ b/weed/filer/leveldb2/leveldb2_store_test.go@@ -49,14 +49,14 @@ func TestCreateAndFind(t *testing.T) {}// checking one upper directory- entries, _ := testFiler.ListDirectoryEntries(ctx, util.FullPath("/home/chris/this/is/one"), "", false, 100, "")+ entries, _ := testFiler.ListDirectoryEntries(ctx, util.FullPath("/home/chris/this/is/one"), "", false, 100, "", "")if len(entries) != 1 {t.Errorf("list entries count: %v", len(entries))return}// checking one upper directory- entries, _ = testFiler.ListDirectoryEntries(ctx, util.FullPath("/"), "", false, 100, "")+ entries, _ = testFiler.ListDirectoryEntries(ctx, util.FullPath("/"), "", false, 100, "", "")if len(entries) != 1 {t.Errorf("list entries count: %v", len(entries))return@@ -75,7 +75,7 @@ func TestEmptyRoot(t *testing.T) {ctx := context.Background()// checking one upper directory- entries, err := testFiler.ListDirectoryEntries(ctx, util.FullPath("/"), "", false, 100, "")+ entries, err := testFiler.ListDirectoryEntries(ctx, util.FullPath("/"), "", false, 100, "", "")if err != nil {t.Errorf("list entries: %v", err)returndiff --git a/weed/server/filer_grpc_server.go b/weed/server/filer_grpc_server.goindex 38472df2a0..efc06f0d69 100644--- a/weed/server/filer_grpc_server.go+++ b/weed/server/filer_grpc_server.go@@ -61,7 +61,7 @@ func (fs *FilerServer) ListEntries(req *filer_pb.ListEntriesRequest, stream filelastFileName := req.StartFromFileNameincludeLastFile := req.InclusiveStartFromfor limit > 0 {- entries, err := fs.filer.ListDirectoryEntries(stream.Context(), util.FullPath(req.Directory), lastFileName, includeLastFile, paginationLimit, req.Prefix)+ entries, err := fs.filer.ListDirectoryEntries(stream.Context(), util.FullPath(req.Directory), lastFileName, includeLastFile, paginationLimit, req.Prefix, "")if err != nil {return errdiff --git a/weed/server/filer_grpc_server_rename.go b/weed/server/filer_grpc_server_rename.goindex fa86737acd..a0c9aedb96 100644--- a/weed/server/filer_grpc_server_rename.go+++ b/weed/server/filer_grpc_server_rename.go@@ -75,7 +75,7 @@ func (fs *FilerServer) moveFolderSubEntries(ctx context.Context, oldParent util.includeLastFile := falsefor {- entries, err := fs.filer.ListDirectoryEntries(ctx, currentDirPath, lastFileName, includeLastFile, 1024, "")+ entries, err := fs.filer.ListDirectoryEntries(ctx, currentDirPath, lastFileName, includeLastFile, 1024, "", "")if err != nil {return err}diff --git a/weed/server/filer_server_handlers_read_dir.go b/weed/server/filer_server_handlers_read_dir.goindex f303ba1d46..ba01ce4f78 100644--- a/weed/server/filer_server_handlers_read_dir.go+++ b/weed/server/filer_server_handlers_read_dir.go@@ -36,7 +36,7 @@ func (fs *FilerServer) listDirectoryHandler(w http.ResponseWriter, r *http.RequelastFileName := r.FormValue("lastFileName")namePattern := r.FormValue("namePattern")- entries, err := fs.filer.ListDirectoryEntries(context.Background(), util.FullPath(path), lastFileName, false, limit, namePattern)+ entries, err := fs.filer.ListDirectoryEntries(context.Background(), util.FullPath(path), lastFileName, false, limit, "", namePattern)if err != nil {glog.V(0).Infof("listDirectory %s %s %d: %s", path, lastFileName, limit, err)