Search in sources :

Example 1 with AffinityKeyMapper

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

the class GridAffinityProcessor method affinityInfoFromNode.

/**
     * Requests {@link AffinityFunction} and {@link AffinityKeyMapper} from remote node.
     *
     * @param cacheName Name of cache on which affinity is requested.
     * @param topVer Topology version.
     * @param n Node from which affinity is requested.
     * @return Affinity cached function.
     * @throws IgniteCheckedException If either local or remote node cannot get deployment for affinity objects.
     */
private AffinityInfo affinityInfoFromNode(String cacheName, AffinityTopologyVersion topVer, ClusterNode n) throws IgniteCheckedException {
    GridTuple3<GridAffinityMessage, GridAffinityMessage, GridAffinityAssignment> t = ctx.closure().callAsyncNoFailover(BROADCAST, affinityJob(cacheName, topVer), F.asList(n), true, /*system pool*/
    0, false).get();
    AffinityFunction f = (AffinityFunction) unmarshall(ctx, n.id(), t.get1());
    AffinityKeyMapper m = (AffinityKeyMapper) unmarshall(ctx, n.id(), t.get2());
    assert m != null;
    // Bring to initial state.
    f.reset();
    m.reset();
    CacheConfiguration ccfg = ctx.cache().cacheConfiguration(cacheName);
    return new AffinityInfo(f, m, t.get3(), ctx.cacheObjects().contextForCache(ccfg));
}
Also used : AffinityKeyMapper(org.apache.ignite.cache.affinity.AffinityKeyMapper) AffinityFunction(org.apache.ignite.cache.affinity.AffinityFunction) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration)

Example 2 with AffinityKeyMapper

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

the class QueryUtils method typeForQueryEntity.

/**
     * Create type candidate for query entity.
     *
     * @param cacheName Cache name.
     * @param cctx Cache context.
     * @param qryEntity Query entity.
     * @param mustDeserializeClss Classes which must be deserialized.
     * @param escape Escape flag.
     * @return Type candidate.
     * @throws IgniteCheckedException If failed.
     */
public static QueryTypeCandidate typeForQueryEntity(String cacheName, GridCacheContext cctx, QueryEntity qryEntity, List<Class<?>> mustDeserializeClss, boolean escape) throws IgniteCheckedException {
    GridKernalContext ctx = cctx.kernalContext();
    CacheConfiguration<?, ?> ccfg = cctx.config();
    boolean binaryEnabled = ctx.cacheObjects().isBinaryEnabled(ccfg);
    CacheObjectContext coCtx = binaryEnabled ? ctx.cacheObjects().contextForCache(ccfg) : null;
    QueryTypeDescriptorImpl desc = new QueryTypeDescriptorImpl(cacheName);
    desc.aliases(qryEntity.getAliases());
    // Key and value classes still can be available if they are primitive or JDK part.
    // We need that to set correct types for _key and _val columns.
    Class<?> keyCls = U.classForName(qryEntity.findKeyType(), null);
    Class<?> valCls = U.classForName(qryEntity.findValueType(), null);
    // If local node has the classes and they are externalizable, we must use reflection properties.
    boolean keyMustDeserialize = mustDeserializeBinary(ctx, keyCls);
    boolean valMustDeserialize = mustDeserializeBinary(ctx, valCls);
    boolean keyOrValMustDeserialize = keyMustDeserialize || valMustDeserialize;
    if (keyCls == null)
        keyCls = Object.class;
    String simpleValType = ((valCls == null) ? typeName(qryEntity.findValueType()) : typeName(valCls));
    desc.name(simpleValType);
    desc.tableName(qryEntity.getTableName());
    if (binaryEnabled && !keyOrValMustDeserialize) {
        // Safe to check null.
        if (SQL_TYPES.contains(valCls))
            desc.valueClass(valCls);
        else
            desc.valueClass(Object.class);
        if (SQL_TYPES.contains(keyCls))
            desc.keyClass(keyCls);
        else
            desc.keyClass(Object.class);
    } else {
        if (valCls == null)
            throw new IgniteCheckedException("Failed to find value class in the node classpath " + "(use default marshaller to enable binary objects) : " + qryEntity.findValueType());
        desc.valueClass(valCls);
        desc.keyClass(keyCls);
    }
    desc.keyTypeName(qryEntity.findKeyType());
    desc.valueTypeName(qryEntity.findValueType());
    desc.keyFieldName(qryEntity.getKeyFieldName());
    desc.valueFieldName(qryEntity.getValueFieldName());
    if (binaryEnabled && keyOrValMustDeserialize) {
        if (keyMustDeserialize)
            mustDeserializeClss.add(keyCls);
        if (valMustDeserialize)
            mustDeserializeClss.add(valCls);
    }
    QueryTypeIdKey typeId;
    QueryTypeIdKey altTypeId = null;
    if (valCls == null || (binaryEnabled && !keyOrValMustDeserialize)) {
        processBinaryMeta(ctx, qryEntity, desc);
        typeId = new QueryTypeIdKey(cacheName, ctx.cacheObjects().typeId(qryEntity.findValueType()));
        if (valCls != null)
            altTypeId = new QueryTypeIdKey(cacheName, valCls);
        if (!cctx.customAffinityMapper() && qryEntity.findKeyType() != null) {
            // Need to setup affinity key for distributed joins.
            String affField = ctx.cacheObjects().affinityField(qryEntity.findKeyType());
            if (affField != null) {
                if (!escape)
                    affField = normalizeObjectName(affField, false);
                desc.affinityKey(affField);
            }
        }
    } else {
        processClassMeta(qryEntity, desc, coCtx);
        AffinityKeyMapper keyMapper = cctx.config().getAffinityMapper();
        if (keyMapper instanceof GridCacheDefaultAffinityKeyMapper) {
            String affField = ((GridCacheDefaultAffinityKeyMapper) keyMapper).affinityKeyPropertyName(desc.keyClass());
            if (affField != null) {
                if (!escape)
                    affField = normalizeObjectName(affField, false);
                desc.affinityKey(affField);
            }
        }
        typeId = new QueryTypeIdKey(cacheName, valCls);
        altTypeId = new QueryTypeIdKey(cacheName, ctx.cacheObjects().typeId(qryEntity.findValueType()));
    }
    return new QueryTypeCandidate(typeId, altTypeId, desc);
}
Also used : GridKernalContext(org.apache.ignite.internal.GridKernalContext) CacheObjectContext(org.apache.ignite.internal.processors.cache.CacheObjectContext) GridCacheDefaultAffinityKeyMapper(org.apache.ignite.internal.processors.cache.GridCacheDefaultAffinityKeyMapper) GridCacheDefaultAffinityKeyMapper(org.apache.ignite.internal.processors.cache.GridCacheDefaultAffinityKeyMapper) AffinityKeyMapper(org.apache.ignite.cache.affinity.AffinityKeyMapper) IgniteCheckedException(org.apache.ignite.IgniteCheckedException)

Example 3 with AffinityKeyMapper

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

the class GridCacheAffinityMapperSelfTest method testFieldAffinityMapperWithWrongClass.

/**
     *
     */
public void testFieldAffinityMapperWithWrongClass() {
    AffinityKeyMapper mapper = new GridCacheDefaultAffinityKeyMapper();
    GridTestUtils.setFieldValue(mapper, "ignite", grid());
    FieldNoAffinityKey key = new FieldNoAffinityKey();
    Object mapped = mapper.affinityKey(key);
    assertEquals(key, mapped);
}
Also used : AffinityKeyMapper(org.apache.ignite.cache.affinity.AffinityKeyMapper)

Example 4 with AffinityKeyMapper

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

the class GridCacheAffinityMapperSelfTest method testFieldAffinityMapper.

/**
     *
     */
public void testFieldAffinityMapper() {
    AffinityKeyMapper mapper = new GridCacheDefaultAffinityKeyMapper();
    GridTestUtils.setFieldValue(mapper, "ignite", grid());
    List<FieldAffinityKey<Integer>> keys = new ArrayList<>();
    for (int i = 1; i <= 10; i++) keys.add(new FieldAffinityKey<>(i, Integer.toString(i)));
    for (int i = 1; i <= 10; i++) {
        FieldAffinityKey<Integer> key = keys.get(i - 1);
        Object mapped = mapper.affinityKey(key);
        info("Mapped key: " + mapped);
        assertNotNull(mapped);
        assertSame(key.affinityKey(), mapped);
    }
}
Also used : AffinityKeyMapper(org.apache.ignite.cache.affinity.AffinityKeyMapper) ArrayList(java.util.ArrayList)

Example 5 with AffinityKeyMapper

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

the class IgfsDataManager method onKernalStart0.

/** {@inheritDoc} */
@SuppressWarnings("unchecked")
@Override
protected void onKernalStart0() throws IgniteCheckedException {
    dataCachePrj = igfsCtx.kernalContext().cache().getOrStartCache(dataCacheName);
    assert dataCachePrj != null;
    dataCache = (IgniteInternalCache) dataCachePrj;
    AffinityKeyMapper mapper = igfsCtx.kernalContext().cache().internalCache(dataCacheName).configuration().getAffinityMapper();
    grpSize = mapper instanceof IgfsGroupDataBlocksKeyMapper ? ((IgfsGroupDataBlocksKeyMapper) mapper).getGroupSize() : 1;
    grpBlockSize = igfsCtx.configuration().getBlockSize() * grpSize;
    assert grpBlockSize != 0;
    igfsCtx.kernalContext().cache().internalCache(dataCacheName).preloader().startFuture().listen(new CI1<IgniteInternalFuture<Object>>() {

        @Override
        public void apply(IgniteInternalFuture<Object> f) {
            dataCacheStartLatch.countDown();
        }
    });
    new Thread(delWorker).start();
}
Also used : AffinityKeyMapper(org.apache.ignite.cache.affinity.AffinityKeyMapper) IgfsGroupDataBlocksKeyMapper(org.apache.ignite.igfs.IgfsGroupDataBlocksKeyMapper) IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture)

Aggregations

AffinityKeyMapper (org.apache.ignite.cache.affinity.AffinityKeyMapper)7 ArrayList (java.util.ArrayList)3 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)2 IgfsGroupDataBlocksKeyMapper (org.apache.ignite.igfs.IgfsGroupDataBlocksKeyMapper)2 HashMap (java.util.HashMap)1 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)1 AffinityFunction (org.apache.ignite.cache.affinity.AffinityFunction)1 AffinityKey (org.apache.ignite.cache.affinity.AffinityKey)1 FileSystemConfiguration (org.apache.ignite.configuration.FileSystemConfiguration)1 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)1 GridKernalContext (org.apache.ignite.internal.GridKernalContext)1 IgniteInternalFuture (org.apache.ignite.internal.IgniteInternalFuture)1 CacheObjectContext (org.apache.ignite.internal.processors.cache.CacheObjectContext)1 GridCacheDefaultAffinityKeyMapper (org.apache.ignite.internal.processors.cache.GridCacheDefaultAffinityKeyMapper)1