Search in sources :

Example 1 with IgniteCacheProxyImpl

use of org.apache.ignite.internal.processors.cache.IgniteCacheProxyImpl in project ignite by apache.

the class GridCommonAbstractTest method calcAffinity.

/**
 * @param cache Cache.
 * @param nodes Nodes.
 */
private List<List<ClusterNode>> calcAffinity(IgniteCache<?, ?> cache, List<ClusterNode> nodes) {
    IgniteCacheProxyImpl proxy = cache.unwrap(IgniteCacheProxyImpl.class);
    GridCacheContext<?, ?> cctx = proxy.context();
    AffinityFunction func = cctx.config().getAffinity();
    AffinityFunctionContext ctx = new GridAffinityFunctionContextImpl(nodes, null, null, AffinityTopologyVersion.NONE, cctx.config().getBackups());
    return func.assignPartitions(ctx);
}
Also used : GridAffinityFunctionContextImpl(org.apache.ignite.internal.processors.affinity.GridAffinityFunctionContextImpl) IgniteCacheProxyImpl(org.apache.ignite.internal.processors.cache.IgniteCacheProxyImpl) AffinityFunction(org.apache.ignite.cache.affinity.AffinityFunction) AffinityFunctionContext(org.apache.ignite.cache.affinity.AffinityFunctionContext)

Example 2 with IgniteCacheProxyImpl

use of org.apache.ignite.internal.processors.cache.IgniteCacheProxyImpl in project ignite by apache.

the class IgniteSqlSinglePartitionMultiParallelismTest method segmenKey.

/**
 * @param segment Target index segment.
 * @return Cache key for target segment.
 */
protected Integer segmenKey(int segment) {
    IgniteCache<Object, Object> cache = ignite(0).cache(CACHE_NAME);
    IgniteCacheProxyImpl proxy = cache.unwrap(IgniteCacheProxyImpl.class);
    GridCacheContext<?, ?> cctx = proxy.context();
    for (int k = 1; k <= KEY_CNT; k++) {
        int keySegment = InlineIndexImpl.calculateSegment(CACHE_PARALLELISM, cctx.affinity().partition(k));
        if (keySegment == segment)
            return k;
    }
    throw new IgniteException("Key is not found. Please, check range of keys and segmentsCnt. " + "Requested segmentId is " + segment);
}
Also used : IgniteException(org.apache.ignite.IgniteException) IgniteCacheProxyImpl(org.apache.ignite.internal.processors.cache.IgniteCacheProxyImpl)

Example 3 with IgniteCacheProxyImpl

use of org.apache.ignite.internal.processors.cache.IgniteCacheProxyImpl in project ignite by apache.

the class GridCommonAbstractTest method partitionKeysIterator.

/**
 * @param cache Cache.
 * @param part Partition.
 * @return Unbounded iterator for partition keys.
 */
protected Iterator<Integer> partitionKeysIterator(IgniteCache<?, ?> cache, int part) {
    IgniteCacheProxyImpl proxy = cache.unwrap(IgniteCacheProxyImpl.class);
    GridCacheContext<?, ?> cctx = proxy.context();
    return new Iterator<Integer>() {

        int cur, next = 0;

        {
            advance();
        }

        private void advance() {
            while (cctx.affinity().partition(cur = next++) != part) ;
        }

        @Override
        public boolean hasNext() {
            return true;
        }

        @Override
        public Integer next() {
            int tmp = cur;
            advance();
            return tmp;
        }
    };
}
Also used : Iterator(java.util.Iterator) IgniteCacheProxyImpl(org.apache.ignite.internal.processors.cache.IgniteCacheProxyImpl)

Example 4 with IgniteCacheProxyImpl

use of org.apache.ignite.internal.processors.cache.IgniteCacheProxyImpl in project ignite by apache.

the class GridCommonAbstractTest method partitionKeys.

/**
 * @param cache Cache.
 * @param part Partition.
 * @param cnt Count.
 * @param skipCnt Skip keys from start.
 * @return List of keys for partition.
 */
protected List<Integer> partitionKeys(IgniteCache<?, ?> cache, int part, int cnt, int skipCnt) {
    IgniteCacheProxyImpl proxy = cache.unwrap(IgniteCacheProxyImpl.class);
    GridCacheContext<?, ?> cctx = proxy.context();
    int k = 0, c = 0, skip0 = 0;
    List<Integer> keys = new ArrayList<>(cnt);
    while (c < cnt) {
        if (cctx.affinity().partition(k) == part) {
            if (skip0 < skipCnt) {
                k++;
                skip0++;
                continue;
            }
            c++;
            keys.add(k);
        }
        k++;
    }
    return keys;
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ArrayList(java.util.ArrayList) IgniteCacheProxyImpl(org.apache.ignite.internal.processors.cache.IgniteCacheProxyImpl)

Aggregations

IgniteCacheProxyImpl (org.apache.ignite.internal.processors.cache.IgniteCacheProxyImpl)4 ArrayList (java.util.ArrayList)1 Iterator (java.util.Iterator)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 IgniteException (org.apache.ignite.IgniteException)1 AffinityFunction (org.apache.ignite.cache.affinity.AffinityFunction)1 AffinityFunctionContext (org.apache.ignite.cache.affinity.AffinityFunctionContext)1 GridAffinityFunctionContextImpl (org.apache.ignite.internal.processors.affinity.GridAffinityFunctionContextImpl)1