Skip to content

IGNITE-28727 Create internal API method to lock cache entry with specific version#13264

Open
vldpyatkov wants to merge 3 commits into
apache:masterfrom
vldpyatkov:ignite-28727
Open

IGNITE-28727 Create internal API method to lock cache entry with specific version#13264
vldpyatkov wants to merge 3 commits into
apache:masterfrom
vldpyatkov:ignite-28727

Conversation

@vldpyatkov

@vldpyatkov vldpyatkov commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

@vldpyatkov vldpyatkov force-pushed the ignite-28727 branch 3 times, most recently from 2b29e34 to 63cf3ce Compare June 25, 2026 09:44
@tkalkirill tkalkirill changed the title IGNITE-28727 IGNITE-28727 Create internal API method to lock cache entry with specific version Jun 26, 2026

@tkalkirill tkalkirill 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.

A few additional general comments:

  1. Please add tests where a lock is acquired via the new API in one transaction and an attempt is made to acquire it via the new API in another; cover both distinct keys and the same key. It would be great to test this with both single-threaded and multi-threaded scenarios.
  2. I didn't see a test checking what happens if the new API is called outside of a pessimistic transaction.
  3. I didn't see a test checking the behavior regarding lock acquisition after the transaction has completed.
    4.waitTimeoutExpiresFirst should be moved to a shared location so there is only one instance of it, accompanied by a clear comment.

* @return Future that resolves to {@code true} if the lock was acquired and the versions matched, or to
* {@code false} otherwise.
*/
public IgniteInternalFuture<Boolean> lockTxEntryAsync(CacheEntry<K, V> entry, long waitTimeout);

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.

What about errors? If it fails, will the method throw an error or will the future complete with an error? Please reflect this in the documentation.

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.

Do you mean a concrete scenario or just in general? I am sure the method can send similar exceptions like other transactional operations (for example, putAllAsync/putAsync) but there are no notes.
I can underline NPE in case there is a null passed as a entrty/collection because it's done right in the method methodA.notNull.
Would it be enough?

* @return Future that resolves to {@code true} if all locks were acquired and all versions matched, or to
* {@code false} otherwise.
*/
public IgniteInternalFuture<Boolean> lockTxEntriesAsync(Collection<CacheEntry<K, V>> entries, long waitTimeout);

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.

What about errors? If it fails, will the method throw an error or will the future complete with an error? Please reflect this in the documentation.

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.

The same as above. We do not describe exceptions with the future that can fail in the other methods. So I do not think it is needed here.

IgniteTxEntry txEntry = internalCache.tx().entry(txKey);

assertNotNull(txEntry);
assertEquals(skipStore, txEntry.skipStore());

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.

Could you explain what these flags mean and why they need to be checked?
I tried looking at the documentation for them, but I still didn't quite understand.

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.

This flag is used to enlist phase in the other operation (put/get e.t.c.). I checked it because in the new method I did not use the old variants of transaction enlist.

@Override protected GridCacheReturn postLock(GridCacheReturn ret) throws IgniteCheckedException {
assert fut.error() == null;

boolean success = Boolean.TRUE.equals(fut.get());

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.

Same about fut.get() as above.

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.

The same; it is a code that is executed after the nested future is complete.

new IgniteCheckedException("Failed to acquire transactional lock in optimistic transaction."));

// Wait for previous per-transaction async operations to finish.
tx.txState().awaitLastFuture();

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 did't understand the reason for this wait.

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 are doing the same in the transaction methods (put/get e.t.c), we just do it in the helpers (syncOp, asyncOp).
The real meaning is waiting for the previous transaction operation completion.

@vldpyatkov

vldpyatkov commented Jun 26, 2026

Copy link
Copy Markdown
Contributor Author

About the text comment above:

  1. Added a test: LockTxEntryOneNodeTest#testLockTxEntryReturnsFalseForLockedKeyAndTrueForOtherKey
  2. It is there: LockTxEntryOneNodeTest#testLockTxEntryAsyncFailsInOptimisticTransaction
  3. It is here: LockTxEntryOneNodeTest#testLockTxEntryFailsWithoutTransaction
  4. Did it.

@github-actions

Copy link
Copy Markdown

Possible compatibility issues. Please, check rolling upgrade cases

This PR modifies protected classes (with Order annotation).
Changes to these classes can break rolling upgrade compatibility.

Affected files:

  • modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearLockRequest.java
  • modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearLockResponse.java

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.

2 participants