Topology validator is used to verify that cluster topology is valid for further cache operations.
The topology validator is invoked every time the cluster topology changes (either a new node joined
or an existing node failed or left).
If topology validator is not configured, then the cluster topology is always considered to be valid.
Whenever the validate(Collection)
method returns true
, then the topology is considered valid
for a certain cache and all operations on this cache will be allowed to proceed. Otherwise, all update operations
on the cache are restricted with the following exceptions:
CacheException
will be thrown for all update operations (put, remove, etc) attempt.
IgniteException
will be thrown for the transaction commit attempt.
After returning
false
and declaring the topology not valid, the topology validator can return
to normal state whenever the next topology change happens.
The example below shows how a validator can be used to allow cache updates only in case if the cluster
topology contains exactly 2 nodes:
new TopologyValidator() {
public boolean validate(Collection nodes) {
return nodes.size() == 2;
}
}
The topology validator can be configured either from code or XML via
CacheConfiguration.setTopologyValidator(TopologyValidator)
method.