Getting Exception while fetching data from database in the flow

六眼飞鱼酱① 提交于 2019-12-23 05:27:39

问题


I am getting the error below:

Step 1: serviceHub.jdbcSession().prepareStatement("Query")

Step 2: I have executed the step1.

Step 3: I am getting the data I needed.

but also I am getting the below exception also.

com.esotericsoftware.kryo.KryoException: java.lang.UnsupportedOperationException: com.zaxxer.hikari.pool.HikariProxyPreparedStatement, which is a closeable resource, has been detected during flow checkpointing. Restoring such resources across node restarts is not supported. Make sure code accessing it is confined to a private method or the reference is nulled out.


Serialization trace:
dataObject (co.paralleluniverse.fibers.Stack)
stack (net.corda.node.services.statemachine.FlowStateMachineImpl)

at com.esotericsoftware.kryo.serializers.ObjectField.write(ObjectField.java:101) ~[kryo-4.0.0.jar:?]
at com.esotericsoftware.kryo.serializers.CompatibleFieldSerializer.write(CompatibleFieldSerializer.java:66) ~[kryo-4.0.0.jar:?]
at com.esotericsoftware.kryo.Kryo.writeObjectOrNull(Kryo.java:629) ~[kryo-4.0.0.jar:?]
at com.esotericsoftware.kryo.serializers.ObjectField.write(ObjectField.java:87) ~[kryo-4.0.0.jar:?]
at com.esotericsoftware.kryo.serializers.FieldSerializer.write(FieldSerializer.java:505) ~[kryo-4.0.0.jar:?]
at co.paralleluniverse.fibers.Fiber$FiberSerializer.write(Fiber.java:2090) ~[quasar-core-0.7.9-jdk8.jar:0.7.9]
at co.paralleluniverse.fibers.Fiber$FiberSerializer.write(Fiber.java:2067) ~[quasar-core-0.7.9-jdk8.jar:0.7.9]
at com.esotericsoftware.kryo.Kryo.writeObject(Kryo.java:575) ~[kryo-4.0.0.jar:?]
at co.paralleluniverse.io.serialization.kryo.ReplaceableObjectKryo.writeClassAndObject(ReplaceableObjectKryo.java:54) ~[quasar-core-0.7.9-jdk8.jar:0.7.9]
at net.corda.nodeapi.internal.serialization.kryo.AbstractKryoSerializationScheme$serialize$1$1.invoke(KryoSerializationScheme.kt:116) ~[corda-node-api-3.3-corda.jar:?]
at net.corda.nodeapi.internal.serialization.kryo.AbstractKryoSerializationScheme$serialize$1$1.invoke(KryoSerializationScheme.kt:37) ~[corda-node-api-3.3-corda.jar:?]
at net.corda.nodeapi.internal.serialization.kryo.AbstractKryoSerializationScheme.withContext(KryoSerializationScheme.kt:80) ~[corda-node-api-3.3-corda.jar:?]
at net.corda.nodeapi.internal.serialization.kryo.AbstractKryoSerializationScheme.access$withContext(KryoSerializationScheme.kt:37) ~[corda-node-api-3.3-corda.jar:?]
at net.corda.nodeapi.internal.serialization.kryo.AbstractKryoSerializationScheme$serialize$1.execute(KryoSerializationScheme.kt:109) ~[corda-node-api-3.3-corda.jar:?]
at net.corda.nodeapi.internal.serialization.kryo.AbstractKryoSerializationScheme$serialize$1.execute(KryoSerializationScheme.kt:37) ~[corda-node-api-3.3-corda.jar:?]
at com.esotericsoftware.kryo.pool.KryoPoolQueueImpl.run(KryoPoolQueueImpl.java:61) ~[kryo-4.0.0.jar:?]
at net.corda.nodeapi.internal.serialization.kryo.AbstractKryoSerializationScheme.serialize(KryoSerializationScheme.kt:108) ~[corda-node-api-3.3-corda.jar:?]
at net.corda.nodeapi.internal.serialization.SerializationFactoryImpl$serialize$1$1.invoke(SerializationScheme.kt:126) ~[corda-node-api-3.3-corda.jar:?]
at net.corda.nodeapi.internal.serialization.SerializationFactoryImpl$serialize$1$1.invoke(SerializationScheme.kt:86) ~[corda-node-api-3.3-corda.jar:?]
at net.corda.core.serialization.SerializationFactory.withCurrentContext(SerializationAPI.kt:66) ~[corda-core-3.3-corda.jar:?]
at net.corda.nodeapi.internal.serialization.SerializationFactoryImpl$serialize$1.invoke(SerializationScheme.kt:126) ~[corda-node-api-3.3-corda.jar:?]
at net.corda.nodeapi.internal.serialization.SerializationFactoryImpl$serialize$1.invoke(SerializationScheme.kt:86) ~[corda-node-api-3.3-corda.jar:?]
at net.corda.core.serialization.SerializationFactory.asCurrent(SerializationAPI.kt:80) ~[corda-core-3.3-corda.jar:?]
at net.corda.nodeapi.internal.serialization.SerializationFactoryImpl.serialize(SerializationScheme.kt:126) ~[corda-node-api-3.3-corda.jar:?]
at net.corda.core.serialization.SerializationAPIKt.serialize(SerializationAPI.kt:231) ~[corda-core-3.3-corda.jar:?]
at net.corda.core.serialization.SerializationAPIKt.serialize$default(SerializationAPI.kt:230) ~[corda-core-3.3-corda.jar:?]
at net.corda.node.services.statemachine.StateMachineManagerImpl.serializeFiber(StateMachineManagerImpl.kt:408) ~[corda-node-3.3-corda.jar:?]
at net.corda.node.services.statemachine.StateMachineManagerImpl.updateCheckpoint(StateMachineManagerImpl.kt:540) ~[corda-node-3.3-corda.jar:?]
at net.corda.node.services.statemachine.StateMachineManagerImpl.access$updateCheckpoint(StateMachineManagerImpl.kt:63) ~[corda-node-3.3-corda.jar:?]
at net.corda.node.services.statemachine.StateMachineManagerImpl$initFiber$2.invoke(StateMachineManagerImpl.kt:440) ~[corda-node-3.3-corda.jar:?]
at net.corda.node.services.statemachine.StateMachineManagerImpl$initFiber$2.invoke(StateMachineManagerImpl.kt:63) ~[corda-node-3.3-corda.jar:?]
at net.corda.node.services.statemachine.FlowStateMachineImpl$suspend$2.write(FlowStateMachineImpl.kt:520) ~[corda-node-3.3-corda.jar:?]
at co.paralleluniverse.fibers.Fiber$3.run(Fiber.java:1994) ~[quasar-core-0.7.9-jdk8.jar:0.7.9]
at co.paralleluniverse.fibers.Fiber.exec(Fiber.java:824) [quasar-core-0.7.9-jdk8.jar:0.7.9]
at co.paralleluniverse.fibers.RunnableFiberTask.doExec(RunnableFiberTask.java:100) [quasar-core-0.7.9-jdk8.jar:0.7.9]
at co.paralleluniverse.fibers.RunnableFiberTask.run(RunnableFiberTask.java:91) [quasar-core-0.7.9-jdk8.jar:0.7.9]
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [?:1.8.0_201]
at java.util.concurrent.FutureTask.run(FutureTask.java:266) [?:1.8.0_201]
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180) [?:1.8.0_201]
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293) [?:1.8.0_201]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [?:1.8.0_201]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [?:1.8.0_201]
at net.corda.node.utilities.AffinityExecutor$ServiceAffinityExecutor$1$thread$1.run(AffinityExecutor.kt:62) [corda-node-3.3-corda.jar:?]
Caused by: java.lang.UnsupportedOperationException: com.zaxxer.hikari.pool.HikariProxyPreparedStatement, which is a closeable resource, has been detected during flow checkpointing. Restoring such resources across node restarts is not supported. Make sure code accessing it is confined to a private method or the reference is nulled out.
at net.corda.nodeapi.internal.serialization.kryo.AutoCloseableSerialisationDetector.write(KryoSerializationScheme.kt:31) ~[corda-node-api-3.3-corda.jar:?]
at net.corda.nodeapi.internal.serialization.kryo.AutoCloseableSerialisationDetector.write(KryoSerializationScheme.kt:26) ~[corda-node-api-3.3-corda.jar:?]
at com.esotericsoftware.kryo.Kryo.writeObject(Kryo.java:575) ~[kryo-4.0.0.jar:?]
at co.paralleluniverse.io.serialization.kryo.ReplaceableObjectKryo.writeClassAndObject(ReplaceableObjectKryo.java:54) ~[quasar-core-0.7.9-jdk8.jar:0.7.9]
at com.esotericsoftware.kryo.serializers.DefaultArraySerializers$ObjectArraySerializer.write(DefaultArraySerializers.java:362) ~[kryo-4.0.0.jar:?]
at com.esotericsoftware.kryo.serializers.DefaultArraySerializers$ObjectArraySerializer.write(DefaultArraySerializers.java:303) ~[kryo-4.0.0.jar:?]
at com.esotericsoftware.kryo.Kryo.writeObject(Kryo.java:575) ~[kryo-4.0.0.jar:?]
at co.paralleluniverse.io.serialization.kryo.ReplaceableObjectKryo.writeObject(ReplaceableObjectKryo.java:85) ~[quasar-core-0.7.9-jdk8.jar:0.7.9]
at com.esotericsoftware.kryo.serializers.ObjectField.write(ObjectField.java:80) ~[kryo-4.0.0.jar:?]
... 42 more

I am trying to fetch data from database in the corda flow using jdbc connection. While fetching the data from database I am getting the above exception.


回答1:


Put the jdbc code into a function not annotated with @Suspendable. Ideally, you should put this code in a @CordaService to cut it off from the rest of the flow code (https://lankydan.dev/2018/08/19/corda-services-101).

Corda checkpoints serialise the current stack when suspending (e.g. calling sendAndReceive). As the error says, the jdbc connection cannot be serialised since it is closable.

Only methods annotated with @Suspendable are checkpointed. More correctly, methods that suspend must be annotated with @Suspendable.



来源:https://stackoverflow.com/questions/57095232/getting-exception-while-fetching-data-from-database-in-the-flow

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!