Browse Source

Filer: Refactor deletion processors for better readability

Extract large callback functions into dedicated private methods to
improve code organization and maintainability.

Changes:
1. Extract processDeletionBatch method
   - Handles deletion of a batch of file IDs
   - Classifies errors (success, not found, retryable, permanent)
   - Manages retry queue additions
   - Consolidates logging logic

2. Extract processRetryBatch method
   - Handles retry attempts for previously failed deletions
   - Processes retry results and updates queue
   - Symmetric to processDeletionBatch for consistency

Benefits:
- Main loop functions (loopProcessingDeletion, loopProcessingDeletionRetry)
  are now concise and focused on orchestration
- Business logic is separated into testable methods
- Reduced nesting depth improves readability
- Easier to understand control flow at a glance
- Better separation of concerns

The refactored methods follow the single responsibility principle,
making the codebase more maintainable and easier to extend.
pull/7402/head
Dimonyga 2 months ago
parent
commit
288695030d
  1. 25
      weed/filer/filer_deletion.go

25
weed/filer/filer_deletion.go

@ -218,6 +218,17 @@ func (f *Filer) loopProcessingDeletion() {
toDeleteFileIds = fileIds
fileIds = fileIds[:0]
}
f.processDeletionBatch(toDeleteFileIds, lookupFunc, retryQueue)
}
})
}
}
}
// processDeletionBatch handles deletion of a batch of file IDs and processes results.
// It classifies errors into retryable and permanent categories, adds retryable failures
// to the retry queue, and logs appropriate messages.
func (f *Filer) processDeletionBatch(toDeleteFileIds []string, lookupFunc func([]string) (map[string]*operation.LookupResult, error), retryQueue *DeletionRetryQueue) {
results := operation.DeleteFileIdsWithLookupVolumeId(f.GrpcDialOption, toDeleteFileIds, lookupFunc)
// Process individual results for better error tracking
@ -264,10 +275,6 @@ func (f *Filer) loopProcessingDeletion() {
glog.V(2).Infof("retry queue size: %d", retryQueue.Size())
}
}
})
}
}
}
// isRetryableError determines if an error is retryable based on its message.
//
@ -327,7 +334,15 @@ func (f *Filer) loopProcessingDeletionRetry(lookupFunc func([]string) (map[strin
}
glog.V(1).Infof("retrying deletion of %d files", len(readyItems))
f.processRetryBatch(readyItems, lookupFunc, retryQueue)
}
}
}
// processRetryBatch attempts to retry deletion of files and processes results.
// Successfully deleted items are removed from tracking, retryable failures are
// re-queued with updated retry counts, and permanent errors are logged and discarded.
func (f *Filer) processRetryBatch(readyItems []*DeletionRetryItem, lookupFunc func([]string) (map[string]*operation.LookupResult, error), retryQueue *DeletionRetryQueue) {
// Extract file IDs from retry items
var fileIds []string
itemsByFileId := make(map[string]*DeletionRetryItem)
@ -367,8 +382,6 @@ func (f *Filer) loopProcessingDeletionRetry(lookupFunc func([]string) (map[strin
glog.V(1).Infof("retry: %d files still failing, will retry again later", retryCount)
}
}
}
}
func (f *Filer) DeleteUncommittedChunks(ctx context.Context, chunks []*filer_pb.FileChunk) {
f.doDeleteChunks(ctx, chunks)

Loading…
Cancel
Save