This commit is contained in:
chrislu 2022-08-21 11:49:29 -07:00
parent 77e4b1376e
commit 388f82f322

View file

@ -129,8 +129,7 @@ func (c *ChunkReadAt) doReadAt(p []byte, offset int64) (n int, err error) {
if startOffset < chunk.LogicOffset { if startOffset < chunk.LogicOffset {
gap := chunk.LogicOffset - startOffset gap := chunk.LogicOffset - startOffset
glog.V(4).Infof("zero [%d,%d)", startOffset, chunk.LogicOffset) glog.V(4).Infof("zero [%d,%d)", startOffset, chunk.LogicOffset)
zero(p, startOffset-offset, gap) n += zero(p, startOffset-offset, gap)
n += int(min(gap, remaining))
startOffset, remaining = chunk.LogicOffset, remaining-gap startOffset, remaining = chunk.LogicOffset, remaining-gap
if remaining <= 0 { if remaining <= 0 {
break break
@ -166,8 +165,7 @@ func (c *ChunkReadAt) doReadAt(p []byte, offset int64) (n int, err error) {
startOffset = max(startOffset-offset, startOffset-remaining-offset) startOffset = max(startOffset-offset, startOffset-remaining-offset)
} }
glog.V(4).Infof("zero2 [%d,%d) of file size %d bytes", startOffset, startOffset+delta, c.fileSize) glog.V(4).Infof("zero2 [%d,%d) of file size %d bytes", startOffset, startOffset+delta, c.fileSize)
zero(p, startOffset, delta) n += zero(p, startOffset, delta)
n += int(delta)
} }
if err == nil && offset+int64(len(p)) >= c.fileSize { if err == nil && offset+int64(len(p)) >= c.fileSize {
@ -206,11 +204,13 @@ func (c *ChunkReadAt) readChunkSliceAt(buffer []byte, chunkView *ChunkView, next
return return
} }
func zero(buffer []byte, start, length int64) { func zero(buffer []byte, start, length int64) int {
end := min(start+length, int64(len(buffer))) end := min(start+length, int64(len(buffer)))
start = max(start, 0)
// zero the bytes // zero the bytes
for o := start; o < end; o++ { for o := start; o < end; o++ {
buffer[o] = 0 buffer[o] = 0
} }
return int(end - start)
} }