use of org.apache.ignite.internal.processors.cache.GridCacheSharedContext in project ignite by apache.
the class IgniteH2Indexing method checkCacheIndexSegmentation.
/**
* @throws IllegalStateException if segmented indices used with non-segmented indices.
*/
private void checkCacheIndexSegmentation(List<Integer> cacheIds) {
if (cacheIds.isEmpty())
// Nothing to check
return;
GridCacheSharedContext sharedCtx = ctx.cache().context();
int expectedParallelism = 0;
for (Integer cacheId : cacheIds) {
GridCacheContext cctx = sharedCtx.cacheContext(cacheId);
assert cctx != null;
if (!cctx.isPartitioned())
continue;
if (expectedParallelism == 0)
expectedParallelism = cctx.config().getQueryParallelism();
else if (cctx.config().getQueryParallelism() != expectedParallelism) {
throw new IllegalStateException("Using indexes with different parallelism levels in same query is " + "forbidden.");
}
}
}
use of org.apache.ignite.internal.processors.cache.GridCacheSharedContext in project ignite by apache.
the class GridCommonAbstractTest method dumpCacheDebugInfo.
/**
* @param ignite Node.
*/
public void dumpCacheDebugInfo(Ignite ignite) {
GridKernalContext ctx = ((IgniteKernal) ignite).context();
log.error("Cache information update [node=" + ignite.name() + ", client=" + ignite.configuration().isClientMode() + ']');
GridCacheSharedContext cctx = ctx.cache().context();
log.error("Pending transactions:");
for (IgniteInternalTx tx : cctx.tm().activeTransactions()) log.error(">>> " + tx);
log.error("Pending explicit locks:");
for (GridCacheExplicitLockSpan lockSpan : cctx.mvcc().activeExplicitLocks()) log.error(">>> " + lockSpan);
log.error("Pending cache futures:");
for (GridCacheFuture<?> fut : cctx.mvcc().activeFutures()) log.error(">>> " + fut);
log.error("Pending atomic cache futures:");
for (GridCacheFuture<?> fut : cctx.mvcc().atomicFutures()) log.error(">>> " + fut);
}
use of org.apache.ignite.internal.processors.cache.GridCacheSharedContext in project ignite by apache.
the class IgniteTxStateImpl method addActiveCache.
/** {@inheritDoc} */
@Override
public void addActiveCache(GridCacheContext cacheCtx, boolean recovery, IgniteTxLocalAdapter tx) throws IgniteCheckedException {
GridCacheSharedContext cctx = cacheCtx.shared();
int cacheId = cacheCtx.cacheId();
if (this.recovery != null && this.recovery != recovery)
throw new IgniteCheckedException("Failed to enlist an entry to existing transaction " + "(cannot transact between recovery and non-recovery caches).");
this.recovery = recovery;
// Check if we can enlist new cache to transaction.
if (!activeCacheIds.contains(cacheId)) {
String err = cctx.verifyTxCompatibility(tx, activeCacheIds, cacheCtx);
if (err != null) {
StringBuilder cacheNames = new StringBuilder();
int idx = 0;
for (int i = 0; i < activeCacheIds.size(); i++) {
int activeCacheId = activeCacheIds.get(i);
cacheNames.append(cctx.cacheContext(activeCacheId).name());
if (idx++ < activeCacheIds.size() - 1)
cacheNames.append(", ");
}
throw new IgniteCheckedException("Failed to enlist new cache to existing transaction (" + err + ") [activeCaches=[" + cacheNames + "]" + ", cacheName=" + cacheCtx.name() + ", cacheSystem=" + cacheCtx.systemTx() + ", txSystem=" + tx.system() + ']');
} else
activeCacheIds.add(cacheId);
if (activeCacheIds.size() == 1)
tx.activeCachesDeploymentEnabled(cacheCtx.deploymentEnabled());
}
}
use of org.apache.ignite.internal.processors.cache.GridCacheSharedContext 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.GridCacheSharedContext in project ignite by apache.
the class IgniteTxOriginatingNodeFailureAbstractSelfTest method testTxOriginatingNodeFails.
/**
* @param keys Keys to update.
* @param partial Flag indicating whether to simulate partial prepared state.
* @throws Exception If failed.
*/
protected void testTxOriginatingNodeFails(Collection<Integer> keys, final boolean partial) throws Exception {
assertFalse(keys.isEmpty());
final Collection<IgniteKernal> grids = new ArrayList<>();
ClusterNode txNode = grid(originatingNode()).localNode();
for (int i = 1; i < gridCount(); i++) grids.add((IgniteKernal) grid(i));
final Map<Integer, String> map = new HashMap<>();
final String initVal = "initialValue";
for (Integer key : keys) {
grid(originatingNode()).cache(DEFAULT_CACHE_NAME).put(key, initVal);
map.put(key, String.valueOf(key));
}
Map<Integer, Collection<ClusterNode>> nodeMap = new HashMap<>();
info("Node being checked: " + grid(1).localNode().id());
for (Integer key : keys) {
Collection<ClusterNode> nodes = new ArrayList<>();
nodes.addAll(grid(1).affinity(DEFAULT_CACHE_NAME).mapKeyToPrimaryAndBackups(key));
nodes.remove(txNode);
nodeMap.put(key, nodes);
}
info("Starting optimistic tx " + "[values=" + map + ", topVer=" + (grid(1)).context().discovery().topologyVersion() + ']');
if (partial)
ignoreMessages(grid(1).localNode().id(), ignoreMessageClass());
final Ignite txIgniteNode = G.ignite(txNode.id());
GridTestUtils.runAsync(new Callable<Object>() {
@Override
public Object call() throws Exception {
IgniteCache<Integer, String> cache = txIgniteNode.cache(DEFAULT_CACHE_NAME);
assertNotNull(cache);
TransactionProxyImpl tx = (TransactionProxyImpl) txIgniteNode.transactions().txStart();
GridNearTxLocal txEx = tx.tx();
assertTrue(txEx.optimistic());
cache.putAll(map);
try {
txEx.prepareNearTxLocal().get(3, TimeUnit.SECONDS);
} catch (IgniteFutureTimeoutCheckedException ignored) {
info("Failed to wait for prepare future completion: " + partial);
}
return null;
}
}).get();
info("Stopping originating node " + txNode);
G.stop(G.ignite(txNode.id()).name(), true);
info("Stopped grid, waiting for transactions to complete.");
boolean txFinished = GridTestUtils.waitForCondition(new GridAbsPredicate() {
@Override
public boolean apply() {
for (IgniteKernal g : grids) {
GridCacheSharedContext<Object, Object> ctx = g.context().cache().context();
int txNum = ctx.tm().idMapSize();
if (txNum != 0)
return false;
}
return true;
}
}, 10000);
assertTrue(txFinished);
info("Transactions finished.");
for (Map.Entry<Integer, Collection<ClusterNode>> e : nodeMap.entrySet()) {
final Integer key = e.getKey();
final String val = map.get(key);
assertFalse(e.getValue().isEmpty());
for (ClusterNode node : e.getValue()) {
compute(G.ignite(node.id()).cluster().forNode(node)).call(new IgniteCallable<Void>() {
/** */
@IgniteInstanceResource
private Ignite ignite;
@Override
public Void call() throws Exception {
IgniteCache<Integer, String> cache = ignite.cache(DEFAULT_CACHE_NAME);
assertNotNull(cache);
assertEquals(partial ? initVal : val, cache.localPeek(key));
return null;
}
});
}
}
for (Map.Entry<Integer, String> e : map.entrySet()) {
for (Ignite g : G.allGrids()) {
UUID locNodeId = g.cluster().localNode().id();
assertEquals("Check failed for node: " + locNodeId, partial ? initVal : e.getValue(), g.cache(DEFAULT_CACHE_NAME).get(e.getKey()));
}
}
}
Aggregations