use of org.apache.geode.cache.query.internal.index.IndexManager in project geode by apache.
the class AbstractRegionEntry method destroy.
/**
* @throws EntryNotFoundException if expectedOldValue is not null and is not equal to current
* value
*/
@Override
@Released
public boolean destroy(LocalRegion region, EntryEventImpl event, boolean inTokenMode, boolean cacheWrite, @Unretained Object expectedOldValue, boolean forceDestroy, boolean removeRecoveredEntry) throws CacheWriterException, EntryNotFoundException, TimeoutException, RegionClearedException {
// A design decision was made to not retrieve the old value from the disk
// if the entry has been evicted to only have the CacheListener afterDestroy
// method ignore it. We don't want to pay the performance penalty. The
// getValueInVM method does not retrieve the value from disk if it has been
// evicted. Instead, it uses the NotAvailable token.
//
// If the region is a WAN queue region, the old value is actually used by the
// afterDestroy callback on a secondary. It is not needed on a primary.
// Since the destroy that sets WAN_QUEUE_TOKEN always originates on the primary
// we only pay attention to WAN_QUEUE_TOKEN if the event is originRemote.
//
// We also read old value from disk or buffer
// in the case where there is a non-null expectedOldValue
// see PartitionedRegion#remove(Object key, Object value)
ReferenceCountHelper.skipRefCountTracking();
@Retained @Released Object curValue = _getValueRetain(region, true);
ReferenceCountHelper.unskipRefCountTracking();
boolean proceed;
try {
if (curValue == null) {
curValue = Token.NOT_AVAILABLE;
}
if (curValue == Token.NOT_AVAILABLE) {
// the state of the transmitting cache's entry & should be used here
if (event.getCallbackArgument() != null && event.getCallbackArgument().equals(RegionQueue.WAN_QUEUE_TOKEN) && event.isOriginRemote()) {
// check originRemote for bug 40508
// curValue = getValue(region); can cause deadlock if GII is occurring
curValue = getValueOnDiskOrBuffer(region);
} else {
FilterProfile fp = region.getFilterProfile();
if (fp != null && (fp.getCqCount() > 0 || expectedOldValue != null)) {
// curValue = getValue(region); can cause deadlock will fault in the value
// and will confuse LRU.
curValue = getValueOnDiskOrBuffer(region);
}
}
}
if (expectedOldValue != null) {
if (!checkExpectedOldValue(expectedOldValue, curValue, region)) {
throw new EntryNotFoundException(LocalizedStrings.AbstractRegionEntry_THE_CURRENT_VALUE_WAS_NOT_EQUAL_TO_EXPECTED_VALUE.toLocalizedString());
}
}
if (inTokenMode && event.hasOldValue()) {
proceed = true;
} else {
proceed = event.setOldValue(curValue, curValue instanceof GatewaySenderEventImpl) || removeRecoveredEntry || forceDestroy || region.getConcurrencyChecksEnabled() || (event.getOperation() == Operation.REMOVE && (curValue == null || curValue == Token.LOCAL_INVALID || curValue == Token.INVALID));
}
} finally {
OffHeapHelper.releaseWithNoTracking(curValue);
}
if (proceed) {
// after the entry not found exception above.
if (!removeRecoveredEntry) {
region.generateAndSetVersionTag(event, this);
}
if (cacheWrite) {
region.cacheWriteBeforeDestroy(event, expectedOldValue);
if (event.getRegion().getServerProxy() != null) {
// server will return a version tag
// update version information (may throw ConcurrentCacheModificationException)
VersionStamp stamp = getVersionStamp();
if (stamp != null) {
stamp.processVersionTag(event);
}
}
}
region.recordEvent(event);
// RegionEntry (the old value) is invalid
if (!region.isProxy() && !isInvalid()) {
IndexManager indexManager = region.getIndexManager();
if (indexManager != null) {
try {
if (isValueNull()) {
@Released Object value = getValueOffHeapOrDiskWithoutFaultIn(region);
try {
Object preparedValue = prepareValueForCache(region, value, false);
_setValue(preparedValue);
releaseOffHeapRefIfRegionBeingClosedOrDestroyed(region, preparedValue);
} finally {
OffHeapHelper.release(value);
}
}
indexManager.updateIndexes(this, IndexManager.REMOVE_ENTRY, IndexProtocol.OTHER_OP);
} catch (QueryException e) {
throw new IndexMaintenanceException(e);
}
}
}
boolean removeEntry = false;
VersionTag v = event.getVersionTag();
if (region.concurrencyChecksEnabled && !removeRecoveredEntry && !event.isFromRILocalDestroy()) {
// Destroy will write a tombstone instead
if (v == null || !v.hasValidVersion()) {
// localDestroy and eviction and ops received with no version tag
// should create a tombstone using the existing version stamp, as should
// (bug #45245) responses from servers that do not have valid version information
VersionStamp stamp = this.getVersionStamp();
if (stamp != null) {
// proxy has no stamps
v = stamp.asVersionTag();
event.setVersionTag(v);
}
}
removeEntry = v == null || !v.hasValidVersion();
} else {
removeEntry = true;
}
if (removeEntry) {
boolean isThisTombstone = isTombstone();
if (inTokenMode && !event.getOperation().isEviction()) {
setValue(region, Token.DESTROYED);
} else {
removePhase1(region, false);
}
if (isThisTombstone) {
region.unscheduleTombstone(this);
}
} else {
makeTombstone(region, v);
}
return true;
} else {
return false;
}
}
use of org.apache.geode.cache.query.internal.index.IndexManager in project geode by apache.
the class AbstractRegion method setIndexManager.
/**
* This method call is guarded by imSync lock created for each region. Set IndexManger for region.
*/
public IndexManager setIndexManager(IndexManager indexManager) {
checkReadiness();
IndexManager oldIdxManager = this.indexManager;
this.indexManager = indexManager;
return oldIdxManager;
}
use of org.apache.geode.cache.query.internal.index.IndexManager in project geode by apache.
the class QueryObserverCallbackJUnitTest method tearDown.
@After
public void tearDown() throws Exception {
CacheUtils.closeCache();
IndexManager indexManager = ((LocalRegion) region).getIndexManager();
if (indexManager != null)
indexManager.destroy();
}
use of org.apache.geode.cache.query.internal.index.IndexManager in project geode by apache.
the class CompiledJunctionInternalsJUnitTest method tearDown.
@After
public void tearDown() throws Exception {
CacheUtils.closeCache();
IndexManager indexManager = ((LocalRegion) region).getIndexManager();
if (indexManager != null)
indexManager.destroy();
}
use of org.apache.geode.cache.query.internal.index.IndexManager in project geode by apache.
the class PartitionedRegion method removeIndex.
/**
* Removes a particular index on this partitioned regions instance.
*
* @param ind Index to be removed.
*
*/
public int removeIndex(Index ind, boolean remotelyOriginated) throws CacheException, ForceReattemptException {
int numBuckets = 0;
IndexTask indexTask = null;
Object prIndex = null;
if (ind != null) {
indexTask = new IndexTask(ind.getName());
prIndex = this.indexes.get(indexTask);
}
// not in create phase, its created successfully).
if (prIndex == null || !(prIndex instanceof Index)) {
logger.info(LocalizedMessage.create(LocalizedStrings.PartitionedRegion_THIS_INDEX__0_IS_NOT_ON_THIS_PARTITONED_REGION___1, new Object[] { ind, this }));
return numBuckets;
}
if (logger.isDebugEnabled()) {
logger.debug("Remove index called, IndexName: {} Index: {} Will be removing all the bucket indexes.", ind.getName(), ind);
}
Index index1 = this.indexManager.getIndex(ind.getName());
if (index1 != null) {
this.indexManager.removeIndex(index1);
}
// marking the index invalid.
if (prIndex != null) {
PartitionedIndex index = (PartitionedIndex) prIndex;
index.acquireIndexWriteLockForRemove();
}
this.indexes.remove(indexTask);
// For releasing the write lock after removal.
try {
synchronized (prIndex) {
List allBucketIndex = ((PartitionedIndex) prIndex).getBucketIndexes();
Iterator it = allBucketIndex.iterator();
if (logger.isDebugEnabled()) {
logger.debug("Will be removing indexes on : {} buckets", allBucketIndex.size());
}
while (it.hasNext()) {
Index in = (Index) it.next();
LocalRegion region = ((LocalRegion) in.getRegion());
region.waitForData();
IndexManager indMng = region.getIndexManager();
indMng.removeIndex(in);
if (logger.isDebugEnabled()) {
logger.debug("Removed index : {} on bucket {}", in, region);
}
numBuckets++;
((PartitionedIndex) prIndex).removeFromBucketIndexes(region, in);
}
// while
}
} finally {
((PartitionedIndex) prIndex).releaseIndexWriteLockForRemove();
}
if (!remotelyOriginated) {
// send remove index message.
RemoveIndexesMessage.RemoveIndexesResponse response;
logger.info(LocalizedMessage.create(LocalizedStrings.PartitionedRegion_SENDING_REMOVEINDEX_MESSAGE_TO_ALL_THE_PARTICIPATING_PRS));
response = (RemoveIndexesMessage.RemoveIndexesResponse) RemoveIndexesMessage.send(this, ind, false);
if (response != null) {
response.waitForResults();
logger.info(LocalizedMessage.create(LocalizedStrings.PartitionedRegion_DONE_WATING_FOR_REMOVE_INDEX));
if (logger.isDebugEnabled()) {
logger.debug("Total number of buckets which removed indexs , locally : {} and remotely removed : {} and the total number of remote buckets : {}", numBuckets, response.getRemoteRemovedIndexes(), response.getTotalRemoteBuckets());
}
}
}
return numBuckets;
}
Aggregations