Browse Source

do not truncate file if any error happens. Truncating will lose all

files after this file entry.
pull/2/head
Chris Lu 12 years ago
parent
commit
b395a5289b
  1. 14
      go/storage/volume.go

14
go/storage/volume.go

@ -143,17 +143,9 @@ func (v *Volume) delete(n *Needle) (uint32, error) {
nv, ok := v.nm.Get(n.Id) nv, ok := v.nm.Get(n.Id)
//fmt.Println("key", n.Id, "volume offset", nv.Offset, "data_size", n.Size, "cached size", nv.Size) //fmt.Println("key", n.Id, "volume offset", nv.Offset, "data_size", n.Size, "cached size", nv.Size)
if ok { if ok {
if err := v.nm.Delete(n.Id); err != nil {
return 0, err
}
offset, err := v.dataFile.Seek(int64(nv.Offset*NeedlePaddingSize), 0)
if err != nil {
return 0, fmt.Errorf("cannot get datafile (%s) position: %s", v.dataFile, err)
}
if _, err = n.Append(v.dataFile, v.Version()); err != nil {
v.dataFile.Truncate(offset)
return 0, err
}
v.nm.Delete(n.Id)
v.dataFile.Seek(int64(nv.Offset*NeedlePaddingSize), 0)
_, err := n.Append(v.dataFile, v.Version())
return nv.Size, err return nv.Size, err
} }
return 0, nil return 0, nil

Loading…
Cancel
Save