-
Notifications
You must be signed in to change notification settings - Fork 15.2k
MINOR: Improve Log layer segment iteration logic and few other areas #10684
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
Merged
junrao
merged 6 commits into
apache:trunk
from
kowshik:MINOR_improve_Log_layer_in_AK_a_bit
May 27, 2021
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
f4bb513
MINOR: Improve Log layer segment iteration logic and few other areas
kowshik d83704e
Minor improvement
kowshik d9b4eb0
Address comments
kowshik ff75dfe
Fix inconsistent Option/null check in Log.collectAbortedTransactions
kowshik c0e8307
Address comments from Jun
kowshik 7a84aa1
Fix build in scala 2.12 and add unit tests
kowshik File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,7 +17,6 @@ | |
| package kafka.log | ||
|
|
||
| import java.io.File | ||
| import java.lang.{Long => JLong} | ||
| import java.util.Map | ||
| import java.util.concurrent.{ConcurrentNavigableMap, ConcurrentSkipListMap} | ||
|
|
||
|
|
@@ -36,7 +35,7 @@ import scala.jdk.CollectionConverters._ | |
| class LogSegments(topicPartition: TopicPartition) { | ||
|
|
||
| /* the segments of the log with key being LogSegment base offset and value being a LogSegment */ | ||
| private val segments: ConcurrentNavigableMap[java.lang.Long, LogSegment] = new ConcurrentSkipListMap[java.lang.Long, LogSegment] | ||
| private val segments: ConcurrentNavigableMap[Long, LogSegment] = new ConcurrentSkipListMap[Long, LogSegment] | ||
|
|
||
| /** | ||
| * @return true if the segments are empty, false otherwise. | ||
|
|
@@ -157,7 +156,7 @@ class LogSegments(topicPartition: TopicPartition) { | |
| * if it exists. | ||
| */ | ||
| @threadsafe | ||
| def floorEntry(offset: Long): Option[Map.Entry[JLong, LogSegment]] = Option(segments.floorEntry(offset)) | ||
| private def floorEntry(offset: Long): Option[Map.Entry[Long, LogSegment]] = Option(segments.floorEntry(offset)) | ||
|
|
||
| /** | ||
| * @return the log segment with the greatest offset less than or equal to the given offset, | ||
|
|
@@ -171,7 +170,7 @@ class LogSegments(topicPartition: TopicPartition) { | |
| * if it exists. | ||
| */ | ||
| @threadsafe | ||
| def lowerEntry(offset: Long): Option[Map.Entry[JLong, LogSegment]] = Option(segments.lowerEntry(offset)) | ||
| private def lowerEntry(offset: Long): Option[Map.Entry[Long, LogSegment]] = Option(segments.lowerEntry(offset)) | ||
|
|
||
| /** | ||
| * @return the log segment with the greatest offset strictly less than the given offset, | ||
|
|
@@ -185,7 +184,7 @@ class LogSegments(topicPartition: TopicPartition) { | |
| * if it exists. | ||
| */ | ||
| @threadsafe | ||
| def higherEntry(offset: Long): Option[Map.Entry[JLong, LogSegment]] = Option(segments.higherEntry(offset)) | ||
| def higherEntry(offset: Long): Option[Map.Entry[Long, LogSegment]] = Option(segments.higherEntry(offset)) | ||
|
kowshik marked this conversation as resolved.
Outdated
|
||
|
|
||
| /** | ||
| * @return the log segment with the smallest offset strictly greater than the given offset, | ||
|
|
@@ -198,7 +197,7 @@ class LogSegments(topicPartition: TopicPartition) { | |
| * @return the entry associated with the smallest offset, if it exists. | ||
| */ | ||
| @threadsafe | ||
| def firstEntry: Option[Map.Entry[JLong, LogSegment]] = Option(segments.firstEntry) | ||
| def firstEntry: Option[Map.Entry[Long, LogSegment]] = Option(segments.firstEntry) | ||
|
|
||
| /** | ||
| * @return the log segment associated with the smallest offset, if it exists. | ||
|
|
@@ -210,11 +209,23 @@ class LogSegments(topicPartition: TopicPartition) { | |
| * @return the entry associated with the greatest offset, if it exists. | ||
| */ | ||
| @threadsafe | ||
| def lastEntry: Option[Map.Entry[JLong, LogSegment]] = Option(segments.lastEntry) | ||
| def lastEntry: Option[Map.Entry[Long, LogSegment]] = Option(segments.lastEntry) | ||
|
|
||
| /** | ||
| * @return the log segment with the greatest offset, if it exists. | ||
| */ | ||
| @threadsafe | ||
| def lastSegment: Option[LogSegment] = lastEntry.map(_.getValue) | ||
|
|
||
| /** | ||
| * @return an iterable with log segments ordered from lowest base offset to highest, | ||
| * each segment returned has a base offset strictly greater than the provided baseOffset. | ||
| */ | ||
| def higherSegments(baseOffset: Long): Iterable[LogSegment] = { | ||
|
Contributor
Author
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. @ijuma If you think this API is a good fit to the requirement, I can add unit tests for it. |
||
| val view = | ||
| Option(segments.higherKey(baseOffset)).map { | ||
| higherOffset => segments.tailMap(higherOffset, true) | ||
| }.getOrElse(collection.immutable.Map[Long, LogSegment]().asJava) | ||
| view.values.asScala | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.