use of org.apache.ignite.internal.GridKernalContext in project ignite by apache.
the class IgniteClusterSnapshotRestoreWithIndexingTest method assertCacheKeys.
/**
* {@inheritDoc}
*/
@Override
protected void assertCacheKeys(IgniteCache<Object, Object> cache, int keysCnt) {
super.assertCacheKeys(cache, keysCnt);
String tblName = new BinaryBasicNameMapper(true).typeName(TYPE_NAME);
for (Ignite grid : G.allGrids()) {
GridKernalContext ctx = ((IgniteEx) grid).context();
String nodeId = ctx.localNodeId().toString();
GridQueryProcessor qry = ((IgniteEx) grid).context().query();
// Make sure SQL works fine.
assertEquals("nodeId=" + nodeId, (long) keysCnt, qry.querySqlFields(new SqlFieldsQuery("SELECT count(*) FROM " + tblName), true).getAll().get(0).get(0));
// Make sure the index is in use.
String explainPlan = (String) qry.querySqlFields(new SqlFieldsQuery("explain SELECT * FROM " + tblName + " WHERE id < 10"), true).getAll().get(0).get(0);
assertTrue("nodeId=" + nodeId + "\n" + explainPlan, explainPlan.contains("ID_ASC_IDX"));
}
}
use of org.apache.ignite.internal.GridKernalContext in project ignite by apache.
the class IgniteClusterSnapshotRestoreWithIndexingTest method assertRebuildIndexes.
/**
* @param cache Ignite cache.
* @param rebuild Rebuild index happened.
*/
private void assertRebuildIndexes(IgniteCache<Object, Object> cache, boolean rebuild) {
for (Ignite grid : G.allGrids()) {
GridKernalContext ctx = ((IgniteEx) grid).context();
assertTrue("nodeId=" + ctx.localNodeId(), grid.cache(cache.getName()).indexReadyFuture().isDone());
// Make sure no index rebuild happened.
assertEquals("nodeId=" + ctx.localNodeId(), rebuild, ctx.cache().cache(cache.getName()).context().cache().metrics0().getIndexRebuildKeysProcessed() > 0);
}
}
use of org.apache.ignite.internal.GridKernalContext in project ignite by apache.
the class RetryCauseMessageSelfTest method testQueryMappingFailureMessage.
/**
* Test query remap failure reason.
*/
@Test
public void testQueryMappingFailureMessage() {
final GridReduceQueryExecutor rdcQryExec = GridTestUtils.getFieldValue(h2Idx, IgniteH2Indexing.class, "rdcQryExec");
final ReducePartitionMapper mapper = GridTestUtils.getFieldValue(rdcQryExec, GridReduceQueryExecutor.class, "mapper");
final IgniteLogger logger = GridTestUtils.getFieldValue(rdcQryExec, GridReduceQueryExecutor.class, "log");
final GridKernalContext ctx = GridTestUtils.getFieldValue(rdcQryExec, GridReduceQueryExecutor.class, "ctx");
GridTestUtils.setFieldValue(rdcQryExec, "mapper", new ReducePartitionMapper(ctx, logger) {
@Override
public ReducePartitionMapResult nodesForPartitions(List<Integer> cacheIds, AffinityTopologyVersion topVer, int[] parts, boolean isReplicatedOnly) {
final ReducePartitionMapResult res = super.nodesForPartitions(cacheIds, topVer, parts, isReplicatedOnly);
return new ReducePartitionMapResult(Collections.emptyList(), res.partitionsMap(), res.queryPartitionsMap());
}
});
try {
SqlFieldsQuery qry = new SqlFieldsQuery(JOIN_SQL).setArgs("Organization #0");
final Throwable throwable = GridTestUtils.assertThrows(log, () -> {
return personCache.query(qry).getAll();
}, CacheException.class, "Failed to map SQL query to topology during timeout:");
throwable.printStackTrace();
} finally {
GridTestUtils.setFieldValue(rdcQryExec, "mapper", mapper);
}
}
use of org.apache.ignite.internal.GridKernalContext in project ignite by apache.
the class RetryCauseMessageSelfTest method testReplicatedCacheReserveFailureMessage.
/**
* Failed to reserve partitions for query (partition of REPLICATED cache is not in OWNING state)
*/
@Ignore("https://issues.apache.org/jira/browse/IGNITE-7039")
@Test
public void testReplicatedCacheReserveFailureMessage() {
GridMapQueryExecutor mapQryExec = GridTestUtils.getFieldValue(h2Idx, IgniteH2Indexing.class, "mapQryExec");
final GridKernalContext ctx = GridTestUtils.getFieldValue(mapQryExec, GridMapQueryExecutor.class, "ctx");
GridTestUtils.setFieldValue(h2Idx, "mapQryExec", new MockGridMapQueryExecutor() {
@Override
public void onQueryRequest(ClusterNode node, GridH2QueryRequest qryReq) throws IgniteCheckedException {
GridCacheContext<?, ?> cctx = ctx.cache().context().cacheContext(qryReq.caches().get(0));
GridDhtLocalPartition part = cctx.topology().localPartition(0, NONE, false);
AtomicLong aState = GridTestUtils.getFieldValue(part, GridDhtLocalPartition.class, "state");
long stateVal = aState.getAndSet(2);
startedExecutor.onQueryRequest(node, qryReq);
aState.getAndSet(stateVal);
}
}.insertRealExecutor(mapQryExec));
SqlQuery<String, Organization> qry = new SqlQuery<>(Organization.class, ORG_SQL);
qry.setDistributedJoins(true);
try {
orgCache.query(qry).getAll();
} catch (CacheException e) {
assertTrue(e.getMessage().contains("Failed to reserve partitions for query (partition of REPLICATED cache is not in OWNING state) ["));
return;
} finally {
GridTestUtils.setFieldValue(h2Idx, "mapQryExec", mapQryExec);
}
fail();
}
use of org.apache.ignite.internal.GridKernalContext in project ignite by apache.
the class SqlViewExporterSpi method register.
/**
* Registers system view as SQL View.
*
* @param sysView System view.
*/
private void register(SystemView<?> sysView) {
if (log.isDebugEnabled())
log.debug("Found new system view [name=" + sysView.name() + ']');
GridKernalContext ctx = ((IgniteEx) ignite()).context();
SystemViewLocal<?> view = sysView instanceof FiltrableSystemView ? new FiltrableSystemViewLocal<>(ctx, sysView) : new SystemViewLocal<>(ctx, sysView);
mgr.createSystemView(SCHEMA_SYS, view);
}
Aggregations