Search in sources :

Example 6 with CacheMetricsImpl

use of org.apache.ignite.internal.processors.cache.CacheMetricsImpl in project ignite by apache.

the class BlockedEvictionsTest method testEvictionMetrics.

/**
 */
@Test
public void testEvictionMetrics() throws Exception {
    stats = true;
    testOperationDuringEviction(true, 1, new Runnable() {

        @Override
        public void run() {
            CacheMetricsImpl metrics = grid(0).cachex(DEFAULT_CACHE_NAME).context().cache().metrics0();
            assertTrue(metrics.evictingPartitionsLeft() > 0);
        }
    });
    awaitPartitionMapExchange(true, true, null);
    CacheMetricsImpl metrics = grid(0).cachex(DEFAULT_CACHE_NAME).context().cache().metrics0();
    assertTrue(metrics.evictingPartitionsLeft() == 0);
}
Also used : CacheMetricsImpl(org.apache.ignite.internal.processors.cache.CacheMetricsImpl) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 7 with CacheMetricsImpl

use of org.apache.ignite.internal.processors.cache.CacheMetricsImpl in project ignite by apache.

the class StopRebuildIndexTest method stopRebuildIndexes.

/**
 * Restart the rebuild of the indexes, checking that it completes gracefully.
 *
 * @param stopRebuildIndexes Stop index rebuild function.
 * @param expThrowEx Expect an exception on index rebuild futures.
 * @throws Exception If failed.
 */
private void stopRebuildIndexes(IgniteThrowableConsumer<IgniteEx> stopRebuildIndexes, boolean expThrowEx) throws Exception {
    prepareBeforeNodeStart();
    int keys = 100_000;
    IgniteEx n = startGrid(0);
    populate(n.cache(DEFAULT_CACHE_NAME), keys);
    GridCacheContext<?, ?> cacheCtx = n.cachex(DEFAULT_CACHE_NAME).context();
    addCacheRowConsumer(nodeName(n), cacheCtx.name(), row -> U.sleep(10));
    forceRebuildIndexes(n, cacheCtx);
    IgniteInternalFuture<?> fut0 = indexRebuildFuture(n, cacheCtx.cacheId());
    assertNotNull(fut0);
    SchemaIndexCacheFuture fut1 = internalIndexRebuildFuture(n, cacheCtx.cacheId());
    assertNotNull(fut1);
    CacheMetricsImpl metrics0 = cacheMetrics0(n, cacheCtx.name());
    assertTrue(metrics0.isIndexRebuildInProgress());
    assertFalse(fut0.isDone());
    assertFalse(fut1.isDone());
    assertNull(fut1.cancelToken().cancelException());
    assertTrue(waitForCondition(() -> metrics0.getIndexRebuildKeysProcessed() >= keys / 100, getTestTimeout()));
    assertTrue(metrics0.isIndexRebuildInProgress());
    assertFalse(fut0.isDone());
    assertFalse(fut1.isDone());
    assertNull(fut1.cancelToken().cancelException());
    stopRebuildIndexes.accept(n);
    assertFalse(metrics0.isIndexRebuildInProgress());
    assertTrue(metrics0.getIndexRebuildKeysProcessed() < keys);
    if (expThrowEx) {
        assertThrows(log, () -> fut0.get(getTestTimeout()), SchemaIndexOperationCancellationException.class, null);
        assertThrows(log, () -> fut1.get(getTestTimeout()), SchemaIndexOperationCancellationException.class, null);
        assertNotNull(fut1.cancelToken().cancelException());
    } else {
        fut0.get(getTestTimeout());
        fut1.get(getTestTimeout());
        assertNull(fut1.cancelToken().cancelException());
    }
    assertNull(internalIndexRebuildFuture(n, cacheCtx.cacheId()));
}
Also used : CacheMetricsImpl(org.apache.ignite.internal.processors.cache.CacheMetricsImpl) IgniteEx(org.apache.ignite.internal.IgniteEx) SchemaIndexCacheFuture(org.apache.ignite.internal.processors.query.schema.SchemaIndexCacheFuture)

Example 8 with CacheMetricsImpl

use of org.apache.ignite.internal.processors.cache.CacheMetricsImpl in project ignite by apache.

the class GridDhtCache method start.

/**
 * {@inheritDoc}
 */
