Skip to content
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

IMap::merge fails for enabled NearCache #19714

Open
kirpichik opened this issue Oct 5, 2021 · 2 comments
Open

IMap::merge fails for enabled NearCache #19714

kirpichik opened this issue Oct 5, 2021 · 2 comments
Labels
Module: IMap Source: Community PR or issue was opened by a community user Team: Core Type: Defect
Milestone

Comments

@kirpichik
Copy link

kirpichik commented Oct 5, 2021

Hazelcast version: 5.0

When a NearCache is used for an IMap then merge(key, value, remappingFunction) operation fails reporting a wrong key type.

Exception output:

Exception in thread "main" java.lang.IllegalArgumentException: key cannot be of type Data!
	at com.hazelcast.internal.util.Preconditions.checkNotInstanceOf(Preconditions.java:300)
	at com.hazelcast.internal.nearcache.impl.DefaultNearCache.checkKeyFormat(DefaultNearCache.java:221)
	at com.hazelcast.internal.nearcache.impl.DefaultNearCache.get(DefaultNearCache.java:123)
	at com.hazelcast.client.map.impl.nearcache.NearCachedClientMapProxy.getCachedValue(NearCachedClientMapProxy.java:597)
	at com.hazelcast.client.map.impl.nearcache.NearCachedClientMapProxy.getInternal(NearCachedClientMapProxy.java:117)
	at com.hazelcast.client.impl.proxy.ClientMapProxy.mergeLocally(ClientMapProxy.java:2174)
	at com.hazelcast.client.impl.proxy.ClientMapProxy.merge(ClientMapProxy.java:2167)
	at Test.main(Test.java:32)

Reproducer:

Config config = new Config();
config.setClusterName("dev");
HazelcastInstance hz = Hazelcast.newHazelcastInstance(config);

ClientConfig clientConfig = new ClientConfig();
clientConfig.setClusterName("dev");
clientConfig.getNetworkConfig().addAddress("localhost:5701");

NearCacheConfig nearCacheConfig = new NearCacheConfig();
clientConfig.setNearCacheConfigMap(Collections.singletonMap("my-map", nearCacheConfig));

HazelcastInstance clientHz = HazelcastClient.newHazelcastClient(clientConfig);

IMap<String, String> map = clientHz.getMap("my-map");
map.merge("1", "John", (current, other) -> current + other);
map.merge("1", "Mary", (current, other) -> current + other);

This problem is very similar to the one described in #13371 and the workaround described in original stackoverflow question setting serialize-keys=true helps avoid exception.

Until the bug is fixed, how safe is this workaround to use? What can it affect?

@ahmetmircik
Copy link
Member

It is about performance, lookup keys are serialized when serialize-keys=true, this can degrade near-cache read performance, if key serialization is expensive. But best to measure to see.

@mmedenjak mmedenjak added Module: IMap Source: Internal PR or issue was opened by an employee Team: Core Source: Community PR or issue was opened by a community user and removed Source: Internal PR or issue was opened by an employee labels Oct 6, 2021
@mmedenjak mmedenjak added this to the 5.1 milestone Oct 6, 2021
@kirpichik
Copy link
Author

I measured the performance using JMH with and without workaround and indeed, the performance of the get operation drops by 40%:

Benchmark                            Mode  Cnt     Score     Error   Units
HazelcastBenchNotSerializeKeys.get  thrpt    5  3332.311 ± 295.684  ops/ms
HazelcastBenchNotSerializeKeys.put  thrpt    5    45.165 ±   2.337  ops/ms
HazelcastBenchSerializeKeys.get     thrpt    5  2028.248 ±   2.397  ops/ms
HazelcastBenchSerializeKeys.put     thrpt    5    44.982 ±   1.246  ops/ms

@AyberkSorgun AyberkSorgun modified the milestones: 5.1, 5.2 Dec 14, 2021
@AyberkSorgun AyberkSorgun modified the milestones: 5.2, 5.2 Backlog Mar 22, 2022
@Holmistr Holmistr modified the milestones: 5.2 Backlog, Backlog May 31, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Module: IMap Source: Community PR or issue was opened by a community user Team: Core Type: Defect
Projects
None yet
Development

No branches or pull requests

5 participants