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

lake: make rangeWrapper filters safe for concurrent use #2969

Merged
merged 1 commit into from
Aug 27, 2021
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
27 changes: 13 additions & 14 deletions lake/sorted.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (

"github.com/brimdata/zed/expr"
"github.com/brimdata/zed/expr/extent"
"github.com/brimdata/zed/field"
"github.com/brimdata/zed/order"
"github.com/brimdata/zed/zbuf"
"github.com/brimdata/zed/zio/zngio"
"github.com/brimdata/zed/zng"
Expand Down Expand Up @@ -65,7 +65,7 @@ func newSortedScanner(ctx context.Context, pool *Pool, zctx *zson.Context, filte
if len(pool.Layout.Keys) != 0 {
// If the scan span does not wholly contain the segment, then
// we must filter out records that fall outside the range.
f = wrapRangeFilter(f, scan.Span, scan.compare, segref.First, segref.Last, pool.Layout.Keys[0])
f = wrapRangeFilter(f, scan.Span, scan.compare, segref.First, segref.Last, pool.Layout)
}
scanner, err := reader.NewScanner(ctx, f)
if err != nil {
Expand Down Expand Up @@ -95,32 +95,32 @@ func newSortedScanner(ctx context.Context, pool *Pool, zctx *zson.Context, filte

type rangeWrapper struct {
zbuf.Filter
first zng.Value
last zng.Value
key field.Path
compare expr.ValueCompareFn
first zng.Value
last zng.Value
layout order.Layout
}

func (r *rangeWrapper) AsFilter() (expr.Filter, error) {
f, err := r.Filter.AsFilter()
if err != nil {
return nil, err
}
compare := extent.CompareFunc(r.layout.Order)
return func(rec *zng.Record) bool {
keyVal, err := rec.Deref(r.key)
keyVal, err := rec.Deref(r.layout.Keys[0])
if err != nil {
// XXX match keyless records.
// See issue #2637.
return true
}
if r.compare(keyVal, r.first) < 0 || r.compare(keyVal, r.last) > 0 {
if compare(keyVal, r.first) < 0 || compare(keyVal, r.last) > 0 {
return false
}
return f == nil || f(rec)
}, nil
}

func wrapRangeFilter(f zbuf.Filter, scan extent.Span, cmp expr.ValueCompareFn, first, last zng.Value, key field.Path) zbuf.Filter {
func wrapRangeFilter(f zbuf.Filter, scan extent.Span, cmp expr.ValueCompareFn, first, last zng.Value, layout order.Layout) zbuf.Filter {
scanFirst := scan.First()
scanLast := scan.Last()
if cmp(scanFirst, first) <= 0 {
Expand All @@ -129,10 +129,9 @@ func wrapRangeFilter(f zbuf.Filter, scan extent.Span, cmp expr.ValueCompareFn, f
}
}
return &rangeWrapper{
Filter: f,
first: scanFirst,
last: scanLast,
key: key,
compare: cmp,
Filter: f,
first: scanFirst,
last: scanLast,
layout: layout,
}
}