Skip to content

IGNITE-29291 Fix wrong near cache values after an ATOMIC invokeAll with a write-through store leaves a key unchanged - #13829

Open
rezataroosheh wants to merge 4 commits into
apache:masterfrom
rezataroosheh:IGNITE-29291
Open

rezataroosheh wants to merge 4 commits into
apache:masterfrom
rezataroosheh:IGNITE-29291

Conversation

@rezataroosheh

@rezataroosheh rezataroosheh commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

JIRA: https://issues.apache.org/jira/browse/IGNITE-29291

What

On an ATOMIC cache with a write-through store, a request with several keys from a client with a near cache now leaves the client's near cache in line with the primary node when some keys of the request are not written. Before this fix, such a key shifted the request index of the keys after it, so the client could:

  • put a value into its near cache for the wrong key, or keep a value that the primary node changed;
  • fail with an AssertionError in GridNearAtomicCache.processNearAtomicUpdateResponse() (assert req.operation() != TRANSFORM), and call the failure handler with CRITICAL_ERROR.

A key is not written when the entry processor leaves it unchanged (read-only invoke), when its new value fails validation, or when the interceptor cancels its put or remove. This applies to invokeAll, putAll, and removeAll.

Why

For such a request, the primary node uses GridDhtAtomicCache.updateWithBatch(). It collects the entries to write in batches, and passes only the request index of the first entry of a batch to updatePartialBatch(), which uses firstEntryIdx + i for the i-th entry. That is right only if no key between them was left out. This index is used for the near values, TTLs, and skipped indexes sent back to the client, and for dhtUpdRes.processedEntriesCount().

Also, a key left out by a read-only invoke or by the interceptor was not sent to the client as skipped. So the client used the value from the request for such a key, or, for invokeAll, had no value for it at all.

Fix

  • updateWithBatch() keeps the request index of each entry of a batch and passes these indexes to updatePartialBatch().
  • A key left out by a read-only invoke or by the interceptor is now sent to the client as skipped, as a key whose value fails validation already was.
  • NearCacheUpdates.addNearTtl() stores the TTL and the expire time at the index of the key instead of appending them. Skipped keys are now added while the request is processed, before the earlier keys in the batch are written, so TTLs are no longer added in key order. GridLongList.set() is added for this.

Known limits

  • After a retry on UnregisteredClassException or UnregisteredBinaryTypeException, the primary node processes the request again from dhtUpdRes.processedEntriesCount(). A key after this index that was sent as skipped in the first pass is processed again. If the entry processor returns a different result the second time, the key can be both skipped and written, and the client keeps its old value. If an entry processor returns the same result, the key is skipped twice, which is harmless.
  • invokeAll can lose the results of keys written before such a retry. This was already the case on master, where the retry could start at a wrong, earlier key and run the entry processor again for keys already written. With this fix, the retry starts after the last written key, so these keys aren't processed again and their results are missing. This can be fixed in a separate ticket.

Related: IGNITE-29241 skips a value whose bytes can't be made in the same way as a value that fails validation, so it relies on this fix.

Tests

AtomicNearCacheInvokeAllWithStoreTest, added to IgniteCacheTestSuite10. Each test starts a server and a client with a near cache, puts -1 to every key from the client, runs one request from the client, and checks the client's near cache:

  • testUnchangedKeyInTheMiddleOfInvokeAll: invokeAll on keys 1, 2, and 3 leaves key 2 unchanged. On master, the near cache has 3 for key 2, and the client fails with the AssertionError above.
  • testUnchangedKeyInTheMiddleOfInvokeAllWithExpiryPolicy: the same, with an expiry policy, so the response also has a TTL for each key.
  • testInterceptorCancelsKeyInTheMiddleOfInvokeAll and testInterceptorCancelsKeyInTheMiddleOfInvokeAllRemove: the entry processor sets or removes every key, and the interceptor cancels key 2.
  • testInterceptorCancelsKeyInTheMiddleOfPutAll and testInterceptorCancelsKeyInTheMiddleOfRemoveAll: the interceptor cancels key 2 of a putAll or a removeAll.
  • testUnchangedKeyAfterPutAndRemoveBatchesOfInvokeAll: invokeAll on keys 1 to 5 sets key 1, removes key 2, sets key 3, leaves key 4 unchanged, and sets key 5, so the keys are written in three batches.

Each new skip and each reset of the batch indexes is covered: removing it from the fix makes the matching test fail with an incorrect near-cache value.

The Contribution Checklist

  • There is a single JIRA ticket related to the pull request.
  • The web-link to the pull request is attached to the JIRA ticket.
  • The JIRA ticket has the Patch Available state.
  • The pull request body describes changes that have been made.
    The description explains WHAT and WHY was made instead of HOW.
  • The pull request title is treated as the final commit message.
    The following pattern must be used: IGNITE-XXXX Change summary where XXXX - number of JIRA issue.
  • A reviewer has been mentioned through the JIRA comments
    (see the Maintainers list)
  • The pull request has been checked by the Teamcity Bot and
    the green visa attached to the JIRA ticket (see tab PR Check at TC.Bot - Instance 1 or TC.Bot - Instance 2)

… an ATOMIC invokeAll with a write-through store leaves a key unchanged
…te-through store when some keys are left unchanged
@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/dht/atomic/NearCacheUpdates.java

@rezataroosheh
rezataroosheh marked this pull request as ready for review November 23, 2026 22:43
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.

1 participant