Skip to content

Commit

Permalink
Revert "reduce lock duration"
Browse files Browse the repository at this point in the history
This reverts commit 9e00455.
  • Loading branch information
Termina1 committed Dec 16, 2024
1 parent ffb771d commit cde0087
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions chotki.go
Original file line number Diff line number Diff line change
Expand Up @@ -496,15 +496,12 @@ func (cho *Chotki) Broadcast(ctx context.Context, records protocol.Records, exce
// Here new packets are timestamped and queued for save
func (cho *Chotki) CommitPacket(ctx context.Context, lit byte, ref rdx.ID, body protocol.Records) (id rdx.ID, err error) {
cho.lock.Lock()
defer cho.lock.Unlock()

if cho.db == nil {
cho.lock.Unlock()
return rdx.BadId, ErrClosed
}

id = (cho.last & ^rdx.OffMask) + rdx.ProInc
cho.last = id
cho.lock.Unlock()
i := protocol.Record('I', id.ZipBytes())
r := protocol.Record('R', ref.ZipBytes())
packet := protocol.Record(lit, i, r, protocol.Join(body...))
Expand Down Expand Up @@ -566,6 +563,13 @@ func (cho *Chotki) drain(ctx context.Context, recs protocol.Records) (err error)
return parseErr
}

if id.Src() == cho.src && id > cho.last {
if id.Off() != 0 {
return rdx.ErrBadPacket
}
cho.last = id
}

pb, noApply := pebble.Batch{}, false

cho.log.DebugCtx(ctx, "new packet", "type", string(lit), "packet", id.String())
Expand Down

0 comments on commit cde0087

Please sign in to comment.