|
@ -237,11 +237,26 @@ func (c *ChunkStreamReader) prepareBufferFor(offset int64) (err error) { |
|
|
|
|
|
|
|
|
// need to seek to a different chunk
|
|
|
// need to seek to a different chunk
|
|
|
currentChunkIndex := sort.Search(len(c.chunkViews), func(i int) bool { |
|
|
currentChunkIndex := sort.Search(len(c.chunkViews), func(i int) bool { |
|
|
return c.chunkViews[i].LogicOffset <= offset |
|
|
|
|
|
|
|
|
return offset < c.chunkViews[i].LogicOffset |
|
|
}) |
|
|
}) |
|
|
if currentChunkIndex == len(c.chunkViews) { |
|
|
if currentChunkIndex == len(c.chunkViews) { |
|
|
|
|
|
// not found
|
|
|
|
|
|
if c.chunkViews[0].LogicOffset <= offset { |
|
|
|
|
|
currentChunkIndex = 0 |
|
|
|
|
|
} else if c.chunkViews[len(c.chunkViews)-1].LogicOffset <= offset { |
|
|
|
|
|
currentChunkIndex = len(c.chunkViews) -1 |
|
|
|
|
|
} else { |
|
|
return io.EOF |
|
|
return io.EOF |
|
|
} |
|
|
} |
|
|
|
|
|
} else if currentChunkIndex > 0 { |
|
|
|
|
|
if c.chunkViews[currentChunkIndex-1].LogicOffset <= offset { |
|
|
|
|
|
currentChunkIndex -= 1 |
|
|
|
|
|
} else { |
|
|
|
|
|
return fmt.Errorf("unexpected1 offset %d", offset) |
|
|
|
|
|
} |
|
|
|
|
|
} else { |
|
|
|
|
|
return fmt.Errorf("unexpected2 offset %d", offset) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
// positioning within the new chunk
|
|
|
// positioning within the new chunk
|
|
|
chunk := c.chunkViews[currentChunkIndex] |
|
|
chunk := c.chunkViews[currentChunkIndex] |
|
|