aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorchrislu <chris.lu@gmail.com>2025-10-26 01:32:50 -0700
committerchrislu <chris.lu@gmail.com>2025-10-26 01:32:50 -0700
commit31f905ce2a2a3cd2643930a34cd786abe6315473 (patch)
treee5f8da33d6eb3985299893e785f53acc521836da
parent51edda33561265e232b1686dfd913f0eb1f923be (diff)
downloadseaweedfs-31f905ce2a2a3cd2643930a34cd786abe6315473.tar.xz
seaweedfs-31f905ce2a2a3cd2643930a34cd786abe6315473.zip
Update disk_location_ec.go
When loadEcShards() fails partway through, some EC shards may already be loaded into the l.ecVolumes map in memory. The previous code only cleaned up filesystem files but left orphaned in-memory state, which could cause memory leaks and inconsistent state.
-rw-r--r--weed/storage/disk_location_ec.go32
1 files changed, 18 insertions, 14 deletions
diff --git a/weed/storage/disk_location_ec.go b/weed/storage/disk_location_ec.go
index 5286ad84f..b30a42ba6 100644
--- a/weed/storage/disk_location_ec.go
+++ b/weed/storage/disk_location_ec.go
@@ -208,26 +208,30 @@ func (l *DiskLocation) loadAllEcShards() (err error) {
continue
}
- if err = l.loadEcShards(sameVolumeShards, collection, volumeId); err != nil {
- // If EC shards failed to load and .dat still exists, clean up EC files to allow .dat file to be used
- // If .dat is gone, log error but don't clean up (may be waiting for shards from other servers)
- if datExists {
- glog.Warningf("Failed to load EC shards for volume %d and .dat exists: %v, cleaning up EC files to use .dat...", volumeId, err)
- l.removeEcVolumeFiles(collection, volumeId)
- } else {
- glog.Warningf("Failed to load EC shards for volume %d: %v (this may be normal for distributed EC volumes)", volumeId, err)
- }
- sameVolumeShards = nil
- prevVolumeId = 0
- continue
+ if err = l.loadEcShards(sameVolumeShards, collection, volumeId); err != nil {
+ // If EC shards failed to load and .dat still exists, clean up EC files to allow .dat file to be used
+ // If .dat is gone, log error but don't clean up (may be waiting for shards from other servers)
+ if datExists {
+ glog.Warningf("Failed to load EC shards for volume %d and .dat exists: %v, cleaning up EC files to use .dat...", volumeId, err)
+ // Clean up any partially loaded in-memory state before removing files
+ l.DestroyEcVolume(volumeId)
+ l.removeEcVolumeFiles(collection, volumeId)
+ } else {
+ glog.Warningf("Failed to load EC shards for volume %d: %v (this may be normal for distributed EC volumes)", volumeId, err)
+ // Clean up any partially loaded in-memory state even if we don't remove files
+ l.DestroyEcVolume(volumeId)
}
- prevVolumeId = volumeId
sameVolumeShards = nil
+ prevVolumeId = 0
continue
}
-
+ prevVolumeId = volumeId
+ sameVolumeShards = nil
+ continue
}
+}
+
// Check for orphaned EC shards without .ecx file (incomplete EC encoding)
// This happens when encoding is interrupted after writing shards but before writing .ecx
if len(sameVolumeShards) > 0 && prevVolumeId != 0 {