Search in sources :

Example 26 with PartitionedIndex

use of org.apache.geode.cache.query.internal.index.PartitionedIndex in project geode by apache.

the class PRQueryDUnitHelper method getCacheSerializableRunnableForIndexUsageCheck.

/**
   * Insure queries on a pr is using index if not fail.
   */
public CacheSerializableRunnable getCacheSerializableRunnableForIndexUsageCheck() {
    SerializableRunnable PrIndexCheck = new CacheSerializableRunnable("PrIndexCheck") {

        @Override
        public void run2() {
            Cache cache = getCache();
            QueryService qs = cache.getQueryService();
            LogWriter logger = cache.getLogger();
            Collection indexes = qs.getIndexes();
            Iterator it = indexes.iterator();
            while (it.hasNext()) {
                PartitionedIndex ind = (PartitionedIndex) it.next();
                /*
           * List bucketIndex = ind.getBucketIndexes(); int k = 0;
           * logger.info("Total number of bucket index : "+bucketIndex.size()); while ( k <
           * bucketIndex.size() ){ Index bukInd = (Index)bucketIndex.get(k);
           * logger.info("Buket Index "+bukInd+"  usage : "+bukInd.getStatistics().getTotalUses());
           * // if number of quries on pr change in
           * getCacheSerializableRunnableForPRQueryAndCompareResults // literal 6 should change.
           * //Asif : With the optmization of Range Queries a where clause // containing something
           * like ID > 4 AND ID < 9 will be evaluated //using a single index lookup, so accordingly
           * modifying the //assert value from 7 to 6 // Anil : With aquiringReadLock during
           * Index.getSizeEstimate(), the // Index usage in case of "ID = 0 OR ID = 1" is increased
           * by 3. int indexUsageWithSizeEstimation = 3; int expectedUse = 6; long indexUse =
           * bukInd.getStatistics().getTotalUses(); // Anil : With chnages to use single index for
           * PR query evaluation, once the index // is identified the same index is used on other PR
           * buckets, the sieEstimation is // done only once, which adds additional index use for
           * only one bucket index. if (!(indexUse == expectedUse || indexUse == (expectedUse +
           * indexUsageWithSizeEstimation))){ fail
           * ("Index usage is not as expected, expected it to be either " + expectedUse + " or " +
           * (expectedUse + indexUsageWithSizeEstimation) + " it is: " + indexUse);
           * //assertIndexDetailsEquals(6 + indexUsageWithSizeEstimation,
           * bukInd.getStatistics().getTotalUses()); } k++; }
           */
                // Shobhit: Now we dont need to check stats per bucket index,
                // stats are accumulated in single pr index stats.
                // Anil : With aquiringReadLock during Index.getSizeEstimate(), the
                // Index usage in case of "ID = 0 OR ID = 1" is increased by 3.
                int indexUsageWithSizeEstimation = 3;
                logger.info("index uses for " + ind.getNumberOfIndexedBuckets() + " index " + ind.getName() + ": " + ind.getStatistics().getTotalUses());
                assertEquals(6, ind.getStatistics().getTotalUses());
            }
        }
    };
    return (CacheSerializableRunnable) PrIndexCheck;
}
Also used : PartitionedIndex(org.apache.geode.cache.query.internal.index.PartitionedIndex) CacheSerializableRunnable(org.apache.geode.cache30.CacheSerializableRunnable) QueryService(org.apache.geode.cache.query.QueryService) LogWriter(org.apache.geode.LogWriter) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) CacheSerializableRunnable(org.apache.geode.cache30.CacheSerializableRunnable) Iterator(java.util.Iterator) Collection(java.util.Collection) Cache(org.apache.geode.cache.Cache)

Example 27 with PartitionedIndex

use of org.apache.geode.cache.query.internal.index.PartitionedIndex in project geode by apache.

the class PRIndexStatisticsJUnitTest method testStatsForCompactMapRangeIndexBeforeRegionCreation.

/**
   * Test MapRenageIndex IndexStatistics for keys, values, updates and uses.
   * 
   * @throws Exception
   */
@Test
public void testStatsForCompactMapRangeIndexBeforeRegionCreation() throws Exception {
    // Destroy region
    createRegion();
    assertEquals(0, region.size());
    keyIndex3 = (IndexProtocol) qs.createIndex("multiKeyIndex6", IndexType.FUNCTIONAL, "positions['DELL', 'YHOO']", "/portfolio");
    // Recreate all entries in the region
    Position.cnt = 0;
    for (int i = 0; i < 100; i++) {
        region.put(Integer.toString(i), new Portfolio(i, i));
    }
    assertTrue(keyIndex3 instanceof PartitionedIndex);
    IndexStatistics keyIndexStats = keyIndex3.getStatistics();
    assertTrue(keyIndexStats instanceof IndexStatistics);
    assertEquals(89, keyIndexStats.getNumberOfBucketIndexes());
    assertEquals(2, keyIndexStats.getNumberOfMapIndexKeys());
    assertEquals(100, keyIndexStats.getNumberOfKeys());
    assertEquals(100, keyIndexStats.getNumberOfValues());
    assertEquals(100, keyIndexStats.getNumUpdates());
    Position.cnt = 0;
    for (int i = 0; i < 100; i++) {
        region.put(Integer.toString(i), new Portfolio(i, i));
    }
    assertEquals(2, keyIndexStats.getNumberOfMapIndexKeys());
    assertEquals(100, keyIndexStats.getNumberOfKeys());
    assertEquals(100, keyIndexStats.getNumberOfValues());
    assertEquals(200, keyIndexStats.getNumUpdates());
    String queryStr = "select * from /portfolio where positions['DELL'] != NULL OR positions['YHOO'] != NULL";
    Query query = qs.newQuery(queryStr);
    for (int i = 0; i < 50; i++) {
        query.execute();
    }
    // Both RangeIndex should be used
    assertEquals((100), keyIndexStats.getTotalUses());
    for (int i = 0; i < 50; i++) {
        region.invalidate(Integer.toString(i));
    }
    assertEquals(2, keyIndexStats.getNumberOfMapIndexKeys());
    assertEquals(50, keyIndexStats.getNumberOfKeys());
    assertEquals(50, keyIndexStats.getNumberOfValues());
    assertEquals(250, keyIndexStats.getNumUpdates());
    for (int i = 0; i < 50; i++) {
        region.destroy(Integer.toString(i));
    }
    assertEquals(2, keyIndexStats.getNumberOfMapIndexKeys());
    assertEquals(50, keyIndexStats.getNumberOfKeys());
    assertEquals(50, keyIndexStats.getNumberOfValues());
    assertEquals(250, keyIndexStats.getNumUpdates());
    for (int i = 50; i < 100; i++) {
        region.destroy(Integer.toString(i));
    }
    assertEquals(300, keyIndexStats.getNumUpdates());
    assertEquals(2, keyIndexStats.getNumberOfMapIndexKeys());
    assertEquals(0, keyIndexStats.getNumberOfKeys());
    qs.removeIndex(keyIndex3);
    region.destroyRegion();
}
Also used : IndexStatistics(org.apache.geode.cache.query.IndexStatistics) PartitionedIndex(org.apache.geode.cache.query.internal.index.PartitionedIndex) Query(org.apache.geode.cache.query.Query) Portfolio(org.apache.geode.cache.query.data.Portfolio) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 28 with PartitionedIndex

use of org.apache.geode.cache.query.internal.index.PartitionedIndex in project geode by apache.

the class PRIndexStatisticsJUnitTest method testStatsForCompactRangeIndex.

/**
   * Test CompactRenageIndex IndexStatistics for keys, values, updates and uses.
   * 
   * @throws Exception
   */
@Test
public void testStatsForCompactRangeIndex() throws Exception {
    createAndPopulateRegion();
    keyIndex2 = (IndexProtocol) qs.createIndex("multiKeyIndex2", IndexType.FUNCTIONAL, "ID", "/portfolio ");
    assertTrue(keyIndex2 instanceof PartitionedIndex);
    IndexStatistics keyIndex1Stats = keyIndex2.getStatistics();
    assertEquals(89, keyIndex1Stats.getNumberOfBucketIndexes());
    // Initial stats test (keys, values & updates)
    assertEquals(100, keyIndex1Stats.getNumberOfKeys());
    assertEquals(100, keyIndex1Stats.getNumberOfValues());
    assertEquals(100, keyIndex1Stats.getNumUpdates());
    for (int i = 0; i < 100; i++) {
        region.put(Integer.toString(i), new Portfolio(i, i));
    }
    assertEquals(100, keyIndex1Stats.getNumberOfKeys());
    assertEquals(100, keyIndex1Stats.getNumberOfValues());
    assertEquals(200, keyIndex1Stats.getNumUpdates());
    // IndexUsed stats test
    String queryStr = "select * from /portfolio where ID > 0";
    Query query = qs.newQuery(queryStr);
    for (int i = 0; i < 50; i++) {
        query.execute();
    }
    assertEquals(50, keyIndex1Stats.getTotalUses());
    // NumOfValues should be reduced.
    for (int i = 0; i < 50; i++) {
        region.invalidate(Integer.toString(i));
    }
    assertEquals(50, keyIndex1Stats.getNumberOfKeys());
    assertEquals(50, keyIndex1Stats.getNumberOfValues());
    assertEquals(250, keyIndex1Stats.getNumUpdates());
    for (int i = 0; i < 50; i++) {
        region.destroy(Integer.toString(i));
    }
    assertEquals(50, keyIndex1Stats.getNumberOfKeys());
    assertEquals(50, keyIndex1Stats.getNumberOfValues());
    assertEquals(250, keyIndex1Stats.getNumUpdates());
    // NumOfKeys should get zero as all values are destroyed
    for (int i = 50; i < 100; i++) {
        region.destroy(Integer.toString(i));
    }
    assertEquals(300, keyIndex1Stats.getNumUpdates());
    assertEquals(0, keyIndex1Stats.getNumberOfKeys());
    qs.removeIndex(keyIndex2);
    region.destroyRegion();
}
Also used : IndexStatistics(org.apache.geode.cache.query.IndexStatistics) PartitionedIndex(org.apache.geode.cache.query.internal.index.PartitionedIndex) Query(org.apache.geode.cache.query.Query) Portfolio(org.apache.geode.cache.query.data.Portfolio) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 29 with PartitionedIndex

