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

Fix order of the returned results from badger backend. #1939

Merged
merged 5 commits into from
Nov 26, 2019

Conversation

burmanm
Copy link
Contributor

@burmanm burmanm commented Nov 21, 2019

Which problem is this PR solving?

Add additional tests to verify that results are returned in correct DESC order as well as add the ability to request StartTime filtering for only TraceIDs, instead of requiring complete Traces.

Fixes #1913

Short description of the changes

Last index scan will now do a reverse scan (badger defaults to ASC) and retain the order when doing the hash-join against previous index scan results. Otherwise the index scans will keep using the sort-merge-join.

@codecov
Copy link

codecov bot commented Nov 21, 2019

Codecov Report

Merging #1939 into master will increase coverage by <.01%.
The diff coverage is 96.77%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1939      +/-   ##
==========================================
+ Coverage   98.43%   98.43%   +<.01%     
==========================================
  Files         198      198              
  Lines        9847     9851       +4     
==========================================
+ Hits         9693     9697       +4     
  Misses        116      116              
  Partials       38       38
Impacted Files Coverage Δ
plugin/storage/badger/spanstore/reader.go 96.79% <96.77%> (+0.04%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update bf64373...1707559. Read the comment docs.

tests to verify this as well as add the ability to request StarTime
filtering for only TraceIDs.

Signed-off-by: Michael Burman <yak@iki.fi>
plugin/storage/badger/spanstore/read_write_test.go Outdated Show resolved Hide resolved

timeMax := model.TimeAsEpochMicroseconds(startTimeMax)
for it.Seek(startIndex); scanFunction(it, indexKeyValue, timeMax); it.Next() {
for it.Seek(startIndex); scanFunction(it, indexKeyValue, plan.startTimeMin); it.Next() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Has changed from startTimeMax to Min - is that correct? Is it because of reversing the time order?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Exactly. We finish the scan when the min timestamp is hit.

key := make([]byte, len(item.Key()))
copy(key, item.Key())
indexResults = append(indexResults, key)
traceIDBytes := item.Key()[len(item.Key())-sizeOfTraceID:]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wondering whether it would be better to move knowledge about how to extract traceIDBytes from the key into the Item type - or possibly have a Key type that encapsulates all the necessary knowledge about how the key is encoded? Could be done as a separate PR, but might make it easier to maintain.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The key is encoded in different way depending on the type of key. For example, primary keys that store the trace have different structure than the indexKeys.

Also, Item/Key are types used internally by badger, so that might be a bit confusing if those names were used. But yes, this could be built as "indexKey" and "traceKey" structs.

@@ -100,48 +98,34 @@ func TestDecodeErrorReturns(t *testing.T) {
assert.Error(t, err)
}

func TestSortMergeIdsDuplicateDetection(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you just clarify why this test is no longer required?

plugin/storage/badger/spanstore/rw_internal_test.go Outdated Show resolved Hide resolved
plugin/storage/badger/spanstore/reader.go Show resolved Hide resolved
plugin/storage/badger/spanstore/reader.go Outdated Show resolved Hide resolved
err := r.store.View(func(txn *badger.Txn) error {
opts := badger.DefaultIteratorOptions
opts.PrefetchValues = false // Don't fetch values since we're only interested in the keys
opts.Reverse = true
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

More recent first?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep.

plugin/storage/badger/spanstore/rw_internal_test.go Outdated Show resolved Hide resolved
… the limit in scanTimeRange only scenario

Signed-off-by: Michael Burman <yak@iki.fi>
Copy link
Contributor

@objectiser objectiser left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only one minor change.

plugin/storage/badger/spanstore/reader.go Outdated Show resolved Hide resolved
… returned values, whichever is smallest

Signed-off-by: Michael Burman <yak@iki.fi>
Copy link
Contributor

@jpkrohling jpkrohling left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just remove the code that is commented out. Otherwise LGTM.

@burmanm
Copy link
Contributor Author

burmanm commented Nov 25, 2019

@jpkrohling As for the code that should be removed.. it was removed already? I think you looked at the wrong side of the compare ;)

@jpkrohling
Copy link
Contributor

As for the code that should be removed.. it was removed already? I think you looked at the wrong side of the compare ;)

What's going on with me... :-)

@jpkrohling jpkrohling merged commit c57e4b7 into jaegertracing:master Nov 26, 2019
@pavolloffay pavolloffay added the storage/badger Issues related to badger storage label Dec 17, 2019
@pavolloffay pavolloffay added this to the Release 1.16 milestone Dec 17, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
storage/badger Issues related to badger storage
Projects
None yet
Development

Successfully merging this pull request may close these issues.

showing latest traces not working properly using all-in-one with badger
4 participants