VictoriaMetrics/lib/logstorage/pipe_skip.go

65 lines
1.3 KiB
Go
Raw Normal View History

2024-04-29 01:44:54 +00:00
package logstorage
import (
"fmt"
"sync/atomic"
)
type pipeSkip struct {
n uint64
}
func (ps *pipeSkip) String() string {
return fmt.Sprintf("skip %d", ps.n)
}
func (ps *pipeSkip) newPipeProcessor(workersCount int, _ <-chan struct{}, _ func(), ppBase pipeProcessor) pipeProcessor {
return &pipeSkipProcessor{
ps: ps,
ppBase: ppBase,
}
}
type pipeSkipProcessor struct {
ps *pipeSkip
ppBase pipeProcessor
rowsProcessed atomic.Uint64
}
2024-04-30 21:03:34 +00:00
func (spp *pipeSkipProcessor) writeBlock(workerID uint, br *blockResult) {
rowsProcessed := spp.rowsProcessed.Add(uint64(len(br.timestamps)))
2024-04-29 01:44:54 +00:00
if rowsProcessed <= spp.ps.n {
return
}
2024-04-30 21:03:34 +00:00
rowsProcessed -= uint64(len(br.timestamps))
2024-04-29 01:44:54 +00:00
if rowsProcessed >= spp.ps.n {
2024-04-30 21:03:34 +00:00
spp.ppBase.writeBlock(workerID, br)
2024-04-29 01:44:54 +00:00
return
}
2024-04-30 21:03:34 +00:00
rowsSkip := spp.ps.n - rowsProcessed
br.skipRows(int(rowsSkip))
spp.ppBase.writeBlock(workerID, br)
2024-04-29 01:44:54 +00:00
}
func (spp *pipeSkipProcessor) flush() error {
return nil
}
func parsePipeSkip(lex *lexer) (*pipeSkip, error) {
if !lex.mustNextToken() {
return nil, fmt.Errorf("missing the number of rows to skip")
}
n, err := parseUint(lex.token)
if err != nil {
return nil, fmt.Errorf("cannot parse the number of rows to skip %q: %w", lex.token, err)
}
lex.nextToken()
ps := &pipeSkip{
n: n,
}
return ps, nil
}