fory: Failed to serialize Hazelcast exceptions using a Hazelcast global Fury serializer configuration, if exceptions not registered with Fury
Search before asking
- I had searched in the issues and found no similar issues.
Version
Fury 0.4.1
Component(s)
Java
Minimal reproduce step
Start a Hazelcast datagrid configured with Fury as a global serializer, here a cluster of 4 instances:
<hazelcast>
......
<tcp-ip enabled="true">
<member>127.0.0.1:5701</member>
<member>127.0.0.1:5702</member>
<member>127.0.0.1:5703</member>
<member>127.0.0.1:5704</member>
</tcp-ip>
......
<serialization>
<portable-version>0</portable-version>
<serializers>
<global-serializer override-java-serialization="true">
org.apache.karaf.cellar.fury.HazelcastGlobalSerializer
</global-serializer>
</serializers>
</serialization>
.....
</hazelcast>
Fury setup:
Fury fury = Fury.builder()
.withLanguage(Language.JAVA)
.withMetaContextShare(false)
.withRefTracking(true)
.withIntCompressed(false)
.withLongCompressed(false)
.withStringCompressed(false)
.withCompatibleMode(CompatibleMode.COMPATIBLE)
.withClassVersionCheck(false)
.withJdkClassSerializableCheck(true)
.withDeserializeUnexistedClass(false)
.withAsyncCompilation(false)
.withCodegen(true)
.ignoreTimeRef(false)
.ignoreStringRef(false)
.ignoreBasicTypesRef(false)
.registerGuavaTypes(false)
.requireClassRegistration(false)
.suppressClassRegistrationWarnings(true)
.build();
Needed registrations to make it work without exceptions:
// Basic Java
fury.register(ReentrantLock.class, true);
fury.register(LinkedBlockingQueue.class, true);
// Karaf Cellar
fury.register(Event.class, true);
fury.register(Command.class, true);
fury.register(HazelcastNode.class, true);
fury.register(RemoteServiceCall.class, true);
fury.register(EndpointDescription.class, true);
fury.register(RemoteServiceResult.class, true);
fury.registerSerializer(StoreNotFoundException.class, new JavaSerializer(fury, StoreNotFoundException.class));
fury.registerSerializer(ProducerNotFoundException.class, new JavaSerializer(fury, ProducerNotFoundException.class));
fury.registerSerializer(RemoteServiceInvocationException.class, new JavaSerializer(fury, RemoteServiceInvocationException.class));
// Hazelcast operational responses
fury.register(ErrorResponse.class, true);
fury.register(NormalResponse.class, true);
fury.register(BackupAckResponse.class, true);
fury.register(CallTimeoutResponse.class, true);
// Hazelcast HazelcastExceptions
fury.registerSerializer(HazelcastException.class, new JavaSerializer(fury, HazelcastException.class));
fury.registerSerializer(ConsistencyLostException.class, new JavaSerializer(fury, ConsistencyLostException.class));
fury.registerSerializer(ServiceNotFoundException.class, new JavaSerializer(fury, ServiceNotFoundException.class));
fury.registerSerializer(LocalMemberResetException.class, new JavaSerializer(fury, LocalMemberResetException.class));
fury.registerSerializer(OperationTimeoutException.class, new JavaSerializer(fury, OperationTimeoutException.class));
fury.registerSerializer(HazelcastOverloadException.class, new JavaSerializer(fury, HazelcastOverloadException.class));
fury.registerSerializer(TargetDisconnectedException.class, new JavaSerializer(fury, TargetDisconnectedException.class));
fury.registerSerializer(RuntimeInterruptedException.class, new JavaSerializer(fury, RuntimeInterruptedException.class));
fury.registerSerializer(ResponseAlreadySentException.class, new JavaSerializer(fury, ResponseAlreadySentException.class));
fury.registerSerializer(DuplicateInstanceNameException.class, new JavaSerializer(fury, DuplicateInstanceNameException.class));
fury.registerSerializer(HazelcastSerializationException.class, new JavaSerializer(fury, HazelcastSerializationException.class));
fury.registerSerializer(DistributedObjectDestroyedException.class, new JavaSerializer(fury, DistributedObjectDestroyedException.class));
fury.registerSerializer(IndeterminateOperationStateException.class, new JavaSerializer(fury, IndeterminateOperationStateException.class));
fury.registerSerializer(PartitionStateVersionMismatchException.class, new JavaSerializer(fury, PartitionStateVersionMismatchException.class));
// Hazelcast core exceptions
fury.registerSerializer(RetryableIOException.class, new JavaSerializer(fury, RetryableIOException.class));
fury.registerSerializer(HazelcastInstanceNotActiveException.class, new JavaSerializer(fury, HazelcastInstanceNotActiveException.class));
// Hazelcast RetryableHazelcastExceptions
fury.registerSerializer(WrongTargetException.class, new JavaSerializer(fury, WrongTargetException.class));
fury.registerSerializer(CallerNotMemberException.class, new JavaSerializer(fury, CallerNotMemberException.class));
fury.registerSerializer(TargetNotMemberException.class, new JavaSerializer(fury, TargetNotMemberException.class));
fury.registerSerializer(RetryableHazelcastException.class, new JavaSerializer(fury, RetryableHazelcastException.class));
fury.registerSerializer(PartitionMigratingException.class, new JavaSerializer(fury, PartitionMigratingException.class));
What did you expect to see?
No exceptions serializing exceptions from other frameworks. Java exceptions are an integral part of the language and should be supported without extra configuration on the part of Fury, because it is not predicable under production circumstances what exceptions need to de (de)serialized to remote runtimes.
What did you see instead?
2024-01-10T16:25:50,267 | WARN | hz.cellar.partition-operation.thread-0 | ObjectStreamSerializer | 109 - fury-core - 0.4.1 | class com.hazelcast.internal.partition.PartitionStateVersionMismatchException customized jdk serialization, which is inefficient. Please replace it with a io.fury.serializer.Serializer or implements java.io.Externalizable
2024-01-10T16:25:50,276 | INFO | hz.cellar.partition-operation.thread-0 | CompileUnit | 109 - fury-core - 0.4.1 | Generate code for com.hazelcast.internal.partition.PartitionStateVersionMismatchExceptionFuryRefCompatibleCodec_1_538624385_503469352 took 1 ms.
2024-01-10T16:25:50,287 | INFO | hz.cellar.partition-operation.thread-0 | JaninoUtils | 109 - fury-core - 0.4.1 | Compile [PartitionStateVersionMismatchExceptionFuryRefCompatibleCodec_1_538624385_503469352] take 10 ms
2024-01-10T16:25:50,291 | INFO | hz.cellar.partition-operation.thread-0 | CompileUnit | 109 - fury-core - 0.4.1 | Generate code for com.hazelcast.core.HazelcastExceptionFuryRefCompatibleCodec_1_538624385_945155533 took 1 ms.
2024-01-10T16:25:50,299 | INFO | hz.cellar.partition-operation.thread-0 | JaninoUtils | 109 - fury-core - 0.4.1 | Compile [HazelcastExceptionFuryRefCompatibleCodec_1_538624385_945155533] take 7 ms
2024-01-10T16:25:50,301 | INFO | hz.cellar.partition-operation.thread-0 | CompileUnit | 109 - fury-core - 0.4.1 | Generate code for io.fury.builder.RuntimeExceptionFuryRefCompatibleCodec_1_1409007106 took 0 ms.
2024-01-10T16:25:50,305 | ERROR | hz.cellar.partition-operation.thread-0 | HazelcastGlobalSerializer | 125 - org.apache.karaf.cellar.fury - 4.2.1.20 | Cannot serialize object com.hazelcast.internal.partition.PartitionStateVersionMismatchException!
2024-01-10T16:25:50,305 | WARN | hz.cellar.partition-operation.thread-0 | OperationRunnerImpl | 107 - com.hazelcast - 3.12.13 | [127.0.0.1]:5701 [AbeelPlatformCluster] [3.12.13] While sending op error... op: com.hazelcast.internal.partition.operation.MigrationRequestOperation{serviceName='hz:core:partitionService', identityHash=52363869, partitionId=0, replicaIndex=0, callId=3853, invocationTime=1704900350264 (2024-01-10 16:25:50.264), waitTimeout=-1, callTimeout=300000, migration=MigrationInfo{uuid=9f6202c4-84e2-468b-856a-9c23ce59e054, partitionId=0, source=[127.0.0.1]:5701 - 06a614a9-b3a0-4139-b62c-a92567a65ca5, sourceCurrentReplicaIndex=0, sourceNewReplicaIndex=-1, destination=[127.0.0.1]:5704 - 98a4f2d3-ba52-4ffb-bc81-71b369b49804, destinationCurrentReplicaIndex=3, destinationNewReplicaIndex=0, master=[127.0.0.1]:5704, initialPartitionVersion=1355, partitionVersionIncrement=2, processing=false, status=ACTIVE}}, error: com.hazelcast.internal.partition.PartitionStateVersionMismatchException: Local partition state version is not equal to master's version! Local: 1288, Master: 1355
com.hazelcast.nio.serialization.HazelcastSerializationException: Failed to serialize 'com.hazelcast.spi.impl.operationservice.impl.responses.ErrorResponse'
at com.hazelcast.internal.serialization.impl.SerializationUtil.handleSerializeException(SerializationUtil.java:82) ~[107:com.hazelcast:3.12.13]
at com.hazelcast.internal.serialization.impl.AbstractSerializationService.toBytes(AbstractSerializationService.java:157) ~[107:com.hazelcast:3.12.13]
at com.hazelcast.internal.serialization.impl.AbstractSerializationService.toBytes(AbstractSerializationService.java:133) ~[107:com.hazelcast:3.12.13]
at com.hazelcast.internal.serialization.impl.AbstractSerializationService.toBytes(AbstractSerializationService.java:124) ~[107:com.hazelcast:3.12.13]
at com.hazelcast.spi.impl.operationservice.impl.OutboundResponseHandler.send(OutboundResponseHandler.java:114) ~[107:com.hazelcast:3.12.13]
at com.hazelcast.spi.impl.operationservice.impl.OutboundResponseHandler.sendResponse(OutboundResponseHandler.java:94) ~[107:com.hazelcast:3.12.13]
at com.hazelcast.spi.Operation.sendResponse(Operation.java:456) ~[107:com.hazelcast:3.12.13]
...
Caused by: com.hazelcast.nio.serialization.HazelcastSerializationException: Failed to serialize 'com.hazelcast.internal.partition.PartitionStateVersionMismatchException'
at com.hazelcast.internal.serialization.impl.SerializationUtil.handleSerializeException(SerializationUtil.java:82) ~[107:com.hazelcast:3.12.13]
at com.hazelcast.internal.serialization.impl.AbstractSerializationService.writeObject(AbstractSerializationService.java:254) ~[107:com.hazelcast:3.12.13]
at com.hazelcast.internal.serialization.impl.ByteArrayObjectDataOutput.writeObject(ByteArrayObjectDataOutput.java:376) ~[107:com.hazelcast:3.12.13]
at com.hazelcast.spi.impl.operationservice.impl.responses.ErrorResponse.writeData(ErrorResponse.java:49) ~[107:com.hazelcast:3.12.13]
at com.hazelcast.internal.serialization.impl.DataSerializableSerializer.write(DataSerializableSerializer.java:244) ~[?:?]
at com.hazelcast.internal.serialization.impl.DataSerializableSerializer.write(DataSerializableSerializer.java:51) ~[?:?]
at com.hazelcast.internal.serialization.impl.StreamSerializerAdapter.write(StreamSerializerAdapter.java:43) ~[?:?]
at com.hazelcast.internal.serialization.impl.AbstractSerializationService.toBytes(AbstractSerializationService.java:154) ~[?:?]
... 12 more
Caused by: java.io.IOException: Compile error:
io.fury.builder.RuntimeExceptionFuryRefCompatibleCodec_1_1409007106:
/* 0001 */ package io.fury.builder;
/* 0002 */
/* 0003 */ import java.util.List;
/* 0004 */ import java.util.Map;
/* 0005 */ import java.util.Set;
/* 0006 */ import io.fury.Fury;
/* 0007 */ import io.fury.memory.MemoryBuffer;
/* 0008 */ import io.fury.resolver.MapRefResolver;
/* 0009 */ import io.fury.resolver.ClassInfo;
/* 0010 */ import io.fury.resolver.ClassInfoHolder;
/* 0011 */ import io.fury.resolver.ClassResolver;
/* 0012 */ import io.fury.builder.Generated;
/* 0013 */ import io.fury.serializer.CodegenSerializer.LazyInitBeanSerializer;
/* 0014 */ import io.fury.serializer.Serializers.EnumSerializer;
/* 0015 */ import io.fury.serializer.Serializer;
/* 0016 */ import io.fury.serializer.StringSerializer;
/* 0017 */ import io.fury.serializer.ObjectSerializer;
/* 0018 */ import io.fury.serializer.CompatibleSerializer;
/* 0019 */ import io.fury.serializer.collection.AbstractCollectionSerializer;
/* 0020 */ import io.fury.serializer.collection.AbstractMapSerializer;
/* 0021 */ import io.fury.builder.Generated.GeneratedCompatibleSerializer;
/* 0022 */
/* 0023 */ public final class RuntimeExceptionFuryRefCompatibleCodec_1_1409007106 extends GeneratedCompatibleSerializer {
/* 0024 */
/* 0025 */ private final MapRefResolver refResolver;
/* 0026 */ private final ClassResolver classResolver;
/* 0027 */ private final StringSerializer strSerializer;
/* 0028 */ private final io.fury.resolver.FieldResolver fieldResolver;
/* 0029 */ private Fury fury;
/* 0030 */
/* 0031 */ public RuntimeExceptionFuryRefCompatibleCodec_1_1409007106(Fury fury, Class classType) {
/* 0032 */ super(fury, classType);
/* 0033 */ this.fury = fury;
/* 0034 */ fury.getClassResolver().setSerializerIfAbsent(classType, this);
/* 0035 */
/* 0036 */ io.fury.resolver.RefResolver refResolver0 = fury.getRefResolver();
/* 0037 */ refResolver = ((MapRefResolver)refResolver0);
/* 0038 */ classResolver = fury.getClassResolver();
/* 0039 */ strSerializer = fury.getStringSerializer();
/* 0040 */ fieldResolver = classResolver.getFieldResolver(java.lang.RuntimeException.class);
/* 0041 */ }
/* 0042 */
/* 0043 */ public RuntimeException readAndSetFields(MemoryBuffer memoryBuffer, Object object) {
/* 0044 */ io.fury.resolver.FieldResolver fieldResolver = this.fieldResolver;
/* 0045 */ long partFieldInfo = memoryBuffer.readInt();
/* 0046 */ RuntimeException bean = (RuntimeException)object;
/* 0047 */ while (((partFieldInfo & 3L) == ((byte)1))) {
/* 0048 */ if ((fieldResolver.skipDataBy4(memoryBuffer, ((int)partFieldInfo)) == 9223372036854775806L)) {
/* 0049 */ return bean;
/* 0050 */ }
/* 0051 */ partFieldInfo = memoryBuffer.readInt();
/* 0052 */ }
/* 0053 */ long value = memoryBuffer.readInt();
/* 0054 */ partFieldInfo = ((value << 32) | (partFieldInfo & 4294967295L));
/* 0055 */ while (((partFieldInfo & 7L) == ((byte)3))) {
/* 0056 */ if ((fieldResolver.skipDataBy8(memoryBuffer, partFieldInfo) == 9223372036854775806L)) {
/* 0057 */ return bean;
/* 0058 */ }
/* 0059 */ partFieldInfo = memoryBuffer.readLong();
/* 0060 */ }
/* 0061 */ while (((partFieldInfo & 7L) == ((byte)7))) {
/* 0062 */ if ((fieldResolver.skipDataBy8(memoryBuffer, partFieldInfo) == 9223372036854775806L)) {
/* 0063 */ return bean;
/* 0064 */ }
/* 0065 */ partFieldInfo = memoryBuffer.readLong();
/* 0066 */ }
/* 0067 */ fieldResolver.skipEndFields(memoryBuffer, partFieldInfo);
/* 0068 */ return bean;
/* 0069 */ }
/* 0070 */
/* 0071 */ @Override public final void write(MemoryBuffer buffer, Object obj) {
/* 0072 */ RuntimeException runtimeException1 = (RuntimeException)obj;
/* 0073 */ buffer.writeLong(9223372036854775806L);
/* 0074 */ }
/* 0075 */
/* 0076 */ @Override public final Object read(MemoryBuffer buffer) {
/* 0077 */ RuntimeException runtimeException2 = new RuntimeException();
/* 0078 */ refResolver.reference(runtimeException2);
/* 0079 */ Object bean0 = (Object)runtimeException2;
/* 0080 */ RuntimeException runtimeException3 = this.readAndSetFields(buffer, bean0);
/* 0081 */ return runtimeException2;
/* 0082 */ }
/* 0083 */
/* 0084 */ }
at org.apache.karaf.cellar.fury.HazelcastGlobalSerializer.write(HazelcastGlobalSerializer.java:191) ~[125:org.apache.karaf.cellar.fury:4.2.1.20]
Anything Else?
Behaviour seems similar to : https://github.com/apache/incubator-fury/issues/878
Are you willing to submit a PR?
- I’m willing to submit a PR!
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 30 (21 by maintainers)
Commits related to this issue
- fix(java): fix ClassLoader npe in loadOrGenCodecClass (#1346) fix ClassLoader npe in `loadOrGenCodecClass` mentioned in #1340 — committed to apache/fory by chaokunyang 3 years ago
Is there a minimal reproduction code I can try locally? Could you check whether your receiver peer get exactly same buffer as writer peer for deserialization?