use of org.apache.geode.cache.query.IndexStatistics in project geode by apache.
the class HashIndexQueryIntegrationTest method helpTestHashIndexRecreate.
private void helpTestHashIndexRecreate() throws Exception {
index = (Index) qs.createHashIndex("idHash", "p.ID", "/portfolios p");
createData(region, 200);
SelectResults noIndexResults = (SelectResults) qs.newQuery("Select * FROM /portfolios p where p.ID = 1").execute();
IndexStatistics ist = index.getStatistics();
assertEquals(200, ist.getNumberOfValues());
assertEquals(200, ist.getNumUpdates());
assertEquals(1, ist.getTotalUses());
region.clear();
ist = index.getStatistics();
assertEquals(0, ist.getNumberOfValues());
assertEquals(1, ist.getTotalUses());
assertEquals(400, ist.getNumUpdates());
createData(region, 200);
SelectResults results = (SelectResults) qs.newQuery("Select * FROM /portfolios p where p.ID = 1").execute();
ist = index.getStatistics();
assertEquals(200, ist.getNumberOfValues());
assertEquals(2, ist.getTotalUses());
assertEquals(600, ist.getNumUpdates());
assertEquals(noIndexResults.size(), results.size());
assertTrue(observer.indexUsed);
}
use of org.apache.geode.cache.query.IndexStatistics in project geode by apache.
the class IndexMaintenanceAsynchJUnitTest method testAddEntry.
@Test
public void testAddEntry() throws Exception {
String queryString;
Object result;
Query query;
try {
IndexStatistics stats = index.getStatistics();
for (int i = 5; i < 9; i++) {
region.put("" + i, new Portfolio(i));
}
final IndexStatistics st = stats;
WaitCriterion ev = new WaitCriterion() {
public boolean done() {
return st.getNumUpdates() == 8;
}
public String description() {
return "index updates never became 8";
}
};
Wait.waitForCriterion(ev, 5000, 200, true);
// queryString= "SELECT DISTINCT * FROM /portfolios p, p.positions.values pos where
// pos.secId='IBM'";
queryString = "SELECT DISTINCT * FROM /portfolios where status = 'active'";
query = CacheUtils.getQueryService().newQuery(queryString);
QueryObserverImpl observer = new QueryObserverImpl();
QueryObserverHolder.setInstance(observer);
result = query.execute();
if (!observer.isIndexesUsed) {
fail("NO INDEX USED");
}
if (((Collection) result).size() != 4) {
fail("Did not obtain expected size of result for the query");
}
// Task ID: IMA 1
} catch (Exception e) {
e.printStackTrace();
}
}
use of org.apache.geode.cache.query.IndexStatistics in project geode by apache.
the class MapRangeIndex method saveIndexAddition.
protected void saveIndexAddition(Object mapKey, Object indexKey, Object value, RegionEntry entry) throws IMQException {
boolean isPr = this.region instanceof BucketRegion;
// Get RangeIndex for it or create it if absent
RangeIndex rg = (RangeIndex) 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 RangeIndex(indexName + "-" + mapKey, region, fromClause, indexedExpression, projectionAttributes, this.originalFromClause, this.originalIndexedExpression, this.canonicalizedDefinitions, stats);
rg.evaluator = this.evaluator;
this.mapKeyToValueIndex.put(mapKey, rg);
if (!isPr) {
this.internalIndexStats.incNumMapIndexKeys(1);
}
}
// rg.internalIndexStats.incUpdatesInProgress(1);
long start = System.nanoTime();
rg.saveMapping(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.entryToMapKeysMap.add(entry, mapKey);
}
use of org.apache.geode.cache.query.IndexStatistics in project geode by apache.
the class MapRangeIndex method doIndexAddition.
protected void doIndexAddition(Object mapKey, Object indexKey, Object value, RegionEntry entry) throws IMQException {
boolean isPr = this.region instanceof BucketRegion;
// Get RangeIndex for it or create it if absent
RangeIndex rg = (RangeIndex) 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 RangeIndex(indexName + "-" + mapKey, region, fromClause, indexedExpression, projectionAttributes, this.originalFromClause, this.originalIndexedExpression, this.canonicalizedDefinitions, stats);
// Shobhit: We need evaluator to verify RegionEntry and IndexEntry inconsistency.
rg.evaluator = this.evaluator;
this.mapKeyToValueIndex.put(mapKey, rg);
if (!isPr) {
this.internalIndexStats.incNumMapIndexKeys(1);
}
}
this.internalIndexStats.incUpdatesInProgress(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.entryToMapKeysMap.add(entry, mapKey);
}
use of org.apache.geode.cache.query.IndexStatistics 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();
}
Aggregations