Java Code Examples for org.apache.ignite.configuration.CacheConfiguration#getAffinity()

The following examples show how to use org.apache.ignite.configuration.CacheConfiguration#getAffinity() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: VisorCacheAffinityConfiguration.java    From ignite with Apache License 2.0 6 votes vote down vote up
/**
 * Create data transfer object for affinity configuration properties.
 *
 * @param ccfg Cache configuration.
 */
public VisorCacheAffinityConfiguration(CacheConfiguration ccfg) {
    AffinityFunction aff = ccfg.getAffinity();

    function = compactClass(aff);
    mapper = compactClass(ccfg.getAffinityMapper());
    partitions = aff.partitions();
    partitionedBackups = ccfg.getBackups();

    Method mthd = findNonPublicMethod(aff.getClass(), "isExcludeNeighbors");

    if (mthd != null) {
        try {
            exclNeighbors = (Boolean)mthd.invoke(aff);
        }
        catch (InvocationTargetException | IllegalAccessException ignored) {
            //  No-op.
        }
    }
}
 
Example 2
Source File: CacheBasedDatasetBuilder.java    From ignite with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@SuppressWarnings("unchecked")
@Override public <C extends Serializable, D extends AutoCloseable> CacheBasedDataset<K, V, C, D> build(
    LearningEnvironmentBuilder envBuilder,
    PartitionContextBuilder<K, V, C> partCtxBuilder,
    PartitionDataBuilder<K, V, C, D> partDataBuilder,
    LearningEnvironment localLearningEnv) {

    UUID datasetId = UUID.randomUUID();

    // Retrieves affinity function of the upstream Ignite Cache.
    CacheConfiguration<K, V> upstreamCacheConfiguration = upstreamCache.getConfiguration(CacheConfiguration.class);
    AffinityFunction upstreamCacheAffinity = upstreamCacheConfiguration.getAffinity();

    // Creates dataset cache configuration with affinity function that mimics to affinity function of the upstream
    // cache.
    CacheConfiguration<Integer, C> datasetCacheConfiguration = new CacheConfiguration<>();
    datasetCacheConfiguration.setName(String.format(DATASET_CACHE_TEMPLATE, upstreamCache.getName(), datasetId));
    datasetCacheConfiguration.setAffinity(new DatasetAffinityFunctionWrapper(upstreamCacheAffinity));

    IgniteCache<Integer, C> datasetCache = ignite.createCache(datasetCacheConfiguration);

    ComputeUtils.initContext(
        ignite,
        upstreamCache.getName(),
        transformerBuilder,
        filter,
        datasetCache.getName(),
        partCtxBuilder,
        envBuilder,
        retries,
        RETRY_INTERVAL,
        upstreamKeepBinary,
        localLearningEnv.deployingContext()
    );

    return new CacheBasedDataset<>(ignite, upstreamCache, filter, transformerBuilder, datasetCache, envBuilder, partDataBuilder, datasetId, upstreamKeepBinary, localLearningEnv, retries);
}
 
Example 3
Source File: IgnitePdsSingleNodeWithIndexingAndGroupPutGetPersistenceSelfTest.java    From ignite with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override protected void configure(IgniteConfiguration cfg) {
    super.configure(cfg);

    for (CacheConfiguration ccfg : cfg.getCacheConfiguration()) {
        AffinityFunction aff = ccfg.getAffinity();

        int parts = aff != null ? aff.partitions() : RendezvousAffinityFunction.DFLT_PARTITION_COUNT;

        ccfg.setGroupName("testGroup-parts" + parts);
    }
}
 
Example 4
Source File: PlatformDotNetConfigurationClosure.java    From ignite with Apache License 2.0 5 votes vote down vote up
/**
 * Find .NET affinity functions in configuration.
 *
 * @param cfg Configuration.
 * @return affinity functions.
 */
private static List<PlatformDotNetAffinityFunction> affinityFunctions(IgniteConfiguration cfg) {
    List<PlatformDotNetAffinityFunction> res = new ArrayList<>();

    CacheConfiguration[] cacheCfg = cfg.getCacheConfiguration();

    if (cacheCfg != null) {
        for (CacheConfiguration ccfg : cacheCfg) {
            if (ccfg.getAffinity() instanceof PlatformDotNetAffinityFunction)
                res.add((PlatformDotNetAffinityFunction)ccfg.getAffinity());
        }
    }

    return res;
}
 
Example 5
Source File: ValidationOnNodeJoinUtils.java    From ignite with Apache License 2.0 5 votes vote down vote up
/**
 * @param node Joining node.
 * @param ctx Context.
 * @param map Cache descriptors.
 * @return Validation result or {@code null} in case of success.
 */
@Nullable static IgniteNodeValidationResult validateHashIdResolvers(
    ClusterNode node,
    GridKernalContext ctx,
    Map<String, DynamicCacheDescriptor> map
) {
    if (!node.isClient()) {
        for (DynamicCacheDescriptor desc : map.values()) {
            CacheConfiguration cfg = desc.cacheConfiguration();

            if (cfg.getAffinity() instanceof RendezvousAffinityFunction) {
                RendezvousAffinityFunction aff = (RendezvousAffinityFunction)cfg.getAffinity();

                Object nodeHashObj = aff.resolveNodeHash(node);

                for (ClusterNode topNode : ctx.discovery().aliveServerNodes()) {
                    Object topNodeHashObj = aff.resolveNodeHash(topNode);

                    if (nodeHashObj.hashCode() == topNodeHashObj.hashCode()) {
                        String errMsg = "Failed to add node to topology because it has the same hash code for " +
                            "partitioned affinity as one of existing nodes [cacheName=" +
                            cfg.getName() + ", existingNodeId=" + topNode.id() + ']';

                        String sndMsg = "Failed to add node to topology because it has the same hash code for " +
                            "partitioned affinity as one of existing nodes [cacheName=" +
                            cfg.getName() + ", existingNodeId=" + topNode.id() + ']';

                        return new IgniteNodeValidationResult(topNode.id(), errMsg, sndMsg);
                    }
                }
            }
        }
    }

    return null;
}