use of org.apache.geode.cache.CacheWriterException in project geode by apache.
the class RemotePutMessage method operateOnRegion.
/**
* This method is called upon receipt and make the desired changes to the Replicate Region. 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 {
// set the internal DS. Required to
this.setInternalDs(r.getSystem());
// checked DS level delta-enabled property
// while sending delta
boolean sendReply = true;
InternalDistributedMember eventSender = originalSender;
if (eventSender == null) {
eventSender = getSender();
}
@Released EntryEventImpl eei = EntryEventImpl.create(r, getOperation(), getKey(), null, /* newValue */
getCallbackArg(), useOriginRemote, /* originRemote - false to force distribution in buckets */
eventSender, true, /* generateCallbacks */
false);
this.event = eei;
try {
if (this.versionTag != null) {
this.versionTag.replaceNullIDs(getSender());
event.setVersionTag(this.versionTag);
}
this.event.setCausedByMessage(this);
event.setPossibleDuplicate(this.possibleDuplicate);
if (this.bridgeContext != null) {
event.setContext(this.bridgeContext);
}
Assert.assertTrue(eventId != null);
event.setEventId(eventId);
// added for cq procesing
if (this.hasOldValue) {
if (this.oldValueIsSerialized) {
event.setSerializedOldValue(getOldValueBytes());
} else {
event.setOldValue(getOldValueBytes());
}
}
if (this.applyDeltaBytes) {
event.setNewValue(this.valObj);
event.setDeltaBytes(this.deltaBytes);
} else {
switch(this.deserializationPolicy) {
case DistributedCacheOperation.DESERIALIZATION_POLICY_LAZY:
event.setSerializedNewValue(getValBytes());
break;
case DistributedCacheOperation.DESERIALIZATION_POLICY_NONE:
event.setNewValue(getValBytes());
break;
default:
throw new AssertionError("unknown deserialization policy: " + deserializationPolicy);
}
}
try {
// the event must show it's true origin for cachewriter invocation
// event.setOriginRemote(true);
// this.op = r.doCacheWriteBeforePut(event, ifNew); // TODO fix this for bug 37072
result = r.getDataView().putEntry(event, this.ifNew, this.ifOld, this.expectedOldValue, this.requireOldValue, this.lastModified, true);
if (!this.result) {
// make sure the region hasn't gone away
r.checkReadiness();
if (!this.ifNew && !this.ifOld) {
// no reason to be throwing an exception, so let's retry
RemoteOperationException fre = new RemoteOperationException(LocalizedStrings.RemotePutMessage_UNABLE_TO_PERFORM_PUT_BUT_OPERATION_SHOULD_NOT_FAIL_0.toLocalizedString());
fre.setHash(key.hashCode());
sendReply(getSender(), getProcessorId(), dm, new ReplyException(fre), r, startTime);
}
}
} catch (CacheWriterException cwe) {
sendReply(getSender(), getProcessorId(), dm, new ReplyException(cwe), r, startTime);
return false;
} catch (PrimaryBucketException pbe) {
sendReply(getSender(), getProcessorId(), dm, new ReplyException(pbe), r, startTime);
return false;
}
// set operation for reply message
setOperation(event.getOperation());
if (sendReply) {
sendReply(getSender(), getProcessorId(), dm, null, r, startTime, event);
}
return false;
} finally {
// OFFHEAP this may be too soon to make this call
this.event.release();
}
}
use of org.apache.geode.cache.CacheWriterException in project geode by apache.
the class BaseCommand method execute.
@Override
public void execute(Message clientMessage, ServerConnection serverConnection) {
// Read the request and update the statistics
long start = DistributionStats.getStatTime();
if (EntryLogger.isEnabled() && serverConnection != null) {
EntryLogger.setSource(serverConnection.getMembershipID(), "c2s");
}
boolean shouldMasquerade = shouldMasqueradeForTx(clientMessage, serverConnection);
try {
if (shouldMasquerade) {
InternalCache cache = serverConnection.getCache();
InternalDistributedMember member = (InternalDistributedMember) serverConnection.getProxyID().getDistributedMember();
TXManagerImpl txMgr = cache.getTxManager();
TXStateProxy tx = null;
try {
tx = txMgr.masqueradeAs(clientMessage, member, false);
cmdExecute(clientMessage, serverConnection, start);
tx.updateProxyServer(txMgr.getMemberId());
} finally {
txMgr.unmasquerade(tx);
}
} else {
cmdExecute(clientMessage, serverConnection, start);
}
} catch (TransactionException | CopyException | SerializationException | CacheWriterException | CacheLoaderException | GemFireSecurityException | PartitionOfflineException | MessageTooLargeException e) {
handleExceptionNoDisconnect(clientMessage, serverConnection, e);
} catch (EOFException eof) {
BaseCommand.handleEOFException(clientMessage, serverConnection, eof);
} catch (InterruptedIOException e) {
// Solaris only
BaseCommand.handleInterruptedIOException(serverConnection, e);
} catch (IOException e) {
BaseCommand.handleIOException(clientMessage, serverConnection, e);
} catch (DistributedSystemDisconnectedException e) {
BaseCommand.handleShutdownException(clientMessage, serverConnection, e);
} catch (VirtualMachineError err) {
SystemFailure.initiateFailure(err);
// now, so don't let this thread continue.
throw err;
} catch (Throwable e) {
BaseCommand.handleThrowable(clientMessage, serverConnection, e);
} finally {
EntryLogger.clearSource();
}
}
use of org.apache.geode.cache.CacheWriterException in project geode by apache.
the class LocalRegion method localDestroy.
@Override
public void localDestroy(Object key, Object aCallbackArgument) throws EntryNotFoundException {
validateKey(key);
checkReadiness();
checkForNoAccess();
@Released EntryEventImpl event = EntryEventImpl.create(this, Operation.LOCAL_DESTROY, key, null, aCallbackArgument, false, getMyId());
if (generateEventID()) {
event.setNewEventId(this.cache.getDistributedSystem());
}
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);
} finally {
event.release();
}
}
use of org.apache.geode.cache.CacheWriterException in project geode by apache.
the class RemoteTransactionDUnitTest method testOriginRemoteIsTrueForRemoteReplicatedRegions.
@Test
public void testOriginRemoteIsTrueForRemoteReplicatedRegions() {
Host host = Host.getHost(0);
VM accessor = host.getVM(0);
VM datastore = host.getVM(1);
initAccessorAndDataStore(accessor, datastore, 0);
class OriginRemoteRRWriter extends CacheWriterAdapter {
int fireC = 0;
int fireD = 0;
int fireU = 0;
public void beforeCreate(EntryEvent event) throws CacheWriterException {
if (!event.isOriginRemote()) {
throw new CacheWriterException("SUP?? This CREATE is supposed to be isOriginRemote");
}
fireC++;
}
public void beforeDestroy(EntryEvent event) throws CacheWriterException {
getGemfireCache().getLoggerI18n().fine("SWAP:writer:createEvent:" + event);
if (!event.isOriginRemote()) {
throw new CacheWriterException("SUP?? This DESTROY is supposed to be isOriginRemote");
}
fireD++;
}
public void beforeUpdate(EntryEvent event) throws CacheWriterException {
if (!event.isOriginRemote()) {
throw new CacheWriterException("SUP?? This UPDATE is supposed to be isOriginRemote");
}
fireU++;
}
}
datastore.invoke(new SerializableCallable() {
public Object call() throws Exception {
Region refRegion = getCache().getRegion(D_REFERENCE);
refRegion.getAttributesMutator().setCacheWriter(new OriginRemoteRRWriter());
return null;
}
});
accessor.invoke(new DoOpsInTX(OP.PUT));
accessor.invoke(new SerializableCallable() {
public Object call() throws Exception {
TXManagerImpl mgr = getGemfireCache().getTxManager();
TXStateProxy tx = mgr.internalSuspend();
assertNotNull(tx);
mgr.internalResume(tx);
mgr.commit();
return null;
}
});
accessor.invoke(new DoOpsInTX(OP.DESTROY));
accessor.invoke(new SerializableCallable() {
public Object call() throws Exception {
TXManagerImpl mgr = getGemfireCache().getTxManager();
TXStateProxy tx = mgr.internalSuspend();
assertNotNull(tx);
mgr.internalResume(tx);
mgr.commit();
return null;
}
});
accessor.invoke(new DoOpsInTX(OP.PUT));
accessor.invoke(new SerializableCallable() {
public Object call() throws Exception {
TXManagerImpl mgr = getGemfireCache().getTxManager();
TXStateProxy tx = mgr.internalSuspend();
assertNotNull(tx);
mgr.internalResume(tx);
mgr.commit();
return null;
}
});
datastore.invoke(new SerializableCallable() {
public Object call() throws Exception {
Region refRegion = getCache().getRegion(D_REFERENCE);
OriginRemoteRRWriter w = (OriginRemoteRRWriter) refRegion.getAttributes().getCacheWriter();
assertEquals(1, w.fireC);
assertEquals(1, w.fireD);
assertEquals(1, w.fireU);
return null;
}
});
}
use of org.apache.geode.cache.CacheWriterException in project geode by apache.
the class PutAllCSDUnitTest method testClientDestroyOfUncreatedEntry.
/**
* Checks to see if a client does a destroy that throws an exception from CacheWriter
* beforeDestroy that the size of the region is still correct. See bug 51583.
*/
@Test
public void testClientDestroyOfUncreatedEntry() throws CacheException, InterruptedException {
final String title = "testClientDestroyOfUncreatedEntry:";
final Host host = Host.getHost(0);
final VM server1 = host.getVM(0);
final VM client1 = host.getVM(1);
final String regionName = getUniqueName();
final String serverHost = NetworkUtils.getServerHostName(server1.getHost());
// set <true, false> means <PR=true, notifyBySubscription=false> to test local-invalidates
final int serverPort1 = createBridgeServer(server1, regionName, 0, false, 0, null);
createClient(client1, regionName, serverHost, new int[] { serverPort1 }, -1, -1, false, true, true);
server1.invoke(addExceptionTag1(expectedExceptions));
client1.invoke(addExceptionTag1(expectedExceptions));
server1.invoke(new CacheSerializableRunnable(title + "server1 add cacheWriter") {
@Override
public void run2() throws CacheException {
Region region = getRootRegion().getSubregion(regionName);
// Install cacheWriter that causes the very first destroy to fail
region.getAttributesMutator().setCacheWriter(new MyWriter(0));
}
});
assertEquals(0, getRegionSize(server1, regionName));
client1.invoke(new CacheSerializableRunnable(title + "client1 destroy") {
@Override
public void run2() throws CacheException {
Region region = getRootRegion().getSubregion(regionName);
try {
region.destroy("bogusKey");
fail("Expect ServerOperationException caused by CacheWriterException");
} catch (ServerOperationException expected) {
assertTrue(expected.getCause() instanceof CacheWriterException);
}
}
});
assertEquals(0, getRegionSize(server1, regionName));
server1.invoke(removeExceptionTag1(expectedExceptions));
client1.invoke(removeExceptionTag1(expectedExceptions));
stopBridgeServers(getCache());
}
Aggregations