Search in sources :

Example 6 with AffinityKeyMapper

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

the class IgfsProcessor method start.

/** {@inheritDoc} */
@Override
public void start(boolean activeOnStart) throws IgniteCheckedException {
    IgniteConfiguration igniteCfg = ctx.config();
    if (igniteCfg.isDaemon())
        return;
    FileSystemConfiguration[] cfgs = igniteCfg.getFileSystemConfiguration();
    assert cfgs != null && cfgs.length > 0;
    // Start IGFS instances.
    for (FileSystemConfiguration cfg : cfgs) {
        assert cfg.getName() != null;
        FileSystemConfiguration cfg0 = new FileSystemConfiguration(cfg);
        boolean metaClient = true;
        CacheConfiguration[] cacheCfgs = igniteCfg.getCacheConfiguration();
        String metaCacheName = cfg.getMetaCacheConfiguration().getName();
        if (cacheCfgs != null) {
            for (CacheConfiguration cacheCfg : cacheCfgs) {
                if (F.eq(cacheCfg.getName(), metaCacheName)) {
                    metaClient = false;
                    break;
                }
            }
        }
        if (igniteCfg.isClientMode() != null && igniteCfg.isClientMode())
            metaClient = true;
        IgfsContext igfsCtx = new IgfsContext(ctx, cfg0, new IgfsMetaManager(cfg0.isRelaxedConsistency(), metaClient), new IgfsDataManager(), new IgfsServerManager(), new IgfsFragmentizerManager());
        // Start managers first.
        for (IgfsManager mgr : igfsCtx.managers()) mgr.start(igfsCtx);
        igfsCache.put(cfg0.getName(), igfsCtx);
    }
    if (log.isDebugEnabled())
        log.debug("IGFS processor started.");
    // doesn't have configured caches.
    if (igniteCfg.isDaemon() || F.isEmpty(igniteCfg.getFileSystemConfiguration()) || F.isEmpty(igniteCfg.getCacheConfiguration()))
        return;
    final Map<String, CacheConfiguration> cacheCfgs = new HashMap<>();
    assert igniteCfg.getCacheConfiguration() != null;
    for (CacheConfiguration ccfg : igniteCfg.getCacheConfiguration()) cacheCfgs.put(ccfg.getName(), ccfg);
    Collection<IgfsAttributes> attrVals = new ArrayList<>();
    assert igniteCfg.getFileSystemConfiguration() != null;
    for (FileSystemConfiguration igfsCfg : igniteCfg.getFileSystemConfiguration()) {
        String dataCacheName = igfsCfg.getDataCacheConfiguration().getName();
        CacheConfiguration cacheCfg = cacheCfgs.get(dataCacheName);
        if (cacheCfg == null)
            // No cache for the given IGFS configuration.
            continue;
        AffinityKeyMapper affMapper = cacheCfg.getAffinityMapper();
        if (!(affMapper instanceof IgfsGroupDataBlocksKeyMapper))
            // Configuration will be validated later, while starting IgfsProcessor.
            continue;
        attrVals.add(new IgfsAttributes(igfsCfg.getName(), igfsCfg.getBlockSize(), ((IgfsGroupDataBlocksKeyMapper) affMapper).getGroupSize(), igfsCfg.getMetaCacheConfiguration().getName(), dataCacheName, igfsCfg.getDefaultMode(), igfsCfg.getPathModes(), igfsCfg.isFragmentizerEnabled()));
    }
    ctx.addNodeAttribute(ATTR_IGFS, attrVals.toArray(new IgfsAttributes[attrVals.size()]));
}
Also used : IgfsGroupDataBlocksKeyMapper(org.apache.ignite.igfs.IgfsGroupDataBlocksKeyMapper) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) AffinityKeyMapper(org.apache.ignite.cache.affinity.AffinityKeyMapper) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) FileSystemConfiguration(org.apache.ignite.configuration.FileSystemConfiguration) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration)

Example 7 with AffinityKeyMapper

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

the class GridCacheAffinityMapperSelfTest method testMethodAffinityMapper.

/**
 */
public void testMethodAffinityMapper() {
    AffinityKeyMapper mapper = new GridCacheDefaultAffinityKeyMapper();
    GridTestUtils.setFieldValue(mapper, "ignite", grid());
    List<AffinityKey<Integer>> keys = new ArrayList<>();
    for (int i = 1; i <= 10; i++) keys.add(new AffinityKey<>(i, Integer.toString(i)));
    for (int i = 1; i <= 10; i++) {
        AffinityKey<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) AffinityKey(org.apache.ignite.cache.affinity.AffinityKey)

Example 8 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() * (long) 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)8 ArrayList (java.util.ArrayList)4 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)3 IgfsGroupDataBlocksKeyMapper (org.apache.ignite.igfs.IgfsGroupDataBlocksKeyMapper)3 HashMap (java.util.HashMap)2 FileSystemConfiguration (org.apache.ignite.configuration.FileSystemConfiguration)2 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)1 BinaryField (org.apache.ignite.binary.BinaryField)1 AffinityFunction (org.apache.ignite.cache.affinity.AffinityFunction)1 AffinityKey (org.apache.ignite.cache.affinity.AffinityKey)1 GridKernalContext (org.apache.ignite.internal.GridKernalContext)1 IgniteInternalFuture (org.apache.ignite.internal.IgniteInternalFuture)1 CacheDefaultBinaryAffinityKeyMapper (org.apache.ignite.internal.processors.cache.CacheDefaultBinaryAffinityKeyMapper)1 CacheObjectContext (org.apache.ignite.internal.processors.cache.CacheObjectContext)1 GridCacheDefaultAffinityKeyMapper (org.apache.ignite.internal.processors.cache.GridCacheDefaultAffinityKeyMapper)1