Search in sources :

Example 6 with AffinityFunction

use of org.apache.ignite.cache.affinity.AffinityFunction in project ignite by apache.

the class RendezvousAffinityFunctionSelfTest method affinityFunction.

/** {@inheritDoc} */
@Override
protected AffinityFunction affinityFunction() {
    AffinityFunction aff = new RendezvousAffinityFunction();
    GridTestUtils.setFieldValue(aff, "ignite", ignite);
    return aff;
}
Also used : AffinityFunction(org.apache.ignite.cache.affinity.AffinityFunction)

Example 7 with AffinityFunction

use of org.apache.ignite.cache.affinity.AffinityFunction in project ignite by apache.

the class RendezvousAffinityFunctionSimpleBenchmark method testAffinityBenchmarkAdd.

/**
     *
     */
public void testAffinityBenchmarkAdd() {
    mode = TopologyModificationMode.ADD;
    AffinityFunction aff0 = new RendezvousAffinityFunctionOld(true, 1024);
    GridTestUtils.setFieldValue(aff0, "ignite", ignite);
    affinityBenchmark(aff0, new RendezvousAffinityFunction(true, 1024));
}
Also used : AffinityFunction(org.apache.ignite.cache.affinity.AffinityFunction)

Example 8 with AffinityFunction

use of org.apache.ignite.cache.affinity.AffinityFunction in project ignite by apache.

the class AtomicCacheAffinityConfigurationTest method testRendezvousAffinity.

/**
     * @throws Exception If failed.
     *
     */
public void testRendezvousAffinity() throws Exception {
    try {
        affinityFunction = new RendezvousAffinityFunction(false, 10);
        startGrids(3);
        for (int i = 0; i < 3; i++) {
            IgniteEx igniteEx = grid(i);
            CacheConfiguration cConf = igniteEx.context().cache().cache("ignite-atomics-sys-cache").configuration();
            AffinityFunction aff = cConf.getAffinity();
            assertNotNull(aff);
            assertEquals(aff.partitions(), affinityFunction.partitions());
            assertEquals(aff.getClass(), affinityFunction.getClass());
        }
        checkAtomics();
    } finally {
        stopAllGrids();
    }
}
Also used : IgniteEx(org.apache.ignite.internal.IgniteEx) RendezvousAffinityFunction(org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction) AffinityFunction(org.apache.ignite.cache.affinity.AffinityFunction) RendezvousAffinityFunction(org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration)

Example 9 with AffinityFunction

use of org.apache.ignite.cache.affinity.AffinityFunction in project ignite by apache.

the class IgniteTxAbstractTest method checkCommit.

/**
     * @param concurrency Concurrency.
     * @param isolation Isolation.
     * @throws Exception If check failed.
     */
protected void checkCommit(TransactionConcurrency concurrency, TransactionIsolation isolation) throws Exception {
    int gridIdx = RAND.nextInt(gridCount());
    Ignite ignite = grid(gridIdx);
    if (isTestDebug())
        debug("Checking commit on grid: " + ignite.cluster().localNode().id());
    for (int i = 0; i < iterations(); i++) {
        IgniteCache<Integer, String> cache = jcache(gridIdx);
        try (Transaction tx = ignite(gridIdx).transactions().txStart(concurrency, isolation, 0, 0)) {
            int prevKey = -1;
            for (Integer key : getKeys()) {
                // Make sure we have the same locking order for all concurrent transactions.
                assert key >= prevKey : "key: " + key + ", prevKey: " + prevKey;
                if (isTestDebug()) {
                    AffinityFunction aff = cache.getConfiguration(CacheConfiguration.class).getAffinity();
                    int part = aff.partition(key);
                    debug("Key affinity [key=" + key + ", partition=" + part + ", affinity=" + U.toShortString(ignite(gridIdx).affinity(DEFAULT_CACHE_NAME).mapPartitionToPrimaryAndBackups(part)) + ']');
                }
                String val = Integer.toString(key);
                switch(getOp()) {
                    case READ:
                        {
                            if (isTestDebug())
                                debug("Reading key [key=" + key + ", i=" + i + ']');
                            val = cache.get(key);
                            if (isTestDebug())
                                debug("Read value for key [key=" + key + ", val=" + val + ']');
                            break;
                        }
                    case WRITE:
                        {
                            if (isTestDebug())
                                debug("Writing key and value [key=" + key + ", val=" + val + ", i=" + i + ']');
                            cache.put(key, val);
                            break;
                        }
                    case REMOVE:
                        {
                            if (isTestDebug())
                                debug("Removing key [key=" + key + ", i=" + i + ']');
                            cache.remove(key);
                            break;
                        }
                    default:
                        {
                            assert false;
                        }
                }
            }
            tx.commit();
            if (isTestDebug())
                debug("Committed transaction [i=" + i + ", tx=" + tx + ']');
        } catch (TransactionOptimisticException e) {
            if (!(concurrency == OPTIMISTIC && isolation == SERIALIZABLE)) {
                log.error("Unexpected error: " + e, e);
                throw e;
            }
        } catch (Throwable e) {
            log.error("Unexpected error: " + e, e);
            throw e;
        }
    }
    Transaction tx = ignite(gridIdx).transactions().tx();
    assertNull("Thread should not have transaction upon completion", tx);
    if (printMemoryStats()) {
        if (cntr.getAndIncrement() % 100 == 0)
            // Print transaction memory stats.
            ((IgniteKernal) grid(gridIdx)).internalCache(DEFAULT_CACHE_NAME).context().tm().printMemoryStats();
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) TransactionOptimisticException(org.apache.ignite.transactions.TransactionOptimisticException) IgniteKernal(org.apache.ignite.internal.IgniteKernal) Transaction(org.apache.ignite.transactions.Transaction) Ignite(org.apache.ignite.Ignite) AffinityFunction(org.apache.ignite.cache.affinity.AffinityFunction) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration)

Example 10 with AffinityFunction

use of org.apache.ignite.cache.affinity.AffinityFunction in project ignite by apache.

the class GridCacheAffinityApiSelfTest method testMapPartitionsToNode.

/**
     * JUnit.
     *
     * @throws Exception If failed.
     */
public void testMapPartitionsToNode() throws Exception {
    Map<Integer, ClusterNode> map = grid(0).affinity(DEFAULT_CACHE_NAME).mapPartitionsToNodes(F.asList(0, 1, 5, 19, 12));
    AffinityFunctionContext ctx = new GridAffinityFunctionContextImpl(new ArrayList<>(grid(0).cluster().nodes()), null, null, new AffinityTopologyVersion(1), 1);
    AffinityFunction aff = affinity();
    List<List<ClusterNode>> assignment = aff.assignPartitions(ctx);
    for (Map.Entry<Integer, ClusterNode> e : map.entrySet()) assert F.eqNodes(F.first(nodes(assignment, aff, e.getKey())), e.getValue());
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) GridAffinityFunctionContextImpl(org.apache.ignite.internal.processors.affinity.GridAffinityFunctionContextImpl) AffinityTopologyVersion(org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion) ArrayList(java.util.ArrayList) List(java.util.List) LinkedList(java.util.LinkedList) AffinityFunctionContext(org.apache.ignite.cache.affinity.AffinityFunctionContext) AffinityFunction(org.apache.ignite.cache.affinity.AffinityFunction) Map(java.util.Map)

Aggregations

AffinityFunction (org.apache.ignite.cache.affinity.AffinityFunction)27 ArrayList (java.util.ArrayList)10 List (java.util.List)10 ClusterNode (org.apache.ignite.cluster.ClusterNode)10 RendezvousAffinityFunction (org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction)9 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)9 AffinityFunctionContext (org.apache.ignite.cache.affinity.AffinityFunctionContext)8 GridAffinityFunctionContextImpl (org.apache.ignite.internal.processors.affinity.GridAffinityFunctionContextImpl)8 AffinityTopologyVersion (org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion)7 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)5 Ignite (org.apache.ignite.Ignite)5 LinkedList (java.util.LinkedList)4 Map (java.util.Map)4 Random (java.util.Random)3 IgniteKernal (org.apache.ignite.internal.IgniteKernal)3 HashSet (java.util.HashSet)2 UUID (java.util.UUID)2 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)2 DiscoveryEvent (org.apache.ignite.events.DiscoveryEvent)2 PlatformAffinityFunction (org.apache.ignite.internal.processors.platform.cache.affinity.PlatformAffinityFunction)2