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.

truncate is a bit faster to reuse the storage

Chris Lu6bc09b18c4a6
diff --git a/weed/util/chunk_cache/chunk_cache_on_disk.go b/weed/util/chunk_cache/chunk_cache_on_disk.go
index d724e925ed..6f87a9a062 100644
--- a/weed/util/chunk_cache/chunk_cache_on_disk.go
+++ b/weed/util/chunk_cache/chunk_cache_on_disk.go
@@ -88,15 +88,17 @@ func (v *ChunkCacheVolume) Shutdown() {
}
}
-func (v *ChunkCacheVolume) destroy() {
+func (v *ChunkCacheVolume) doReset() {
v.Shutdown()
- os.Remove(v.fileName + ".dat")
- os.Remove(v.fileName + ".idx")
+ os.Truncate(v.fileName + ".dat", 0)
+ os.Truncate(v.fileName + ".idx", 0)
+ glog.V(4).Infof("cache removeAll %s ...", v.fileName + ".ldb")
os.RemoveAll(v.fileName + ".ldb")
+ glog.V(4).Infof("cache removed %s", v.fileName + ".ldb")
}
func (v *ChunkCacheVolume) Reset() (*ChunkCacheVolume, error) {
- v.destroy()
+ v.doReset()
return LoadOrCreateChunkCacheVolume(v.fileName, v.sizeLimit)
}