问题描述
我在支持高可用性的Spring Boot MVC应用程序中使用Hazelcast,它具有4个具有相同逻辑的实例,这些实例以双活模式运行。
这4个对象共享一个分布式对象映射。
I use Hazelcast within Spring Boot MVC application that supports high availability, it has 4 instances of the same logic which run as active-active.All of the 4 share one distributed map of objects.
由于用户操作(访问特定控制器),我触发了EntryProcessor(map.submitToKey )在共享地图上。我以为这样的操作只会在一个节点上运行一次处理器,但是相反,所有4个节点都同时运行同一处理器。
As a result of user action (access to specific controller) I trigger a EntryProcessor (map.submitToKey) on the shared map. I thought that such action would run the processor only once, on a single node, but instead all of the 4 nodes run the same processor at the same time.
是否可以在单个节点上执行分布式地图的EntryProcessor?
Is there an option to execute distributed map's EntryProcessor on a single node?
推荐答案
如果地图不需要任何备份,则 EntryProcessor
可以安全地从null javadoc / com / hazelcast / map / EntryProcessor.html#getBackupProcessor-- rel = nofollow noreferrer> getBackupProcessor()。当返回 null
时,备份节点将不执行任何 EntryBackupProcessor
。
If your map doesn't need any backups then EntryProcessor
can safely return null
from getBackupProcessor(). When returned null
, backup nodes will not execute any EntryBackupProcessor
.
否则,如果您为地图配置了备份,但为null com / hazelcast / map / EntryBackupProcessor.html rel = nofollow noreferrer> EntryBackupProcessor ,则条目不会复制到备份节点。就像没有为地图配置任何备份一样。主数据库和备份数据库最终将变得不一致。当主服务器崩溃时,您将丢失由 EntryProcessor
完成的更新。
Otherwise if you configured backups for map but return null
for EntryBackupProcessor, then entry won't be replicated to the backup nodes. It will treated as if there's no backups configured for map. Primary and backups will become inconsistent eventually. When primary crashes you will lose the updates done by EntryProcessor
.
在这种情况下,如果需要备份,您将可以编写自定义的 EntryBackupProcessor
,它可以复制主要 EntryProcessor
的执行结果,而不是执行 EntryProcessor
的逻辑。例如:
In this case, if you need backups, you can write a custom EntryBackupProcessor
, which can just replicate the result of primary EntryProcessor
's execution, instead of executing EntryProcessor
's logic. For example:
class CustomEntryBackupProcessor implements EntryBackupProcessor {
private Object resultOfEntryProcessor;
@Override
public void processBackup(Map.Entry entry) {
entry.setValue(resultOfEntryProcessor);
}
}
这篇关于Hazelcast分布式地图处理器在单个节点上的执行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!