Skip to content

Verify that ZKLock is not engaged on capacity clean#11131

Merged
artembilan merged 4 commits into
spring-projects:mainfrom
cppwfs:SI-11113B
Jun 18, 2026
Merged

Verify that ZKLock is not engaged on capacity clean#11131
artembilan merged 4 commits into
spring-projects:mainfrom
cppwfs:SI-11113B

Conversation

@cppwfs

@cppwfs cppwfs commented Jun 17, 2026

Copy link
Copy Markdown
Contributor
  • Do not remove entry if it still has a zk lock from cache when cacheCapacity limit has been reached.
  • If the oldest entry in the cache can't be removed because it is locked. Find the next oldest entry and remove it
  • Add test that validates the fix

Resolves: #11113

Auto-cherry-pick to 7.0.x & 6.5.x

- Do not remove entry if it still has a zk lock from
  cache when cacheCapacity limit has been reached.
- If the oldest entry in the cache can't be removed
  because it is locked.  Find the next oldest entry
  and remove it
- Add test that validates the fix

Resolves: spring-projects#11113

**Auto-cherry-pick to 7.0.x & 6.5.x**
@cppwfs cppwfs requested a review from artembilan June 17, 2026 20:51

@artembilan artembilan left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can we go with Fixes: sentence instead ?
Otherwise our Backport bot won’t create required issues:

if: contains(github.event.head_commit.message, 'Fixes:') || contains(github.event.head_commit.message, 'Closes:')
.

I think silent eviction from the cache will lead to the same dead lock on ZK entry again. I mean we have just obtained but not locked. So, it got evicted. Then we lock a bit later and obtain the same key again and got dead lock.
We may consider to put into cache back on lock() call or so.
But feels more like we are fighting ghosts and walking in loops.
I would say let’s just leave cache logic without iterator removal.
And probably let’s change the default strategy for removal flag !

if (!eldest.getValue().isAcquiredInThisProcess()) {
return true;
}
Iterator<Entry<String, ZkLock>> iterator = entrySet().iterator();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I just assume that iterator returns entries from oldest first.
Therefore, the first next() gives us exactly the eldest entry we’ve just rejected.
And the next one: I’ll just believe you that we can call that remove() from the current remove logic.

- Remove override of bounded, now default bounded value is true
boolean acquired = lock1.tryLock(10, TimeUnit.SECONDS);

// Fail the test if the lock was not acquired within the timeframe
assertThat(acquired).isTrue();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think this really should go to the try..finally.
And probably without any comments.

We also can have an assertion that lock1 is same as lock.

// cache is full
lock.lock();
try {
registry.obtain("test2");

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Let's add here comment like:

Although cache is full, this does not evict an old entry because it is locked yet

public boolean bounded() {
return false;
}
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Every class member should be surrounded with blank lines.
Much easier to ready the code and add new members.

- Update testLockEvictionWithAnotherLockOnTheKey comments to
  reflect eviction failure

try {
assertThat(acquired).isTrue();
assertThat(lock1).isEqualTo(lock);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why equal but not same?
According to the cache purpose, the get has to return the same object.

- When the verifying duplicate locks
@artembilan artembilan merged commit 50499bf into spring-projects:main Jun 18, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Prevent eviction of held locks from ZooKeeper registry

2 participants