Search in sources :

Example 81 with RendezvousAffinityFunction

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;
}
Also used : IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) RendezvousAffinityFunction(org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) TcpDiscoverySpi(org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi)

Example 82 with RendezvousAffinityFunction

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;
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) IgniteNodeValidationResult(org.apache.ignite.spi.IgniteNodeValidationResult) RendezvousAffinityFunction(org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction) GridTimeoutObject(org.apache.ignite.internal.processors.timeout.GridTimeoutObject) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) NearCacheConfiguration(org.apache.ignite.configuration.NearCacheConfiguration) Nullable(org.jetbrains.annotations.Nullable)

Example 83 with RendezvousAffinityFunction

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);
}
Also used : PlatformAffinityFunction(org.apache.ignite.internal.processors.platform.cache.affinity.PlatformAffinityFunction) PlatformDotNetAffinityFunction(org.apache.ignite.platform.dotnet.PlatformDotNetAffinityFunction) RendezvousAffinityFunction(org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction) RendezvousAffinityFunction(org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction) AffinityFunction(org.apache.ignite.cache.affinity.AffinityFunction) PlatformAffinityFunction(org.apache.ignite.internal.processors.platform.cache.affinity.PlatformAffinityFunction) PlatformDotNetAffinityFunction(org.apache.ignite.platform.dotnet.PlatformDotNetAffinityFunction)

Example 84 with RendezvousAffinityFunction

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;
}
Also used : RendezvousAffinityFunction(org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration)

Example 85 with RendezvousAffinityFunction

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;
}
Also used : RendezvousAffinityFunction(org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction) Person(org.apache.ignite.examples.ml.dataset.model.Person) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration)

Aggregations

RendezvousAffinityFunction (org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction)142 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)126 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)71 TcpDiscoverySpi (org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi)48 DataRegionConfiguration (org.apache.ignite.configuration.DataRegionConfiguration)33 DataStorageConfiguration (org.apache.ignite.configuration.DataStorageConfiguration)33 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)11 Ignite (org.apache.ignite.Ignite)11 IgniteEx (org.apache.ignite.internal.IgniteEx)11 BinaryConfiguration (org.apache.ignite.configuration.BinaryConfiguration)10 NearCacheConfiguration (org.apache.ignite.configuration.NearCacheConfiguration)10 ThreadLocalRandom (java.util.concurrent.ThreadLocalRandom)8 AffinityFunction (org.apache.ignite.cache.affinity.AffinityFunction)8 ArrayList (java.util.ArrayList)7 Random (java.util.Random)7 IgniteCache (org.apache.ignite.IgniteCache)7 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)7 QueryEntity (org.apache.ignite.cache.QueryEntity)4 Transaction (org.apache.ignite.transactions.Transaction)4 GridCacheDatabaseSharedManager (org.apache.ignite.internal.processors.cache.persistence.GridCacheDatabaseSharedManager)3