use of org.apache.ignite.internal.processors.cache.DynamicCacheDescriptor in project ignite by apache.
the class AbstractSchemaSelfTest method affinityNode.
/**
* Check whether this is affinity node for cache.
*
* @param node Node.
* @param cacheName Cache name.
* @return {@code True} if affinity node.
*/
private static boolean affinityNode(IgniteEx node, String cacheName) {
if (node.configuration().isClientMode())
return false;
DynamicCacheDescriptor cacheDesc = node.context().cache().cacheDescriptor(cacheName);
IgnitePredicate<ClusterNode> filter = cacheDesc.cacheConfiguration().getNodeFilter();
return filter == null || filter.apply(node.localNode());
}
use of org.apache.ignite.internal.processors.cache.DynamicCacheDescriptor in project ignite by apache.
the class AbstractSchemaSelfTest method assertNoIndexDescriptor.
/**
* Assert index doesn't exist in particular node's cache descriptor.
*
* @param node Node.
* @param cacheName Cache name.
* @param idxName Index name.
*/
protected static void assertNoIndexDescriptor(IgniteEx node, String cacheName, String idxName) {
awaitCompletion();
DynamicCacheDescriptor desc = node.context().cache().cacheDescriptor(cacheName);
if (desc == null)
return;
for (QueryEntity entity : desc.schema().entities()) {
for (QueryIndex idx : entity.getIndexes()) {
if (F.eq(idxName, QueryUtils.indexName(entity, idx)))
fail("Index exists: " + idxName);
}
}
}
use of org.apache.ignite.internal.processors.cache.DynamicCacheDescriptor in project ignite by apache.
the class H2DynamicTableSelfTest method doTestCreateTable.
/**
* Test that {@code CREATE TABLE} with given template cache name actually creates new cache,
* H2 table and type descriptor on all nodes, optionally with cache type check.
* @param tplCacheName Template cache name.
* @param mode Expected cache mode, or {@code null} if no check is needed.
*/
private void doTestCreateTable(String tplCacheName, CacheMode mode) {
executeDdl("CREATE TABLE \"Person\" (\"id\" int, \"city\" varchar," + " \"name\" varchar, \"surname\" varchar, \"age\" int, PRIMARY KEY (\"id\", \"city\")) WITH " + (F.isEmpty(tplCacheName) ? "" : "\"template=" + tplCacheName + "\",") + "\"backups=10,atomicity=atomic\"");
for (int i = 0; i < 4; i++) {
IgniteEx node = grid(i);
assertNotNull(node.cache("Person"));
DynamicCacheDescriptor cacheDesc = node.context().cache().cacheDescriptor("Person");
assertNotNull(cacheDesc);
if (mode == CacheMode.REPLICATED)
assertEquals(Integer.MAX_VALUE, cacheDesc.cacheConfiguration().getBackups());
else
assertEquals(10, cacheDesc.cacheConfiguration().getBackups());
assertEquals(CacheAtomicityMode.ATOMIC, cacheDesc.cacheConfiguration().getAtomicityMode());
assertTrue(cacheDesc.sql());
if (mode != null)
assertEquals(mode, cacheDesc.cacheConfiguration().getCacheMode());
QueryTypeDescriptorImpl desc = typeExisting(node, "Person", "Person");
assertEquals(Object.class, desc.keyClass());
assertEquals("PersonKey", desc.keyTypeName());
assertEquals(Object.class, desc.valueClass());
assertEquals("Person", desc.valueTypeName());
assertEquals(F.asList("id", "city", "name", "surname", "age"), new ArrayList<>(desc.fields().keySet()));
assertProperty(desc, "id", Integer.class, true);
assertProperty(desc, "city", String.class, true);
assertProperty(desc, "name", String.class, false);
assertProperty(desc, "surname", String.class, false);
assertProperty(desc, "age", Integer.class, false);
GridH2Table tbl = ((IgniteH2Indexing) node.context().query().getIndexing()).dataTable("PUBLIC", "Person");
assertNotNull(tbl);
}
}
use of org.apache.ignite.internal.processors.cache.DynamicCacheDescriptor in project ignite by apache.
the class CacheLateAffinityAssignmentTest method calculateAffinity.
/**
* @param topVer Topology version.
* @param filterByRcvd If {@code true} filters caches by 'receivedFrom' property.
* @param cur Optional current affinity.
* @throws Exception If failed.
* @return {@code True} if some primary node changed comparing to given affinity.
*/
private boolean calculateAffinity(long topVer, boolean filterByRcvd, @Nullable Map<String, List<List<ClusterNode>>> cur) throws Exception {
List<Ignite> all = G.allGrids();
IgniteKernal ignite = (IgniteKernal) Collections.min(all, new Comparator<Ignite>() {
@Override
public int compare(Ignite n1, Ignite n2) {
return Long.compare(n1.cluster().localNode().order(), n2.cluster().localNode().order());
}
});
assert all.size() > 0;
Map<Integer, List<List<ClusterNode>>> assignments = idealAff.get(topVer);
if (assignments == null)
idealAff.put(topVer, assignments = new HashMap<>());
GridKernalContext ctx = ignite.context();
GridCacheSharedContext cctx = ctx.cache().context();
AffinityTopologyVersion topVer0 = new AffinityTopologyVersion(topVer);
cctx.discovery().topologyFuture(topVer).get();
List<GridDhtPartitionsExchangeFuture> futs = cctx.exchange().exchangeFutures();
DiscoveryEvent evt = null;
long stopTime = System.currentTimeMillis() + 10_000;
boolean primaryChanged = false;
do {
for (int i = futs.size() - 1; i >= 0; i--) {
GridDhtPartitionsExchangeFuture fut = futs.get(i);
if (fut.topologyVersion().equals(topVer0)) {
evt = fut.discoveryEvent();
break;
}
}
if (evt == null) {
U.sleep(500);
futs = cctx.exchange().exchangeFutures();
} else
break;
} while (System.currentTimeMillis() < stopTime);
assertNotNull("Failed to find exchange future:", evt);
Collection<ClusterNode> allNodes = ctx.discovery().cacheNodes(topVer0);
for (DynamicCacheDescriptor cacheDesc : ctx.cache().cacheDescriptors()) {
if (assignments.get(cacheDesc.cacheId()) != null)
continue;
if (filterByRcvd && cacheDesc.receivedFrom() != null && ctx.discovery().node(topVer0, cacheDesc.receivedFrom()) == null)
continue;
AffinityFunction func = cacheDesc.cacheConfiguration().getAffinity();
func = cctx.cache().clone(func);
cctx.kernalContext().resource().injectGeneric(func);
List<ClusterNode> affNodes = new ArrayList<>();
IgnitePredicate<ClusterNode> filter = cacheDesc.cacheConfiguration().getNodeFilter();
for (ClusterNode n : allNodes) {
if (!CU.clientNode(n) && (filter == null || filter.apply(n)))
affNodes.add(n);
}
Collections.sort(affNodes, GridNodeOrderComparator.INSTANCE);
AffinityFunctionContext affCtx = new GridAffinityFunctionContextImpl(affNodes, previousAssignment(topVer, cacheDesc.cacheId()), evt, topVer0, cacheDesc.cacheConfiguration().getBackups());
List<List<ClusterNode>> assignment = func.assignPartitions(affCtx);
if (cur != null) {
List<List<ClusterNode>> prev = cur.get(cacheDesc.cacheConfiguration().getName());
assertEquals(prev.size(), assignment.size());
if (!primaryChanged) {
for (int p = 0; p < prev.size(); p++) {
List<ClusterNode> nodes0 = prev.get(p);
List<ClusterNode> nodes1 = assignment.get(p);
if (nodes0.size() > 0 && nodes1.size() > 0) {
ClusterNode p0 = nodes0.get(0);
ClusterNode p1 = nodes1.get(0);
if (allNodes.contains(p0) && !p0.equals(p1)) {
primaryChanged = true;
log.info("Primary changed [cache=" + cacheDesc.cacheConfiguration().getName() + ", part=" + p + ", prev=" + F.nodeIds(nodes0) + ", new=" + F.nodeIds(nodes1) + ']');
break;
}
}
}
}
}
assignments.put(cacheDesc.cacheId(), assignment);
}
return primaryChanged;
}
use of org.apache.ignite.internal.processors.cache.DynamicCacheDescriptor in project ignite by apache.
the class GridQueryProcessor method onSchemaProposeDiscovery.
/**
* Process schema propose message from discovery thread.
*
* @param msg Message.
* @return {@code True} if exchange should be triggered.
*/
private boolean onSchemaProposeDiscovery(SchemaProposeDiscoveryMessage msg) {
SchemaAbstractOperation op = msg.operation();
UUID opId = op.id();
String cacheName = op.cacheName();
if (!msg.initialized()) {
// Ensure cache exists on coordinator node.
DynamicCacheDescriptor cacheDesc = ctx.cache().cacheDescriptor(cacheName);
if (cacheDesc == null) {
if (log.isDebugEnabled())
log.debug("Received schema propose discovery message, but cache doesn't exist " + "(will report error) [opId=" + opId + ", msg=" + msg + ']');
msg.onError(new SchemaOperationException(SchemaOperationException.CODE_CACHE_NOT_FOUND, cacheName));
} else {
CacheConfiguration ccfg = cacheDesc.cacheConfiguration();
if (ccfg.getCacheMode() == CacheMode.LOCAL) {
// Distributed operation is not allowed on LOCAL caches.
if (log.isDebugEnabled())
log.debug("Received schema propose discovery message, but cache is LOCAL " + "(will report error) [opId=" + opId + ", msg=" + msg + ']');
msg.onError(new SchemaOperationException("Schema changes are not supported for LOCAL cache."));
} else {
// Preserve deployment ID so that we can distinguish between different caches with the same name.
if (msg.deploymentId() == null)
msg.deploymentId(cacheDesc.deploymentId());
assert F.eq(cacheDesc.deploymentId(), msg.deploymentId());
}
}
}
// Complete client future and exit immediately in case of error.
if (msg.hasError()) {
SchemaOperationClientFuture cliFut = schemaCliFuts.remove(opId);
if (cliFut != null)
cliFut.onDone(msg.error());
return false;
}
return onSchemaProposeDiscovery0(msg);
}
Aggregations