-
Notifications
You must be signed in to change notification settings - Fork 14k
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
MINOR: Improve Log layer segment iteration logic and few other areas #10684
MINOR: Improve Log layer segment iteration logic and few other areas #10684
Conversation
010858d
to
c1b293f
Compare
* Returns an iterable to log segments ordered from lowest base offset to highest. | ||
* Each segment in the returned iterable has a base offset strictly greater than the provided baseOffset. | ||
*/ | ||
def higherSegments(baseOffset: Long): Iterable[LogSegment] = { |
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.
@ijuma If you think this API is a good fit to the requirement, I can add unit tests for it.
cc @junrao |
|
||
done = fetchDataInfo != null || segmentEntryOpt.isEmpty | ||
done = fetchDataInfo != null || segmentOpt.isEmpty |
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.
can we simply use while (fetchDataInfo == null && segmentOpt.isDefined)
rather than while (!done)
?
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.
Done. Please see 80c40171302546be2dcf2444167d7f375f0b820d.
LGTM Thanks @kowshik |
0134a4d
to
4ffeaa3
Compare
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.
@kowshik : Thanks for the PR. A couple of comments below.
|
||
done = fetchDataInfo != null || segmentEntryOpt.isEmpty | ||
fetchDataInfo = addAbortedTransactions(startOffset, segment, fetchDataInfo) | ||
} else segmentOpt = segmentsIterator.nextOption() |
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.
The old logic supports skipping forward multiple segments to find the right data. The new logic seems to only support skipping forward once. It would be useful to preserve the original semantic.
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.
That is an excellent catch. Sorry I missed this. Done, changed it now.
val view = | ||
Option(segments.higherKey(baseOffset)).map { | ||
higherOffset => segments.tailMap(higherOffset, true) | ||
}.getOrElse(new ConcurrentSkipListMap[Long, LogSegment]()) |
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.
Could we return a constant empty map?
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.
Done.
e718bce
to
4b83603
Compare
Thanks for the review @junrao! I have addressed your comments in 4b836034415c3d5f6b84384ef9be1e75b66edc4b. |
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.
@kowshik : Thanks for the updated PR. There seems to be a compilation error in java 8.
4b83603
to
4d86571
Compare
4d86571
to
7a84aa1
Compare
@junrao Thanks for the review and for catching this issue! I've fixed the build now. The issue was that the code in I have now also added unit tests for the newly introduced The PR is ready for review again. |
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.
@kowshik : Thanks for the updated PR. LGTM
Log.collectAbortedTransactions()
I've restored a previously used logic, such that it would handle the case where the starting segment could be null. This was the case previously, but the PR KAFKA-12552: Introduce LogSegments class abstracting the segments map #10401 accidentally changed the behavior causing the code to assume that the starting segment won't be null.Log.rebuildProducerState()
I've removed usage of theallSegments
local variable. The logic looks a bit simpler after I removed it.LogSegments.higherSegments()
API. This is now used to make the logic a bit more readable inLog. collectAbortedTransactions()
andLog.deletableSegments()
APIs.java.lang.Long
inLogSegments
class' segments map definition.LogSegments
API from public to private, as they need not be public.Tests:
Relying on existing unit tests.