Skip to content

Return last evaluated progress on lock timeout in RestrictionTrackers.getProgress - #40205

Merged
damccorm merged 3 commits into
apache:masterfrom
damccorm:fix-restriction-tracker-progress-cache
Sep 22, 2026
Merged

damccorm merged 3 commits into
apache:masterfrom
damccorm:fix-restriction-tracker-progress-cache

Conversation

@damccorm

@damccorm damccorm commented Sep 21, 2026 •

Copy link
Copy Markdown
Contributor

Previously, RestrictionTrackerObserverWithProgress.getProgress only used lock.tryLock with a timeout until initial progress was reported (!hasInitialProgress), falling back to an unbounded blocking getProgressBlocking() call afterwards. If a subsequent tryClaim or trySplit held the lock for a long duration, getProgress() would still block indefinitely.

This change:

  1. Caches lastProgress (initialized to Progress.NONE) and always uses lock.tryLock(timeOutSec, TimeUnit.SECONDS) in getProgress.
  2. When getProgress fails to acquire the lock, sets needsProgressUpdate = true and returns lastProgress.
  3. Before releasing the lock in other RestrictionTrackerObserver methods (tryClaim, currentRestriction, trySplit, checkDone), checks if (needsProgressUpdate) and calls updateProgressBlocking() inside a try ... finally { lock.unlock(); } block so that lastProgress is kept fresh and the lock is always released.

@damccorm

Copy link
Copy Markdown
Contributor Author

R: @Abacn

@github-actions

Copy link
Copy Markdown
Contributor

Stopping reviewer notifications for this pull request: review requested by someone other than the bot, ceding control. If you'd like to restart, comment assign set of reviewers

@damccorm

Copy link
Copy Markdown
Contributor Author

cc/ @scwhittle as well

try {
updateProgressBlocking();
} finally {
lock.unlock();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We now have mixed calls of unlock() and lock.unlock(). Consider name the new unlock() method updateProgressAndUnlock() ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I didn't do this because updateProgressAndUnlock() implies that we're always updating progress, which we're not. But I see the downside, and I think I prefer your approach.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done

delegate.checkDone();
} finally {
lock.unlock();
unlock();

@Abacn Abacn Sep 21, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Do all 4 occurrences of lock.unlock() -> updateProgressAndUnlock(); changes really need to update the progress cache as part of their method calls?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Probably not, but the needsProgressUpdate is super cheap, so I'd prefer to keep it.

needsProgressUpdate = true;
Thread.currentThread().interrupt();
}
return lastProgress;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is this correct if a split has occurred?
lastProgress may have been in the context of before the split which might confuse the runner.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

We can probably just unconditionally update progress after a split to fix this.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done

@scwhittle scwhittle left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think that this seems safe now.

@damccorm
damccorm merged commit a40d8cd into apache:master Sep 22, 2026
25 checks passed
Amar3tto pushed a commit that referenced this pull request Sep 29, 2026
….getProgress (#40205)

* Return last evaluated progress on lock timeout in RestrictionTrackers.getProgress

* Update progress before unlocking when needsProgressUpdate is set

* Unconditionally update progress after trySplit and rename unlock to updateProgressAndUnlock
Amar3tto added a commit that referenced this pull request Sep 29, 2026
[release-2.77] Cherry-pick RestrictionTrackers lock timeout fixes (#40205, #40251)
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.

4 participants