Search in sources :

Example 56 with GridKernalContext

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"));
    }
}
Also used : BinaryBasicNameMapper(org.apache.ignite.binary.BinaryBasicNameMapper) GridKernalContext(org.apache.ignite.internal.GridKernalContext) IgniteEx(org.apache.ignite.internal.IgniteEx) GridQueryProcessor(org.apache.ignite.internal.processors.query.GridQueryProcessor) Ignite(org.apache.ignite.Ignite) SqlFieldsQuery(org.apache.ignite.cache.query.SqlFieldsQuery)

Example 57 with GridKernalContext

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);
    }
}
Also used : GridKernalContext(org.apache.ignite.internal.GridKernalContext) IgniteEx(org.apache.ignite.internal.IgniteEx) Ignite(org.apache.ignite.Ignite)

Example 58 with GridKernalContext

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);
    }
}
Also used : AffinityTopologyVersion(org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion) GridKernalContext(org.apache.ignite.internal.GridKernalContext) SqlFieldsQuery(org.apache.ignite.cache.query.SqlFieldsQuery) IgniteLogger(org.apache.ignite.IgniteLogger) AbstractIndexingCommonTest(org.apache.ignite.internal.processors.cache.index.AbstractIndexingCommonTest) Test(org.junit.Test)

Example 59 with GridKernalContext

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();
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) Organization(org.apache.ignite.internal.processors.query.h2.twostep.JoinSqlTestHelper.Organization) SqlQuery(org.apache.ignite.cache.query.SqlQuery) CacheException(javax.cache.CacheException) GridKernalContext(org.apache.ignite.internal.GridKernalContext) GridH2QueryRequest(org.apache.ignite.internal.processors.query.h2.twostep.msg.GridH2QueryRequest) AtomicLong(java.util.concurrent.atomic.AtomicLong) GridDhtLocalPartition(org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtLocalPartition) Ignore(org.junit.Ignore) AbstractIndexingCommonTest(org.apache.ignite.internal.processors.cache.index.AbstractIndexingCommonTest) Test(org.junit.Test)

Example 60 with GridKernalContext

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);
}
Also used : FiltrableSystemView(org.apache.ignite.spi.systemview.view.FiltrableSystemView) GridKernalContext(org.apache.ignite.internal.GridKernalContext) IgniteEx(org.apache.ignite.internal.IgniteEx)

Aggregations

GridKernalContext (org.apache.ignite.internal.GridKernalContext)61 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)14 IgniteEx (org.apache.ignite.internal.IgniteEx)13 GridCacheSharedContext (org.apache.ignite.internal.processors.cache.GridCacheSharedContext)12 ClusterNode (org.apache.ignite.cluster.ClusterNode)11 ArrayList (java.util.ArrayList)10 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)10 List (java.util.List)9 IgniteLogger (org.apache.ignite.IgniteLogger)9 AffinityTopologyVersion (org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion)9 File (java.io.File)8 Map (java.util.Map)8 UUID (java.util.UUID)8 Ignite (org.apache.ignite.Ignite)8 IgniteKernal (org.apache.ignite.internal.IgniteKernal)8 Nullable (org.jetbrains.annotations.Nullable)8 Test (org.junit.Test)8 Collection (java.util.Collection)7 IgniteException (org.apache.ignite.IgniteException)7 FilePageStoreManager (org.apache.ignite.internal.processors.cache.persistence.file.FilePageStoreManager)7