Browse Source

volume copying adds cleaning up on error

fix https://github.com/chrislusf/seaweedfs/issues/1253
pull/1287/head
Chris Lu 5 years ago
parent
commit
cea52a4faf
  1. 20
      weed/server/volume_grpc_copy.go

20
weed/server/volume_grpc_copy.go

@ -25,7 +25,20 @@ func (vs *VolumeServer) VolumeCopy(ctx context.Context, req *volume_server_pb.Vo
v := vs.store.GetVolume(needle.VolumeId(req.VolumeId))
if v != nil {
return nil, fmt.Errorf("volume %d already exists", req.VolumeId)
glog.V(0).Infof("volume %d already exists. deleted before copying...", req.VolumeId)
err := vs.store.UnmountVolume(needle.VolumeId(req.VolumeId))
if err != nil {
return nil, fmt.Errorf("failed to mount existing volume %d: %v", req.VolumeId, err)
}
err = vs.store.DeleteVolume(needle.VolumeId(req.VolumeId))
if err != nil {
return nil, fmt.Errorf("failed to delete existing volume %d: %v", req.VolumeId, err)
}
glog.V(0).Infof("deleted exisitng volume %d before copying.", req.VolumeId)
}
location := vs.store.FindFreeLocation()
@ -73,10 +86,15 @@ func (vs *VolumeServer) VolumeCopy(ctx context.Context, req *volume_server_pb.Vo
idxFileName = volumeFileName + ".idx"
datFileName = volumeFileName + ".dat"
defer func() {
if err != nil && volumeFileName != "" {
os.Remove(idxFileName)
os.Remove(datFileName)
os.Remove(volumeFileName + ".vif")
}
}()
if err != nil && volumeFileName != "" {
return nil, err
}

Loading…
Cancel
Save