Skip to content
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][ml] Avoid repetitive nested lock for isMessageDeleted in ManagedCursorImpl #23609

Merged
merged 1 commit into from
Nov 19, 2024

Conversation

Denovo1998
Copy link
Contributor

Main Issue: #23605

Motivation

The following are all related to the org.apache.bookkeeper.mledger.impl.ManagedCursorImpl#isMessageDeleted:

@Override
public boolean isMessageDeleted(Position position) {
lock.readLock().lock();
try {
return position.compareTo(markDeletePosition) <= 0
|| individualDeletedMessages.contains(position.getLedgerId(), position.getEntryId());
} finally {
lock.readLock().unlock();
}
}

  1. A write lock has already been acquired, but a read lock has been acquired as well. This doesn't pose a major problem, but it does result in some unnecessary additional overhead.

    lock.writeLock().lock();
    try {
    if (log.isDebugEnabled()) {
    log.debug("[{}] [{}] Deleting individual messages at {}. Current status: {} - md-position: {}",
    ledger.getName(), name, positions, individualDeletedMessages, markDeletePosition);
    }
    for (Position pos : positions) {
    Position position = requireNonNull(pos);
    if (ledger.getLastConfirmedEntry().compareTo(position) < 0) {
    if (log.isDebugEnabled()) {
    log.debug(
    "[{}] Failed mark delete due to invalid markDelete {} is ahead of last-confirmed-entry {} "
    + "for cursor [{}]", ledger.getName(), position, ledger.getLastConfirmedEntry(), name);
    }
    callback.deleteFailed(new ManagedLedgerException("Invalid mark deleted position"), ctx);
    return;
    }
    if (isMessageDeleted(position)) {

  2. The performance impact of nested read locks can be negligible, but frequent acquisition and release of locks will slightly increase system overhead.

    lock.readLock().lock();
    try {
    positions.stream().filter(this::isMessageDeleted).forEach(alreadyAcknowledgedPositions::add);
    } finally {
    lock.readLock().unlock();
    }

Modifications

Verifying this change

  • Make sure that the change passes the CI checks.

(Please pick either of the following options)

This change is a trivial rework / code cleanup without any test coverage.

(or)

This change is already covered by existing tests, such as (please describe tests).

(or)

This change added tests and can be verified as follows:

(example:)

  • Added integration tests for end-to-end deployment with large payloads (10MB)
  • Extended integration test for recovery after broker failure

Does this pull request potentially affect one of the following parts:

If the box was checked, please highlight the changes

  • Dependencies (add or upgrade a dependency)
  • The public API
  • The schema
  • The default values of configurations
  • The threading model
  • The binary protocol
  • The REST endpoints
  • The admin CLI options
  • The metrics
  • Anything that affects deployment

Documentation

  • doc
  • doc-required
  • doc-not-needed
  • doc-complete

Matching PR in forked repository

PR in forked repository:

@github-actions github-actions bot added the doc-not-needed Your PR changes do not impact docs label Nov 18, 2024
@Denovo1998
Copy link
Contributor Author

@lhotari @dao-jun PTAL!

Copy link
Member

@lhotari lhotari left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@lhotari lhotari added this to the 4.1.0 milestone Nov 19, 2024
@lhotari lhotari changed the title [cleanup][ml] Clean up nested read-write lock code in ManagedCursor [improve][ml] Avoid nested lock for isMessageDeleted in ManagedCursorImpl Nov 19, 2024
@lhotari lhotari changed the title [improve][ml] Avoid nested lock for isMessageDeleted in ManagedCursorImpl [improve][ml] Avoid repetitive nested lock for isMessageDeleted in ManagedCursorImpl Nov 19, 2024
@codecov-commenter
Copy link

codecov-commenter commented Nov 19, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 74.38%. Comparing base (bbc6224) to head (2d2f159).
Report is 737 commits behind head on master.

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff              @@
##             master   #23609      +/-   ##
============================================
+ Coverage     73.57%   74.38%   +0.80%     
- Complexity    32624    34458    +1834     
============================================
  Files          1877     1944      +67     
  Lines        139502   147128    +7626     
  Branches      15299    16224     +925     
============================================
+ Hits         102638   109437    +6799     
- Misses        28908    29264     +356     
- Partials       7956     8427     +471     
Flag Coverage Δ
inttests 27.61% <80.00%> (+3.02%) ⬆️
systests 24.34% <80.00%> (+0.02%) ⬆️
unittests 73.76% <100.00%> (+0.92%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
...che/bookkeeper/mledger/impl/ManagedCursorImpl.java 80.24% <100.00%> (+0.94%) ⬆️

... and 655 files with indirect coverage changes

---- 🚨 Try these New Features:

@lhotari lhotari merged commit 895e968 into apache:master Nov 19, 2024
57 of 59 checks passed
lhotari pushed a commit that referenced this pull request Nov 21, 2024
lhotari pushed a commit that referenced this pull request Nov 21, 2024
lhotari pushed a commit that referenced this pull request Nov 21, 2024
nikhil-ctds pushed a commit to datastax/pulsar that referenced this pull request Nov 26, 2024
…nagedCursorImpl (apache#23609)

(cherry picked from commit 895e968)
(cherry picked from commit 96cf000)
srinath-ctds pushed a commit to datastax/pulsar that referenced this pull request Nov 26, 2024
…nagedCursorImpl (apache#23609)

(cherry picked from commit 895e968)
(cherry picked from commit 96cf000)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants