Search in sources :

Example 1 with IndexStatistics

use of org.apache.geode.cache.query.IndexStatistics in project geode by apache.

the class CompactMapRangeIndex method doIndexAddition.

protected void doIndexAddition(Object mapKey, Object indexKey, Object value, RegionEntry entry) throws IMQException {
    if (indexKey == null) {
        indexKey = IndexManager.NULL;
    }
    if (mapKey == null) {
        mapKey = IndexManager.NULL;
    }
    boolean isPr = this.region instanceof BucketRegion;
    // Get RangeIndex for it or create it if absent
    CompactRangeIndex rg = (CompactRangeIndex) this.mapKeyToValueIndex.get(mapKey);
    if (rg == null) {
        // use previously created MapRangeIndexStatistics
        IndexStatistics stats = this.internalIndexStats;
        PartitionedIndex prIndex = null;
        if (isPr) {
            prIndex = (PartitionedIndex) this.getPRIndex();
            prIndex.incNumMapKeysStats(mapKey);
        }
        rg = new CompactRangeIndex(indexName + "-" + mapKey, region, fromClause, indexedExpression, projectionAttributes, this.originalFromClause, this.originalIndexedExpression, this.canonicalizedDefinitions, stats);
        rg.instantiateEvaluator(this.ich, ((AbstractIndex.IMQEvaluator) this.evaluator).getIndexResultSetType());
        this.mapKeyToValueIndex.put(mapKey, rg);
        if (!isPr) {
            this.internalIndexStats.incNumMapIndexKeys(1);
        }
    }
    long start = System.nanoTime();
    rg.addMapping(indexKey, value, entry);
    // This call is skipped when addMapping is called from MapRangeIndex
    // rg.internalIndexStats.incNumUpdates();
    this.internalIndexStats.incUpdatesInProgress(-1);
    long end = System.nanoTime() - start;
    this.internalIndexStats.incUpdateTime(end);
    this.internalIndexStats.incNumUpdates();
    // add to mapkey to indexkey map
    Map mapKeyToIndexKey = this.entryToMapKeyIndexKeyMap.get(entry);
    if (mapKeyToIndexKey == null) {
        mapKeyToIndexKey = new HashMap();
        entryToMapKeyIndexKeyMap.put(entry, mapKeyToIndexKey);
    }
    mapKeyToIndexKey.put(mapKey, indexKey);
}
Also used : InternalIndexStatistics(org.apache.geode.cache.query.internal.index.AbstractIndex.InternalIndexStatistics) IndexStatistics(org.apache.geode.cache.query.IndexStatistics) BucketRegion(org.apache.geode.internal.cache.BucketRegion) HashMap(java.util.HashMap) HashMap(java.util.HashMap) Map(java.util.Map)

Example 2 with IndexStatistics

use of org.apache.geode.cache.query.IndexStatistics in project geode by apache.

the class CompactMapRangeIndex method saveIndexAddition.

protected void saveIndexAddition(Object mapKey, Object indexKey, Object value, RegionEntry entry) throws IMQException {
    if (indexKey == null) {
        indexKey = IndexManager.NULL;
    }
    if (mapKey == null) {
        mapKey = IndexManager.NULL;
    }
    boolean isPr = this.region instanceof BucketRegion;
    // Get RangeIndex for it or create it if absent
    CompactRangeIndex rg = (CompactRangeIndex) this.mapKeyToValueIndex.get(mapKey);
    if (rg == null) {
        // use previously created MapRangeIndexStatistics
        IndexStatistics stats = this.internalIndexStats;
        PartitionedIndex prIndex = null;
        if (isPr) {
            prIndex = (PartitionedIndex) this.getPRIndex();
            prIndex.incNumMapKeysStats(mapKey);
        }
        rg = new CompactRangeIndex(indexName + "-" + mapKey, region, fromClause, indexedExpression, projectionAttributes, this.originalFromClause, this.originalIndexedExpression, this.canonicalizedDefinitions, stats);
        rg.instantiateEvaluator(this.ich, ((AbstractIndex.IMQEvaluator) this.evaluator).getIndexResultSetType());
        this.mapKeyToValueIndex.put(mapKey, rg);
        if (!isPr) {
            this.internalIndexStats.incNumMapIndexKeys(1);
        }
    }
    this.internalIndexStats.incUpdatesInProgress(1);
    long start = System.nanoTime();
    // add to mapkey to indexkey map
    Map mapKeyToIndexKey = this.entryToMapKeyIndexKeyMap.get(entry);
    if (mapKeyToIndexKey == null) {
        mapKeyToIndexKey = new HashMap();
        entryToMapKeyIndexKeyMap.put(entry, mapKeyToIndexKey);
    }
    // Due to the way indexes are stored, we are actually doing an "update" here
    // and removing old keys that no longer exist for this region entry
    Object oldKey = mapKeyToIndexKey.get(mapKey);
    if (oldKey == null) {
        rg.addMapping(indexKey, value, entry);
    } else if ((oldKey != null && !oldKey.equals(indexKey))) {
        rg.addMapping(indexKey, value, entry);
        rg.removeMapping(oldKey, entry);
    }
    this.internalIndexStats.incUpdatesInProgress(-1);
    long end = System.nanoTime() - start;
    this.internalIndexStats.incUpdateTime(end);
    this.internalIndexStats.incNumUpdates();
    mapKeyToIndexKey.put(mapKey, indexKey);
}
Also used : InternalIndexStatistics(org.apache.geode.cache.query.internal.index.AbstractIndex.InternalIndexStatistics) IndexStatistics(org.apache.geode.cache.query.IndexStatistics) BucketRegion(org.apache.geode.internal.cache.BucketRegion) HashMap(java.util.HashMap) HashMap(java.util.HashMap) Map(java.util.Map)

Example 3 with IndexStatistics

use of org.apache.geode.cache.query.IndexStatistics in project geode by apache.

the class IndexCreationJUnitTest method testIndexInitializationForOverFlowRegions.

@Test
public void testIndexInitializationForOverFlowRegions() throws Exception {
    InternalDistributedSystem.getAnyInstance().disconnect();
    File file = new File("persistData0");
    file.mkdir();
    {
        Properties props = new Properties();
        props.setProperty(NAME, "test");
        props.setProperty(MCAST_PORT, "0");
        props.setProperty(STATISTIC_SAMPLING_ENABLED, "true");
        props.setProperty(ENABLE_TIME_STATISTICS, "true");
        props.setProperty(CACHE_XML_FILE, getClass().getResource("index-recovery-overflow.xml").toURI().getPath());
        DistributedSystem ds = DistributedSystem.connect(props);
        // Create the cache which causes the cache-xml-file to be parsed
        Cache cache = CacheFactory.create(ds);
        QueryService qs = cache.getQueryService();
        Region region = cache.getRegion("mainReportRegion");
        for (int i = 0; i < 100; i++) {
            Portfolio pf = new Portfolio(i);
            pf.setCreateTime(i);
            region.put("" + i, pf);
        }
        IndexStatistics is1 = qs.getIndex(region, "status").getStatistics();
        assertEquals(2, is1.getNumberOfKeys());
        assertEquals(100, is1.getNumberOfValues());
        IndexStatistics is2 = qs.getIndex(region, "ID").getStatistics();
        assertEquals(100, is2.getNumberOfKeys());
        assertEquals(100, is2.getNumberOfValues());
        // verify that a query on the creation time works as expected
        SelectResults results = (SelectResults) qs.newQuery("<trace>SELECT * FROM /mainReportRegion.entrySet mr Where mr.value.createTime > 1L and mr.value.createTime < 3L").execute();
        assertEquals("OQL index results did not match", 1, results.size());
        cache.close();
        ds.disconnect();
    }
    {
        Properties props = new Properties();
        props.setProperty(NAME, "test");
        props.setProperty(MCAST_PORT, "0");
        props.setProperty(STATISTIC_SAMPLING_ENABLED, "true");
        props.setProperty(ENABLE_TIME_STATISTICS, "true");
        props.setProperty(CACHE_XML_FILE, getClass().getResource("index-recovery-overflow.xml").toURI().getPath());
        DistributedSystem ds = DistributedSystem.connect(props);
        Cache cache = CacheFactory.create(ds);
        QueryService qs = cache.getQueryService();
        Region region = cache.getRegion("mainReportRegion");
        assertTrue("Index initialization time should not be 0.", ((LocalRegion) region).getCachePerfStats().getIndexInitializationTime() > 0);
        IndexStatistics is1 = qs.getIndex(region, "status").getStatistics();
        assertEquals(2, is1.getNumberOfKeys());
        assertEquals(100, is1.getNumberOfValues());
        IndexStatistics is2 = qs.getIndex(region, "ID").getStatistics();
        assertEquals(100, is2.getNumberOfKeys());
        assertEquals(100, is2.getNumberOfValues());
        // verify that a query on the creation time works as expected
        SelectResults results = (SelectResults) qs.newQuery("<trace>SELECT * FROM /mainReportRegion.entrySet mr Where mr.value.createTime > 1L and mr.value.createTime < 3L").execute();
        assertEquals("OQL index results did not match", 1, results.size());
        ds.disconnect();
        FileUtils.deleteDirectory(file);
    }
}
Also used : IndexStatistics(org.apache.geode.cache.query.IndexStatistics) SelectResults(org.apache.geode.cache.query.SelectResults) DefaultQueryService(org.apache.geode.cache.query.internal.DefaultQueryService) QueryService(org.apache.geode.cache.query.QueryService) Portfolio(org.apache.geode.cache.query.data.Portfolio) LocalRegion(org.apache.geode.internal.cache.LocalRegion) Region(org.apache.geode.cache.Region) LocalRegion(org.apache.geode.internal.cache.LocalRegion) Properties(java.util.Properties) File(java.io.File) InternalDistributedSystem(org.apache.geode.distributed.internal.InternalDistributedSystem) DistributedSystem(org.apache.geode.distributed.DistributedSystem) Cache(org.apache.geode.cache.Cache) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 4 with IndexStatistics

use of org.apache.geode.cache.query.IndexStatistics in project geode by apache.

the class IndexMaintenanceAsynchJUnitTest method init.

private static void init() {
    try {
        String queryString;
        Query query;
        Object result;
        Cache cache = CacheUtils.getCache();
        region = CacheUtils.createRegion("portfolios", Portfolio.class, false);
        for (int i = 0; i < 4; i++) {
            region.put("" + i, new Portfolio(i));
        }
        qs = cache.getQueryService();
        index = (IndexProtocol) qs.createIndex("statusIndex", IndexType.FUNCTIONAL, "status", "/portfolios");
        IndexStatistics stats = index.getStatistics();
        assertEquals(4, stats.getNumUpdates());
        // queryString= "SELECT DISTINCT * FROM /portfolios p, p.positions.values pos where
        // pos.secId='IBM'";
        queryString = "SELECT DISTINCT * FROM /portfolios";
        query = CacheUtils.getQueryService().newQuery(queryString);
        result = query.execute();
    } catch (Exception e) {
        e.printStackTrace();
    }
    isInitDone = true;
}
Also used : IndexStatistics(org.apache.geode.cache.query.IndexStatistics) Query(org.apache.geode.cache.query.Query) Portfolio(org.apache.geode.cache.query.data.Portfolio) Cache(org.apache.geode.cache.Cache)

Example 5 with IndexStatistics

use of org.apache.geode.cache.query.IndexStatistics in project geode by apache.

the class IndexMaintainceJUnitTest method test004DestroyEntry.

@Test
public void test004DestroyEntry() throws Exception {
    IndexStatistics stats = index.getStatistics();
    region.put("4", new Portfolio(4));
    region.destroy("4");
    assertEquals(4, stats.getNumberOfValues());
    // Set results = new HashSet();
    // index.query("active", OQLLexerTokenTypes.TOK_EQ, results,new ExecutionContext(null,
    // CacheUtils.getCache()));
    SelectResults results = region.query("status = 'active'");
    assertEquals(2, results.size());
}
Also used : IndexStatistics(org.apache.geode.cache.query.IndexStatistics) SelectResults(org.apache.geode.cache.query.SelectResults) Portfolio(org.apache.geode.cache.query.data.Portfolio) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Aggregations

IndexStatistics (org.apache.geode.cache.query.IndexStatistics)31 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)24 Test (org.junit.Test)24 Portfolio (org.apache.geode.cache.query.data.Portfolio)23 Query (org.apache.geode.cache.query.Query)19 PartitionedIndex (org.apache.geode.cache.query.internal.index.PartitionedIndex)8 SelectResults (org.apache.geode.cache.query.SelectResults)6 BucketRegion (org.apache.geode.internal.cache.BucketRegion)4 Region (org.apache.geode.cache.Region)3 HashMap (java.util.HashMap)2 Map (java.util.Map)2 Cache (org.apache.geode.cache.Cache)2 Index (org.apache.geode.cache.query.Index)2 InternalIndexStatistics (org.apache.geode.cache.query.internal.index.AbstractIndex.InternalIndexStatistics)2 File (java.io.File)1 Properties (java.util.Properties)1 QueryService (org.apache.geode.cache.query.QueryService)1 Numbers (org.apache.geode.cache.query.data.Numbers)1 DefaultQueryService (org.apache.geode.cache.query.internal.DefaultQueryService)1 DistributedSystem (org.apache.geode.distributed.DistributedSystem)1