use of org.apache.ignite.configuration.CacheConfiguration in project ignite by apache.
the class CacheApiExample method main.
/**
* Executes example.
*
* @param args Command line arguments, none required.
* @throws IgniteException If example execution failed.
*/
public static void main(String[] args) throws IgniteException {
try (Ignite ignite = Ignition.start("examples/config/example-ignite.xml")) {
System.out.println();
System.out.println(">>> Cache API example started.");
CacheConfiguration<Integer, String> cfg = new CacheConfiguration<>();
cfg.setCacheMode(CacheMode.PARTITIONED);
cfg.setName(CACHE_NAME);
// Auto-close cache at the end of the example.
try (IgniteCache<Integer, String> cache = ignite.getOrCreateCache(cfg)) {
// Demonstrate atomic map operations.
atomicMapOperations(cache);
} finally {
// Distributed cache could be removed from cluster only by #destroyCache() call.
ignite.destroyCache(CACHE_NAME);
}
}
}
use of org.apache.ignite.configuration.CacheConfiguration in project ignite by apache.
the class RedisProtocolSelfTest method getConfiguration.
/** {@inheritDoc} */
@Override
protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);
cfg.setLocalHost(HOST);
assert cfg.getConnectorConfiguration() == null;
ConnectorConfiguration redisCfg = new ConnectorConfiguration();
redisCfg.setHost(HOST);
redisCfg.setPort(PORT);
cfg.setConnectorConfiguration(redisCfg);
TcpDiscoverySpi disco = new TcpDiscoverySpi();
disco.setIpFinder(IP_FINDER);
cfg.setDiscoverySpi(disco);
CacheConfiguration ccfg = defaultCacheConfiguration();
ccfg.setStatisticsEnabled(true);
ccfg.setIndexedTypes(String.class, String.class);
cfg.setCacheConfiguration(ccfg);
return cfg;
}
use of org.apache.ignite.configuration.CacheConfiguration in project ignite by apache.
the class GridCachePartitionExchangeManager method clientTopology.
/**
* @param cacheId Cache ID.
* @param exchFut Exchange future.
* @return Topology.
*/
public GridDhtPartitionTopology clientTopology(int cacheId, GridDhtPartitionsExchangeFuture exchFut) {
GridClientPartitionTopology top = clientTops.get(cacheId);
if (top != null)
return top;
Object affKey = null;
DynamicCacheDescriptor desc = cctx.cache().cacheDescriptor(cacheId);
if (desc != null) {
CacheConfiguration ccfg = desc.cacheConfiguration();
AffinityFunction aff = ccfg.getAffinity();
affKey = cctx.kernalContext().affinity().similaryAffinityKey(aff, ccfg.getNodeFilter(), ccfg.getBackups(), aff.partitions());
}
GridClientPartitionTopology old = clientTops.putIfAbsent(cacheId, top = new GridClientPartitionTopology(cctx, cacheId, exchFut, affKey));
return old != null ? old : top;
}
use of org.apache.ignite.configuration.CacheConfiguration in project ignite by apache.
the class GridCacheProcessor method addCacheOnJoinFromPersistentStore.
/**
* @param caches Caches map.
* @param templates Templates map.
* @throws IgniteCheckedException If failed.
*/
private void addCacheOnJoinFromPersistentStore(Map<String, CacheJoinNodeDiscoveryData.CacheInfo> caches, Map<String, CacheJoinNodeDiscoveryData.CacheInfo> templates) throws IgniteCheckedException {
assert !ctx.config().isDaemon();
if (sharedCtx.pageStore() != null && sharedCtx.database().persistenceEnabled()) {
Set<String> savedCacheNames = sharedCtx.pageStore().savedCacheNames();
savedCacheNames.removeAll(caches.keySet());
savedCacheNames.removeAll(internalCaches);
if (!F.isEmpty(savedCacheNames)) {
if (log.isInfoEnabled())
log.info("Register persistent caches: " + savedCacheNames);
for (String name : savedCacheNames) {
CacheConfiguration cfg = sharedCtx.pageStore().readConfiguration(name);
// TODO IGNITE-5306 - set correct SQL flag below.
if (cfg != null)
addCacheOnJoin(cfg, false, caches, templates);
}
}
}
}
use of org.apache.ignite.configuration.CacheConfiguration 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;
}
Aggregations