use of org.infinispan.query.core.stats.IndexStatistics in project infinispan by infinispan.
the class LocalIndexSyncStateTransferTest method getIndexCountPerEntity.
private Map<String, Long> getIndexCountPerEntity(Cache<Integer, Object> cache) {
IndexStatistics indexStatistics = Search.getSearchStatistics(cache).getIndexStatistics();
Map<String, IndexInfo> stringIndexInfoMap = await(indexStatistics.computeIndexInfos().toCompletableFuture());
return stringIndexInfoMap.entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, e -> e.getValue().count()));
}
use of org.infinispan.query.core.stats.IndexStatistics in project infinispan by infinispan.
the class QueryCoreTest method testStats.
@Test
public void testStats() {
String q = String.format("FROM %s", Person.class.getName());
// Cache without stats enabled
QueryFactory queryFactory = Search.getQueryFactory(cache);
Query<Person> query = queryFactory.create(q);
query.execute().list();
SearchStatistics searchStatistics = Search.getSearchStatistics(cache);
QueryStatistics queryStatistics = searchStatistics.getQueryStatistics();
IndexStatistics indexStatistics = searchStatistics.getIndexStatistics();
assertTrue(await(indexStatistics.computeIndexInfos()).isEmpty());
assertTrue(await(Search.getClusteredSearchStatistics(cache)).getIndexStatistics().indexInfos().isEmpty());
assertEquals(0, queryStatistics.getNonIndexedQueryCount());
// Cache with stats enabled
queryFactory = Search.getQueryFactory(cacheWithStats);
query = queryFactory.create(String.format("FROM %s", Person.class.getName()));
query.execute().list();
searchStatistics = Search.getSearchStatistics(cacheWithStats);
queryStatistics = searchStatistics.getQueryStatistics();
indexStatistics = searchStatistics.getIndexStatistics();
assertTrue(await(indexStatistics.computeIndexInfos()).isEmpty());
assertTrue(await(Search.getClusteredSearchStatistics(cacheWithStats).thenCompose(s -> s.getIndexStatistics().computeIndexInfos())).isEmpty());
assertEquals(1, queryStatistics.getNonIndexedQueryCount());
assertTrue(queryStatistics.getNonIndexedQueryAvgTime() > 0);
assertTrue(queryStatistics.getNonIndexedQueryMaxTime() > 0);
assertTrue(queryStatistics.getNonIndexedQueryTotalTime() > 0);
assertEquals(q, queryStatistics.getSlowestNonIndexedQuery());
}
use of org.infinispan.query.core.stats.IndexStatistics in project infinispan by infinispan.
the class CacheResourceV2 method getDetailResponse.
private RestResponse getDetailResponse(Cache<?, ?> cache) {
Configuration configuration = SecurityActions.getCacheConfiguration(cache.getAdvancedCache());
EmbeddedCacheManager cacheManager = invocationHelper.getRestCacheManager().getInstance();
GlobalConfiguration globalConfiguration = SecurityActions.getCacheManagerConfiguration(cacheManager);
PersistenceManager persistenceManager = SecurityActions.getPersistenceManager(cacheManager, cache.getName());
Stats stats = null;
Boolean rehashInProgress = null;
Boolean indexingInProgress = null;
Boolean queryable = null;
try {
// TODO Shouldn't we return the clustered stats, like Hot Rod does?
stats = cache.getAdvancedCache().getStats();
DistributionManager distributionManager = cache.getAdvancedCache().getDistributionManager();
rehashInProgress = distributionManager != null && distributionManager.isRehashInProgress();
} catch (SecurityException ex) {
// Admin is needed
}
Boolean rebalancingEnabled = null;
try {
LocalTopologyManager localTopologyManager = SecurityActions.getComponentRegistry(cache.getAdvancedCache()).getComponent(LocalTopologyManager.class);
if (localTopologyManager != null) {
rebalancingEnabled = localTopologyManager.isCacheRebalancingEnabled(cache.getName());
}
} catch (Exception ex) {
// Getting rebalancing status might raise an exception
}
Integer size = null;
if (globalConfiguration.metrics().accurateSize()) {
try {
size = cache.size();
} catch (SecurityException ex) {
// Bulk Read is needed
}
}
SearchStatistics searchStatistics = Search.getSearchStatistics(cache);
IndexStatistics indexStatistics = searchStatistics.getIndexStatistics();
indexingInProgress = indexStatistics.reindexing();
queryable = invocationHelper.getRestCacheManager().isCacheQueryable(cache);
boolean statistics = configuration.statistics().enabled();
boolean indexed = configuration.indexing().enabled();
CacheFullDetail fullDetail = new CacheFullDetail();
fullDetail.stats = stats;
StringBuilderWriter sw = new StringBuilderWriter();
try (ConfigurationWriter w = ConfigurationWriter.to(sw).withType(APPLICATION_JSON).build()) {
invocationHelper.getParserRegistry().serialize(w, cache.getName(), configuration);
}
fullDetail.configuration = sw.toString();
fullDetail.size = size;
fullDetail.rehashInProgress = rehashInProgress;
fullDetail.indexingInProgress = indexingInProgress;
fullDetail.persistent = persistenceManager.isEnabled();
fullDetail.bounded = configuration.memory().whenFull().isEnabled();
fullDetail.indexed = indexed;
fullDetail.hasRemoteBackup = configuration.sites().hasBackups();
fullDetail.secured = configuration.security().authorization().enabled();
fullDetail.transactional = configuration.transaction().transactionMode().isTransactional();
fullDetail.statistics = statistics;
fullDetail.queryable = queryable;
fullDetail.rebalancingEnabled = rebalancingEnabled;
fullDetail.keyStorage = cache.getAdvancedCache().getKeyDataConversion().getStorageMediaType();
fullDetail.valueStorage = cache.getAdvancedCache().getValueDataConversion().getStorageMediaType();
return addEntityAsJson(fullDetail.toJson(), new NettyRestResponse.Builder()).build();
}
Aggregations