Search in sources :

Example 1 with IndexStatistics

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()));
}
Also used : IndexStatistics(org.infinispan.query.core.stats.IndexStatistics) AnotherGrassEater(org.infinispan.query.test.AnotherGrassEater) ConfigurationBuilder(org.infinispan.configuration.cache.ConfigurationBuilder) MultipleCacheManagersTest(org.infinispan.test.MultipleCacheManagersTest) IndexStatistics(org.infinispan.query.core.stats.IndexStatistics) FunctionalTestUtils.await(org.infinispan.functional.FunctionalTestUtils.await) Person(org.infinispan.query.test.Person) HashMap(java.util.HashMap) Test(org.testng.annotations.Test) Cache(org.infinispan.Cache) Supplier(java.util.function.Supplier) Collectors(java.util.stream.Collectors) List(java.util.List) CacheMode(org.infinispan.configuration.cache.CacheMode) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) QueryTestSCI(org.infinispan.query.test.QueryTestSCI) Map(java.util.Map) LOCAL_HEAP(org.infinispan.configuration.cache.IndexStorage.LOCAL_HEAP) IndexInfo(org.infinispan.query.core.stats.IndexInfo) Search(org.infinispan.query.Search) IndexInfo(org.infinispan.query.core.stats.IndexInfo) HashMap(java.util.HashMap) Map(java.util.Map)

Example 2 with IndexStatistics

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());
}
Also used : IndexStatistics(org.infinispan.query.core.stats.IndexStatistics) SingleCacheManagerTest(org.infinispan.test.SingleCacheManagerTest) ConfigurationBuilder(org.infinispan.configuration.cache.ConfigurationBuilder) QueryStatistics(org.infinispan.query.core.stats.QueryStatistics) IndexStatistics(org.infinispan.query.core.stats.IndexStatistics) FunctionalTestUtils.await(org.infinispan.functional.FunctionalTestUtils.await) Test(org.testng.annotations.Test) QueryFactory(org.infinispan.query.dsl.QueryFactory) Cache(org.infinispan.Cache) AssertJUnit.assertTrue(org.testng.AssertJUnit.assertTrue) SearchStatistics(org.infinispan.query.core.stats.SearchStatistics) List(java.util.List) EmbeddedCacheManager(org.infinispan.manager.EmbeddedCacheManager) Search(org.infinispan.query.core.Search) TestCacheManagerFactory(org.infinispan.test.fwk.TestCacheManagerFactory) Query(org.infinispan.query.dsl.Query) AssertJUnit.assertEquals(org.testng.AssertJUnit.assertEquals) QueryFactory(org.infinispan.query.dsl.QueryFactory) SearchStatistics(org.infinispan.query.core.stats.SearchStatistics) QueryStatistics(org.infinispan.query.core.stats.QueryStatistics) SingleCacheManagerTest(org.infinispan.test.SingleCacheManagerTest) Test(org.testng.annotations.Test)

Example 3 with IndexStatistics

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();
}
Also used : StringBuilderWriter(org.infinispan.commons.io.StringBuilderWriter) GlobalConfiguration(org.infinispan.configuration.global.GlobalConfiguration) SearchStatistics(org.infinispan.query.core.stats.SearchStatistics) ConfigurationWriter(org.infinispan.commons.configuration.io.ConfigurationWriter) GlobalConfiguration(org.infinispan.configuration.global.GlobalConfiguration) RemoteStoreConfiguration(org.infinispan.persistence.remote.configuration.RemoteStoreConfiguration) Configuration(org.infinispan.configuration.cache.Configuration) PersistenceManager(org.infinispan.persistence.manager.PersistenceManager) ConfigurationBuilder(org.infinispan.configuration.cache.ConfigurationBuilder) EmbeddedCacheManager(org.infinispan.manager.EmbeddedCacheManager) RestResponseException(org.infinispan.rest.RestResponseException) IndexStatistics(org.infinispan.query.core.stats.IndexStatistics) Stats(org.infinispan.stats.Stats) DistributionManager(org.infinispan.distribution.DistributionManager) LocalTopologyManager(org.infinispan.topology.LocalTopologyManager)

Aggregations

ConfigurationBuilder (org.infinispan.configuration.cache.ConfigurationBuilder)3 IndexStatistics (org.infinispan.query.core.stats.IndexStatistics)3 List (java.util.List)2 Cache (org.infinispan.Cache)2 FunctionalTestUtils.await (org.infinispan.functional.FunctionalTestUtils.await)2 EmbeddedCacheManager (org.infinispan.manager.EmbeddedCacheManager)2 SearchStatistics (org.infinispan.query.core.stats.SearchStatistics)2 Test (org.testng.annotations.Test)2 HashMap (java.util.HashMap)1 Map (java.util.Map)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 Supplier (java.util.function.Supplier)1 Collectors (java.util.stream.Collectors)1 ConfigurationWriter (org.infinispan.commons.configuration.io.ConfigurationWriter)1 StringBuilderWriter (org.infinispan.commons.io.StringBuilderWriter)1 CacheMode (org.infinispan.configuration.cache.CacheMode)1 Configuration (org.infinispan.configuration.cache.Configuration)1 LOCAL_HEAP (org.infinispan.configuration.cache.IndexStorage.LOCAL_HEAP)1 GlobalConfiguration (org.infinispan.configuration.global.GlobalConfiguration)1 DistributionManager (org.infinispan.distribution.DistributionManager)1