use of org.apache.geode.internal.cache.RegionEntry in project geode by apache.
the class RangeIndex method dump.
public String dump() {
StringBuilder sb = new StringBuilder(toString()).append(" {\n");
sb.append("Null Values\n");
Iterator nI = nullMappedEntries.entrySet().iterator();
while (nI.hasNext()) {
Map.Entry mapEntry = (Map.Entry) nI.next();
RegionEntry e = (RegionEntry) mapEntry.getKey();
Object value = mapEntry.getValue();
sb.append(" RegionEntry.key = ").append(e.getKey());
sb.append(" Value.type = ").append(value.getClass().getName());
if (value instanceof Collection) {
sb.append(" Value.size = ").append(((Collection) value).size());
}
sb.append("\n");
}
sb.append(" -----------------------------------------------\n");
sb.append("Undefined Values\n");
Iterator uI = undefinedMappedEntries.entrySet().iterator();
while (uI.hasNext()) {
Map.Entry mapEntry = (Map.Entry) uI.next();
RegionEntry e = (RegionEntry) mapEntry.getKey();
Object value = mapEntry.getValue();
sb.append(" RegionEntry.key = ").append(e.getKey());
sb.append(" Value.type = ").append(value.getClass().getName());
if (value instanceof Collection) {
sb.append(" Value.size = ").append(((Collection) value).size());
}
sb.append("\n");
}
sb.append(" -----------------------------------------------\n");
Iterator i1 = this.valueToEntriesMap.entrySet().iterator();
while (i1.hasNext()) {
Map.Entry indexEntry = (Map.Entry) i1.next();
sb.append(" Key = ").append(indexEntry.getKey()).append("\n");
sb.append(" Value Type = ").append(" ").append(indexEntry.getValue().getClass().getName()).append("\n");
if (indexEntry.getValue() instanceof Map) {
sb.append(" Value Size = ").append(" ").append(((Map) indexEntry.getValue()).size()).append("\n");
}
Iterator i2 = ((RegionEntryToValuesMap) indexEntry.getValue()).entrySet().iterator();
while (i2.hasNext()) {
Map.Entry mapEntry = (Map.Entry) i2.next();
RegionEntry e = (RegionEntry) mapEntry.getKey();
Object value = mapEntry.getValue();
sb.append(" RegionEntry.key = ").append(e.getKey());
sb.append(" Value.type = ").append(value.getClass().getName());
if (value instanceof Collection) {
sb.append(" Value.size = ").append(((Collection) value).size());
}
sb.append("\n");
// sb.append(" Value.type = ").append(value).append("\n");
}
sb.append(" -----------------------------------------------\n");
}
sb.append("}// Index ").append(getName()).append(" end");
return sb.toString();
}
use of org.apache.geode.internal.cache.RegionEntry in project geode by apache.
the class AbstractIndex method populateListForEquiJoin.
/**
* This will populate resultSet from both type of indexes, {@link CompactRangeIndex} and
* {@link RangeIndex}.
*/
void populateListForEquiJoin(List list, Object outerEntries, Object innerEntries, ExecutionContext context, Object key) throws FunctionDomainException, TypeMismatchException, NameResolutionException, QueryInvocationTargetException {
Assert.assertTrue(outerEntries != null && innerEntries != null, "OuterEntries or InnerEntries must not be null");
Object[][] values = new Object[2][];
Iterator itr = null;
int j = 0;
while (j < 2) {
boolean isRangeIndex = false;
if (j == 0) {
if (outerEntries instanceof RegionEntryToValuesMap) {
itr = ((RegionEntryToValuesMap) outerEntries).map.entrySet().iterator();
isRangeIndex = true;
} else if (outerEntries instanceof CloseableIterator) {
itr = (Iterator) outerEntries;
}
} else {
if (innerEntries instanceof RegionEntryToValuesMap) {
itr = ((RegionEntryToValuesMap) innerEntries).map.entrySet().iterator();
isRangeIndex = true;
} else if (innerEntries instanceof CloseableIterator) {
itr = (Iterator) innerEntries;
}
}
// extract the values from the RegionEntries
List dummy = new ArrayList();
RegionEntry re = null;
IndexStoreEntry ie = null;
Object val = null;
Object entryVal = null;
IndexInfo[] indexInfo = (IndexInfo[]) context.cacheGet(CompiledValue.INDEX_INFO);
IndexInfo indInfo = indexInfo[j];
while (itr.hasNext()) {
if (isRangeIndex) {
Map.Entry entry = (Map.Entry) itr.next();
val = entry.getValue();
if (val instanceof Collection) {
entryVal = ((Iterable) val).iterator().next();
} else {
entryVal = val;
}
re = (RegionEntry) entry.getKey();
} else {
ie = (IndexStoreEntry) itr.next();
}
// Bug#41010: We need to verify if Inner and Outer Entries
// are consistent with index key values.
boolean ok = true;
if (isRangeIndex) {
if (re.isUpdateInProgress()) {
ok = ((RangeIndex) indInfo._getIndex()).verifyEntryAndIndexValue(re, entryVal, context);
}
} else if (ie.isUpdateInProgress()) {
ok = ((CompactRangeIndex) indInfo._getIndex()).verifyInnerAndOuterEntryValues(ie, context, indInfo, key);
}
if (ok) {
if (isRangeIndex) {
if (val instanceof Collection) {
dummy.addAll((Collection) val);
} else {
dummy.add(val);
}
} else {
if (IndexManager.IS_TEST_EXPANSION) {
dummy.addAll(((CompactRangeIndex) indInfo._getIndex()).expandValue(context, key, null, OQLLexerTokenTypes.TOK_EQ, -1, ie.getDeserializedValue()));
} else {
dummy.add(ie.getDeserializedValue());
}
}
}
}
Object[] newValues = new Object[dummy.size()];
dummy.toArray(newValues);
values[j++] = newValues;
}
list.add(values);
}
use of org.apache.geode.internal.cache.RegionEntry in project geode by apache.
the class MemoryIndexStore method printAll.
public String printAll() {
StringBuffer sb = new StringBuffer();
Iterator iterator = this.valueToEntriesMap.entrySet().iterator();
while (iterator.hasNext()) {
Map.Entry mapEntry = (Map.Entry) iterator.next();
sb.append("Key: " + mapEntry.getKey());
Object value = mapEntry.getValue();
if (value instanceof Collection) {
Iterator entriesIterator = ((Collection) value).iterator();
while (entriesIterator.hasNext()) {
sb.append(" Value:" + getTargetObject((RegionEntry) entriesIterator.next()));
}
} else {
sb.append(" Value:" + getTargetObject((RegionEntry) value));
}
sb.append("\n");
}
return sb.toString();
}
use of org.apache.geode.internal.cache.RegionEntry in project geode by apache.
the class MemoryIndexStore method updateMapping.
@Override
public void updateMapping(Object indexKey, Object oldKey, RegionEntry re, Object oldValue) throws IMQException {
try {
if (DefaultQuery.testHook != null) {
DefaultQuery.testHook.doTestHook(3);
}
// Check if reverse-map is present.
if (IndexManager.isObjectModificationInplace()) {
// If reverse map get the old index key from reverse map.
if (this.entryToValuesMap.containsKey(re)) {
oldKey = this.entryToValuesMap.get(re);
}
} else {
// forward map.
if (oldValue != null && oldValue == getTargetObjectInVM(re)) {
oldKey = getOldKey(indexKey, re);
}
}
// No need to update the map if new and old index key are same.
if (oldKey != null && oldKey.equals(TypeUtils.indexKeyFor(indexKey))) {
return;
}
boolean retry = false;
indexKey = TypeUtils.indexKeyFor(indexKey);
if (indexKey.equals(QueryService.UNDEFINED)) {
Object targetObject = getTargetObjectForUpdate(re);
if (Token.isInvalidOrRemoved(targetObject)) {
if (oldKey != null) {
basicRemoveMapping(oldKey, re, false);
}
return;
}
}
do {
retry = false;
Object regionEntries = this.valueToEntriesMap.putIfAbsent(indexKey, re);
if (regionEntries == TRANSITIONING_TOKEN) {
retry = true;
continue;
} else if (regionEntries == null) {
internalIndexStats.incNumKeys(1);
numIndexKeys.incrementAndGet();
} else if (regionEntries instanceof RegionEntry) {
IndexElemArray elemArray = new IndexElemArray();
if (DefaultQuery.testHook != null) {
DefaultQuery.testHook.doTestHook("BEGIN_TRANSITION_FROM_REGION_ENTRY_TO_ELEMARRAY");
}
elemArray.add(regionEntries);
elemArray.add(re);
if (!this.valueToEntriesMap.replace(indexKey, regionEntries, elemArray)) {
retry = true;
}
if (DefaultQuery.testHook != null) {
DefaultQuery.testHook.doTestHook("TRANSITIONED_FROM_REGION_ENTRY_TO_ELEMARRAY");
}
if (DefaultQuery.testHook != null) {
DefaultQuery.testHook.doTestHook("COMPLETE_TRANSITION_FROM_REGION_ENTRY_TO_ELEMARRAY");
}
} else if (regionEntries instanceof IndexConcurrentHashSet) {
// basicRemoveMapping();
synchronized (regionEntries) {
((IndexConcurrentHashSet) regionEntries).add(re);
}
if (regionEntries != this.valueToEntriesMap.get(indexKey)) {
retry = true;
}
} else {
IndexElemArray elemArray = (IndexElemArray) regionEntries;
synchronized (elemArray) {
if (elemArray.size() >= IndexManager.INDEX_ELEMARRAY_THRESHOLD) {
IndexConcurrentHashSet set = new IndexConcurrentHashSet(IndexManager.INDEX_ELEMARRAY_THRESHOLD + 20, 0.75f, 1);
if (DefaultQuery.testHook != null) {
DefaultQuery.testHook.doTestHook("BEGIN_TRANSITION_FROM_ELEMARRAY_TO_CONCURRENT_HASH_SET");
}
// retry?
if (!this.valueToEntriesMap.replace(indexKey, regionEntries, TRANSITIONING_TOKEN)) {
retry = true;
} else {
if (DefaultQuery.testHook != null) {
DefaultQuery.testHook.doTestHook("TRANSITIONED_FROM_ELEMARRAY_TO_TOKEN");
}
set.add(re);
set.addAll(elemArray);
if (!this.valueToEntriesMap.replace(indexKey, TRANSITIONING_TOKEN, set)) {
// This should never happen. If we see this in the log, then something is wrong
// with the TRANSITIONING TOKEN and synchronization of changing collection types
// we should then just go from RE to CHS and completely remove the Elem Array.
region.getCache().getLogger().warning("Unable to transition from index elem to concurrent hash set. Index needs to be recreated");
throw new IndexMaintenanceException("Unable to transition from index elem to concurrent hash set. Index needs to be recreated");
}
if (DefaultQuery.testHook != null) {
DefaultQuery.testHook.doTestHook("COMPLETE_TRANSITION_FROM_ELEMARRAY_TO_CONCURRENT_HASH_SET");
}
}
} else {
elemArray.add(re);
if (regionEntries != this.valueToEntriesMap.get(indexKey)) {
retry = true;
}
}
}
}
// Add to reverse Map with the new value.
if (!retry) {
// oldKey is not null only for an update
if (oldKey != null) {
basicRemoveMapping(oldKey, re, false);
}
if (IndexManager.isObjectModificationInplace()) {
this.entryToValuesMap.put(re, indexKey);
}
}
} while (retry);
} catch (TypeMismatchException ex) {
throw new IMQException("Could not add object of type " + indexKey.getClass().getName(), ex);
}
internalIndexStats.incNumValues(1);
}
use of org.apache.geode.internal.cache.RegionEntry in project geode by apache.
the class HashIndex method dump.
public String dump() {
StringBuilder sb = new StringBuilder(toString()).append(" {").append(getLineSeparator());
sb.append(" -----------------------------------------------").append(getLineSeparator());
for (Object anEntriesSet : this.entriesSet) {
Entry indexEntry = (Entry) anEntriesSet;
sb.append(" Key = ").append(indexEntry.getKey()).append(getLineSeparator());
sb.append(" Value Type = ").append(' ').append(indexEntry.getValue().getClass().getName()).append(getLineSeparator());
if (indexEntry.getValue() instanceof Collection) {
sb.append(" Value Size = ").append(' ').append(((Collection) indexEntry.getValue()).size()).append(getLineSeparator());
} else if (indexEntry.getValue() instanceof RegionEntry) {
sb.append(" Value Size = ").append(" " + 1).append(getLineSeparator());
} else {
throw new AssertionError("value instance of " + indexEntry.getValue().getClass().getName());
}
Collection entrySet = regionEntryCollection(indexEntry.getValue());
for (Object anEntrySet : entrySet) {
RegionEntry e = (RegionEntry) anEntrySet;
Object value = getTargetObject(e);
sb.append(" RegionEntry.key = ").append(e.getKey());
sb.append(" Value.type = ").append(value.getClass().getName());
if (value instanceof Collection) {
sb.append(" Value.size = ").append(((Collection) value).size());
}
sb.append(getLineSeparator());
}
sb.append(" -----------------------------------------------").append(getLineSeparator());
}
sb.append("}// Index ").append(getName()).append(" end");
return sb.toString();
}
Aggregations