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
rename: delete source entry metadata only, skipping hard links
chrislu03466f955e79
diff --git a/weed/filer/filer_delete_entry.go b/weed/filer/filer_delete_entry.goindex 425da7ceaf..c774f5d279 100644--- a/weed/filer/filer_delete_entry.go+++ b/weed/filer/filer_delete_entry.go@@ -125,7 +125,11 @@ func (f *Filer) doDeleteEntryMetaAndData(ctx context.Context, entry *Entry, shouglog.V(3).Infof("deleting entry %v, delete chunks: %v", entry.FullPath, shouldDeleteChunks)- if storeDeletionErr := f.Store.DeleteOneEntry(ctx, entry); storeDeletionErr != nil {+ if !entry.IsDirectory() && !shouldDeleteChunks {+ if storeDeletionErr := f.Store.DeleteOneEntrySkipHardlink(ctx, entry.FullPath); storeDeletionErr != nil {+ return fmt.Errorf("filer store delete skip hardlink: %v", storeDeletionErr)+ }+ } else if storeDeletionErr := f.Store.DeleteOneEntry(ctx, entry); storeDeletionErr != nil {return fmt.Errorf("filer store delete: %v", storeDeletionErr)}if !entry.IsDirectory() {diff --git a/weed/filer/filerstore_wrapper.go b/weed/filer/filerstore_wrapper.goindex a9650f7664..548a2c9df7 100644--- a/weed/filer/filerstore_wrapper.go+++ b/weed/filer/filerstore_wrapper.go@@ -23,6 +23,7 @@ type VirtualFilerStore interface {FilerStoreDeleteHardLink(ctx context.Context, hardLinkId HardLinkId) errorDeleteOneEntry(ctx context.Context, entry *Entry) error+ DeleteOneEntrySkipHardlink(ctx context.Context, fullpath util.FullPath) errorAddPathSpecificStore(path string, storeId string, store FilerStore)OnBucketCreation(bucket string)OnBucketDeletion(bucket string)@@ -216,6 +217,18 @@ func (fsw *FilerStoreWrapper) DeleteOneEntry(ctx context.Context, existingEntryreturn actualStore.DeleteEntry(ctx, existingEntry.FullPath)}+func (fsw *FilerStoreWrapper) DeleteOneEntrySkipHardlink(ctx context.Context, fullpath util.FullPath) (err error) {+ actualStore := fsw.getActualStore(fullpath)+ stats.FilerStoreCounter.WithLabelValues(actualStore.GetName(), "delete").Inc()+ start := time.Now()+ defer func() {+ stats.FilerStoreHistogram.WithLabelValues(actualStore.GetName(), "delete").Observe(time.Since(start).Seconds())+ }()++ glog.V(4).Infof("DeleteOneEntrySkipHardlink %s", fullpath)+ return actualStore.DeleteEntry(ctx, fullpath)+}+func (fsw *FilerStoreWrapper) DeleteFolderChildren(ctx context.Context, fp util.FullPath) (err error) {actualStore := fsw.getActualStore(fp + "/")stats.FilerStoreCounter.WithLabelValues(actualStore.GetName(), "deleteFolderChildren").Inc()diff --git a/weed/mount/meta_cache/meta_cache.go b/weed/mount/meta_cache/meta_cache.goindex 7f997c5b03..994f00463e 100644--- a/weed/mount/meta_cache/meta_cache.go+++ b/weed/mount/meta_cache/meta_cache.go@@ -62,7 +62,7 @@ func (mc *MetaCache) doInsertEntry(ctx context.Context, entry *filer.Entry) erroreturn mc.localStore.InsertEntry(ctx, entry)}-func (mc *MetaCache) AtomicUpdateEntryFromFiler(ctx context.Context, oldPath util.FullPath, newEntry *filer.Entry) error {+func (mc *MetaCache) AtomicUpdateEntryFromFiler(ctx context.Context, oldPath util.FullPath, newEntry *filer.Entry, shouldDeleteChunks bool) error {//mc.Lock()//defer mc.Unlock()@@ -74,8 +74,14 @@ func (mc *MetaCache) AtomicUpdateEntryFromFiler(ctx context.Context, oldPath uti// leave the update to the following InsertEntry operation} else {glog.V(3).Infof("DeleteEntry %s", oldPath)- if err := mc.localStore.DeleteEntry(ctx, oldPath); err != nil {- return err+ if shouldDeleteChunks {+ if err := mc.localStore.DeleteEntry(ctx, oldPath); err != nil {+ return err+ }+ } else {+ if err := mc.localStore.DeleteOneEntrySkipHardlink(ctx, oldPath); err != nil {+ return err+ }}}}@@ -112,6 +118,12 @@ func (mc *MetaCache) FindEntry(ctx context.Context, fp util.FullPath) (entry *fireturn}+func (mc *MetaCache) DeleteEntrySkipHardlink(ctx context.Context, fp util.FullPath) (err error) {+ //mc.Lock()+ //defer mc.Unlock()+ return mc.localStore.DeleteOneEntrySkipHardlink(ctx, fp)+}+func (mc *MetaCache) DeleteEntry(ctx context.Context, fp util.FullPath) (err error) {//mc.Lock()//defer mc.Unlock()diff --git a/weed/mount/meta_cache/meta_cache_subscribe.go b/weed/mount/meta_cache/meta_cache_subscribe.goindex a0c5935ca7..12ce8d8a79 100644--- a/weed/mount/meta_cache/meta_cache_subscribe.go+++ b/weed/mount/meta_cache/meta_cache_subscribe.go@@ -36,7 +36,7 @@ func SubscribeMetaEvents(mc *MetaCache, selfSignature int32, client filer_pb.Filglog.V(4).Infof("creating %v", key)newEntry = filer.FromPbEntry(dir, message.NewEntry)}- err := mc.AtomicUpdateEntryFromFiler(context.Background(), oldPath, newEntry)+ err := mc.AtomicUpdateEntryFromFiler(context.Background(), oldPath, newEntry, message.DeleteChunks)if err == nil {if message.OldEntry != nil && message.NewEntry != nil {oldKey := util.NewFullPath(resp.Directory, message.OldEntry.Name)diff --git a/weed/mount/weedfs_rename.go b/weed/mount/weedfs_rename.goindex 9c83a4b94a..44f3c910c3 100644--- a/weed/mount/weedfs_rename.go+++ b/weed/mount/weedfs_rename.go@@ -217,7 +217,7 @@ func (wfs *WFS) handleRenameResponse(ctx context.Context, resp *filer_pb.StreamRif resp.EventNotification.NewEntry != nil {// with new entry, the old entry name also exists. This is the first step to create new entrynewEntry := filer.FromPbEntry(resp.EventNotification.NewParentPath, resp.EventNotification.NewEntry)- if err := wfs.metaCache.AtomicUpdateEntryFromFiler(ctx, "", newEntry); err != nil {+ if err := wfs.metaCache.AtomicUpdateEntryFromFiler(ctx, "", newEntry, false); err != nil {return err}@@ -231,7 +231,7 @@ func (wfs *WFS) handleRenameResponse(ctx context.Context, resp *filer_pb.StreamR} else if resp.EventNotification.OldEntry != nil {// without new entry, only old entry name exists. This is the second step to delete old entry- if err := wfs.metaCache.AtomicUpdateEntryFromFiler(ctx, util.NewFullPath(resp.Directory, resp.EventNotification.OldEntry.Name), nil); err != nil {+ if err := wfs.metaCache.AtomicUpdateEntryFromFiler(ctx, util.NewFullPath(resp.Directory, resp.EventNotification.OldEntry.Name), nil, resp.EventNotification.DeleteChunks); err != nil {return err}}