简体   繁体   English

Hazelcast-java.lang.IllegalArgumentException:键不能为Data类型

[英]Hazelcast - java.lang.IllegalArgumentException: key cannot be of type Data

W've just upgraded our application from Hazelcast 3.8.0 to 3.10.1. 我们刚刚将我们的应用程序从Hazelcast 3.8.0升级到了3.10.1。

We am getting an error message "key cannot be of type Data!" 我们收到一条错误消息“密钥不能为数据类型!” when accessing data in Hazelcast. 在Hazelcast中访问数据时。

java.lang.IllegalArgumentException: key cannot be of type Data!
at com.hazelcast.util.Preconditions.checkNotInstanceOf(Preconditions.java:300)
at com.hazelcast.internal.nearcache.impl.DefaultNearCache.checkKeyFormat(DefaultNearCache.java:226)
at com.hazelcast.internal.nearcache.impl.DefaultNearCache.get(DefaultNearCache.java:114)
at com.hazelcast.map.impl.tx.TransactionalMapProxySupport.getCachedValue(TransactionalMapProxySupport.java:183)
at com.hazelcast.map.impl.tx.TransactionalMapProxySupport.getInternal(TransactionalMapProxySupport.java:132)
at com.hazelcast.map.impl.tx.TransactionalMapProxy.get(TransactionalMapProxy.java:110)
at com.hazelcast.client.impl.protocol.task.transactionalmap.TransactionalMapGetMessageTask.innerCall(TransactionalMapGetMessageTask.java:43)
at com.hazelcast.client.impl.protocol.task.AbstractTransactionalMessageTask.call(AbstractTransactionalMessageTask.java:34)
at com.hazelcast.client.impl.protocol.task.AbstractCallableMessageTask.processMessage(AbstractCallableMessageTask.java:35)
at com.hazelcast.client.impl.protocol.task.AbstractMessageTask.initializeAndProcessMessage(AbstractMessageTask.java:130)
at com.hazelcast.client.impl.protocol.task.AbstractMessageTask.run(AbstractMessageTask.java:110)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
at com.hazelcast.util.executor.HazelcastManagedThread.executeRun(HazelcastManagedThread.java:64)
at com.hazelcast.util.executor.HazelcastManagedThread.run(HazelcastManagedThread.java:80)
at ------ submitted from ------.(Unknown Source)

I am 100% sure that the "key" We're using is a String. 我100%确定我们正在使用的“键”是一个字符串。 The code snippet looks like this: 该代码段如下所示:

 String key = getKey(blah, blah);

 TransactionContext context = client.newTransactionContext();
 context.beginTransaction();
 TransactionalMap<String, AppPrefs> dataMap = context.getMap(MAP_NAME);
 try {
        prefs = dataMap.get(key);
        context.commitTransaction();

     } catch (Throwable t) {
        LOGGER.error("Error getting AppPrefs.", t);
        context.rollbackTransaction();
     }

The line of code throwing the error is: 引发错误的代码行是:

prefs = dataMap.get(key);

There is nothing between the line of code that sets the String 设置字符串的代码行之间没有任何内容

String key = getKey(blah, blah);

and the line that blows :( 和吹线:(

Following the source code through, the TransactionalMapProxySupport's method "toNearCacheKeyWithStrategy" has this logic: 遵循源代码,TransactionalMapProxySupport的方法“ toNearCacheKeyWithStrategy”具有以下逻辑:

final Object toNearCacheKeyWithStrategy(Object key) {
    if (!nearCacheEnabled) {
        return key;
    }

    return serializeKeys ? ss.toData(key, partitionStrategy) : key;
}

The "DefaultNearCache" object then does a 然后,“ DefaultNearCache”对象执行

private void checkKeyFormat(K key) {
    if (!serializeKeys) {
        checkNotInstanceOf(Data.class, key, "key cannot be of type Data!");
    }
}

So it looks like the property of "TransactionalMapProxySupport" called "serializeKeyes" must have been FALSE but the same-named property in "DefaultNearCache"must have been true :( 因此,看起来名为“ serializeKeyes”的“ TransactionalMapProxySupport”属性必须为FALSE,但“ DefaultNearCache”中的同名属性必须为true :(

The history of "DefaultNearCache" in git shows that the code was changed a year ago with the message: "Changed serialize-keys default for Near Cache from true to false" git中“ DefaultNearCache”的历史记录表明该代码在一年前已更改,并显示以下消息:“将近缓存的序列化键默认值从true更改为false”

Is there some configuration I should be setting? 我应该设置一些配置吗?

The config I have for the map is simply: 我在地图上的配置很简单:

<near-cache name="AppPrefsCache">
  <!-- Cache locally for 10 mins -->
  <max-idle-seconds>600</max-idle-seconds>
</near-cache>

Ah! 啊! It appears that I can add a " serialize-keys" tag of (true|false) to this xml and set the value. 看来我可以将(true | false)的“ serialize-keys”标签添加到此xml并设置值。

It appears that different bits of the Hazelcast codebase are assuming a different default value for "serialize-keys". 看来,Hazelcast代码库的不同位为“序列化键”假定了不同的默认值。 Either it should be a mandatory element in the config or the default should be the same everywhere, yes? 要么它是配置中的必需元素,要么默认值在各处都相同,是吗?

The mentioned behavior is really a bug in Hazelcast. 提到的行为确实是Hazelcast中的错误。 I've created a new GitHub issue for it, so we can handle it properly - hazelcast/hazelcast#13371 . 我为此创建了一个新的GitHub问题,因此我们可以正确处理它-hazelcast / hazelcast#13371

The workaround for versions affected by the bug is to set serialize-keys to true in the near-cache configuration. 受该错误影响的版本的解决方法是,在near-cache配置中将serialize-keys设置为true The false value won't help here. false值在这里无济于事。

Config config = new Config();
config.getMapConfig(testName)
    .setNearCacheConfig(new NearCacheConfig().setSerializeKeys(true));

Thanks for the report and great investigation, Peter. 彼得,感谢您的报告和出色的调查。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 WEKA:java.lang.IllegalArgumentException:未知数据类型:int4 - WEKA: java.lang.IllegalArgumentException: Unknown data type: int4 spring-data-solr java.lang.IllegalArgumentException:不是托管类型 - spring-data-solr java.lang.IllegalArgumentException: Not a managed type java.lang.IllegalArgumentException:空键 - java.lang.IllegalArgumentException: Empty key java.lang.IllegalArgumentException:无效的键码 - java.lang.IllegalArgumentException: Invalid key code java.lang.IllegalArgumentException:参数类型不匹配 - java.lang.IllegalArgumentException: argument type mismatch java.lang.IllegalArgumentException:不是托管类型:class - java.lang.IllegalArgumentException: Not a managed type: class java.lang.IllegalArgumentException: uri 不能是 null - java.lang.IllegalArgumentException: uri cannot be null java.lang.IllegalArgumentException:不是托管类型:classTestEntity - java.lang.IllegalArgumentException: Not an managed type: classTestEntity java.lang.IllegalArgumentException问题:不是托管类型 - Problem with java.lang.IllegalArgumentException: Not a managed type java.lang.IllegalArgumentException:不是托管类型: - java.lang.IllegalArgumentException: Not a managed type:
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM