-
Notifications
You must be signed in to change notification settings - Fork 14.5k
KAFKA-10409: Refactor Kakfa Streams RocksDB Iterators #18610
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
base: trunk
Are you sure you want to change the base?
KAFKA-10409: Refactor Kakfa Streams RocksDB Iterators #18610
Conversation
c5f8d03
to
f147674
Compare
f147674
to
3338e09
Compare
Signed-off-by: Joao Pedro Fonseca Dantas <fonsdant@gmail.com>
Signed-off-by: Joao Pedro Fonseca Dantas <fonsdant@gmail.com>
3338e09
to
9a614c1
Compare
A label of 'needs-attention' was automatically added to this PR in order to raise the |
Hi, @ableegoldman! Could you help me with this PR? :) |
Yep! Will take a look in the next day or so 🙂 |
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.
thanks @fonsdant this is a great cleanup! I left some minor suggestions inline, I'm not super familiar with this part of the code so feel free to take it or leave it
* <p>The iterator is thread-safe for sequential operations but should not be accessed concurrently from multiple | ||
* threads without external synchronization.</p> |
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.
what does this mean? doesn't that just mean it's not thread safe?
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.
Updated.
* @throws NoSuchElementException If there are no more elements in the iterator. | ||
*/ | ||
@Override | ||
public Bytes peekNextKey() { |
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.
existing test coverage for this class is below average (e.g. there's not peekNextKey
in the test) - could you add that?
cc @ableegoldman it may be good to refactor the existing tests alongside this one so that instead of one really big test we had individual tests for each piece of functionality so it's easier to confirm the test coverage is good
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.
In progress.
return super.hasNext(); | ||
protected KeyValue<Bytes, byte[]> makeNext() { | ||
loadNextKeys(); | ||
if (noTimestampNext == null && withTimestampNext == null) return allDone(); |
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.
There seems to be a functionality change. Not sure if this is intentional or not but it looks like we drop checking the condition where the iterators are not valid. (In other words, there's a branch where after loadNextKeys()
, noTimestampNext
is still null
but iterator.isValid()
.
Not sure what might cause this condition.
The old code:
if (nextNoTimestamp == null && iterNoTimestamp.isValid()) {
nextNoTimestamp = iterNoTimestamp.key();
}
if (nextWithTimestamp == null && iterWithTimestamp.isValid()) {
nextWithTimestamp = iterWithTimestamp.key();
}
if (nextNoTimestamp == null && !iterNoTimestamp.isValid()) {
if (nextWithTimestamp == null && !iterWithTimestamp.isValid()) {
return allDone();
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.
Although this branch is not explicit, I think it is covered. In the old code, allDone is only called if both nextTimestamp are null and both are invalid. So this is already checked on previous branches (in the new code, on loadNextKeys). That is, if both next are null, in loadNextKeys: 1) if they are valid, they will get next keys and will no longer be null (and will not go into allDone when loadNextKeys is finished since they have become different from null); 2) if they are invalid, they will remain null and will go into allDone after loadNextKeys is finished.
return forward | ||
? comparison < 0 || (toInclusive && comparison == 0) | ||
: comparison > 0 || (toInclusive && comparison == 0); |
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.
return forward | |
? comparison < 0 || (toInclusive && comparison == 0) | |
: comparison > 0 || (toInclusive && comparison == 0); | |
return (toInclusive && comparison == 0) || (forward ? comparison < 0 : comparison > 0); |
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.
Updated.
this.toInclusive = toInclusive; | ||
this.withTimestampIterator = withTimestampIterator; | ||
|
||
this.rawLastKey = initializeIterators(from, to); |
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.
generally it's better for constructors not to have side effects - otherwise it's possible that if something throws an exception during instantiation the close
method won't be called.
this doesn't seem to be a regression (the old code did that as well for the RangeIterator) so consider this comment an optional suggestion
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.
Updated.
Signed-off-by: Joao Pedro Fonseca Dantas <fonsdant@gmail.com>
Signed-off-by: Joao Pedro Fonseca Dantas <fonsdant@gmail.com>
@agavra, thanks for reviewing! I have pushed some commits :) |
Signed-off-by: Joao Pedro Fonseca Dantas <fonsdant@gmail.com>
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.
This LGTM once the tests are in :) will make it easier to convince me that there's no functionality changes. Thanks for addressing the comments.
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.
Took a quick look and I think it looks good, but as Almog mentioned the existing test coverage is seriously lacking so it'll be great to fill in some the tests here. I'll do a closer pass once you push the new tests 🙂
This PR is being marked as stale since it has not had any activity in 90 days. If you If you are having difficulty finding a reviewer, please reach out on the [mailing list](https://kafka.apache.org/contact). If this PR is no longer valid or desired, please feel free to close it. If no activity occurs in the next 30 days, it will be automatically closed. |
@agavra, sorry for the delay, I am resuming the work. How could I check the coverage report for streams only? According on readme, I can run P.S.: I was missing -PenableTestCoverage=true, I got it :) |
Key refactorings:
RocksDBDualCFRangeIterator
forDualColumnFamilyAccessor#all
, since it iterate over all when passingnull
asfrom
andto
key ranges;loadNextKeys()
;fetchNextKeyValue()
;handleWithTimestampOnly()
;handleNoTimestampOnly()
;compareAndHandleKeys()
;isInRange()
; andensureOpen()
.makeNext()
;next()
; andhasNext()
.noTimestampNext
;withTimestampNext
;noTimestampIterator
; andwithTimestampIterator
.