Browse Source

fix write volume over size MaxPossibleVolumeSize (#5190)

Co-authored-by: Yang Wang <yangwang@weride.ai>
pull/5198/head
skycope 12 months ago
committed by GitHub
parent
commit
0e8a54f6f6
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      weed/storage/needle/needle_write.go
  2. 13
      weed/storage/volume_write.go

2
weed/storage/needle/needle_write.go

@ -127,7 +127,7 @@ func (n *Needle) Append(w backend.BackendStorageFile, version Version) (offset u
err = fmt.Errorf("Cannot Read Current Volume Position: %v", e) err = fmt.Errorf("Cannot Read Current Volume Position: %v", e)
return return
} }
if offset >= MaxPossibleVolumeSize && n.Size.IsValid() {
if offset >= MaxPossibleVolumeSize && len(n.Data) != 0 {
err = fmt.Errorf("Volume Size %d Exceeded %d", offset, MaxPossibleVolumeSize) err = fmt.Errorf("Volume Size %d Exceeded %d", offset, MaxPossibleVolumeSize)
return return
} }

13
weed/storage/volume_write.go

@ -107,16 +107,9 @@ func (v *Volume) asyncRequestAppend(request *needle.AsyncRequest) {
func (v *Volume) syncWrite(n *needle.Needle, checkCookie bool) (offset uint64, size Size, isUnchanged bool, err error) { func (v *Volume) syncWrite(n *needle.Needle, checkCookie bool) (offset uint64, size Size, 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())
actualSize := needle.GetActualSize(Size(len(n.Data)), v.Version())
v.dataFileAccessLock.Lock() v.dataFileAccessLock.Lock()
defer v.dataFileAccessLock.Unlock() defer v.dataFileAccessLock.Unlock()
if MaxPossibleVolumeSize < v.nm.ContentSize()+uint64(actualSize) {
err = fmt.Errorf("volume size limit %d exceeded! current size is %d", MaxPossibleVolumeSize, v.nm.ContentSize())
return
}
return v.doWriteRequest(n, checkCookie) return v.doWriteRequest(n, checkCookie)
} }
@ -193,7 +186,6 @@ func (v *Volume) doWriteRequest(n *needle.Needle, checkCookie bool) (offset uint
func (v *Volume) syncDelete(n *needle.Needle) (Size, error) { func (v *Volume) syncDelete(n *needle.Needle) (Size, error) {
// glog.V(4).Infof("delete needle %s", needle.NewFileIdFromNeedle(v.Id, n).String()) // glog.V(4).Infof("delete needle %s", needle.NewFileIdFromNeedle(v.Id, n).String())
actualSize := needle.GetActualSize(0, v.Version())
v.dataFileAccessLock.Lock() v.dataFileAccessLock.Lock()
defer v.dataFileAccessLock.Unlock() defer v.dataFileAccessLock.Unlock()
@ -201,11 +193,6 @@ func (v *Volume) syncDelete(n *needle.Needle) (Size, error) {
return 0, nil return 0, nil
} }
if MaxPossibleVolumeSize < v.nm.ContentSize()+uint64(actualSize) {
err := fmt.Errorf("volume size limit %d exceeded! current size is %d", MaxPossibleVolumeSize, v.nm.ContentSize())
return 0, err
}
return v.doDeleteRequest(n) return v.doDeleteRequest(n)
} }

Loading…
Cancel
Save