我正在寻找一些方法来在hazelcast中对大量数据(1 Million+的记录)进行增量更新。
使用案例是,为hazelcast客户端提供对象的映射,在映射的值中,仅填充某些字段,其余字段为空。如果字段被更改,我们希望替换它们,但如果它们为空或相同,则不会发生任何更改。
我们目前使用入口处理器来做这件事,但我相信我们在构造函数中传递的Map将被发送到集群的每个成员,这是低效的。有没有更好的方法来做这件事?
private Map mapOfNewValues;
public DomainClassDeltaUpdateEntryProcessor(Map mapOfNewValues) {
this.mapOfNewValues = mapOfNewValues;
}
@Override
public Object process(Map.Entry<String, DomainClass> entry) {
DomainClass oldDomain = entry.getValue();
if (oldDomain != null) {
DomainClass newDomainObj = (DomainClass) map.get(entry.getKey());
if (newDomainObj != null) {
entry.setValue(getDelta(oldDomain,newDomainObj));
}
}
return null;
}调用时使用
map.executeOnKeys(deltaMap.keySet(), new DomainClassDeltaUpdateEntryProcessor(deltaMap));发布于 2019-05-22 03:00:12
您可以在客户端查看,并使用executeOnKey。这样,您可以使用单独的调用为每个ket发送更新,因此如果您在map中有1000个键&4个成员,那么您只需要发送100个分布在4个成员之间的更新,而不是向所有4个成员发送全部1000个更新&每个调用将只包含一个增量对象。
所以在客户端,你可以这样做:
mapOfNewValues.entrySet().forEach(e -> if(e.getValue() != null) map.executeOnKey(e.getKey(), new DomainClassDeltaUpdateEntryProcessor(e.getValue())));https://stackoverflow.com/questions/56219068
复制相似问题