From 5b43bddf20cb8b184d6defa29a8e9001f1708a12 Mon Sep 17 00:00:00 2001 From: Chris Lu Date: Sat, 15 Aug 2020 09:33:41 -0700 Subject: [PATCH] proper deletion ordering delete central file store first, then delete local cache --- weed/filer2/filer_delete_entry.go | 1 + weed/filesys/dir.go | 20 +++++++++----------- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/weed/filer2/filer_delete_entry.go b/weed/filer2/filer_delete_entry.go index a528f9152..d6a72e830 100644 --- a/weed/filer2/filer_delete_entry.go +++ b/weed/filer2/filer_delete_entry.go @@ -65,6 +65,7 @@ func (f *Filer) doBatchDeleteFolderMetaAndData(ctx context.Context, entry *Entry } if lastFileName == "" && !isRecursive && len(entries) > 0 { // only for first iteration in the loop + glog.Errorf("deleting a folder %s has children: %+v", entry.FullPath, entries) return nil, fmt.Errorf("fail to delete non-empty folder: %s", entry.FullPath) } diff --git a/weed/filesys/dir.go b/weed/filesys/dir.go index 818e85fd6..50ca6df5d 100644 --- a/weed/filesys/dir.go +++ b/weed/filesys/dir.go @@ -218,7 +218,7 @@ func (dir *Dir) Mkdir(ctx context.Context, req *fuse.MkdirRequest) (fs.Node, err func (dir *Dir) Lookup(ctx context.Context, req *fuse.LookupRequest, resp *fuse.LookupResponse) (node fs.Node, err error) { - glog.V(4).Infof("dir Lookup %s: %s by %s", dir.FullPath(), req.Name, req.Header.String()) + glog.V(5).Infof("dir Lookup %s: %s by %s", dir.FullPath(), req.Name, req.Header.String()) fullFilePath := util.NewFullPath(dir.FullPath(), req.Name) dirPath := util.FullPath(dir.FullPath()) @@ -316,10 +316,6 @@ func (dir *Dir) removeOneFile(req *fuse.RemoveRequest) error { dir.wfs.deleteFileChunks(entry.Chunks) - dir.wfs.fsNodeCache.DeleteFsNode(filePath) - - dir.wfs.metaCache.DeleteEntry(context.Background(), filePath) - glog.V(3).Infof("remove file: %v", req) err = filer_pb.Remove(dir.wfs, dir.FullPath(), req.Name, false, false, false, false) if err != nil { @@ -327,27 +323,29 @@ func (dir *Dir) removeOneFile(req *fuse.RemoveRequest) error { return fuse.ENOENT } + dir.wfs.metaCache.DeleteEntry(context.Background(), filePath) + dir.wfs.fsNodeCache.DeleteFsNode(filePath) + return nil } func (dir *Dir) removeFolder(req *fuse.RemoveRequest) error { - t := util.NewFullPath(dir.FullPath(), req.Name) - dir.wfs.fsNodeCache.DeleteFsNode(t) - - dir.wfs.metaCache.DeleteEntry(context.Background(), t) - glog.V(3).Infof("remove directory entry: %v", req) err := filer_pb.Remove(dir.wfs, dir.FullPath(), req.Name, true, false, false, false) if err != nil { - glog.V(3).Infof("remove %s/%s: %v", dir.FullPath(), req.Name, err) + glog.V(0).Infof("remove %s/%s: %v", dir.FullPath(), req.Name, err) if strings.Contains(err.Error(), "non-empty"){ return fuse.EEXIST } return fuse.ENOENT } + t := util.NewFullPath(dir.FullPath(), req.Name) + dir.wfs.metaCache.DeleteEntry(context.Background(), t) + dir.wfs.fsNodeCache.DeleteFsNode(t) + return nil }