diff options
| author | chrislu <chris.lu@gmail.com> | 2022-08-21 15:04:50 -0700 |
|---|---|---|
| committer | chrislu <chris.lu@gmail.com> | 2022-08-21 15:04:50 -0700 |
| commit | fb5808e0c39d00c32a896b44614a232566a014a7 (patch) | |
| tree | 83127aa10e1b0637051dad381778fa1fd4ade4c1 | |
| parent | 5790d01c6f1397c40c3f88e50722fab1e7d7d4f4 (diff) | |
| download | seaweedfs-fb5808e0c39d00c32a896b44614a232566a014a7.tar.xz seaweedfs-fb5808e0c39d00c32a896b44614a232566a014a7.zip | |
EC: with multiple volume locations, the ec rebuilding may fail
| -rw-r--r-- | weed/server/volume_grpc_erasure_coding.go | 53 |
1 files changed, 33 insertions, 20 deletions
diff --git a/weed/server/volume_grpc_erasure_coding.go b/weed/server/volume_grpc_erasure_coding.go index 3d1de1a4f..1a0668321 100644 --- a/weed/server/volume_grpc_erasure_coding.go +++ b/weed/server/volume_grpc_erasure_coding.go @@ -90,6 +90,15 @@ func (vs *VolumeServer) VolumeEcShardsRebuild(ctx context.Context, req *volume_s var rebuiltShardIds []uint32 for _, location := range vs.store.Locations { + _, _, existingShardCount, err := checkEcVolumeStatus(bName, location) + if err != nil { + return nil, err + } + + if existingShardCount == 0 { + continue + } + if util.FileExists(path.Join(location.IdxDirectory, baseFileName+".ecx")) { // write .ec00 ~ .ec13 files dataBaseFileName := path.Join(location.Directory, baseFileName) @@ -206,19 +215,36 @@ func deleteEcShardIdsForEachLocation(bName string, location *storage.DiskLocatio return nil } - // check whether to delete the .ecx and .ecj file also - hasEcxFile := false - hasIdxFile := false - existingShardCount := 0 + hasEcxFile, hasIdxFile, existingShardCount, err := checkEcVolumeStatus(bName, location) + if err != nil { + return err + } + if hasEcxFile && existingShardCount == 0 { + if err := os.Remove(indexBaseFilename + ".ecx"); err != nil { + return err + } + os.Remove(indexBaseFilename + ".ecj") + + if !hasIdxFile { + // .vif is used for ec volumes and normal volumes + os.Remove(dataBaseFilename + ".vif") + } + } + + return nil +} + +func checkEcVolumeStatus(bName string, location *storage.DiskLocation) (hasEcxFile bool, hasIdxFile bool, existingShardCount int, err error) { + // check whether to delete the .ecx and .ecj file also fileInfos, err := os.ReadDir(location.Directory) if err != nil { - return err + return false, false, 0, err } if location.IdxDirectory != location.Directory { idxFileInfos, err := os.ReadDir(location.IdxDirectory) if err != nil { - return err + return false, false, 0, err } fileInfos = append(fileInfos, idxFileInfos...) } @@ -235,20 +261,7 @@ func deleteEcShardIdsForEachLocation(bName string, location *storage.DiskLocatio existingShardCount++ } } - - if hasEcxFile && existingShardCount == 0 { - if err := os.Remove(indexBaseFilename + ".ecx"); err != nil { - return err - } - os.Remove(indexBaseFilename + ".ecj") - - if !hasIdxFile { - // .vif is used for ec volumes and normal volumes - os.Remove(dataBaseFilename + ".vif") - } - } - - return nil + return hasEcxFile, hasIdxFile, existingShardCount, nil } func (vs *VolumeServer) VolumeEcShardsMount(ctx context.Context, req *volume_server_pb.VolumeEcShardsMountRequest) (*volume_server_pb.VolumeEcShardsMountResponse, error) { |
