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()]));
}
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);
}
}
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();
}
Aggregations