Search in sources :

Example 1 with GridCacheDefaultAffinityKeyMapper

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

the class IgniteCacheObjectProcessorImpl method contextForCache.

/** {@inheritDoc} */
@Override
public CacheObjectContext contextForCache(CacheConfiguration ccfg) throws IgniteCheckedException {
    assert ccfg != null;
    boolean storeVal = !ccfg.isCopyOnRead() || (!isBinaryEnabled(ccfg) && (QueryUtils.isEnabled(ccfg) || ctx.config().isPeerClassLoadingEnabled()));
    CacheObjectContext res = new CacheObjectContext(ctx, ccfg.getName(), ccfg.getAffinityMapper() != null ? ccfg.getAffinityMapper() : new GridCacheDefaultAffinityKeyMapper(), ccfg.isCopyOnRead(), storeVal, ctx.config().isPeerClassLoadingEnabled() && !isBinaryEnabled(ccfg));
    ctx.resource().injectGeneric(res.defaultAffMapper());
    return res;
}
Also used : GridCacheDefaultAffinityKeyMapper(org.apache.ignite.internal.processors.cache.GridCacheDefaultAffinityKeyMapper) CacheObjectContext(org.apache.ignite.internal.processors.cache.CacheObjectContext)

Example 2 with GridCacheDefaultAffinityKeyMapper

use of org.apache.ignite.internal.processors.cache.GridCacheDefaultAffinityKeyMapper 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 GridCacheDefaultAffinityKeyMapper

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

the class IgfsProcessorValidationSelfTest method testLocalIfAffinityMapperIsWrongClass.

/**
     * @throws Exception If failed.
     */
public void testLocalIfAffinityMapperIsWrongClass() throws Exception {
    for (FileSystemConfiguration igfsCfg : g1Cfg.getFileSystemConfiguration()) {
        igfsCfg.setDataCacheConfiguration(dataCache(1024));
        igfsCfg.setMetaCacheConfiguration(metaCache());
        igfsCfg.getMetaCacheConfiguration().setAffinityMapper(new GridCacheDefaultAffinityKeyMapper());
        igfsCfg.getDataCacheConfiguration().setAffinityMapper(new GridCacheDefaultAffinityKeyMapper());
    }
    checkGridStartFails(g1Cfg, "Invalid IGFS data cache configuration (key affinity mapper class should be", true);
}
Also used : GridCacheDefaultAffinityKeyMapper(org.apache.ignite.internal.processors.cache.GridCacheDefaultAffinityKeyMapper) FileSystemConfiguration(org.apache.ignite.configuration.FileSystemConfiguration)

Aggregations

GridCacheDefaultAffinityKeyMapper (org.apache.ignite.internal.processors.cache.GridCacheDefaultAffinityKeyMapper)3 CacheObjectContext (org.apache.ignite.internal.processors.cache.CacheObjectContext)2 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)1 AffinityKeyMapper (org.apache.ignite.cache.affinity.AffinityKeyMapper)1 FileSystemConfiguration (org.apache.ignite.configuration.FileSystemConfiguration)1 GridKernalContext (org.apache.ignite.internal.GridKernalContext)1