mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2024-01-19 02:48:24 +00:00
volume copying adds cleaning up on error
fix https://github.com/chrislusf/seaweedfs/issues/1253
This commit is contained in:
parent
c981975627
commit
cea52a4faf
|
@ -25,7 +25,20 @@ func (vs *VolumeServer) VolumeCopy(ctx context.Context, req *volume_server_pb.Vo
|
||||||
|
|
||||||
v := vs.store.GetVolume(needle.VolumeId(req.VolumeId))
|
v := vs.store.GetVolume(needle.VolumeId(req.VolumeId))
|
||||||
if v != nil {
|
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()
|
location := vs.store.FindFreeLocation()
|
||||||
|
@ -73,10 +86,15 @@ func (vs *VolumeServer) VolumeCopy(ctx context.Context, req *volume_server_pb.Vo
|
||||||
idxFileName = volumeFileName + ".idx"
|
idxFileName = volumeFileName + ".idx"
|
||||||
datFileName = volumeFileName + ".dat"
|
datFileName = volumeFileName + ".dat"
|
||||||
|
|
||||||
|
defer func() {
|
||||||
if err != nil && volumeFileName != "" {
|
if err != nil && volumeFileName != "" {
|
||||||
os.Remove(idxFileName)
|
os.Remove(idxFileName)
|
||||||
os.Remove(datFileName)
|
os.Remove(datFileName)
|
||||||
os.Remove(volumeFileName + ".vif")
|
os.Remove(volumeFileName + ".vif")
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
|
if err != nil && volumeFileName != "" {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue