Search in sources :

Example 16 with AffinityFunction

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

the class GridOffHeapPartitionedMapPerformanceAbstractTest method beforeTest.

/** {@inheritDoc} */
@Override
protected void beforeTest() throws Exception {
    map = newMap();
    if (keys == null) {
        keys = new T3[LOAD_CNT];
        wrappers = new GridByteArrayWrapper[LOAD_CNT];
        AffinityFunction aff = new RendezvousAffinityFunction();
        Random rnd = new Random();
        for (int i = 0; i < LOAD_CNT; i++) {
            byte[] key = new byte[rnd.nextInt(511) + 1];
            rnd.nextBytes(key);
            GridByteArrayWrapper wrap = new GridByteArrayWrapper(key);
            keys[i] = new T3<>(aff.partition(wrap), wrap.hashCode(), key);
            wrappers[i] = wrap;
        }
    }
}
Also used : Random(java.util.Random) RendezvousAffinityFunction(org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction) AffinityFunction(org.apache.ignite.cache.affinity.AffinityFunction) RendezvousAffinityFunction(org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction)

Example 17 with AffinityFunction

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

the class GridOffHeapPartitionedMapPerformanceAbstractTest method beforeTest.

/** {@inheritDoc} */
@Override
protected void beforeTest() throws Exception {
    map = newMap();
    if (keys == null) {
        keys = new T3[LOAD_CNT];
        wrappers = new GridByteArrayWrapper[LOAD_CNT];
        AffinityFunction aff = new RendezvousAffinityFunction();
        Random rnd = new Random();
        for (int i = 0; i < LOAD_CNT; i++) {
            byte[] key = new byte[rnd.nextInt(511) + 1];
            rnd.nextBytes(key);
            GridByteArrayWrapper wrap = new GridByteArrayWrapper(key);
            keys[i] = new T3<>(aff.partition(wrap), wrap.hashCode(), key);
            wrappers[i] = wrap;
        }
    }
}
Also used : GridByteArrayWrapper(org.apache.ignite.internal.util.offheap.GridByteArrayWrapper) Random(java.util.Random) RendezvousAffinityFunction(org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction) RendezvousAffinityFunction(org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction) AffinityFunction(org.apache.ignite.cache.affinity.AffinityFunction)

Example 18 with AffinityFunction

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

the class GridCachePartitionedAffinityExcludeNeighborsPerformanceTest method getConfiguration.

/** {@inheritDoc} */
@Override
protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
    IgniteConfiguration c = super.getConfiguration(igniteInstanceName);
    TcpDiscoverySpi spi = new TcpDiscoverySpi();
    spi.setIpFinder(ipFinder);
    c.setDiscoverySpi(spi);
    CacheConfiguration cc = defaultCacheConfiguration();
    cc.setCacheMode(PARTITIONED);
    cc.setBackups(2);
    AffinityFunction aff = new RendezvousAffinityFunction(excNeighbores);
    cc.setAffinity(aff);
    cc.setRebalanceMode(NONE);
    c.setCacheConfiguration(cc);
    return c;
}
Also used : IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) RendezvousAffinityFunction(org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction) RendezvousAffinityFunction(org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction) AffinityFunction(org.apache.ignite.cache.affinity.AffinityFunction) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) TcpDiscoverySpi(org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi)

Example 19 with AffinityFunction

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

the class GridCachePartitionedPreloadEventsSelfTest method cacheConfiguration.

/** {@inheritDoc} */
@Override
protected CacheConfiguration cacheConfiguration() {
    CacheConfiguration cacheCfg = super.cacheConfiguration();
    if (replicatedAffinity)
        // replicate entries to all nodes
        cacheCfg.setAffinity(notSerializableProxy(new AffinityFunction() {

            /** {@inheritDoc} */
            @Override
            public void reset() {
            }

            /** {@inheritDoc} */
            @Override
            public int partitions() {
                return 1;
            }

            /** {@inheritDoc} */
            @Override
            public int partition(Object key) {
                return 0;
            }

            /** {@inheritDoc} */
            @Override
            public List<List<ClusterNode>> assignPartitions(AffinityFunctionContext affCtx) {
                List<ClusterNode> nodes = new ArrayList<>(affCtx.currentTopologySnapshot());
                return Collections.singletonList(nodes);
            }

            /** {@inheritDoc} */
            @Override
            public void removeNode(UUID nodeId) {
            }
        }, AffinityFunction.class));
    cacheCfg.setRebalanceDelay(rebalanceDelay);
    return cacheCfg;
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) ArrayList(java.util.ArrayList) List(java.util.List) UUID(java.util.UUID) AffinityFunction(org.apache.ignite.cache.affinity.AffinityFunction) AffinityFunctionContext(org.apache.ignite.cache.affinity.AffinityFunctionContext) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration)

Example 20 with AffinityFunction

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

the class IgniteTxAbstractTest method checkRollback.

/**
     * @param map Map to check.
     * @param concurrency Concurrency.
     * @param isolation Isolation.
     * @throws IgniteCheckedException If check failed.
     */
protected void checkRollback(ConcurrentMap<Integer, String> map, 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);
        Transaction tx = ignite(gridIdx).transactions().txStart(concurrency, isolation, 0, 0);
        try {
            for (Integer key : getKeys()) {
                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:
                        {
                            debug("Reading key: " + key);
                            checkMap(map, key, cache.get(key));
                            break;
                        }
                    case WRITE:
                        {
                            debug("Writing key and value [key=" + key + ", val=" + val + ']');
                            checkMap(map, key, cache.getAndPut(key, val));
                            break;
                        }
                    case REMOVE:
                        {
                            debug("Removing key: " + key);
                            checkMap(map, key, cache.getAndRemove(key));
                            break;
                        }
                    default:
                        {
                            assert false;
                        }
                }
            }
            tx.rollback();
            debug("Rolled back transaction: " + tx);
        } catch (TransactionOptimisticException e) {
            tx.rollback();
            log.warning("Rolled back transaction due to optimistic exception [tx=" + tx + ", e=" + e + ']');
            throw e;
        } catch (Exception e) {
            tx.rollback();
            error("Rolled back transaction due to exception [tx=" + tx + ", e=" + e + ']');
            throw e;
        } finally {
            Transaction t1 = ignite(gridIdx).transactions().tx();
            debug("t1=" + t1);
            assert t1 == null : "Thread should not have transaction upon completion ['t==tx'=" + (t1 == tx) + ", t=" + t1 + ']';
        }
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) TransactionOptimisticException(org.apache.ignite.transactions.TransactionOptimisticException) Transaction(org.apache.ignite.transactions.Transaction) Ignite(org.apache.ignite.Ignite) AffinityFunction(org.apache.ignite.cache.affinity.AffinityFunction) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) TransactionOptimisticException(org.apache.ignite.transactions.TransactionOptimisticException) IgniteCheckedException(org.apache.ignite.IgniteCheckedException)

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