aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorchrislu <chris.lu@gmail.com>2024-06-09 12:14:10 -0700
committerchrislu <chris.lu@gmail.com>2024-06-09 12:14:10 -0700
commitdbfbabac5592d7dd5e4999c35b0619aa20921d6b (patch)
treebe02a262e7a0a2d2268d07211fde88f43b3532a4
parent2150289442f1f84903ada4514807c5c397545440 (diff)
downloadseaweedfs-dbfbabac5592d7dd5e4999c35b0619aa20921d6b.tar.xz
seaweedfs-dbfbabac5592d7dd5e4999c35b0619aa20921d6b.zip
simplify
-rw-r--r--weed/filer/filer_deletion.go43
1 files changed, 7 insertions, 36 deletions
diff --git a/weed/filer/filer_deletion.go b/weed/filer/filer_deletion.go
index 439a5296f..ccb732380 100644
--- a/weed/filer/filer_deletion.go
+++ b/weed/filer/filer_deletion.go
@@ -2,7 +2,6 @@ package filer
import (
"github.com/seaweedfs/seaweedfs/weed/storage"
- "math"
"strings"
"time"
@@ -138,47 +137,19 @@ func (f *Filer) DeleteChunksNotRecursive(chunks []*filer_pb.FileChunk) {
}
func (f *Filer) deleteChunksIfNotNew(oldEntry, newEntry *Entry) {
-
- if oldEntry == nil {
- return
+ var oldChunks, newChunks []*filer_pb.FileChunk
+ if oldEntry != nil {
+ oldChunks = oldEntry.GetChunks()
}
- if newEntry == nil {
- f.DeleteChunks(oldEntry.GetChunks())
- return
+ if newEntry != nil {
+ newChunks = newEntry.GetChunks()
}
- var toDelete []*filer_pb.FileChunk
- newChunkIds := make(map[string]bool)
- newDataChunks, newManifestChunks, err := ResolveChunkManifest(f.MasterClient.GetLookupFileIdFunction(),
- newEntry.GetChunks(), 0, math.MaxInt64)
- if err != nil {
- glog.Errorf("Failed to resolve new entry chunks when delete old entry chunks. new: %s, old: %s",
- newEntry.GetChunks(), oldEntry.Chunks)
- return
- }
- for _, newChunk := range newDataChunks {
- newChunkIds[newChunk.GetFileIdString()] = true
- }
- for _, newChunk := range newManifestChunks {
- newChunkIds[newChunk.GetFileIdString()] = true
- }
-
- oldDataChunks, oldManifestChunks, err := ResolveChunkManifest(f.MasterClient.GetLookupFileIdFunction(),
- oldEntry.GetChunks(), 0, math.MaxInt64)
+ toDelete, err := MinusChunks(f.MasterClient.GetLookupFileIdFunction(), oldChunks, newChunks)
if err != nil {
glog.Errorf("Failed to resolve old entry chunks when delete old entry chunks. new: %s, old: %s",
- newEntry.GetChunks(), oldEntry.GetChunks())
+ newChunks, oldChunks)
return
}
- for _, oldChunk := range oldDataChunks {
- if _, found := newChunkIds[oldChunk.GetFileIdString()]; !found {
- toDelete = append(toDelete, oldChunk)
- }
- }
- for _, oldChunk := range oldManifestChunks {
- if _, found := newChunkIds[oldChunk.GetFileIdString()]; !found {
- toDelete = append(toDelete, oldChunk)
- }
- }
f.DeleteChunksNotRecursive(toDelete)
}