-
Notifications
You must be signed in to change notification settings - Fork 453
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
[dbnode] Optimize block range scan in queryWithSpan #3813
Changes from all commits
2327419
0a7db36
f341b43
60f500d
66a94fb
15dfb50
7c4a702
399e276
0cf97a6
e2590eb
79c1ef9
0a65bd3
4c5005f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -544,15 +544,30 @@ func (b *block) queryWithSpan( | |
doc := iter.Current() | ||
if md, ok := doc.Metadata(); ok && md.OnIndexSeries != nil { | ||
var ( | ||
inBlock bool | ||
currentBlock = opts.StartInclusive.Truncate(b.blockSize) | ||
inBlock bool | ||
currentBlock = opts.StartInclusive.Truncate(b.blockSize) | ||
endExclusive = opts.EndExclusive | ||
minIndexed, maxIndexed = md.OnIndexSeries.IndexedRange() | ||
) | ||
for !inBlock { | ||
|
||
if maxIndexed == 0 { | ||
// Empty range. | ||
continue | ||
} | ||
|
||
// Narrow down the range of blocks to scan because the client could have | ||
// queried for an arbitrary wide range. | ||
if currentBlock.Before(minIndexed) { | ||
currentBlock = minIndexed | ||
} | ||
maxIndexedExclusive := maxIndexed.Add(time.Nanosecond) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why add the nanosecond? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To convert inclusive timestamp to exclusive one. So that we can compare and replace |
||
if endExclusive.After(maxIndexedExclusive) { | ||
endExclusive = maxIndexedExclusive | ||
} | ||
|
||
for !inBlock && currentBlock.Before(endExclusive) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So, I don't quite follow this for loop. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. TBH I'm not really familiar with this aspect, either. I saw the opportunity to optimize this code without affecting its semantics, in which case I don't have to fully understand the context of it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hm, this loop behaves slightly different than before. Previously, this loop was being iterated no less than once, now it might not iterate at all. While the current implementation is more correct, maybe the less correct version was necessary for proper functioning? (Though conditions when the behavior would differ seem to be too rare for this to matter). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You mean the case when |
||
inBlock = md.OnIndexSeries.IndexedForBlockStart(currentBlock) | ||
currentBlock = currentBlock.Add(b.blockSize) | ||
if !currentBlock.Before(opts.EndExclusive) { | ||
break | ||
} | ||
} | ||
|
||
if !inBlock { | ||
|
@@ -628,7 +643,7 @@ func (b *block) addQueryResults( | |
return batch, size, docsCount, err | ||
} | ||
|
||
// AggIter acquires a read lock on the block to get the set of segments for the returned iterator. However, the | ||
// AggregateIter acquires a read lock on the block to get the set of segments for the returned iterator. However, the | ||
// segments are searched and results are processed lazily in the returned iterator. The segments are finalized when | ||
// the ctx is finalized to ensure the mmaps are not freed until the ctx closes. This allows the returned results to | ||
// reference data in the mmap without copying. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: why the separate method instead of inlining in
IndexedRange
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IndexedRange
is onEntry
struct,indexedRangeWithRLock
is onentryIndexState
.