Search in sources :

Example 26 with GridKernalContext

use of org.apache.ignite.internal.GridKernalContext in project ignite by apache.

the class MockWalIteratorFactory method iterator.

/**
 * Creates iterator
 * @param wal WAL directory without node consistent id
 * @param walArchive WAL archive without node consistent id
 * @return iterator
 * @throws IgniteCheckedException if IO failed
 */
@SuppressWarnings("unchecked")
public WALIterator iterator(File wal, File walArchive) throws IgniteCheckedException {
    final DataStorageConfiguration persistentCfg1 = Mockito.mock(DataStorageConfiguration.class);
    when(persistentCfg1.getWalPath()).thenReturn(wal.getAbsolutePath());
    when(persistentCfg1.getWalArchivePath()).thenReturn(walArchive.getAbsolutePath());
    when(persistentCfg1.getWalSegments()).thenReturn(segments);
    when(persistentCfg1.getWalBufferSize()).thenReturn(DataStorageConfiguration.DFLT_WAL_BUFF_SIZE);
    when(persistentCfg1.getWalRecordIteratorBufferSize()).thenReturn(DataStorageConfiguration.DFLT_WAL_RECORD_ITERATOR_BUFFER_SIZE);
    when(persistentCfg1.getWalSegmentSize()).thenReturn(DataStorageConfiguration.DFLT_WAL_SEGMENT_SIZE);
    final FileIOFactory fileIOFactory = new DataStorageConfiguration().getFileIOFactory();
    when(persistentCfg1.getFileIOFactory()).thenReturn(fileIOFactory);
    final IgniteConfiguration cfg = Mockito.mock(IgniteConfiguration.class);
    when(cfg.getDataStorageConfiguration()).thenReturn(persistentCfg1);
    final GridKernalContext ctx = Mockito.mock(GridKernalContext.class);
    when(ctx.config()).thenReturn(cfg);
    when(ctx.clientNode()).thenReturn(false);
    when(ctx.pdsFolderResolver()).thenReturn(new PdsFoldersResolver() {

        @Override
        public PdsFolderSettings resolveFolders() {
            return new PdsFolderSettings(new File("."), subfolderName, consistentId, null, false);
        }
    });
    final GridDiscoveryManager disco = Mockito.mock(GridDiscoveryManager.class);
    when(ctx.discovery()).thenReturn(disco);
    final IgniteWriteAheadLogManager mgr = new FileWriteAheadLogManager(ctx);
    final GridCacheSharedContext sctx = Mockito.mock(GridCacheSharedContext.class);
    when(sctx.kernalContext()).thenReturn(ctx);
    when(sctx.discovery()).thenReturn(disco);
    when(sctx.gridConfig()).thenReturn(cfg);
    final GridCacheDatabaseSharedManager db = Mockito.mock(GridCacheDatabaseSharedManager.class);
    when(db.pageSize()).thenReturn(pageSize);
    when(sctx.database()).thenReturn(db);
    when(sctx.logger(any(Class.class))).thenReturn(log);
    mgr.start(sctx);
    return mgr.replay(null);
}
Also used : FileIOFactory(org.apache.ignite.internal.processors.cache.persistence.file.FileIOFactory) IgniteWriteAheadLogManager(org.apache.ignite.internal.pagemem.wal.IgniteWriteAheadLogManager) GridCacheDatabaseSharedManager(org.apache.ignite.internal.processors.cache.persistence.GridCacheDatabaseSharedManager) GridKernalContext(org.apache.ignite.internal.GridKernalContext) GridCacheSharedContext(org.apache.ignite.internal.processors.cache.GridCacheSharedContext) DataStorageConfiguration(org.apache.ignite.configuration.DataStorageConfiguration) GridDiscoveryManager(org.apache.ignite.internal.managers.discovery.GridDiscoveryManager) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) PdsFoldersResolver(org.apache.ignite.internal.processors.cache.persistence.filename.PdsFoldersResolver) FileWriteAheadLogManager(org.apache.ignite.internal.processors.cache.persistence.wal.FileWriteAheadLogManager) PdsFolderSettings(org.apache.ignite.internal.processors.cache.persistence.filename.PdsFolderSettings) File(java.io.File)

Example 27 with GridKernalContext

use of org.apache.ignite.internal.GridKernalContext in project ignite by apache.

the class RetryCauseMessageSelfTest method testPartitionedCacheReserveFailureMessage.

/**
 * Failed to reserve partitions for query (partition of PARTITIONED cache cannot be reserved)
 */
@Test
public void testPartitionedCacheReserveFailureMessage() {
    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, Person> qry = new SqlQuery<String, Person>(Person.class, JOIN_SQL).setArgs("Organization #0");
    qry.setDistributedJoins(true);
    try {
        personCache.query(qry).getAll();
    } catch (CacheException e) {
        assertTrue(e.getMessage().contains("Failed to reserve partitions for query (partition of PARTITIONED " + "cache is not found or not in OWNING state) "));
        return;
    } finally {
        GridTestUtils.setFieldValue(h2Idx, "mapQryExec", mapQryExec);
    }
    fail();
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) 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) Person(org.apache.ignite.internal.processors.query.h2.twostep.JoinSqlTestHelper.Person) AbstractIndexingCommonTest(org.apache.ignite.internal.processors.cache.index.AbstractIndexingCommonTest) Test(org.junit.Test)

