Skip to content

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.

clear cache directory when mount exits (#6605)

lizhengui00761249d8dde37
diff --git a/weed/command/mount_std.go b/weed/command/mount_std.go
index e4209449aa..f00daba8a3 100644
--- a/weed/command/mount_std.go
+++ b/weed/command/mount_std.go
@@ -284,5 +284,7 @@ func RunMount(option *MountOptions, umask os.FileMode) bool {
server.Serve()
+ seaweedFileSystem.ClearCacheDir()
+
return true
}
diff --git a/weed/mount/weedfs.go b/weed/mount/weedfs.go
index 7b67a8f32f..77ffb7e779 100644
--- a/weed/mount/weedfs.go
+++ b/weed/mount/weedfs.go
@@ -224,6 +224,12 @@ func (wfs *WFS) getCurrentFiler() pb.ServerAddress {
return wfs.option.FilerAddresses[i]
}
+func (wfs *WFS) ClearCacheDir() {
+ wfs.metaCache.Shutdown()
+ os.RemoveAll(wfs.option.getUniqueCacheDirForWrite())
+ os.RemoveAll(wfs.option.getUniqueCacheDirForRead())
+}
+
func (option *Option) setupUniqueCacheDirectory() {
cacheUniqueId := util.Md5String([]byte(option.MountDirectory + string(option.FilerAddresses[0]) + option.FilerMountRootPath + util.Version()))[0:8]
option.uniqueCacheDirForRead = path.Join(option.CacheDirForRead, cacheUniqueId)