use of org.apache.geode.cache.CacheWriterException in project geode by apache.
the class DestroyMessage method operateOnPartitionedRegion.
/**
* This method is called upon receipt and make the desired changes to the PartitionedRegion Note:
* It is very important that this message does NOT cause any deadlocks as the sender will wait
* indefinitely for the acknowledgement
*/
@Override
protected boolean operateOnPartitionedRegion(DistributionManager dm, PartitionedRegion r, long startTime) throws EntryExistsException, DataLocationException {
InternalDistributedMember eventSender = originalSender;
if (eventSender == null) {
eventSender = getSender();
}
@Released EntryEventImpl event = null;
try {
if (this.bridgeContext != null) {
event = EntryEventImpl.create(r, getOperation(), this.key, null, /* newValue */
getCallbackArg(), false, /* originRemote */
eventSender, true);
event.setContext(this.bridgeContext);
} else // bridgeContext != null
{
event = EntryEventImpl.create(r, getOperation(), this.key, null, /* newValue */
getCallbackArg(), false, /* originRemote - false to force distribution in buckets */
eventSender, true, /* generateCallbacks */
false);
}
if (this.versionTag != null) {
this.versionTag.replaceNullIDs(getSender());
event.setVersionTag(this.versionTag);
}
event.setInvokePRCallbacks(!notificationOnly);
Assert.assertTrue(eventId != null);
event.setEventId(eventId);
event.setPossibleDuplicate(this.posDup);
PartitionedRegionDataStore ds = r.getDataStore();
boolean sendReply = true;
if (!notificationOnly) {
Assert.assertTrue(ds != null, "This process should have storage for an item in " + this.toString());
try {
Integer bucket = Integer.valueOf(PartitionedRegionHelper.getHashKey(r, null, this.key, null, this.cbArg));
// try {
// // the event must show its true origin for cachewriter invocation
// event.setOriginRemote(true);
// event.setPartitionMessage(this);
// r.doCacheWriteBeforeDestroy(event);
// }
// finally {
// event.setOriginRemote(false);
// }
event.setCausedByMessage(this);
r.getDataView().destroyOnRemote(event, true, /* cacheWrite */
this.expectedOldValue);
if (logger.isTraceEnabled(LogMarker.DM)) {
logger.trace(LogMarker.DM, "{} updated bucket: {} with key: {}", getClass().getName(), bucket, this.key);
}
} catch (CacheWriterException cwe) {
sendReply(getSender(), this.processorId, dm, new ReplyException(cwe), r, startTime);
return false;
} catch (EntryNotFoundException eee) {
logger.trace(LogMarker.DM, "{}: operateOnRegion caught EntryNotFoundException", getClass().getName());
ReplyMessage.send(getSender(), getProcessorId(), new ReplyException(eee), getReplySender(dm), r.isInternalRegion());
// this prevents us from acking later
sendReply = false;
} catch (PrimaryBucketException pbe) {
sendReply(getSender(), getProcessorId(), dm, new ReplyException(pbe), r, startTime);
sendReply = false;
} finally {
this.versionTag = event.getVersionTag();
}
} else {
@Released EntryEventImpl e2 = createListenerEvent(event, r, dm.getDistributionManagerId());
try {
r.invokeDestroyCallbacks(EnumListenerEvent.AFTER_DESTROY, e2, r.isInitialized(), true);
} finally {
// if e2 == ev then no need to free it here. The outer finally block will get it.
if (e2 != event) {
e2.release();
}
}
}
return sendReply;
} finally {
if (event != null) {
event.release();
}
}
}
use of org.apache.geode.cache.CacheWriterException in project geode by apache.
the class CacheLoaderTestCase method testCacheWriterOnLoad.
/**
* Tests that a <code>CacheWriter</code> gets invoked on a <code>load</code>.
*/
@Test
public void testCacheWriterOnLoad() throws CacheException {
final String name = this.getUniqueName();
final Object key = this.getUniqueName();
final Object oldValue = new Integer(42);
final Object newValue = new Integer(43);
TestCacheLoader loader = new TestCacheLoader() {
public Object load2(LoaderHelper helper) throws CacheLoaderException {
return oldValue;
}
};
TestCacheWriter writer = new TestCacheWriter() {
public void beforeCreate2(EntryEvent event) throws CacheWriterException {
assertEquals(oldValue, event.getNewValue());
assertTrue(event.getOperation().isLoad());
assertTrue(event.getOperation().isLocalLoad());
assertFalse(event.getOperation().isNetLoad());
assertFalse(event.getOperation().isNetSearch());
}
};
AttributesFactory factory = new AttributesFactory(getRegionAttributes());
factory.setCacheLoader(loader);
factory.setCacheWriter(writer);
Region region = createRegion(name, factory.create());
loader.wasInvoked();
assertEquals(oldValue, region.get(key));
assertTrue(loader.wasInvoked());
assertTrue(writer.wasInvoked());
writer = new TestCacheWriter() {
public void beforeUpdate2(EntryEvent event) throws CacheWriterException {
assertEquals(oldValue, event.getOldValue());
assertEquals(newValue, event.getNewValue());
assertFalse(event.getOperation().isLoad());
assertFalse(event.getOperation().isLocalLoad());
assertFalse(event.getOperation().isNetLoad());
assertFalse(event.getOperation().isNetSearch());
}
};
region.getAttributesMutator().setCacheWriter(writer);
region.put(key, newValue);
assertFalse(loader.wasInvoked());
assertTrue(writer.wasInvoked());
}
use of org.apache.geode.cache.CacheWriterException in project geode by apache.
the class LocalRegion method basicDestroyRegion.
void basicDestroyRegion(RegionEventImpl event, boolean cacheWrite, boolean lock, boolean callbackEvents) throws CacheWriterException, TimeoutException {
preDestroyChecks();
final TXStateProxy tx = this.cache.getTXMgr().internalSuspend();
try {
boolean acquiredLock = false;
if (lock) {
try {
acquireDestroyLock();
acquiredLock = true;
} catch (CancelException ignore) {
if (logger.isDebugEnabled()) {
logger.debug("basicDestroyRegion: acquireDestroyLock failed due to cache closure, region = {}", getFullPath());
}
}
}
try {
// maintain destroy lock and TXStateInterface
// I moved checkRegionDestroyed up out of the following
// try block because it does not seem correct to deliver
// a destroy event to the clients of the region was already
// destroyed on the server.
checkRegionDestroyed(false);
// see bug 47736
boolean cancelledByCacheWriterException = false;
HashSet eventSet = null;
try {
// ensure that destroy events are dispatched
if (this instanceof PartitionedRegion && !((PartitionedRegion) this).getParallelGatewaySenderIds().isEmpty()) {
((PartitionedRegion) this).destroyParallelGatewaySenderRegion(event.getOperation(), cacheWrite, lock, callbackEvents);
}
if (this.parentRegion != null) {
// "Bubble up" the cache statistics to parent if this regions are more recent
this.parentRegion.updateStats();
}
try {
eventSet = callbackEvents ? new HashSet() : null;
this.destroyedSubregionSerialNumbers = collectSubregionSerialNumbers();
recursiveDestroyRegion(eventSet, event, cacheWrite);
} catch (CancelException e) {
// a serious problem.
if (!this.cache.forcedDisconnect()) {
logger.warn(LocalizedMessage.create(LocalizedStrings.LocalRegion_RECURSIVEDESTROYREGION_RECURSION_FAILED_DUE_TO_CACHE_CLOSURE_REGION_0, getFullPath()), e);
}
} catch (CacheWriterException cwe) {
cancelledByCacheWriterException = true;
throw cwe;
}
// at this point all subregions are destroyed and this region has been marked as destroyed
// and postDestroyRegion has been called for each region. The only detail left is
// unhooking this region from the parent subregion map, and sending listener events
Assert.assertTrue(this.isDestroyed);
// artifacts From Management Layer
if (!isInternalRegion()) {
InternalDistributedSystem system = this.cache.getInternalDistributedSystem();
system.handleResourceEvent(ResourceEvent.REGION_REMOVE, this);
}
try {
LocalRegion parent = this.parentRegion;
if (parent == null) {
this.cache.removeRoot(this);
} else {
parent.subregions.remove(this.regionName, this);
}
} catch (CancelException e) {
// I don't think this should ever happens: bulletproofing for bug 39454
if (!this.cache.forcedDisconnect()) {
logger.warn(LocalizedMessage.create(LocalizedStrings.LocalRegion_BASICDESTROYREGION_PARENT_REMOVAL_FAILED_DUE_TO_CACHE_CLOSURE_REGION_0, getFullPath()), e);
}
}
} finally {
// ensure that destroy events are dispatched
if (!cancelledByCacheWriterException) {
// We only need to notify bridgeClients of the top level region destroy
// which it will take and do a localRegionDestroy.
// So we pass it event and NOT eventSet
event.setEventType(EnumListenerEvent.AFTER_REGION_DESTROY);
notifyBridgeClients(event);
}
// since some of the destroys happened.
if (eventSet != null && callbackEvents) {
try {
sendPendingRegionDestroyEvents(eventSet);
} catch (CancelException ignore) {
// ignore, we're mute.
}
}
}
} finally {
if (acquiredLock) {
try {
releaseDestroyLock();
} catch (CancelException ignore) {
// ignore
}
}
}
} finally {
this.cache.getTXMgr().internalResume(tx);
}
}
use of org.apache.geode.cache.CacheWriterException in project geode by apache.
the class LocalRegion method localDestroyNoCallbacks.
/**
* WARNING: this method is overridden in subclasses.
*/
protected void localDestroyNoCallbacks(Object key) {
if (logger.isDebugEnabled()) {
logger.debug("localDestroyNoCallbacks key={}", key);
}
checkReadiness();
validateKey(key);
@Released EntryEventImpl event = EntryEventImpl.create(this, Operation.LOCAL_DESTROY, key, false, getMyId(), false, /* generateCallbacks */
true);
try {
// expectedOldValue
basicDestroy(event, false, null);
} catch (CacheWriterException e) {
// cache writer not called
throw new Error(LocalizedStrings.LocalRegion_CACHE_WRITER_SHOULD_NOT_HAVE_BEEN_CALLED_FOR_LOCALDESTROY.toLocalizedString(), e);
} catch (TimeoutException e) {
// no distributed lock
throw new Error(LocalizedStrings.LocalRegion_NO_DISTRIBUTED_LOCK_SHOULD_HAVE_BEEN_ATTEMPTED_FOR_LOCALDESTROY.toLocalizedString(), e);
} catch (EntryNotFoundException ignore) {
// not a problem
} finally {
event.release();
}
}
use of org.apache.geode.cache.CacheWriterException in project geode by apache.
the class RemoteDestroyMessage method operateOnRegion.
/**
* This method is called upon receipt and make the desired changes to the PartitionedRegion Note:
* It is very important that this message does NOT cause any deadlocks as the sender will wait
* indefinitely for the acknowledgement
*/
@Override
protected boolean operateOnRegion(DistributionManager dm, LocalRegion r, long startTime) throws EntryExistsException, RemoteOperationException {
InternalDistributedMember eventSender = originalSender;
if (eventSender == null) {
eventSender = getSender();
}
@Released EntryEventImpl event = null;
try {
if (this.bridgeContext != null) {
event = EntryEventImpl.create(r, getOperation(), getKey(), null, /* newValue */
getCallbackArg(), false, /* originRemote */
eventSender, true);
event.setContext(this.bridgeContext);
// for cq processing and client notification by BS.
if (this.hasOldValue) {
if (this.oldValueIsSerialized) {
event.setSerializedOldValue(getOldValueBytes());
} else {
event.setOldValue(getOldValueBytes());
}
}
} else // bridgeContext != null
{
event = EntryEventImpl.create(r, getOperation(), getKey(), null, /* newValue */
getCallbackArg(), this.useOriginRemote, eventSender, true, /* generateCallbacks */
false);
}
event.setCausedByMessage(this);
if (this.versionTag != null) {
this.versionTag.replaceNullIDs(getSender());
event.setVersionTag(this.versionTag);
}
// for cq processing and client notification by BS.
if (this.hasOldValue) {
if (this.oldValueIsSerialized) {
event.setSerializedOldValue(getOldValueBytes());
} else {
event.setOldValue(getOldValueBytes());
}
}
Assert.assertTrue(eventId != null);
event.setEventId(eventId);
event.setPossibleDuplicate(this.possibleDuplicate);
try {
r.getDataView().destroyOnRemote(event, true, this.expectedOldValue);
sendReply(dm, event.getVersionTag());
} catch (CacheWriterException cwe) {
sendReply(getSender(), this.processorId, dm, new ReplyException(cwe), r, startTime);
return false;
} catch (EntryNotFoundException eee) {
if (logger.isDebugEnabled()) {
logger.debug("operateOnRegion caught EntryNotFoundException", eee);
}
ReplyMessage.send(getSender(), getProcessorId(), new ReplyException(eee), getReplySender(dm), r.isInternalRegion());
} catch (DataLocationException e) {
if (logger.isDebugEnabled()) {
logger.debug("operateOnRegion caught DataLocationException");
}
ReplyMessage.send(getSender(), getProcessorId(), new ReplyException(e), getReplySender(dm), r.isInternalRegion());
}
return false;
} finally {
if (event != null) {
event.release();
}
}
}
Aggregations