在Ignite缓存中插入数据时出现以下错误?

时间:2018-01-04 06:46:26

标签: java apache caching ignite

如果我使用String而不是JsonObject,则在缓存值中使用JsonObject(GSON Library)时会发生此错误,然后操作成功执行。

在缓存中插入数据时遇到的错误:

javax.cache.CacheException: class org.apache.ignite.transactions.TransactionRollbackException: Transaction has been rolled back: 9557fcfb061-00000000-078a-a446-0000-000000000001
    at org.apache.ignite.internal.processors.cache.GridCacheUtils.convertToCacheException(GridCacheUtils.java:1287)
    at org.apache.ignite.internal.processors.cache.IgniteCacheProxyImpl.cacheException(IgniteCacheProxyImpl.java:1648)
    at org.apache.ignite.internal.processors.cache.IgniteCacheProxyImpl.put(IgniteCacheProxyImpl.java:1008)
    at org.apache.ignite.internal.processors.cache.GatewayProtectedCacheProxy.put(GatewayProtectedCacheProxy.java:872)
    at com.clouzer.databaseoperation.DataBaseOperation.getAllUSerGson(DataBaseOperation.java:527)
    at com.mstorm.ignition.gson.LoginCacheOperation.createLoginCache(LoginCacheOperation.java:38)
    at com.mstorm.ignition.gson.IgniteCacheCreator.createCaches(IgniteCacheCreator.java:30)
    at com.mstorm.ignition.gson.IgniteServer.main(IgniteServer.java:102)
Caused by: class org.apache.ignite.transactions.TransactionRollbackException: Transaction has been rolled back: 9557fcfb061-00000000-078a-a446-0000-000000000001
    at org.apache.ignite.internal.util.IgniteUtils$11.apply(IgniteUtils.java:860)
    at org.apache.ignite.internal.util.IgniteUtils$11.apply(IgniteUtils.java:858)
    ... 8 more
Caused by: class org.apache.ignite.internal.transactions.IgniteTxRollbackCheckedException: Transaction has been rolled back: 9557fcfb061-00000000-078a-a446-0000-000000000001
    at org.apache.ignite.internal.processors.cache.GridCacheAdapter.syncOp(GridCacheAdapter.java:4054)
    at org.apache.ignite.internal.processors.cache.GridCacheAdapter.put0(GridCacheAdapter.java:2340)
    at org.apache.ignite.internal.processors.cache.GridCacheAdapter.put(GridCacheAdapter.java:2321)
    at org.apache.ignite.internal.processors.cache.GridCacheAdapter.put(GridCacheAdapter.java:2298)
    at org.apache.ignite.internal.processors.cache.IgniteCacheProxyImpl.put(IgniteCacheProxyImpl.java:1005)
    ... 5 more
Caused by: class org.apache.ignite.IgniteCheckedException: Can not set final com.google.gson.internal.LinkedTreeMap field com.google.gson.JsonObject.members to java.util.LinkedHashMap
    at org.apache.ignite.internal.util.IgniteUtils.cast(IgniteUtils.java:7252)
    at org.apache.ignite.internal.util.future.GridFutureAdapter.resolve(GridFutureAdapter.java:259)
    at org.apache.ignite.internal.util.future.GridFutureAdapter.get0(GridFutureAdapter.java:171)
    at org.apache.ignite.internal.util.future.GridFutureAdapter.get(GridFutureAdapter.java:140)
    at org.apache.ignite.internal.processors.cache.distributed.near.GridNearTxLocal$10.applyx(GridNearTxLocal.java:2396)
    at org.apache.ignite.internal.processors.cache.distributed.near.GridNearTxLocal$10.applyx(GridNearTxLocal.java:2392)
    at org.apache.ignite.internal.util.lang.IgniteClosureX.apply(IgniteClosureX.java:38)
    at org.apache.ignite.internal.util.future.GridFutureChainListener.applyCallback(GridFutureChainListener.java:78)
    at org.apache.ignite.internal.util.future.GridFutureChainListener.apply(GridFutureChainListener.java:70)
    at org.apache.ignite.internal.util.future.GridFutureChainListener.apply(GridFutureChainListener.java:30)
    at org.apache.ignite.internal.util.future.GridFutureAdapter.notifyListener(GridFutureAdapter.java:383)
    at org.apache.ignite.internal.util.future.GridFutureAdapter.listen(GridFutureAdapter.java:353)
    at org.apache.ignite.internal.util.future.GridFutureAdapter$ChainFuture.<init>(GridFutureAdapter.java:572)
    at org.apache.ignite.internal.util.future.GridFutureAdapter.chain(GridFutureAdapter.java:358)
    at org.apache.ignite.internal.processors.cache.distributed.near.GridNearTxLocal.optimisticPutFuture(GridNearTxLocal.java:2391)
    at org.apache.ignite.internal.processors.cache.distributed.near.GridNearTxLocal.putAsync0(GridNearTxLocal.java:622)
    at org.apache.ignite.internal.processors.cache.distributed.near.GridNearTxLocal.putAsync(GridNearTxLocal.java:385)
    at org.apache.ignite.internal.processors.cache.GridCacheAdapter$22.op(GridCacheAdapter.java:2342)
    at org.apache.ignite.internal.processors.cache.GridCacheAdapter$22.op(GridCacheAdapter.java:2340)
    at org.apache.ignite.internal.processors.cache.GridCacheAdapter.syncOp(GridCacheAdapter.java:4040)
    ... 9 more

缓存配置:

CacheConfiguration<String, JsonObject> cacheConfig = new CacheConfiguration<>();
            cacheConfig.setName("CACHE_NAME");
            cacheConfig.setReadThrough(true);
            cacheConfig.setBackups(2);
            cacheConfig.setAtomicityMode(CacheAtomicityMode.TRANSACTIONAL);
            cacheConfig.setWriteThrough(true);
            cacheConfig.setCacheStoreFactory(FactoryBuilder.factoryOf(ObjectLoader.class));
            IgniteCache<String, JsonObject> cache = ignite.getOrCreateCache(cacheConfig);

运营:

1.创建JsonObject(使用GSON库)

2.将缓存加载器设置为用于持久存储的给定缓存

3.从点燃客户端

将数据插入缓存

4.观察问题

1 个答案:

答案 0 :(得分:1)

问题是,self.env['hr.payslip'].salaryfunction()具有JsonObject类型的members字段,而Ignite LinkedTreeMap是默认字段,会将其反序列化为BinaryMarshaller某种原因。

为避免这种情况,您可以使用其他编组程序,例如LinkedHashMap

<强> UPD:

原来,如果你配置OptimizedMarshaller,那么只有来自缓存的put和gets才能正常工作。但是,如果您尝试OptimizedMarshaller get(...)的反序列化表示的某个字段,那么JVM将崩溃。

原因是JsonObject具有以下LinkedTreeMap方法:

writeReplace()

因此,如果您序列化它,然后反序列化,那么您将获得private Object writeReplace() throws ObjectStreamException { return new LinkedHashMap(this); } 而不是LinkedHashMap的实例。所以,LinkedTreeMap没有做错任何事。

<强>要点:

看起来你不应该将BinaryMarshaller放入缓存中。它没有实现JsonObject,因此作者没有考虑序列化它。我想,你必须用JSON字符串替换Serializable