mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-11-21 14:44:00 +00:00
app/vminsert: properly read trailing line without newline in the end
This fixes https://github.com/VictoriaMetrics/VictoriaMetrics/issues/60
This commit is contained in:
parent
0371c216a7
commit
0b78d228d2
2 changed files with 8 additions and 3 deletions
|
@ -20,6 +20,7 @@ const defaultBlockSize = 64 * 1024
|
|||
//
|
||||
// Returns (dstBuf, tailBuf).
|
||||
func ReadLinesBlock(r io.Reader, dstBuf, tailBuf []byte) ([]byte, []byte, error) {
|
||||
origDstBufLen := len(dstBuf)
|
||||
if cap(dstBuf) < defaultBlockSize {
|
||||
dstBuf = bytesutil.Resize(dstBuf, defaultBlockSize)
|
||||
}
|
||||
|
@ -32,6 +33,13 @@ again:
|
|||
if err == nil {
|
||||
return dstBuf, tailBuf, fmt.Errorf("no forward progress made")
|
||||
}
|
||||
if err == io.EOF && len(dstBuf) > origDstBufLen {
|
||||
// Missing newline in the end of stream. This is OK,
|
||||
/// so suppress io.EOF for now. It will be returned during the next
|
||||
// call to ReadLinesBlock.
|
||||
// This fixes https://github.com/VictoriaMetrics/VictoriaMetrics/issues/60 .
|
||||
return dstBuf, tailBuf, nil
|
||||
}
|
||||
return dstBuf, tailBuf, err
|
||||
}
|
||||
dstBuf = dstBuf[:len(dstBuf)+n]
|
||||
|
|
|
@ -29,9 +29,6 @@ func TestReadLinesBlockFailure(t *testing.T) {
|
|||
// empty string
|
||||
f("")
|
||||
|
||||
// no newline in nonempty string
|
||||
f("foobar")
|
||||
|
||||
// too long string
|
||||
b := make([]byte, maxLineSize+1)
|
||||
f(string(b))
|
||||
|
|
Loading…
Reference in a new issue