Skip to content

Commit

Permalink
[sqlite] use eof as good error
Browse files Browse the repository at this point in the history
  • Loading branch information
nevgeny committed Aug 25, 2023
1 parent d9fa5bb commit 0f300ce
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion internal/sqlite/binlog_engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package sqlite

import (
"errors"
"io"
"time"

binlog2 "github.com/vkcom/statshouse/internal/vkgo/binlog"
Expand All @@ -24,6 +25,19 @@ const (
maxReplicaQueueBytes = 1 << 30 // 1GB
)

func isEOFErr(err error) bool {
return err == binlog2.ErrorNotEnoughData ||
err == io.EOF ||
err == io.ErrUnexpectedEOF ||
errors.Is(err, binlog2.ErrorNotEnoughData) ||
errors.Is(err, io.EOF) ||
errors.Is(err, io.ErrUnexpectedEOF)
}

func isExpectedError(err error) bool {
return errors.Is(err, binlog2.ErrorUnknownMagic) || isEOFErr(err)
}

// Apply is used when re-reading or when working as a replica
func (impl *binlogEngineReplicaImpl) Apply(payload []byte) (newOffset int64, err error) {
defer impl.e.opt.StatsOptions.measureActionDurationSince("engine_apply", time.Now())
Expand Down Expand Up @@ -83,7 +97,7 @@ func (impl *binlogEngineReplicaImpl) apply(payload []byte) (newOffset int64, err
err1 := binlogUpdateOffset(conn, newOffset)
if err != nil {
errToReturn = err
if !errors.Is(err, binlog2.ErrorUnknownMagic) && !errors.Is(err, binlog2.ErrorNotEnoughData) {
if !isExpectedError(err) {
return err
}
}
Expand Down

0 comments on commit 0f300ce

Please sign in to comment.