Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

merge: Batches not getting Unreferenced #5171

Merged
merged 1 commit into from
Jul 9, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion runtime/sam/op/merge/merge.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ type Op struct {
// The head-of-line (hol) queue is maintained as a min-heap on cmp of
// hol.vals[0] (see Less) so that the next Read always returns
// hol[0].vals[0].
hol []*puller
hol []*puller
unref zbuf.Batch
}

var _ zbuf.Puller = (*Op)(nil)
Expand All @@ -55,6 +56,10 @@ func (o *Op) Pull(done bool) (zbuf.Batch, error) {
if err != nil {
return nil, err
}
if o.unref != nil {
o.unref.Unref()
o.unref = nil
}
if done {
return nil, o.propagateDone()
}
Expand All @@ -70,6 +75,7 @@ func (o *Op) Pull(done bool) (zbuf.Batch, error) {
// way, it's safe to return min's remaining values as a batch.
batch := min.batch
if len(min.vals) < len(batch.Values()) {
defer batch.Unref()
batch = zbuf.WrapBatch(batch, min.vals)
}
ok, err := min.replenish()
Expand All @@ -86,13 +92,19 @@ func (o *Op) Pull(done bool) (zbuf.Batch, error) {
}

func (o *Op) Read() (*zed.Value, error) {
if o.unref != nil {
o.unref.Unref()
o.unref = nil
}
if o.Len() == 0 {
return nil, nil
}
u := o.hol[0]
val := &u.vals[0]
u.vals = u.vals[1:]
if len(u.vals) == 0 {
// Need to unref on next call to Read (or Pull) so keep this around.
o.unref = u.batch
ok, err := u.replenish()
if err != nil {
return nil, err
Expand Down