merge
This commit is contained in:
bingoohuang 2019-07-22 11:05:05 +08:00 committed by GitHub
commit 93a7df500f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 31 deletions

View File

@ -1,4 +1,4 @@
package main package load_test_leveldb
import ( import (
"crypto/md5" "crypto/md5"

View File

@ -217,11 +217,10 @@ func (s *Store) WriteVolumeNeedle(i needle.VolumeId, n *needle.Needle) (size uin
err = fmt.Errorf("volume %d is read only", i) err = fmt.Errorf("volume %d is read only", i)
return return
} }
// TODO: count needle size ahead if MaxPossibleVolumeSize >= v.ContentSize()+uint64(needle.GetActualSize(size, v.version)) {
if MaxPossibleVolumeSize >= v.ContentSize()+uint64(size) {
_, size, isUnchanged, err = v.writeNeedle(n) _, size, isUnchanged, err = v.writeNeedle(n)
} else { } else {
err = fmt.Errorf("Volume Size Limit %d Exceeded! Current size is %d", s.GetVolumeSizeLimit(), v.ContentSize()) err = fmt.Errorf("volume size limit %d exceeded! current size is %d", s.GetVolumeSizeLimit(), v.ContentSize())
} }
return return
} }
@ -231,10 +230,17 @@ func (s *Store) WriteVolumeNeedle(i needle.VolumeId, n *needle.Needle) (size uin
} }
func (s *Store) DeleteVolumeNeedle(i needle.VolumeId, n *needle.Needle) (uint32, error) { func (s *Store) DeleteVolumeNeedle(i needle.VolumeId, n *needle.Needle) (uint32, error) {
if v := s.findVolume(i); v != nil && !v.readOnly { if v := s.findVolume(i); v != nil {
return v.deleteNeedle(n) if v.readOnly {
return 0, fmt.Errorf("volume %d is read only", i)
} }
return 0, nil if MaxPossibleVolumeSize >= v.ContentSize()+uint64(needle.GetActualSize(0, v.version)) {
return v.deleteNeedle(n)
} else {
return 0, fmt.Errorf("volume size limit %d exceeded! current size is %d", s.GetVolumeSizeLimit(), v.ContentSize())
}
}
return 0, fmt.Errorf("volume %d not found on %s:%d", i, s.Ip, s.Port)
} }
func (s *Store) ReadVolumeNeedle(i needle.VolumeId, n *needle.Needle) (int, error) { func (s *Store) ReadVolumeNeedle(i needle.VolumeId, n *needle.Needle) (int, error) {

View File

@ -53,30 +53,6 @@ func (v *Volume) Destroy() (err error) {
return return
} }
// AppendBlob append a blob to end of the data file, used in replication
func (v *Volume) AppendBlob(b []byte) (offset int64, err error) {
if v.readOnly {
err = fmt.Errorf("%s is read-only", v.dataFile.Name())
return
}
v.dataFileAccessLock.Lock()
defer v.dataFileAccessLock.Unlock()
if offset, err = v.dataFile.Seek(0, 2); err != nil {
glog.V(0).Infof("failed to seek the end of file: %v", err)
return
}
//ensure file writing starting from aligned positions
if offset%NeedlePaddingSize != 0 {
offset = offset + (NeedlePaddingSize - offset%NeedlePaddingSize)
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)
return
}
}
_, err = v.dataFile.Write(b)
return
}
func (v *Volume) writeNeedle(n *needle.Needle) (offset uint64, size uint32, isUnchanged bool, err error) { func (v *Volume) writeNeedle(n *needle.Needle) (offset uint64, size uint32, isUnchanged bool, err error) {
glog.V(4).Infof("writing needle %s", needle.NewFileIdFromNeedle(v.Id, n).String()) glog.V(4).Infof("writing needle %s", needle.NewFileIdFromNeedle(v.Id, n).String())
if v.readOnly { if v.readOnly {