use of org.apache.geode.cache.query.internal.index.PartitionedIndex in project geode by apache.

the class PRIndexStatisticsJUnitTest method testStatsForCompactRangeIndexBeforeRegionCreation.

/**
   * Test CompactRenageIndex IndexStatistics for keys, values, updates and uses.
   * 
   * @throws Exception
   */
@Test
public void testStatsForCompactRangeIndexBeforeRegionCreation() throws Exception {
    // Destroy region
    createRegion();
    assertEquals(0, region.size());
    keyIndex2 = (IndexProtocol) qs.createIndex("multiKeyIndex5", IndexType.FUNCTIONAL, "ID", "/portfolio ");
    // Recreate all entries in the region
    for (int i = 0; i < 100; i++) {
        region.put(Integer.toString(i), new Portfolio(i, i));
    }
    assertTrue(keyIndex2 instanceof PartitionedIndex);
    IndexStatistics keyIndex1Stats = keyIndex2.getStatistics();
    assertEquals(89, keyIndex1Stats.getNumberOfBucketIndexes());
    // Initial stats test (keys, values & updates)
    assertEquals(100, keyIndex1Stats.getNumberOfKeys());
    assertEquals(100, keyIndex1Stats.getNumberOfValues());
    assertEquals(100, keyIndex1Stats.getNumUpdates());
    for (int i = 0; i < 100; i++) {
        region.put(Integer.toString(i), new Portfolio(i, i));
    }
    assertEquals(100, keyIndex1Stats.getNumberOfKeys());
    assertEquals(100, keyIndex1Stats.getNumberOfValues());
    assertEquals(200, keyIndex1Stats.getNumUpdates());
    // IndexUsed stats test
    String queryStr = "select * from /portfolio where ID > 0";
    Query query = qs.newQuery(queryStr);
    for (int i = 0; i < 50; i++) {
        query.execute();
    }
    assertEquals(50, keyIndex1Stats.getTotalUses());
    // NumOfValues should be reduced.
    for (int i = 0; i < 50; i++) {
        region.invalidate(Integer.toString(i));
    }
    assertEquals(50, keyIndex1Stats.getNumberOfKeys());
    assertEquals(50, keyIndex1Stats.getNumberOfValues());
    assertEquals(250, keyIndex1Stats.getNumUpdates());
    for (int i = 0; i < 50; i++) {
        region.destroy(Integer.toString(i));
    }
    assertEquals(50, keyIndex1Stats.getNumberOfKeys());
    assertEquals(50, keyIndex1Stats.getNumberOfValues());
    assertEquals(250, keyIndex1Stats.getNumUpdates());
    // NumOfKeys should get zero as all values are destroyed
    for (int i = 50; i < 100; i++) {
        region.destroy(Integer.toString(i));
    }
    assertEquals(300, keyIndex1Stats.getNumUpdates());
    assertEquals(0, keyIndex1Stats.getNumberOfKeys());
    qs.removeIndex(keyIndex2);
    region.destroyRegion();
}
Also used : IndexStatistics(org.apache.geode.cache.query.IndexStatistics) PartitionedIndex(org.apache.geode.cache.query.internal.index.PartitionedIndex) Query(org.apache.geode.cache.query.Query) Portfolio(org.apache.geode.cache.query.data.Portfolio) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 30 with PartitionedIndex

use of org.apache.geode.cache.query.internal.index.PartitionedIndex in project geode by apache.

