use of org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction in project ignite by apache.
the class IgniteCachePartitionLossPolicySelfTest method getConfiguration.
/**
* {@inheritDoc}
*/
@Override
protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
IgniteConfiguration cfg = super.getConfiguration(gridName);
((TcpDiscoverySpi) cfg.getDiscoverySpi()).setIpFinder(ipFinder);
cfg.setClientMode(client);
CacheConfiguration<Integer, Integer> cacheCfg = new CacheConfiguration<>(CACHE_NAME);
cacheCfg.setCacheMode(PARTITIONED);
cacheCfg.setBackups(0);
cacheCfg.setWriteSynchronizationMode(FULL_SYNC);
cacheCfg.setPartitionLossPolicy(partLossPlc);
cacheCfg.setAffinity(new RendezvousAffinityFunction(false, 32));
cfg.setCacheConfiguration(cacheCfg);
return cfg;
}
use of org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction in project ignite by apache.
the class GridCacheProcessor method validateHashIdResolvers.
/**
* @param node Joining node.
* @return Validation result or {@code null} in case of success.
*/
@Nullable
private IgniteNodeValidationResult validateHashIdResolvers(ClusterNode node) {
if (!node.isClient()) {
for (DynamicCacheDescriptor desc : cacheDescriptors().values()) {
CacheConfiguration cfg = desc.cacheConfiguration();
if (cfg.getAffinity() instanceof RendezvousAffinityFunction) {
RendezvousAffinityFunction aff = (RendezvousAffinityFunction) cfg.getAffinity();
Object nodeHashObj = aff.resolveNodeHash(node);
for (ClusterNode topNode : ctx.discovery().allNodes()) {
Object topNodeHashObj = aff.resolveNodeHash(topNode);
if (nodeHashObj.hashCode() == topNodeHashObj.hashCode()) {
String errMsg = "Failed to add node to topology because it has the same hash code for " + "partitioned affinity as one of existing nodes [cacheName=" + cfg.getName() + ", existingNodeId=" + topNode.id() + ']';
String sndMsg = "Failed to add node to topology because it has the same hash code for " + "partitioned affinity as one of existing nodes [cacheName=" + cfg.getName() + ", existingNodeId=" + topNode.id() + ']';
return new IgniteNodeValidationResult(topNode.id(), errMsg, sndMsg);
}
}
}
}
}
return null;
}
use of org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction in project ignite by apache.
the class PlatformConfigurationUtils method writeAffinityFunction.
/**
* Writes the affinity functions.
*
* @param out Stream.
* @param f Affinity.
*/
private static void writeAffinityFunction(BinaryRawWriter out, AffinityFunction f) {
if (f instanceof PlatformDotNetAffinityFunction)
f = ((PlatformDotNetAffinityFunction) f).getFunc();
if (f instanceof RendezvousAffinityFunction) {
out.writeByte((byte) 2);
RendezvousAffinityFunction f0 = (RendezvousAffinityFunction) f;
out.writeInt(f0.getPartitions());
out.writeBoolean(f0.isExcludeNeighbors());
// override flags
out.writeByte((byte) 0);
// user func
out.writeObject(null);
} else if (f instanceof PlatformAffinityFunction) {
PlatformAffinityFunction f0 = (PlatformAffinityFunction) f;
AffinityFunction baseFunc = f0.getBaseFunc();
if (baseFunc instanceof RendezvousAffinityFunction) {
out.writeByte((byte) 2);
out.writeInt(f0.partitions());
out.writeBoolean(((RendezvousAffinityFunction) baseFunc).isExcludeNeighbors());
out.writeByte(f0.getOverrideFlags());
out.writeObject(f0.getUserFunc());
} else {
out.writeByte((byte) 3);
out.writeInt(f0.partitions());
// exclude neighbors
out.writeBoolean(false);
out.writeByte(f0.getOverrideFlags());
out.writeObject(f0.getUserFunc());
}
} else
out.writeByte((byte) 0);
}
use of org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction in project ignite by apache.
the class DistributedLinearRegressionWithLSQRTrainerExample method getTestCache.
/**
* Fills cache with data and returns it.
*
* @param ignite Ignite instance.
* @return Filled Ignite Cache.
*/
private static IgniteCache<Integer, double[]> getTestCache(Ignite ignite) {
CacheConfiguration<Integer, double[]> cacheConfiguration = new CacheConfiguration<>();
cacheConfiguration.setName("TEST_" + UUID.randomUUID());
cacheConfiguration.setAffinity(new RendezvousAffinityFunction(false, 10));
IgniteCache<Integer, double[]> cache = ignite.createCache(cacheConfiguration);
for (int i = 0; i < data.length; i++) cache.put(i, data[i]);
return cache;
}
use of org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction in project ignite by apache.
the class CacheBasedDatasetExample method createCache.
/**
*/
private static IgniteCache<Integer, Person> createCache(Ignite ignite) {
CacheConfiguration<Integer, Person> cacheConfiguration = new CacheConfiguration<>();
cacheConfiguration.setName("PERSONS");
cacheConfiguration.setAffinity(new RendezvousAffinityFunction(false, 2));
IgniteCache<Integer, Person> persons = ignite.createCache(cacheConfiguration);
persons.put(1, new Person("Mike", 42, 10000));
persons.put(2, new Person("John", 32, 64000));
persons.put(3, new Person("George", 53, 120000));
persons.put(4, new Person("Karl", 24, 70000));
return persons;
}
Aggregations