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