Browse Source

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.
pull/7384/head
chrislu 1 month ago
parent
commit
31f905ce2a
  1. 32
      weed/storage/disk_location_ec.go

32
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 {

Loading…
Cancel
Save