the class PRIndexStatisticsJUnitTest method testStatsForCompactMapRangeIndex.

/**
   * Test CompactMapRenageIndex IndexStatistics for keys, values, updates and uses.
   * 
   * @throws Exception
   */
@Test
public void testStatsForCompactMapRangeIndex() throws Exception {
    createAndPopulateRegion();
    keyIndex3 = (IndexProtocol) qs.createIndex("multiKeyIndex3", IndexType.FUNCTIONAL, "positions['DELL', 'YHOO']", "/portfolio p");
    assertTrue(keyIndex3 instanceof PartitionedIndex);
    IndexStatistics keyIndexStats = keyIndex3.getStatistics();
    assertTrue(keyIndexStats instanceof IndexStatistics);
    assertEquals(89, keyIndexStats.getNumberOfBucketIndexes());
    assertEquals(2, keyIndexStats.getNumberOfMapIndexKeys());
    assertEquals(100, keyIndexStats.getNumberOfKeys());
    assertEquals(100, keyIndexStats.getNumberOfValues());
    assertEquals(100, keyIndexStats.getNumUpdates());
    for (int i = 0; i < 100; i++) {
        region.put(Integer.toString(i), new Portfolio(i, i));
    }
    assertEquals(2, keyIndexStats.getNumberOfMapIndexKeys());
    assertEquals(100, keyIndexStats.getNumberOfKeys());
    assertEquals(100, keyIndexStats.getNumberOfValues());
    assertEquals(200, keyIndexStats.getNumUpdates());
    String queryStr = "select * from /portfolio where positions['DELL'] != NULL OR positions['YHOO'] != NULL";
    Query query = qs.newQuery(queryStr);
    for (int i = 0; i < 50; i++) {
        query.execute();
    }
    // Both RangeIndex should be used
    assertEquals(100, /* Execution time */
    keyIndexStats.getTotalUses());
    for (int i = 0; i < 50; i++) {
        region.invalidate(Integer.toString(i));
    }
    assertEquals(2, keyIndexStats.getNumberOfMapIndexKeys());
    assertEquals(50, keyIndexStats.getNumberOfKeys());
    assertEquals(50, keyIndexStats.getNumberOfValues());
    assertEquals(250, keyIndexStats.getNumUpdates());
    for (int i = 0; i < 50; i++) {
        region.destroy(Integer.toString(i));
    }
    assertEquals(2, keyIndexStats.getNumberOfMapIndexKeys());
    assertEquals(50, keyIndexStats.getNumberOfKeys());
    assertEquals(50, keyIndexStats.getNumberOfValues());
    assertEquals(250, keyIndexStats.getNumUpdates());
    for (int i = 50; i < 100; i++) {
        region.destroy(Integer.toString(i));
    }
    assertEquals(300, keyIndexStats.getNumUpdates());
    assertEquals(2, keyIndexStats.getNumberOfMapIndexKeys());
    assertEquals(0, keyIndexStats.getNumberOfKeys());
    qs.removeIndex(keyIndex3);
    region.destroyRegion();
}
Also used : IndexStatistics(org.apache.geode.cache.query.IndexStatistics) PartitionedIndex(org.apache.geode.cache.query.internal.index.PartitionedIndex) Query(org.apache.geode.cache.query.Query) Portfolio(org.apache.geode.cache.query.data.Portfolio) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Aggregations

PartitionedIndex (org.apache.geode.cache.query.internal.index.PartitionedIndex)32 Index (org.apache.geode.cache.query.Index)17 Query (org.apache.geode.cache.query.Query)17 Test (org.junit.Test)17 Portfolio (org.apache.geode.cache.query.data.Portfolio)15 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)13 SelectResults (org.apache.geode.cache.query.SelectResults)9 CacheSerializableRunnable (org.apache.geode.cache30.CacheSerializableRunnable)9 AttributesFactory (org.apache.geode.cache.AttributesFactory)8 PartitionAttributesFactory (org.apache.geode.cache.PartitionAttributesFactory)8 IndexStatistics (org.apache.geode.cache.query.IndexStatistics)8 AbstractIndex (org.apache.geode.cache.query.internal.index.AbstractIndex)8 CacheException (org.apache.geode.cache.CacheException)7 QueryService (org.apache.geode.cache.query.QueryService)7 IOException (java.io.IOException)6 Region (org.apache.geode.cache.Region)6 SerializableRunnable (org.apache.geode.test.dunit.SerializableRunnable)6 Iterator (java.util.Iterator)5 LogWriter (org.apache.geode.LogWriter)5 Cache (org.apache.geode.cache.Cache)5