From 8e4bffc66b212a44a57dd03ee6c5869e921069ad Mon Sep 17 00:00:00 2001 From: chrislu Date: Tue, 3 Sep 2024 21:19:10 -0700 Subject: [PATCH] copy ec shards to disks already having ec volumes fix https://github.com/seaweedfs/seaweedfs/issues/5615 --- weed/server/volume_grpc_copy.go | 4 +++- weed/server/volume_grpc_erasure_coding.go | 5 ++++- weed/storage/store.go | 8 +++++--- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/weed/server/volume_grpc_copy.go b/weed/server/volume_grpc_copy.go index 6548b7c56..d34a74f55 100644 --- a/weed/server/volume_grpc_copy.go +++ b/weed/server/volume_grpc_copy.go @@ -63,7 +63,9 @@ func (vs *VolumeServer) VolumeCopy(req *volume_server_pb.VolumeCopyRequest, stre if req.DiskType != "" { diskType = req.DiskType } - location := vs.store.FindFreeLocation(types.ToDiskType(diskType)) + location := vs.store.FindFreeLocation(func(location *storage.DiskLocation) bool { + return location.DiskType == types.ToDiskType(diskType) + }) if location == nil { return fmt.Errorf("no space left for disk type %s", types.ToDiskType(diskType).ReadableString()) } diff --git a/weed/server/volume_grpc_erasure_coding.go b/weed/server/volume_grpc_erasure_coding.go index e4346dffe..546bf8109 100644 --- a/weed/server/volume_grpc_erasure_coding.go +++ b/weed/server/volume_grpc_erasure_coding.go @@ -143,7 +143,10 @@ func (vs *VolumeServer) VolumeEcShardsCopy(ctx context.Context, req *volume_serv glog.V(0).Infof("VolumeEcShardsCopy: %v", req) - location := vs.store.FindFreeLocation(types.HardDriveType) + location := vs.store.FindFreeLocation(func(location *storage.DiskLocation) bool { + _, found := location.FindEcVolume(needle.VolumeId(req.VolumeId)) + return found + }) if location == nil { return nil, fmt.Errorf("no space left") } diff --git a/weed/storage/store.go b/weed/storage/store.go index 8f3b763fc..2a92ae934 100644 --- a/weed/storage/store.go +++ b/weed/storage/store.go @@ -138,10 +138,10 @@ func (s *Store) findVolume(vid needle.VolumeId) *Volume { } return nil } -func (s *Store) FindFreeLocation(diskType DiskType) (ret *DiskLocation) { +func (s *Store) FindFreeLocation(filterFn func(location *DiskLocation) bool) (ret *DiskLocation) { max := int32(0) for _, location := range s.Locations { - if diskType != location.DiskType { + if filterFn != nil && !filterFn(location) { continue } if location.isDiskSpaceLow { @@ -162,7 +162,9 @@ func (s *Store) addVolume(vid needle.VolumeId, collection string, needleMapKind if s.findVolume(vid) != nil { return fmt.Errorf("Volume Id %d already exists!", vid) } - if location := s.FindFreeLocation(diskType); location != nil { + if location := s.FindFreeLocation(func(location *DiskLocation) bool { + return location.DiskType == diskType + }); location != nil { glog.V(0).Infof("In dir %s adds volume:%v collection:%s replicaPlacement:%v ttl:%v", location.Directory, vid, collection, replicaPlacement, ttl) if volume, err := NewVolume(location.Directory, location.IdxDirectory, collection, vid, needleMapKind, replicaPlacement, ttl, preallocate, memoryMapMaxSizeMb, ldbTimeout); err == nil {