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);
}
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);
}
}
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;
}
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());
}
use of org.apache.geode.cache.query.IndexStatistics in project geode by apache.
the class IndexStatisticsJUnitTest method testStatsForCompactRangeIndexAfterRecreate.
@Test
public void testStatsForCompactRangeIndexAfterRecreate() throws Exception {
keyIndex2 = (IndexProtocol) qs.createIndex("multiKeyIndex2", IndexType.FUNCTIONAL, "ID", "/portfolio ");
assertTrue(keyIndex2 instanceof CompactRangeIndex);
IndexStatistics keyIndex1Stats = keyIndex2.getStatistics();
// 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));
}
String queryStr = "select * from /portfolio where ID > 0";
Query query = qs.newQuery(queryStr);
for (int i = 0; i < 50; i++) {
query.execute();
}
assertEquals(100, keyIndex1Stats.getNumberOfKeys());
assertEquals(100, keyIndex1Stats.getNumberOfValues());
assertEquals(200, keyIndex1Stats.getNumUpdates());
assertEquals(50, keyIndex1Stats.getTotalUses());
region.clear();
assertEquals(0, keyIndex1Stats.getNumberOfKeys());
assertEquals(0, keyIndex1Stats.getNumberOfValues());
assertEquals(400, keyIndex1Stats.getNumUpdates());
assertEquals(50, keyIndex1Stats.getTotalUses());
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(500, keyIndex1Stats.getNumUpdates());
for (int i = 0; i < 50; i++) {
query.execute();
}
assertEquals(100, keyIndex1Stats.getTotalUses());
qs.removeIndex(keyIndex2);
}
Aggregations