|
|
|
@ -12,11 +12,11 @@ import (
|
|
|
|
|
|
|
|
|
|
// MatchRequest represents a search request
|
|
|
|
|
type MatchRequest struct {
|
|
|
|
|
chunks []*Chunk
|
|
|
|
|
pattern *Pattern
|
|
|
|
|
final bool
|
|
|
|
|
sort bool
|
|
|
|
|
clearCache bool
|
|
|
|
|
chunks []*Chunk
|
|
|
|
|
pattern *Pattern
|
|
|
|
|
final bool
|
|
|
|
|
sort bool
|
|
|
|
|
revision int
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Matcher is responsible for performing search
|
|
|
|
@ -29,6 +29,7 @@ type Matcher struct {
|
|
|
|
|
partitions int
|
|
|
|
|
slab []*util.Slab
|
|
|
|
|
mergerCache map[string]*Merger
|
|
|
|
|
revision int
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const (
|
|
|
|
@ -38,7 +39,7 @@ const (
|
|
|
|
|
|
|
|
|
|
// NewMatcher returns a new Matcher
|
|
|
|
|
func NewMatcher(patternBuilder func([]rune) *Pattern,
|
|
|
|
|
sort bool, tac bool, eventBox *util.EventBox) *Matcher {
|
|
|
|
|
sort bool, tac bool, eventBox *util.EventBox, revision int) *Matcher {
|
|
|
|
|
partitions := util.Min(numPartitionsMultiplier*runtime.NumCPU(), maxPartitions)
|
|
|
|
|
return &Matcher{
|
|
|
|
|
patternBuilder: patternBuilder,
|
|
|
|
@ -48,7 +49,8 @@ func NewMatcher(patternBuilder func([]rune) *Pattern,
|
|
|
|
|
reqBox: util.NewEventBox(),
|
|
|
|
|
partitions: partitions,
|
|
|
|
|
slab: make([]*util.Slab, partitions),
|
|
|
|
|
mergerCache: make(map[string]*Merger)}
|
|
|
|
|
mergerCache: make(map[string]*Merger),
|
|
|
|
|
revision: revision}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Loop puts Matcher in action
|
|
|
|
@ -70,8 +72,9 @@ func (m *Matcher) Loop() {
|
|
|
|
|
events.Clear()
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
if request.sort != m.sort || request.clearCache {
|
|
|
|
|
if request.sort != m.sort || request.revision != m.revision {
|
|
|
|
|
m.sort = request.sort
|
|
|
|
|
m.revision = request.revision
|
|
|
|
|
m.mergerCache = make(map[string]*Merger)
|
|
|
|
|
clearChunkCache()
|
|
|
|
|
}
|
|
|
|
@ -140,11 +143,11 @@ func (m *Matcher) scan(request MatchRequest) (*Merger, bool) {
|
|
|
|
|
|
|
|
|
|
numChunks := len(request.chunks)
|
|
|
|
|
if numChunks == 0 {
|
|
|
|
|
return EmptyMerger, false
|
|
|
|
|
return EmptyMerger(request.revision), false
|
|
|
|
|
}
|
|
|
|
|
pattern := request.pattern
|
|
|
|
|
if pattern.IsEmpty() {
|
|
|
|
|
return PassMerger(&request.chunks, m.tac), false
|
|
|
|
|
return PassMerger(&request.chunks, m.tac, request.revision), false
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cancelled := util.NewAtomicBool(false)
|
|
|
|
@ -218,11 +221,11 @@ func (m *Matcher) scan(request MatchRequest) (*Merger, bool) {
|
|
|
|
|
partialResult := <-resultChan
|
|
|
|
|
partialResults[partialResult.index] = partialResult.matches
|
|
|
|
|
}
|
|
|
|
|
return NewMerger(pattern, partialResults, m.sort, m.tac), false
|
|
|
|
|
return NewMerger(pattern, partialResults, m.sort, m.tac, request.revision), false
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Reset is called to interrupt/signal the ongoing search
|
|
|
|
|
func (m *Matcher) Reset(chunks []*Chunk, patternRunes []rune, cancel bool, final bool, sort bool, clearCache bool) {
|
|
|
|
|
func (m *Matcher) Reset(chunks []*Chunk, patternRunes []rune, cancel bool, final bool, sort bool, revision int) {
|
|
|
|
|
pattern := m.patternBuilder(patternRunes)
|
|
|
|
|
|
|
|
|
|
var event util.EventType
|
|
|
|
@ -231,5 +234,5 @@ func (m *Matcher) Reset(chunks []*Chunk, patternRunes []rune, cancel bool, final
|
|
|
|
|
} else {
|
|
|
|
|
event = reqRetry
|
|
|
|
|
}
|
|
|
|
|
m.reqBox.Set(event, MatchRequest{chunks, pattern, final, sort && pattern.sortable, clearCache})
|
|
|
|
|
m.reqBox.Set(event, MatchRequest{chunks, pattern, final, sort && pattern.sortable, revision})
|
|
|
|
|
}
|
|
|
|
|