mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-05 02:27:26 +01:00
filer: end retried deletions of chunks on volumes the master no longer knows (#12860)
* filer: end retried deletions of chunks on volumes the master no longer knows The deletion lookup read volume locations from the client's cache only. A chunk on a volume the cluster no longer has (a dropped collection, a removed bucket) found no location, so no volume server was asked, no deletion result came back, and the retry queue re-queued it "to avoid loss". The durable deletion ledger keeps such ids and reloads them with a fresh retry count on every restart, so MaxRetryAttempts never ends them: on one deployment 2,337 chunks on 159 deleted volumes were retried 2-4 times an hour for days, ~7,000 warnings an hour. The retry loop's lookup now asks the master about the volumes the cache does not know. A location found is used. A "volume id N not found" answer is not proof on its own (a live volume whose server is away answers the same, and so does a follower's cold cache), so it only starts a streak on the retry item: once the master has answered it for VolumeGoneGrace (30 min) over at least VolumeGoneMinAnswers (3) retries in a row, the chunk counts as deleted with its volume and leaves the queue and the ledger. Any other outcome, a failure to ask included, resets the streak and keeps the id retried as before. The hot deletion loop and the remote-cache flush keep the cache-only lookup. * filer: hold a volume-gone deletion for MaxRetryDelay before dropping it A volume server that is down for longer than half an hour gets the same "not found" answer from the master as a deleted volume, so the 30 minute grace dropped pending deletions of chunks that come back with the server. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * filer: test the answer count once the volume-gone grace has passed Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Chris Lu <chrislusf@users.noreply.github.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2 files changed
+208
-22
No files matched your search
+140
-22
@@ -17,6 +17,7 @@ import (
|
||||
"github.com/seaweedfs/seaweedfs/weed/glog"
|
||||
"github.com/seaweedfs/seaweedfs/weed/operation"
|
||||
"github.com/seaweedfs/seaweedfs/weed/pb/filer_pb"
|
||||
"github.com/seaweedfs/seaweedfs/weed/pb/master_pb"
|
||||
"github.com/seaweedfs/seaweedfs/weed/pb/volume_server_pb"
|
||||
"github.com/seaweedfs/seaweedfs/weed/wdclient"
|
||||
)
|
||||
@@ -68,10 +69,14 @@ type DeletionRetryItem struct {
|
||||
NextRetryAt time.Time
|
||||
LastError string
|
||||
ledgerEpoch uint64 // pendingDeletions epoch when the item was queued; expiry forgets only a matching epoch
|
||||
heapIndex int // index in the heap (for heap.Interface)
|
||||
inFlight bool // true when item is being processed, prevents duplicate additions
|
||||
manifest *filer_pb.FileChunk
|
||||
fsync bool
|
||||
// goneSince and goneSeen track consecutive retries the master answered
|
||||
// "volume not found" for (volumeGoneConfirmed).
|
||||
goneSince time.Time
|
||||
goneSeen int
|
||||
heapIndex int // index in the heap (for heap.Interface)
|
||||
inFlight bool // true when item is being processed, prevents duplicate additions
|
||||
manifest *filer_pb.FileChunk
|
||||
fsync bool
|
||||
}
|
||||
|
||||
// retryHeap implements heap.Interface for DeletionRetryItem
|
||||
@@ -310,29 +315,126 @@ func LookupByMasterClientFn(masterClient *wdclient.MasterClient) func(vids []str
|
||||
m := make(map[string]*operation.LookupResult)
|
||||
for _, vid := range vids {
|
||||
locs, _ := masterClient.GetVidLocations(vid)
|
||||
var locations []operation.Location
|
||||
for _, loc := range locs {
|
||||
locations = append(locations, operation.Location{
|
||||
Url: loc.Url,
|
||||
PublicUrl: loc.PublicUrl,
|
||||
GrpcPort: loc.GrpcPort,
|
||||
})
|
||||
}
|
||||
m[vid] = &operation.LookupResult{
|
||||
VolumeOrFileId: vid,
|
||||
Locations: locations,
|
||||
Locations: toOperationLocations(locs),
|
||||
}
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
}
|
||||
|
||||
func toOperationLocations(locs []wdclient.Location) []operation.Location {
|
||||
var locations []operation.Location
|
||||
for _, loc := range locs {
|
||||
locations = append(locations, operation.Location{
|
||||
Url: loc.Url,
|
||||
PublicUrl: loc.PublicUrl,
|
||||
GrpcPort: loc.GrpcPort,
|
||||
})
|
||||
}
|
||||
return locations
|
||||
}
|
||||
|
||||
// volumeGoneError starts the lookup error of a volume the master answered
|
||||
// "not found" for. That is what a deleted volume (a dropped collection, a
|
||||
// removed bucket) answers, but also a live one whose server is disconnected
|
||||
// for now, or one a follower master has not cached yet; so the retry loop
|
||||
// ends such a deletion only once the answer has held (volumeGoneConfirmed).
|
||||
const volumeGoneError = "volume not found by the master"
|
||||
|
||||
const (
|
||||
// masterLookupTimeout bounds the retry loop's master lookup.
|
||||
masterLookupTimeout = 5 * time.Second
|
||||
// VolumeGoneGrace and VolumeGoneMinAnswers: how long, and over how many
|
||||
// retries in a row, the master must answer "not found" for a volume
|
||||
// before its pending chunk deletions count as done. A volume server that
|
||||
// is down gets the same answer, so the grace outlasts a maintenance
|
||||
// window rather than a reconnect.
|
||||
VolumeGoneGrace = MaxRetryDelay
|
||||
VolumeGoneMinAnswers = 3
|
||||
)
|
||||
|
||||
// retryLookupFn is the retry loop's lookup: the client's cache, then the
|
||||
// master for the volumes the cache does not know. Without it a chunk on a
|
||||
// deleted volume reached no volume server, got no deletion result, and was
|
||||
// re-queued forever: the durable ledger reloads it with a fresh retry count
|
||||
// on every restart.
|
||||
func retryLookupFn(masterClient *wdclient.MasterClient) func(vids []string) (map[string]*operation.LookupResult, error) {
|
||||
return lookupWithMasterFallback(masterClient.GetVidLocations, func(vids []string) (*master_pb.LookupVolumeResponse, error) {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), masterLookupTimeout)
|
||||
defer cancel()
|
||||
var resp *master_pb.LookupVolumeResponse
|
||||
err := masterClient.WithClient(ctx, false, func(client master_pb.SeaweedClient) error {
|
||||
r, err := client.LookupVolume(ctx, &master_pb.LookupVolumeRequest{VolumeOrFileIds: vids})
|
||||
resp = r
|
||||
return err
|
||||
})
|
||||
return resp, err
|
||||
})
|
||||
}
|
||||
|
||||
// lookupWithMasterFallback resolves locations from the cache and asks the
|
||||
// master about the rest. A volume the master has no location for and answers
|
||||
// "... not found" carries volumeGoneError; any failure to ask leaves the
|
||||
// volume without locations, as before (no result, retried).
|
||||
func lookupWithMasterFallback(cached func(vid string) ([]wdclient.Location, error),
|
||||
askMaster func(vids []string) (*master_pb.LookupVolumeResponse, error)) func(vids []string) (map[string]*operation.LookupResult, error) {
|
||||
return func(vids []string) (map[string]*operation.LookupResult, error) {
|
||||
m := make(map[string]*operation.LookupResult)
|
||||
var missing []string
|
||||
for _, vid := range vids {
|
||||
locs, _ := cached(vid)
|
||||
m[vid] = &operation.LookupResult{VolumeOrFileId: vid, Locations: toOperationLocations(locs)}
|
||||
if len(m[vid].Locations) == 0 {
|
||||
missing = append(missing, vid)
|
||||
}
|
||||
}
|
||||
if len(missing) == 0 {
|
||||
return m, nil
|
||||
}
|
||||
resp, err := askMaster(missing)
|
||||
if err != nil || resp == nil {
|
||||
glog.V(1).Infof("deletion retry: master lookup of %d uncached volumes: %v", len(missing), err)
|
||||
return m, nil
|
||||
}
|
||||
for _, vl := range resp.VolumeIdLocations {
|
||||
vid := vl.VolumeOrFileId
|
||||
if i := strings.Index(vid, ","); i > 0 {
|
||||
vid = vid[:i]
|
||||
}
|
||||
r, ok := m[vid]
|
||||
if !ok || len(r.Locations) > 0 {
|
||||
continue
|
||||
}
|
||||
for _, loc := range vl.Locations {
|
||||
r.Locations = append(r.Locations, operation.Location{Url: loc.Url, PublicUrl: loc.PublicUrl, GrpcPort: int(loc.GrpcPort)})
|
||||
}
|
||||
if len(r.Locations) == 0 && strings.HasSuffix(vl.Error, "not found") {
|
||||
r.Error = volumeGoneError + ": " + vl.Error
|
||||
}
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
}
|
||||
|
||||
// volumeGoneConfirmed records one more "volume not found" answer for the item
|
||||
// and reports whether the answers have held long enough to treat the chunk as
|
||||
// gone with its volume. Any other outcome resets the streak.
|
||||
func volumeGoneConfirmed(item *DeletionRetryItem, now time.Time) bool {
|
||||
if item.goneSeen == 0 {
|
||||
item.goneSince = now
|
||||
}
|
||||
item.goneSeen++
|
||||
return item.goneSeen >= VolumeGoneMinAnswers && now.Sub(item.goneSince) >= VolumeGoneGrace
|
||||
}
|
||||
|
||||
func (f *Filer) loopProcessingDeletion() {
|
||||
|
||||
lookupFunc := LookupByMasterClientFn(f.MasterClient)
|
||||
|
||||
// Start retry processor in a separate goroutine
|
||||
go f.loopProcessingDeletionRetry(lookupFunc)
|
||||
go f.loopProcessingDeletionRetry(retryLookupFn(f.MasterClient))
|
||||
|
||||
ticker := time.NewTicker(DeletionPollInterval)
|
||||
defer ticker.Stop()
|
||||
@@ -406,7 +508,7 @@ func (f *Filer) processDeletionBatch(ctx context.Context, toDeleteFileIds []stri
|
||||
case deletionOutcomeNotFound:
|
||||
notFoundCount++
|
||||
f.forgetDeletion(fileId, fsynced) // already gone: drop from durable ledger
|
||||
case deletionOutcomeRetryable, deletionOutcomeNoResult:
|
||||
case deletionOutcomeRetryable, deletionOutcomeNoResult, deletionOutcomeVolumeGone:
|
||||
retryableErrorCount++
|
||||
// Keep in the durable ledger: not confirmed, must survive restarts.
|
||||
f.DeletionRetryQueue.AddOrUpdate(fileId, outcome.errorMsg, f.deletionEpoch(fileId))
|
||||
@@ -447,11 +549,12 @@ func (f *Filer) processDeletionBatch(ctx context.Context, toDeleteFileIds []stri
|
||||
}
|
||||
|
||||
const (
|
||||
deletionOutcomeSuccess = "success"
|
||||
deletionOutcomeNotFound = "not_found"
|
||||
deletionOutcomeRetryable = "retryable"
|
||||
deletionOutcomePermanent = "permanent"
|
||||
deletionOutcomeNoResult = "no_result"
|
||||
deletionOutcomeSuccess = "success"
|
||||
deletionOutcomeNotFound = "not_found"
|
||||
deletionOutcomeRetryable = "retryable"
|
||||
deletionOutcomePermanent = "permanent"
|
||||
deletionOutcomeNoResult = "no_result"
|
||||
deletionOutcomeVolumeGone = "volume_gone"
|
||||
)
|
||||
|
||||
// deletionOutcome represents the result of classifying deletion results for a file
|
||||
@@ -513,6 +616,9 @@ func classifyDeletionOutcome(fileId string, resultsByFileId map[string][]*volume
|
||||
hasSuccess := false
|
||||
|
||||
for _, res := range fileIdResults {
|
||||
if strings.HasPrefix(res.Error, volumeGoneError) {
|
||||
return deletionOutcome{status: deletionOutcomeVolumeGone, errorMsg: res.Error}
|
||||
}
|
||||
if res.Error == "" {
|
||||
hasSuccess = true
|
||||
continue
|
||||
@@ -638,11 +744,20 @@ func (f *Filer) processRetryBatch(readyItems []*DeletionRetryItem, lookupFunc fu
|
||||
outcomes := deleteFilesAndClassify(context.Background(), f.volumeGrpcDialOption(), fileIds, fsyncIds, lookupFunc)
|
||||
|
||||
// Process outcomes - iterate over readyItems to ensure all items are accounted for
|
||||
var successCount, notFoundCount, retryCount, permanentErrorCount int
|
||||
var successCount, notFoundCount, retryCount, permanentErrorCount, volumeGoneCount int
|
||||
for _, item := range readyItems {
|
||||
outcome := outcomes[item.FileId]
|
||||
_, fsynced := fsyncIds[item.FileId]
|
||||
|
||||
if outcome.status != deletionOutcomeVolumeGone {
|
||||
item.goneSeen = 0
|
||||
}
|
||||
if outcome.status == deletionOutcomeVolumeGone && volumeGoneConfirmed(item, time.Now()) {
|
||||
// the master has not known the volume for VolumeGoneGrace: the
|
||||
// chunk went with it
|
||||
volumeGoneCount++
|
||||
outcome.status = deletionOutcomeNotFound
|
||||
}
|
||||
switch outcome.status {
|
||||
case deletionOutcomeSuccess:
|
||||
successCount++
|
||||
@@ -653,7 +768,7 @@ func (f *Filer) processRetryBatch(readyItems []*DeletionRetryItem, lookupFunc fu
|
||||
notFoundCount++
|
||||
f.DeletionRetryQueue.Remove(item) // Remove from queue (already deleted)
|
||||
f.forgetDeletion(item.FileId, fsynced) // already gone: drop from durable ledger
|
||||
case deletionOutcomeRetryable, deletionOutcomeNoResult:
|
||||
case deletionOutcomeRetryable, deletionOutcomeNoResult, deletionOutcomeVolumeGone:
|
||||
retryCount++
|
||||
if outcome.status == deletionOutcomeNoResult {
|
||||
glog.Warningf("no deletion result for retried file %s, re-queuing to avoid loss", item.FileId)
|
||||
@@ -678,6 +793,9 @@ func (f *Filer) processRetryBatch(readyItems []*DeletionRetryItem, lookupFunc fu
|
||||
if retryCount > 0 {
|
||||
glog.V(1).Infof("retry: %d files still failing, will retry again later", retryCount)
|
||||
}
|
||||
if volumeGoneCount > 0 {
|
||||
glog.V(0).Infof("retry: %d files were on volumes the master has not known for %v, dropped as deleted with their volume", volumeGoneCount, VolumeGoneGrace)
|
||||
}
|
||||
if permanentErrorCount > 0 {
|
||||
glog.Warningf("retry: %d files failed with permanent errors", permanentErrorCount)
|
||||
}
|
||||
|
||||
@@ -8,8 +8,13 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"google.golang.org/grpc"
|
||||
"google.golang.org/grpc/credentials/insecure"
|
||||
|
||||
"github.com/seaweedfs/seaweedfs/weed/cluster/lock_manager"
|
||||
"github.com/seaweedfs/seaweedfs/weed/pb/master_pb"
|
||||
"github.com/seaweedfs/seaweedfs/weed/util"
|
||||
"github.com/seaweedfs/seaweedfs/weed/wdclient"
|
||||
)
|
||||
|
||||
// readPersistedLedger pulls the persisted ledger payload straight from the store
|
||||
@@ -582,3 +587,66 @@ func contains(haystack []string, needle string) bool {
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// A pending deletion on a volume the master no longer knows leaves the ledger
|
||||
// only once the master's "not found" has held for VolumeGoneGrace over
|
||||
// VolumeGoneMinAnswers retries: before that (a volume server away for a while,
|
||||
// a follower's cold cache) and whenever the master cannot answer, it stays.
|
||||
// Without this, the ledger reloaded such ids on every restart and retried them
|
||||
// forever.
|
||||
func TestDeletionLedgerVolumeGoneConfirmed(t *testing.T) {
|
||||
withPersistedConfig(t, true)
|
||||
noCache := func(vid string) ([]wdclient.Location, error) { return nil, fmt.Errorf("volume %s not cached", vid) }
|
||||
gone := lookupWithMasterFallback(noCache, func(vids []string) (*master_pb.LookupVolumeResponse, error) {
|
||||
resp := &master_pb.LookupVolumeResponse{}
|
||||
for _, v := range vids {
|
||||
resp.VolumeIdLocations = append(resp.VolumeIdLocations, &master_pb.LookupVolumeResponse_VolumeIdLocation{
|
||||
VolumeOrFileId: v, Error: "volume id " + v + " not found"})
|
||||
}
|
||||
return resp, nil
|
||||
})
|
||||
unavailable := lookupWithMasterFallback(noCache, func(vids []string) (*master_pb.LookupVolumeResponse, error) {
|
||||
return nil, fmt.Errorf("rpc error: code = Unavailable desc = master is warming up, topology is still loading")
|
||||
})
|
||||
|
||||
f := newLedgerTestFiler(newStubFilerStore())
|
||||
f.GrpcDialOption = grpc.WithTransportCredentials(insecure.NewCredentials())
|
||||
f.queueDeletions(false, "274,01")
|
||||
pending := func() bool { return f.deletionEpoch("274,01") != 0 }
|
||||
item := &DeletionRetryItem{FileId: "274,01", ledgerEpoch: f.deletionEpoch("274,01")}
|
||||
|
||||
// first answers: kept
|
||||
f.processRetryBatch([]*DeletionRetryItem{item}, gone)
|
||||
f.processRetryBatch([]*DeletionRetryItem{item}, gone)
|
||||
if !pending() || item.goneSeen != 2 {
|
||||
t.Fatalf("after two answers: pending=%v goneSeen=%d, want kept with a streak of 2", pending(), item.goneSeen)
|
||||
}
|
||||
// the master cannot answer: kept, and the streak starts over
|
||||
item.goneSince = time.Now().Add(-VolumeGoneGrace - time.Minute)
|
||||
f.processRetryBatch([]*DeletionRetryItem{item}, unavailable)
|
||||
if !pending() || item.goneSeen != 0 {
|
||||
t.Fatalf("master unavailable: pending=%v goneSeen=%d, want kept with the streak reset", pending(), item.goneSeen)
|
||||
}
|
||||
// enough answers, but not for long enough: kept
|
||||
for i := 0; i < VolumeGoneMinAnswers+2; i++ {
|
||||
f.processRetryBatch([]*DeletionRetryItem{item}, gone)
|
||||
}
|
||||
if !pending() {
|
||||
t.Fatalf("answers within a few seconds dropped the deletion; want kept until VolumeGoneGrace")
|
||||
}
|
||||
// held for longer than the grace, but over too few answers: kept
|
||||
f.processRetryBatch([]*DeletionRetryItem{item}, unavailable)
|
||||
f.processRetryBatch([]*DeletionRetryItem{item}, gone)
|
||||
item.goneSince = time.Now().Add(-VolumeGoneGrace - time.Minute)
|
||||
for i := 1; i < VolumeGoneMinAnswers-1; i++ {
|
||||
f.processRetryBatch([]*DeletionRetryItem{item}, gone)
|
||||
}
|
||||
if !pending() {
|
||||
t.Fatalf("%d answers over the grace dropped the deletion; want kept until %d", item.goneSeen, VolumeGoneMinAnswers)
|
||||
}
|
||||
// enough answers over the grace: dropped from the ledger
|
||||
f.processRetryBatch([]*DeletionRetryItem{item}, gone)
|
||||
if pending() {
|
||||
t.Fatalf("volume unknown to the master for %v: the deletion is still pending", VolumeGoneGrace)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user