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);
}
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());
}
Aggregations