Hazelcast distributed map processor execution on a single node

女生的网名这么多〃 提交于 2019-12-24 06:20:36

问题


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.

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.

Is there an option to execute distributed map's EntryProcessor on a single node?


回答1:


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.

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.

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);            
    }
}


来源:https://stackoverflow.com/questions/52606016/hazelcast-distributed-map-processor-execution-on-a-single-node

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