我创建了自定义条目处理器,用于通过扩展AbstractEntryProcessor
来更新地图条目。
当我的应用程序在两个实例上的集群中运行,并且执行了条目处理器时,我收到以下异常:
com.hazelcast.nio.serialization.HazelcastSerializationException: Failed to serialize 'com.hazelcast.spi.impl.operationservice.impl.operations.Backup'
at com.hazelcast.internal.serialization.impl.SerializationUtil.handleSerializeException(SerializationUtil.java:73)
at com.hazelcast.internal.serialization.impl.AbstractSerializationService.toBytes(AbstractSerializationService.java:143)
at com.hazelcast.internal.serialization.impl.AbstractSerializationService.toBytes(AbstractSerializationService.java:124)
at com.hazelcast.spi.impl.operationservice.impl.OperationServiceImpl.send(OperationServiceImpl.java:406)
at com.hazelcast.spi.impl.operationservice.impl.OperationBackupHandler.sendSingleBackup(OperationBackupHandler.java:187)
at com.hazelcast.spi.impl.operationservice.impl.OperationBackupHandler.makeBackups(OperationBackupHandler.java:159)
at com.hazelcast.spi.impl.operationservice.impl.OperationBackupHandler.backup(OperationBackupHandler.java:78)
at com.hazelcast.spi.impl.operationservice.impl.OperationRunnerImpl.sendBackup(OperationRunnerImpl.java:270)
at com.hazelcast.spi.impl.operationservice.impl.OperationRunnerImpl.handleResponse(OperationRunnerImpl.java:253)
at com.hazelcast.spi.impl.operationservice.impl.OperationRunnerImpl.run(OperationRunnerImpl.java:182)
at com.hazelcast.spi.impl.operationexecutor.impl.OperationThread.process(OperationThread.java:122)
at com.hazelcast.spi.impl.operationexecutor.impl.OperationThread.run(OperationThread.java:102)
Caused by: com.hazelcast.nio.serialization.HazelcastSerializationException: Failed to serialize 'com.hazelcast.map.impl.operation.PartitionWideEntryWithPredicateBackupOperation'
at com.hazelcast.internal.serialization.impl.SerializationUtil.handleSerializeException(SerializationUtil.java:73)
at com.hazelcast.internal.serialization.impl.AbstractSerializationService.writeObject(AbstractSerializationService.java:201)
at com.hazelcast.internal.serialization.impl.ByteArrayObjectDataOutput.writeObject(ByteArrayObjectDataOutput.java:371)
at com.hazelcast.spi.impl.operationservice.impl.operations.Backup.writeInternal(Backup.java:222)
at com.hazelcast.spi.Operation.writeData(Operation.java:472)
at com.hazelcast.internal.serialization.impl.DataSerializableSerializer.write(DataSerializableSerializer.java:161)
at com.hazelcast.internal.serialization.impl.DataSerializableSerializer.write(DataSerializableSerializer.java:52)
at com.hazelcast.internal.serialization.impl.StreamSerializerAdapter.write(StreamSerializerAdapter.java:41)
at com.hazelcast.internal.serialization.impl.AbstractSerializationService.toBytes(AbstractSerializationService.java:140)
... 10 common frames omitted
Caused by: com.hazelcast.nio.serialization.HazelcastSerializationException: Failed to serialize 'com.hazelcast.map.AbstractEntryProcessor$EntryBackupProcessorImpl'
at com.hazelcast.internal.serialization.impl.SerializationUtil.handleSerializeException(SerializationUtil.java:73)
at com.hazelcast.internal.serialization.impl.AbstractSerializationService.writeObject(AbstractSerializationService.java:201)
at com.hazelcast.internal.serialization.impl.ByteArrayObjectDataOutput.writeObject(ByteArrayObjectDataOutput.java:371)
at com.hazelcast.map.impl.operation.PartitionWideEntryBackupOperation.writeInternal(PartitionWideEntryBackupOperation.java:98)
at com.hazelcast.map.impl.operation.PartitionWideEntryWithPredicateBackupOperation.writeInternal(PartitionWideEntryWithPredicateBackupOperation.java:51)
at com.hazelcast.spi.Operation.writeData(Operation.java:472)
at com.hazelcast.internal.serialization.impl.DataSerializableSerializer.write(DataSerializableSerializer.java:161)
at com.hazelcast.internal.serialization.impl.DataSerializableSerializer.write(DataSerializableSerializer.java:52)
at com.hazelcast.internal.serialization.impl.StreamSerializerAdapter.write(StreamSerializerAdapter.java:41)
at com.hazelcast.internal.serialization.impl.AbstractSerializationService.writeObject(AbstractSerializationService.java:199)
... 17 common frames omitted
Caused by: java.util.ConcurrentModificationException: null
at java.util.ArrayList.writeObject(Unknown Source)
at sun.reflect.GeneratedMethodAccessor143.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at java.io.ObjectStreamClass.invokeWriteObject(Unknown Source)
at java.io.ObjectOutputStream.writeSerialData(Unknown Source)
at java.io.ObjectOutputStream.writeOrdinaryObject(Unknown Source)
at java.io.ObjectOutputStream.writeObject0(Unknown Source)
at java.io.ObjectOutputStream.defaultWriteFields(Unknown Source)
at java.io.ObjectOutputStream.writeSerialData(Unknown Source)
at java.io.ObjectOutputStream.writeOrdinaryObject(Unknown Source)
at java.io.ObjectOutputStream.writeObject0(Unknown Source)
at java.io.ObjectOutputStream.writeObject(Unknown Source)
at java.util.ArrayList.writeObject(Unknown Source)
at sun.reflect.GeneratedMethodAccessor143.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at java.io.ObjectStreamClass.invokeWriteObject(Unknown Source)
at java.io.ObjectOutputStream.writeSerialData(Unknown Source)
at java.io.ObjectOutputStream.writeOrdinaryObject(Unknown Source)
at java.io.ObjectOutputStream.writeObject0(Unknown Source)
at java.io.ObjectOutputStream.defaultWriteFields(Unknown Source)
at java.io.ObjectOutputStream.writeSerialData(Unknown Source)
at java.io.ObjectOutputStream.writeOrdinaryObject(Unknown Source)
at java.io.ObjectOutputStream.writeObject0(Unknown Source)
at java.io.ObjectOutputStream.defaultWriteFields(Unknown Source)
at java.io.ObjectOutputStream.writeSerialData(Unknown Source)
at java.io.ObjectOutputStream.writeOrdinaryObject(Unknown Source)
at java.io.ObjectOutputStream.writeObject0(Unknown Source)
at java.io.ObjectOutputStream.writeObject(Unknown Source)
at com.hazelcast.internal.serialization.impl.JavaDefaultSerializers$JavaSerializer.write(JavaDefaultSerializers.java:242)
at com.hazelcast.internal.serialization.impl.StreamSerializerAdapter.write(StreamSerializerAdapter.java:41)
at com.hazelcast.internal.serialization.impl.AbstractSerializationService.writeObject(AbstractSerializationService.java:199)
... 25 common frames omitted
我的入门处理器如下所示:
public class HRUpdateRacesWithEntriesProcessor extends AbstractEntryProcessor<HRMeeting.HRMeetingKey, HRMeeting> {
private List<HRRace> races;
private Date date;
public HRUpdateRacesWithEntriesProcessor(List<HRRace> races, Date date) {
this.races = races;
this.date = date;
}
@Override
public Object process(Map.Entry<HRMeeting.HRMeetingKey, HRMeeting> entry) {
HRMeeting meeting = entry.getValue();
races.stream()
.filter(race -> entry.getKey().equals(new HRMeeting.HRMeetingKey(race.getMeetingDate(), race.getCourseId())))
.forEach(newRace -> {
Optional<HRRace> matchedRace =
meeting.getRaces().stream().filter(origin -> origin.getKey().equals(newRace.getKey())).findFirst();
if (newRace.getEntries() != null && matchedRace.isPresent()) {
newRace.setUpdateDate(date);
newRace.getEntries().stream()
.filter(hrEntry -> matchedRace.get().getEntries().stream().map(el -> el.getKey())
.collect(Collectors.toList()).contains(hrEntry.getKey()))
.forEach(hrEntry -> hrEntry.setUpdateDate(date));
matchedRace.get().getEntries().retainAll(newRace.getEntries());
newRace.getEntries().addAll(matchedRace.get().getEntries());
}
meeting.getRaces()
.removeIf(hrRace -> matchedRace.isPresent() && matchedRace.get().getKey().equals(hrRace.getKey()));
meeting.getRaces().add(newRace);
});
entry.setValue(meeting);
return null;
}
}
对于序列化,我的entites实现了java Serializible
。是可以成为问题的原因吗?
我正在使用hazelcast-3.8-SNAPSHOT
请帮我解决。
答案 0 :(得分:2)
这可能是一个简单的问题。当我试图在Hazelcast中将一个Object放到IMap时,我遇到了同样的错误。在我的例子中,我试图放置的对象并没有实现Serializable。
所以,我认为你应该检查一下是否实现了Serializable in&#34; com.hazelcast.spi.impl.operationservice.impl.operations.Backup&#34;像
公共类备份实现Serializable { ... }
答案 1 :(得分:0)
我认为你的问题是以某种方式(实际上很难遵循流程流)从EntryProcessor实现中捕获内容,因此尝试使用Serializable进行序列化。无论如何DataSerializable / IdentifiedDataSerializable不是java.util.Serializable来防止意外的序列化(如你的情况)发生:)
我猜是日期:
.forEach(hrEntry -> hrEntry.setUpdateDate(date));
我希望这会有所帮助,你可能需要寻找实际捕获的值。
答案 2 :(得分:0)
你可以发布Serializable类吗?因为我遇到错误的serialVersionUID时出现此错误。你有一个serialVersionUID并且它是一个常数(所有部署都是一样的)吗?