@Override
public void start() throws IgniteCheckedException {
    CacheMetricsImpl m = new CacheMetricsImpl(ctx);
    m.delegate(ctx.dht().near().metrics0());
    metrics = m;
    ctx.dr().resetMetrics();
    super.start();
}
Also used : CacheMetricsImpl(org.apache.ignite.internal.processors.cache.CacheMetricsImpl)

Example 9 with CacheMetricsImpl

use of org.apache.ignite.internal.processors.cache.CacheMetricsImpl in project ignite by apache.

the class PartitionsEvictManager method updateMetrics.

/**
 * @param grp Cache group.
 * @param c Update closure.
 */
private void updateMetrics(CacheGroupContext grp, EvictReason reason, BiConsumer<EvictReason, CacheMetricsImpl> c) {
    if (reason != EvictReason.CLEARING_ON_RECOVERY) {
        for (GridCacheContext cctx : grp.caches()) {
            if (cctx.statisticsEnabled()) {
                final CacheMetricsImpl metrics = cctx.cache().metrics0();
                c.accept(reason, metrics);
            }
        }
    }
}
Also used : GridCacheContext(org.apache.ignite.internal.processors.cache.GridCacheContext) CacheMetricsImpl(org.apache.ignite.internal.processors.cache.CacheMetricsImpl)

Example 10 with CacheMetricsImpl

use of org.apache.ignite.internal.processors.cache.CacheMetricsImpl in project ignite by apache.

the class GridCacheQueryManager method runFieldsQuery.

/**
 * Processes fields query request.
 *
 * @param qryInfo Query info.
 */
