|
@ -60,8 +60,6 @@ func (v *Volume) AppendBlob(b []byte) (offset int64, err error) { |
|
|
if offset, err = v.dataFile.Seek(0, 2); err != nil { |
|
|
if offset, err = v.dataFile.Seek(0, 2); err != nil { |
|
|
glog.V(0).Infof("failed to seek the end of file: %v", err) |
|
|
glog.V(0).Infof("failed to seek the end of file: %v", err) |
|
|
return |
|
|
return |
|
|
} else if offset != int64(v.dataFileSize) { |
|
|
|
|
|
glog.V(0).Infof("dataFileSize %d != actual data file size: %d", v.dataFileSize, offset) |
|
|
|
|
|
} |
|
|
} |
|
|
//ensure file writing starting from aligned positions
|
|
|
//ensure file writing starting from aligned positions
|
|
|
if offset%NeedlePaddingSize != 0 { |
|
|
if offset%NeedlePaddingSize != 0 { |
|
@ -69,12 +67,9 @@ func (v *Volume) AppendBlob(b []byte) (offset int64, err error) { |
|
|
if offset, err = v.dataFile.Seek(offset, 0); err != nil { |
|
|
if offset, err = v.dataFile.Seek(offset, 0); err != nil { |
|
|
glog.V(0).Infof("failed to align in datafile %s: %v", v.dataFile.Name(), err) |
|
|
glog.V(0).Infof("failed to align in datafile %s: %v", v.dataFile.Name(), err) |
|
|
return |
|
|
return |
|
|
} else if offset != int64(v.dataFileSize) { |
|
|
|
|
|
glog.V(0).Infof("dataFileSize %d != actual data file size: %d", v.dataFileSize, offset) |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
_, err = v.dataFile.Write(b) |
|
|
_, err = v.dataFile.Write(b) |
|
|
v.dataFileSize += int64(len(b)) |
|
|
|
|
|
return |
|
|
return |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -91,12 +86,10 @@ func (v *Volume) writeNeedle(n *Needle) (size uint32, err error) { |
|
|
glog.V(4).Infof("needle is unchanged!") |
|
|
glog.V(4).Infof("needle is unchanged!") |
|
|
return |
|
|
return |
|
|
} |
|
|
} |
|
|
var offset, actualSize int64 |
|
|
|
|
|
|
|
|
var offset int64 |
|
|
if offset, err = v.dataFile.Seek(0, 2); err != nil { |
|
|
if offset, err = v.dataFile.Seek(0, 2); err != nil { |
|
|
glog.V(0).Infof("failed to seek the end of file: %v", err) |
|
|
glog.V(0).Infof("failed to seek the end of file: %v", err) |
|
|
return |
|
|
return |
|
|
} else if offset != int64(v.dataFileSize) { |
|
|
|
|
|
glog.V(0).Infof("dataFileSize %d != actual data file size: %d", v.dataFileSize, offset) |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
//ensure file writing starting from aligned positions
|
|
|
//ensure file writing starting from aligned positions
|
|
@ -108,13 +101,12 @@ func (v *Volume) writeNeedle(n *Needle) (size uint32, err error) { |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if size, actualSize, err = n.Append(v.dataFile, v.Version()); err != nil { |
|
|
|
|
|
|
|
|
if size, _, err = n.Append(v.dataFile, v.Version()); err != nil { |
|
|
if e := v.dataFile.Truncate(offset); e != nil { |
|
|
if e := v.dataFile.Truncate(offset); e != nil { |
|
|
err = fmt.Errorf("%s\ncannot truncate %s: %v", err, v.dataFile.Name(), e) |
|
|
err = fmt.Errorf("%s\ncannot truncate %s: %v", err, v.dataFile.Name(), e) |
|
|
} |
|
|
} |
|
|
return |
|
|
return |
|
|
} |
|
|
} |
|
|
v.dataFileSize += actualSize |
|
|
|
|
|
|
|
|
|
|
|
nv, ok := v.nm.Get(n.Id) |
|
|
nv, ok := v.nm.Get(n.Id) |
|
|
if !ok || int64(nv.Offset)*NeedlePaddingSize < offset { |
|
|
if !ok || int64(nv.Offset)*NeedlePaddingSize < offset { |
|
@ -139,18 +131,15 @@ func (v *Volume) deleteNeedle(n *Needle) (uint32, error) { |
|
|
//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 && nv.Size != TombstoneFileSize { |
|
|
if ok && nv.Size != TombstoneFileSize { |
|
|
size := nv.Size |
|
|
size := nv.Size |
|
|
// println("adding tombstone", n.Id, "at offset", v.dataFileSize)
|
|
|
|
|
|
if err := v.nm.Delete(n.Id, uint32(v.dataFileSize/NeedlePaddingSize)); err != nil { |
|
|
|
|
|
|
|
|
offset, err := v.dataFile.Seek(0, 2) |
|
|
|
|
|
if err != nil { |
|
|
return size, err |
|
|
return size, err |
|
|
} |
|
|
} |
|
|
if offset, err := v.dataFile.Seek(0, 2); err != nil { |
|
|
|
|
|
|
|
|
if err := v.nm.Delete(n.Id, uint32(offset/NeedlePaddingSize)); err != nil { |
|
|
return size, err |
|
|
return size, err |
|
|
} else if offset != int64(v.dataFileSize) { |
|
|
|
|
|
glog.V(0).Infof("dataFileSize %d != actual data file size: %d, deleteMarker: %d", v.dataFileSize, offset, getActualSize(0)) |
|
|
|
|
|
} |
|
|
} |
|
|
n.Data = nil |
|
|
n.Data = nil |
|
|
_, actualSize, err := n.Append(v.dataFile, v.Version()) |
|
|
|
|
|
v.dataFileSize += actualSize |
|
|
|
|
|
|
|
|
_, _, err = n.Append(v.dataFile, v.Version()) |
|
|
return size, err |
|
|
return size, err |
|
|
} |
|
|
} |
|
|
return 0, nil |
|
|
return 0, nil |
|
|