Browse Source

fix reading when filling zeros

pull/1427/head
Chris Lu 4 years ago
parent
commit
cd43738245
  1. 4
      weed/filer2/reader_at.go
  2. 30
      weed/filer2/reader_at_test.go

4
weed/filer2/reader_at.go

@ -82,8 +82,8 @@ func (c *ChunkReadAt) doReadAt(p []byte, offset int64) (n int, err error) {
}
if startOffset < chunk.LogicOffset {
gap := int(chunk.LogicOffset - startOffset)
glog.V(4).Infof("zero [%d,%d)", n, n+gap)
n += gap
glog.V(4).Infof("zero [%d,%d)", startOffset, startOffset+int64(gap))
n += int(min(int64(gap), remaining))
startOffset, remaining = chunk.LogicOffset, remaining-int64(gap)
if remaining <= 0 {
break

30
weed/filer2/reader_at_test.go

@ -124,3 +124,33 @@ func TestReaderAt0(t *testing.T) {
testReadAt(t, readerAt, 10, 5, 0, io.EOF)
}
func TestReaderAt1(t *testing.T) {
visibles := []VisibleInterval{
{
start: 2,
stop: 5,
fileId: "1",
chunkSize: 9,
},
}
readerAt := &ChunkReadAt{
chunkViews: ViewFromVisibleIntervals(visibles, 0, math.MaxInt64),
lookupFileId: nil,
readerLock: sync.Mutex{},
fileSize: 20,
chunkCache: &mockChunkCache{},
}
testReadAt(t, readerAt, 0, 20, 20, io.EOF)
testReadAt(t, readerAt, 1, 7, 7, nil)
testReadAt(t, readerAt, 0, 1, 1, nil)
testReadAt(t, readerAt, 18, 4, 2, io.EOF)
testReadAt(t, readerAt, 12, 4, 4, nil)
testReadAt(t, readerAt, 4, 20, 16, io.EOF)
testReadAt(t, readerAt, 4, 10, 10, nil)
testReadAt(t, readerAt, 1, 10, 10, nil)
}
Loading…
Cancel
Save