use of org.apache.ignite.configuration.NearCacheConfiguration in project ignite by apache.
the class JdbcThinDynamicIndexAbstractSelfTest method cacheConfig.
/** {@inheritDoc} */
@SuppressWarnings("unchecked")
@Override
CacheConfiguration cacheConfig() {
CacheConfiguration ccfg = super.cacheConfig();
ccfg.setWriteSynchronizationMode(CacheWriteSynchronizationMode.FULL_SYNC);
ccfg.setCacheMode(cacheMode());
ccfg.setAtomicityMode(atomicityMode());
if (nearCache())
ccfg.setNearConfiguration(new NearCacheConfiguration());
return ccfg;
}
use of org.apache.ignite.configuration.NearCacheConfiguration in project ignite by apache.
the class GridCacheProcessor method prepareCacheChangeRequest.
/**
* Prepares DynamicCacheChangeRequest for cache creation.
*
* @param ccfg Cache configuration
* @param cacheName Cache name
* @param nearCfg Near cache configuration
* @param cacheType Cache type
* @param sql Whether the cache needs to be created as the result of SQL {@code CREATE TABLE} command.
* @param failIfExists Fail if exists flag.
* @param failIfNotStarted If {@code true} fails if cache is not started.
* @return Request or {@code null} if cache already exists.
* @throws IgniteCheckedException if some of pre-checks failed
* @throws CacheExistsException if cache exists and failIfExists flag is {@code true}
*/
private DynamicCacheChangeRequest prepareCacheChangeRequest(@Nullable CacheConfiguration ccfg, String cacheName, @Nullable NearCacheConfiguration nearCfg, CacheType cacheType, boolean sql, boolean failIfExists, boolean failIfNotStarted) throws IgniteCheckedException {
DynamicCacheDescriptor desc = cacheDescriptor(cacheName);
DynamicCacheChangeRequest req = new DynamicCacheChangeRequest(UUID.randomUUID(), cacheName, ctx.localNodeId());
req.sql(sql);
req.failIfExists(failIfExists);
if (ccfg != null) {
cloneCheckSerializable(ccfg);
if (desc != null) {
if (failIfExists) {
throw new CacheExistsException("Failed to start cache " + "(a cache with the same name is already started): " + cacheName);
} else {
CacheConfiguration descCfg = desc.cacheConfiguration();
// Check if we were asked to start a near cache.
if (nearCfg != null) {
if (CU.affinityNode(ctx.discovery().localNode(), descCfg.getNodeFilter())) {
// If we are on a data node and near cache was enabled, return success, else - fail.
if (descCfg.getNearConfiguration() != null)
return null;
else
throw new IgniteCheckedException("Failed to start near " + "cache (local node is an affinity node for cache): " + cacheName);
} else
// If local node has near cache, return success.
req.clientStartOnly(true);
} else
req.clientStartOnly(true);
req.deploymentId(desc.deploymentId());
req.startCacheConfiguration(descCfg);
req.schema(desc.schema());
}
} else {
req.deploymentId(IgniteUuid.randomUuid());
CacheConfiguration cfg = new CacheConfiguration(ccfg);
CacheObjectContext cacheObjCtx = ctx.cacheObjects().contextForCache(cfg);
initialize(cfg, cacheObjCtx);
req.startCacheConfiguration(cfg);
req.schema(new QuerySchema(cfg.getQueryEntities()));
}
} else {
req.clientStartOnly(true);
if (desc != null)
ccfg = desc.cacheConfiguration();
if (ccfg == null) {
if (failIfNotStarted) {
throw new CacheExistsException("Failed to start client cache " + "(a cache with the given name is not started): " + cacheName);
} else
return null;
}
req.deploymentId(desc.deploymentId());
req.startCacheConfiguration(ccfg);
req.schema(desc.schema());
}
if (nearCfg != null)
req.nearCacheConfiguration(nearCfg);
req.cacheType(cacheType);
return req;
}
use of org.apache.ignite.configuration.NearCacheConfiguration in project ignite by apache.
the class GridCacheProcessor method lifecycleAwares.
/**
* @param ccfg Cache configuration.
* @param objs Extra components.
* @return Components provided in cache configuration which can implement {@link LifecycleAware} interface.
*/
private Iterable<Object> lifecycleAwares(CacheConfiguration ccfg, Object... objs) {
Collection<Object> ret = new ArrayList<>(7 + objs.length);
ret.add(ccfg.getAffinity());
ret.add(ccfg.getAffinityMapper());
ret.add(ccfg.getEvictionFilter());
ret.add(ccfg.getEvictionPolicy());
ret.add(ccfg.getInterceptor());
ret.add(ccfg.getTopologyValidator());
NearCacheConfiguration nearCfg = ccfg.getNearConfiguration();
if (nearCfg != null)
ret.add(nearCfg.getNearEvictionPolicy());
Collections.addAll(ret, objs);
return ret;
}
use of org.apache.ignite.configuration.NearCacheConfiguration in project ignite by apache.
the class PlatformProcessorImpl method getOrCreateNearCache.
/** {@inheritDoc} */
@Override
public PlatformTargetProxy getOrCreateNearCache(@Nullable String cacheName, long memPtr) {
NearCacheConfiguration cfg = getNearCacheConfiguration(memPtr);
IgniteCacheProxy cache = (IgniteCacheProxy) ctx.grid().getOrCreateNearCache(cacheName, cfg);
return createPlatformCache(cache);
}
use of org.apache.ignite.configuration.NearCacheConfiguration in project ignite by apache.
the class PlatformProcessorImpl method createNearCache.
/** {@inheritDoc} */
@Override
public PlatformTargetProxy createNearCache(@Nullable String cacheName, long memPtr) {
NearCacheConfiguration cfg = getNearCacheConfiguration(memPtr);
IgniteCacheProxy cache = (IgniteCacheProxy) ctx.grid().createNearCache(cacheName, cfg);
return createPlatformCache(cache);
}
Aggregations