EC: clean up if failed in the middle

This commit is contained in:
Chris Lu 2021-09-11 02:07:14 -07:00
parent f7f01ac209
commit a243d7e047

View file

@ -49,6 +49,17 @@ func (vs *VolumeServer) VolumeEcShardsGenerate(ctx context.Context, req *volume_
return nil, fmt.Errorf("existing collection:%v unexpected input: %v", v.Collection, req.Collection)
}
shouldCleanup := true
defer func() {
if !shouldCleanup {
return
}
for i := 0; i < erasure_coding.TotalShardsCount; i++ {
os.Remove(fmt.Sprintf("%s.ec%2d", baseFileName, i))
}
os.Remove(v.IndexFileName() + ".ecx")
}()
// write .ec00 ~ .ec13 files
if err := erasure_coding.WriteEcFiles(baseFileName); err != nil {
return nil, fmt.Errorf("WriteEcFiles %s: %v", baseFileName, err)
@ -64,6 +75,8 @@ func (vs *VolumeServer) VolumeEcShardsGenerate(ctx context.Context, req *volume_
return nil, fmt.Errorf("WriteEcFiles %s: %v", baseFileName, err)
}
shouldCleanup = false
return &volume_server_pb.VolumeEcShardsGenerateResponse{}, nil
}