protected void runFieldsQuery(GridCacheQueryInfo qryInfo) {
    assert qryInfo != null;
    if (!enterBusy()) {
        if (cctx.localNodeId().equals(qryInfo.senderId()))
            throw new IllegalStateException("Failed to process query request (grid is stopping).");
        // Ignore remote requests when when node is stopping.
        return;
    }
    try {
        if (log.isDebugEnabled())
            log.debug("Running query: " + qryInfo);
        boolean rmvRes = true;
        FieldsResult res = null;
        final boolean statsEnabled = cctx.statisticsEnabled();
        final boolean readEvt = cctx.events().isRecordable(EVT_CACHE_QUERY_OBJECT_READ);
        try {
            // Preparing query closures.
            IgniteReducer<Object, Object> rdc = (IgniteReducer<Object, Object>) qryInfo.reducer();
            injectResources(rdc);
            GridCacheQueryAdapter<?> qry = qryInfo.query();
            int pageSize = qry.pageSize();
            Collection<Object> data = null;
            Collection<Object> entities = null;
            if (qryInfo.local() || rdc != null || cctx.isLocalNode(qryInfo.senderId()))
                data = new ArrayList<>(pageSize);
            else
                entities = new ArrayList<>(pageSize);
            String taskName = cctx.kernalContext().task().resolveTaskName(qry.taskHash());
            res = qryInfo.local() ? executeFieldsQuery(qry, qryInfo.arguments(), qryInfo.local(), taskName, recipient(qryInfo.senderId(), qryInfo.requestId())) : fieldsQueryResult(qryInfo, taskName);
            // If metadata needs to be returned to user and cleaned from internal fields - copy it.
            List<GridQueryFieldMetadata> meta = qryInfo.includeMetaData() ? (res.metaData() != null ? new ArrayList<>(res.metaData()) : null) : res.metaData();
            if (!qryInfo.includeMetaData())
                meta = null;
            GridCloseableIterator<?> it = new GridSpiCloseableIteratorWrapper<Object>(res.iterator(recipient(qryInfo.senderId(), qryInfo.requestId())));
            if (log.isDebugEnabled())
                log.debug("Received fields iterator [iterHasNext=" + it.hasNext() + ']');
            if (!it.hasNext()) {
                if (rdc != null)
                    data = Collections.singletonList(rdc.reduce());
                onFieldsPageReady(qryInfo.local(), qryInfo, meta, entities, data, true, null);
                return;
            }
            int cnt = 0;
            boolean metaSent = false;
            while (!Thread.currentThread().isInterrupted() && it.hasNext()) {
                long start = statsEnabled ? System.nanoTime() : 0L;
                Object row = it.next();
                // Query is cancelled.
                if (row == null) {
                    onPageReady(qryInfo.local(), qryInfo, null, null, true, null);
                    break;
                }
                if (statsEnabled) {
                    CacheMetricsImpl metrics = cctx.cache().metrics0();
                    metrics.onRead(true);
                    metrics.addGetTimeNanos(System.nanoTime() - start);
                }
                if (readEvt && cctx.gridEvents().hasListener(EVT_CACHE_QUERY_OBJECT_READ)) {
                    cctx.gridEvents().record(new CacheQueryReadEvent<K, V>(cctx.localNode(), "SQL fields query result set row read.", EVT_CACHE_QUERY_OBJECT_READ, CacheQueryType.SQL_FIELDS.name(), cctx.name(), null, qry.clause(), null, null, qryInfo.arguments(), securitySubjectId(cctx), taskName, null, null, null, row));
                }
                if ((qryInfo.local() || rdc != null || cctx.isLocalNode(qryInfo.senderId()))) {
                    // Reduce.
                    if (rdc != null) {
                        if (!rdc.collect(row))
                            break;
                    } else
                        data.add(row);
                } else
                    entities.add(row);
                if (rdc == null && ((!qryInfo.allPages() && ++cnt == pageSize) || !it.hasNext())) {
                    onFieldsPageReady(qryInfo.local(), qryInfo, !metaSent ? meta : null, entities, data, !it.hasNext(), null);
                    if (it.hasNext())
                        rmvRes = false;
                    if (!qryInfo.allPages())
                        return;
                }
            }
            if (rdc != null) {
                onFieldsPageReady(qryInfo.local(), qryInfo, meta, null, Collections.singletonList(rdc.reduce()), true, null);
            }
        } catch (IgniteCheckedException e) {
            if (log.isDebugEnabled() || !e.hasCause(SQLException.class))
                U.error(log, "Failed to run fields query [qry=" + qryInfo + ", node=" + cctx.nodeId() + ']', e);
            else {
                if (e.hasCause(SQLException.class))
                    U.error(log, "Failed to run fields query [node=" + cctx.nodeId() + ", msg=" + e.getCause(SQLException.class).getMessage() + ']');
                else
                    U.error(log, "Failed to run fields query [node=" + cctx.nodeId() + ", msg=" + e.getMessage() + ']');
            }
            onFieldsPageReady(qryInfo.local(), qryInfo, null, null, null, true, e);
        } catch (Throwable e) {
            U.error(log, "Failed to run fields query [qry=" + qryInfo + ", node=" + cctx.nodeId() + "]", e);
            onFieldsPageReady(qryInfo.local(), qryInfo, null, null, null, true, e);
            if (e instanceof Error)
                throw (Error) e;
        } finally {
            if (qryInfo.local()) {
                // Don't we need to always remove local iterators?
                if (rmvRes && res != null) {
                    try {
                        res.closeIfNotShared(recipient(qryInfo.senderId(), qryInfo.requestId()));
                    } catch (IgniteCheckedException e) {
                        U.error(log, "Failed to close local iterator [qry=" + qryInfo + ", node=" + cctx.nodeId() + "]", e);
                    }
                }
            } else if (rmvRes)
                removeFieldsQueryResult(qryInfo.senderId(), qryInfo.requestId());
        }
    } finally {
        leaveBusy();
    }
}
Also used : GridSpiCloseableIteratorWrapper(org.apache.ignite.internal.util.GridSpiCloseableIteratorWrapper) SQLException(java.sql.SQLException) CacheMetricsImpl(org.apache.ignite.internal.processors.cache.CacheMetricsImpl) ArrayList(java.util.ArrayList) GridQueryFieldMetadata(org.apache.ignite.internal.processors.query.GridQueryFieldMetadata) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteReducer(org.apache.ignite.lang.IgniteReducer) CacheObject(org.apache.ignite.internal.processors.cache.CacheObject) KeyCacheObject(org.apache.ignite.internal.processors.cache.KeyCacheObject)

Aggregations

CacheMetricsImpl (org.apache.ignite.internal.processors.cache.CacheMetricsImpl)12 ArrayList (java.util.ArrayList)4 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)4 ClusterNode (org.apache.ignite.cluster.ClusterNode)4 GridCacheContext (org.apache.ignite.internal.processors.cache.GridCacheContext)4 UUID (java.util.UUID)3 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)3 AffinityTopologyVersion (org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion)3 Collection (java.util.Collection)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 Iterator (java.util.Iterator)2 List (java.util.List)2 Map (java.util.Map)2 Set (java.util.Set)2 AtomicReference (java.util.concurrent.atomic.AtomicReference)2 IgniteLogger (org.apache.ignite.IgniteLogger)2 CacheRebalanceMode (org.apache.ignite.cache.CacheRebalanceMode)2 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)2 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)2