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);
}
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()));
}
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();
}
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);
}
}
}
}
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();
}
}
Aggregations