-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
[improve][broker] Make CompactedTopicImpl.findStartPointLoop work more efficiently #17976
[improve][broker] Make CompactedTopicImpl.findStartPointLoop work more efficiently #17976
Conversation
5adcaf8
to
88939f8
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.
Great catch!
The fix looks good to me. How can the test cover the new improvement?
|
||
// Sparse ledger makes multi entry has same data, this is used to construct complex environments to verify that the | ||
// smallest position with the correct data is found. | ||
private static final TreeMap<Long,Long> ORIGIN_SPARSE_LEDGER = new TreeMap<>(); |
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.
private static final TreeMap<Long,Long> ORIGIN_SPARSE_LEDGER = new TreeMap<>(); | |
private static final TreeMap<Long, Long> ORIGIN_SPARSE_LEDGER = new TreeMap<>(); |
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.
Already fixed
ORIGIN_SPARSE_LEDGER.put(10L,1010L); | ||
ORIGIN_SPARSE_LEDGER.put(20L,1020L); | ||
ORIGIN_SPARSE_LEDGER.put(50L,1050L); | ||
ORIGIN_SPARSE_LEDGER.put(Long.MAX_VALUE,Long.MAX_VALUE); |
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.
ORIGIN_SPARSE_LEDGER.put(Long.MAX_VALUE,Long.MAX_VALUE); | |
ORIGIN_SPARSE_LEDGER.put(Long.MAX_VALUE, Long.MAX_VALUE); |
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.
Already fixed
private static CacheLoader<Long, MessageIdData> mockCacheLoader(long start, long end, final long targetMessageId, | ||
AtomicLong bingoMarker){ | ||
// Mock ledger. | ||
final TreeMap<Long,Long> sparseLedger = new TreeMap<>(); |
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.
final TreeMap<Long,Long> sparseLedger = new TreeMap<>(); | |
final TreeMap<Long, Long> sparseLedger = new TreeMap<>(); |
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.
Already fixed
sparseLedger.putAll(ORIGIN_SPARSE_LEDGER.subMap(start, end + 1)); | ||
sparseLedger.put(Long.MAX_VALUE,Long.MAX_VALUE); | ||
|
||
Function<Long,Long> findMessageIdFunc = entryId -> sparseLedger.ceilingEntry(entryId).getValue(); |
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.
Function<Long,Long> findMessageIdFunc = entryId -> sparseLedger.ceilingEntry(entryId).getValue(); | |
Function<Long, Long> findMessageIdFunc = entryId -> sparseLedger.ceilingEntry(entryId).getValue(); |
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.
Already fixed
88939f8
to
f49dc91
Compare
already append test "testRecursionNumberOfFindStartPointLoop" to cover this case. |
* Why should we check the recursion number of "findStartPointLoop", see: #17976 | ||
*/ | ||
@Test | ||
public void testRecursionNumberOfFindStartPointLoop() throws Exception { |
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.
Seems that this function won't throw any Exceptions
.
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.
Already removed. Thanks
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.
Looks great to me.
/pulsarbot rerun-failure-checks |
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.
LGTM
Motivation & Modifications
CompactedTopicImpl.findStartPointLoop
uses the binary search, but the implementation had a flaw that caused several more loops to be executed. If an array like this:[1,2,3...100]
, and we search value2
in this array,CompactedTopicImpl.findStartPointLoop
will execute the following loops:We can optimize the loop like this:
Documentation
doc
doc-required
doc-not-needed
doc-complete
Matching PR in forked repository
PR in forked repository: