Skip to content
This repository has been archived by the owner on Feb 8, 2019. It is now read-only.

Resolve bug: when search with 'prev.op==le', same span may appear repeated in result view #6

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
26 changes: 24 additions & 2 deletions htrace-htraced/go/src/htrace/htraced/datastore.go
Original file line number Diff line number Diff line change
Expand Up @@ -872,13 +872,22 @@ func (pred *predicateData) spanPtrIsBefore(a *common.Span, b *common.Span) bool
return true
}
// Compare the spans according to this predicate.
// if spans has same relevantSpanData, compare the span Id.
aVal := pred.extractRelevantSpanData(a)
bVal := pred.extractRelevantSpanData(b)
cmp := bytes.Compare(aVal, bVal)
if pred.Op.IsDescending() {
return cmp > 0
if cmp == 0 {
return bytes.Compare(a.Id, b.Id) > 0
} else {
return cmp > 0
}
} else {
return cmp < 0
if cmp == 0 {
return bytes.Compare(a.Id, b.Id) < 0
} else {
return cmp < 0
}
}
}

Expand Down Expand Up @@ -1042,7 +1051,20 @@ func (pred *predicateData) createSource(store *dataStore, prev *common.Span) (*s
searchKey = append([]byte{src.keyPrefix}, pred.key...)
}
for i := range src.iters {
// Seek moves the iterator the position of the key given or, if the key
// doesn't exist, the next key that does exist in the database.
// link: https://github.com/jmhodges/levigo/blob/master/iterator.go#L126
src.iters[i].Seek(searchKey)

// When 'pred.op == common.LESS_THAN_OR_EQUALS', and execute 'src.iters[i[.Seek(searchKey)'
// the iterator may still leave in the same position with prev.
// To avoid this, check the key of iterator.
if src.iters[i].Valid() {
key := src.iters[i].Key()
if src.pred.Op.IsDescending() && bytes.Compare(key, searchKey) > 0 {
src.iters[i].Prev()
}
}
}
ret = &src
return ret, nil
Expand Down