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
Fixed TransactionalMapProxy with Near Cache #13385
Fixed TransactionalMapProxy with Near Cache #13385
Conversation
This removes one indirection, which makes inlining easier for the JVM. It also shortens the code a bit.
The Near Cache key for a TransactionalMapProxy was not deserialized when it was in binary format, which happens when a Hazelcast client is used. Another problem was that the Near Cache key was created first, even if it was not used at all. Especially with this fix, we might run into an unused deserialization, when no Near Cache was configured. The order of read-only calls is: * read value from internal TXN map (always binary key) * read value from Near Cache (binary/object key) * read value from remote (always binary key) The Near Cache key creation has been moved behind the TXN map lookup. This prevents the key creation if it's not used at all. It uses the original and binary key, to prevent a duplicated (de)serialization. The order of write/remove calls is: * remove the value (always binary key) * invalidate the Near Cache (binary/object key) The Near Cache key creation has been moved to the invalidation method, so behind all checks if the Near Cache is enabled. This prevents the key creation if it's not used at all.
context.beginTransaction(); | ||
try { | ||
TransactionalMap<Object, Object> txnMap = context.getMap(mapName); | ||
assertNull("Expected null for a non-existent key", txnMap.get("key")); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These calls are passed as Data
key to the TransactionalMapProxy
, which broke the Near Cache lookup before (key was not deserialized).
if (!nearCacheEnabled) { | ||
return null; | ||
} | ||
return serializeKeys ? dataKey : ss.toObject(key); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ss.toObject(key)
is the fix for the Data
keys from Hazelcast clients. The deserialization is just executed when a Near Cache is configured (since the other txn lookups need the Data
key).
@Donnerbart as far as i see, here exists a fundamental problem of calling server-side near-cached proxy object during a client request. This seems not expected. Because near cache should be application specific but in this case, a remote client is using a server-side near-cache (this is not the case for non-tx imap for example). Maybe a proper fix should eliminate near-cache usage at all when proxy is used by a client request? WDYT? |
Hmm, good point. I can close this PR in favor of a proper fix. Feel free to pick up any code change from this PR, if it's helpful. |
The Near Cache key for a
TransactionalMapProxy
was not deserialized when it was in binary format, which happens when a Hazelcast client is used.Another problem was that the Near Cache key was created first, even if it was not used at all. Especially with this fix, we might run into an unused deserialization, when no Near Cache was configured.
The order of read-only calls is:
The Near Cache key creation has been moved behind the internal TX map lookup. This prevents the key creation if it's not used at all. It uses the original and binary key, to prevent a duplicated (de)serialization.
The order of write/remove calls is:
The Near Cache key creation has been moved to the invalidation method, so behind all checks if the Near Cache is enabled. This prevents the key creation if it's not used at all.
Fixes #13371