Example 28 with GridKernalContext

use of org.apache.ignite.internal.GridKernalContext in project ignite by apache.

the class RetryCauseMessageSelfTest method testUpdateQueryMappingFailureMessage.

/**
 * Test update query remap failure reason.
 */
@Test
public void testUpdateQueryMappingFailureMessage() {
    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 {
        final SqlFieldsQueryEx qry = new SqlFieldsQueryEx(UPDATE_SQL, false).setArgs("New Name");
        GridTestUtils.assertThrows(log, () -> {
            return personCache.query(qry).getAll();
        }, CacheException.class, "Failed to map SQL query to topology during timeout");
        qry.setArgs("Another Name");
        qry.setSkipReducerOnUpdate(true);
        GridTestUtils.assertThrows(log, () -> {
            return personCache.query(qry).getAll();
        }, CacheException.class, "Failed to determine nodes participating in the update. ");
    } finally {
        GridTestUtils.setFieldValue(rdcQryExec, "mapper", mapper);
    }
}
Also used : AffinityTopologyVersion(org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion) GridKernalContext(org.apache.ignite.internal.GridKernalContext) SqlFieldsQueryEx(org.apache.ignite.internal.processors.cache.query.SqlFieldsQueryEx) IgniteLogger(org.apache.ignite.IgniteLogger) AbstractIndexingCommonTest(org.apache.ignite.internal.processors.cache.index.AbstractIndexingCommonTest) Test(org.junit.Test)

Example 29 with GridKernalContext

use of org.apache.ignite.internal.GridKernalContext in project ignite by apache.

the class GridH2IndexBase method initDistributedJoinMessaging.

/**
 * @param tbl Table.
 */
protected final void initDistributedJoinMessaging(GridH2Table tbl) {
    final GridH2RowDescriptor desc = tbl.rowDescriptor();
    if (desc != null && desc.context() != null) {
        ctx = desc.context();
        GridKernalContext ctx = desc.context().kernalContext();
        log = ctx.log(getClass());
        msgTopic = new IgniteBiTuple<>(GridTopic.TOPIC_QUERY, tbl.identifierString() + '.' + getName());
        msgLsnr = new GridMessageListener() {

            @Override
            public void onMessage(UUID nodeId, Object msg, byte plc) {
                GridSpinBusyLock l = desc.indexing().busyLock();
                if (!l.enterBusy())
                    return;
                try {
                    onMessage0(nodeId, msg);
                } finally {
                    l.leaveBusy();
                }
            }
        };
        ctx.io().addMessageListener(msgTopic, msgLsnr);
    } else {
        msgTopic = null;
        msgLsnr = null;
        log = new NullLogger();
    }
}
Also used : GridSpinBusyLock(org.apache.ignite.internal.util.GridSpinBusyLock) NullLogger(org.apache.ignite.logger.NullLogger) GridKernalContext(org.apache.ignite.internal.GridKernalContext) GridMessageListener(org.apache.ignite.internal.managers.communication.GridMessageListener) CacheObject(org.apache.ignite.internal.processors.cache.CacheObject) UUID(java.util.UUID)

Example 30 with GridKernalContext

use of org.apache.ignite.internal.GridKernalContext in project ignite by apache.

the class IgfsServerManagerIpcEndpointRegistrationAbstractSelfTest method checkRegisteredIpcEndpoints.

/**
 * Counts all registered IPC endpoints.
 *
 * @return Tuple2 where (tcp endpoints count, shmem endpoints count).
 * @throws Exception If failed.
 */
protected T2<Integer, Integer> checkRegisteredIpcEndpoints() throws Exception {
    GridKernalContext ctx = ((IgniteKernal) grid()).context();
    int tcp = 0;
    int shmem = 0;
    for (GridPortRecord record : ctx.ports().records()) {
        if (record.clazz() == IpcSharedMemoryServerEndpoint.class)
            shmem++;
        else if (record.clazz() == IpcServerTcpEndpoint.class)
            tcp++;
    }
    return new T2<>(tcp, shmem);
}
Also used : IgniteKernal(org.apache.ignite.internal.IgniteKernal) GridKernalContext(org.apache.ignite.internal.GridKernalContext) GridPortRecord(org.apache.ignite.internal.processors.port.GridPortRecord) IpcServerTcpEndpoint(org.apache.ignite.internal.util.ipc.loopback.IpcServerTcpEndpoint) IpcServerTcpEndpoint(org.apache.ignite.internal.util.ipc.loopback.IpcServerTcpEndpoint) IpcSharedMemoryServerEndpoint(org.apache.ignite.internal.util.ipc.shmem.IpcSharedMemoryServerEndpoint) T2(org.apache.ignite.internal.util.typedef.T2)

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