use of org.apache.ignite.configuration.NearCacheConfiguration in project ignite by apache.
the class ClusterCachesInfo method onStateChangeRequest.
/**
* @param msg Message.
* @param topVer Current topology version.
* @param curState Current cluster state.
* @return Exchange action.
* @throws IgniteCheckedException If configuration validation failed.
*/
public ExchangeActions onStateChangeRequest(ChangeGlobalStateMessage msg, AffinityTopologyVersion topVer, DiscoveryDataClusterState curState) throws IgniteCheckedException {
ExchangeActions exchangeActions = new ExchangeActions();
if (msg.activate() == curState.active())
return exchangeActions;
if (msg.activate()) {
for (DynamicCacheDescriptor desc : orderedCaches(CacheComparators.DIRECT)) {
desc.startTopologyVersion(topVer);
DynamicCacheChangeRequest req = new DynamicCacheChangeRequest(msg.requestId(), desc.cacheName(), msg.initiatorNodeId());
req.startCacheConfiguration(desc.cacheConfiguration());
req.cacheType(desc.cacheType());
T2<CacheConfiguration, NearCacheConfiguration> locCfg = locCfgsForActivation.get(desc.cacheName());
if (locCfg != null) {
if (locCfg.get1() != null)
req.startCacheConfiguration(locCfg.get1());
req.nearCacheConfiguration(locCfg.get2());
req.locallyConfigured(true);
}
exchangeActions.addCacheToStart(req, desc);
}
for (CacheGroupDescriptor grpDesc : registeredCacheGroups().values()) exchangeActions.addCacheGroupToStart(grpDesc);
List<StoredCacheData> storedCfgs = msg.storedCacheConfigurations();
if (storedCfgs != null) {
List<DynamicCacheChangeRequest> reqs = new ArrayList<>();
IgniteUuid deploymentId = msg.id();
for (StoredCacheData storedCfg : storedCfgs) {
CacheConfiguration ccfg = storedCfg.config();
if (!registeredCaches.containsKey(ccfg.getName())) {
DynamicCacheChangeRequest req = new DynamicCacheChangeRequest(msg.requestId(), ccfg.getName(), msg.initiatorNodeId());
req.deploymentId(deploymentId);
req.startCacheConfiguration(ccfg);
req.cacheType(ctx.cache().cacheType(ccfg.getName()));
req.schema(new QuerySchema(storedCfg.queryEntities()));
req.sql(storedCfg.sql());
reqs.add(req);
}
}
CacheChangeProcessResult res = processCacheChangeRequests(exchangeActions, reqs, topVer, true);
if (!res.errs.isEmpty()) {
IgniteCheckedException err = new IgniteCheckedException("Failed to activate cluster.");
for (IgniteCheckedException err0 : res.errs) err.addSuppressed(err0);
throw err;
}
}
} else {
locCfgsForActivation = new HashMap<>();
for (DynamicCacheDescriptor desc : orderedCaches(CacheComparators.REVERSE)) {
DynamicCacheChangeRequest req = DynamicCacheChangeRequest.stopRequest(ctx, desc.cacheName(), desc.sql(), false);
exchangeActions.addCacheToStop(req, desc);
if (ctx.discovery().cacheClientNode(ctx.discovery().localNode(), desc.cacheName()))
locCfgsForActivation.put(desc.cacheName(), new T2<>((CacheConfiguration) null, (NearCacheConfiguration) null));
}
for (CacheGroupDescriptor grpDesc : registeredCacheGroups().values()) exchangeActions.addCacheGroupToStop(grpDesc, false);
}
return exchangeActions;
}
use of org.apache.ignite.configuration.NearCacheConfiguration in project ignite by apache.
the class GridDhtPartitionsExchangeFuture method initCachesOnLocalJoin.
/**
* @throws IgniteCheckedException If failed.
*/
private void initCachesOnLocalJoin() throws IgniteCheckedException {
cctx.activate();
LocalJoinCachesContext locJoinCtx = exchActions == null ? null : exchActions.localJoinContext();
List<T2<DynamicCacheDescriptor, NearCacheConfiguration>> caches = locJoinCtx == null ? null : locJoinCtx.caches();
if (!cctx.kernalContext().clientNode()) {
List<DynamicCacheDescriptor> startDescs = new ArrayList<>();
if (caches != null) {
for (T2<DynamicCacheDescriptor, NearCacheConfiguration> c : caches) {
DynamicCacheDescriptor startDesc = c.get1();
if (CU.isPersistentCache(startDesc.cacheConfiguration(), cctx.gridConfig().getDataStorageConfiguration()))
startDescs.add(startDesc);
}
}
cctx.database().readCheckpointAndRestoreMemory(startDescs);
}
cctx.cache().startCachesOnLocalJoin(locJoinCtx, initialVersion());
}
use of org.apache.ignite.configuration.NearCacheConfiguration in project ignite by apache.
the class GridCacheVersionMultinodeTest method cacheConfiguration.
/**
* {@inheritDoc}
*/
@Override
protected CacheConfiguration cacheConfiguration(String igniteInstanceName) throws Exception {
CacheConfiguration ccfg = super.cacheConfiguration(igniteInstanceName);
assert atomicityMode != null;
ccfg.setAtomicityMode(atomicityMode);
ccfg.setNearConfiguration(near ? new NearCacheConfiguration() : null);
return ccfg;
}
use of org.apache.ignite.configuration.NearCacheConfiguration in project ignite by apache.
the class CrossCacheTxRandomOperationsTest method cacheConfiguration.
/**
* @param name Cache name.
* @param cacheMode Cache mode.
* @param writeSync Write synchronization mode.
* @param nearCache Near cache flag.
* @return Cache configuration.
*/
protected CacheConfiguration cacheConfiguration(String name, CacheMode cacheMode, CacheWriteSynchronizationMode writeSync, boolean nearCache) {
CacheConfiguration ccfg = new CacheConfiguration(DEFAULT_CACHE_NAME);
ccfg.setName(name);
ccfg.setCacheMode(cacheMode);
ccfg.setAtomicityMode(TRANSACTIONAL);
ccfg.setWriteSynchronizationMode(writeSync);
if (cacheMode == PARTITIONED)
ccfg.setBackups(1);
ccfg.setAffinity(new RendezvousAffinityFunction());
if (nearCache)
ccfg.setNearConfiguration(new NearCacheConfiguration());
return ccfg;
}
use of org.apache.ignite.configuration.NearCacheConfiguration in project ignite by apache.
the class IgniteCacheGroupsTest method cacheApiTest.
/**
* @param cacheMode Cache mode.
* @param atomicityMode Atomicity mode.
* @param backups Number of backups.
* @param heapCache On heap cache flag.
* @param nearSrv {@code True} if near cache should be used on a server side.
* @param nearClient {@code True} if near cache should be used on a client side.
* @throws Exception If failed.
*/
private void cacheApiTest(CacheMode cacheMode, CacheAtomicityMode atomicityMode, int backups, boolean heapCache, boolean nearSrv, boolean nearClient) throws Exception {
Ignite srv0 = ignite(0);
NearCacheConfiguration nearCfg = nearSrv ? new NearCacheConfiguration() : null;
srv0.createCache(cacheConfiguration(GROUP1, "cache-0", cacheMode, atomicityMode, backups, heapCache).setNearConfiguration(nearCfg));
srv0.createCache(cacheConfiguration(GROUP1, "cache-1", cacheMode, atomicityMode, backups, heapCache));
srv0.createCache(cacheConfiguration(GROUP2, "cache-2", cacheMode, atomicityMode, backups, heapCache).setNearConfiguration(nearCfg));
srv0.createCache(cacheConfiguration(null, "cache-3", cacheMode, atomicityMode, backups, heapCache));
if (nearClient) {
Ignite clientNode = ignite(4);
clientNode.createNearCache("cache-0", new NearCacheConfiguration());
clientNode.createNearCache("cache-2", new NearCacheConfiguration());
}
try {
for (final Ignite node : Ignition.allGrids()) {
List<Callable<?>> ops = new ArrayList<>();
for (int i = 0; i < 4; i++) ops.add(testSet(node.cache("cache-" + i), cacheMode, atomicityMode, backups, heapCache, node));
// Async operations.
GridTestUtils.runMultiThreaded(ops, "cacheApiTest");
}
} finally {
for (int i = 0; i < 4; i++) srv0.destroyCache("cache-" + i);
}
}
Aggregations