use of org.apache.geode.cache.UnsupportedOperationInTransactionException in project geode by apache.
the class DelExecutor method executeCommand.
@Override
public void executeCommand(Command command, ExecutionHandlerContext context) {
if (context.hasTransaction())
throw new UnsupportedOperationInTransactionException();
List<byte[]> commandElems = command.getProcessedCommand();
if (commandElems.size() < 2) {
command.setResponse(Coder.getErrorResponse(context.getByteBufAllocator(), ArityDef.DEL));
return;
}
int numRemoved = 0;
for (int i = 1; i < commandElems.size(); i++) {
byte[] byteKey = commandElems.get(i);
ByteArrayWrapper key = new ByteArrayWrapper(byteKey);
RedisDataType type = context.getRegionProvider().getRedisDataType(key);
if (removeEntry(key, type, context))
numRemoved++;
}
command.setResponse(Coder.getIntegerResponse(context.getByteBufAllocator(), numRemoved));
}
use of org.apache.geode.cache.UnsupportedOperationInTransactionException in project geode by apache.
the class FlushAllExecutor method executeCommand.
@Override
public void executeCommand(Command command, ExecutionHandlerContext context) {
if (context.hasTransaction())
throw new UnsupportedOperationInTransactionException();
for (Entry<String, RedisDataType> e : context.getRegionProvider().metaEntrySet()) {
try {
String skey = e.getKey();
RedisDataType type = e.getValue();
removeEntry(Coder.stringToByteWrapper(skey), type, context);
} catch (EntryDestroyedException e1) {
continue;
}
}
command.setResponse(Coder.getSimpleStringResponse(context.getByteBufAllocator(), "OK"));
}
use of org.apache.geode.cache.UnsupportedOperationInTransactionException in project geode by apache.
the class TXJUnitTest method testClearRegionNotSupported.
/**
* make sure that we throw an UnsupportedOperationInTransactionException
*
* @throws Exception
*/
@Test
public void testClearRegionNotSupported() throws Exception {
CacheTransactionManager ctm = this.cache.getCacheTransactionManager();
AttributesFactory af = new AttributesFactory();
Region r = this.cache.createRegion("dRegion", af.create());
PartitionAttributes pa = new PartitionAttributesFactory().setRedundantCopies(0).setTotalNumBuckets(1).create();
af.setPartitionAttributes(pa);
Region pr = this.cache.createRegion("prRegion", af.create());
ctm.begin();
try {
pr.clear();
fail("Should have thrown UnsupportedOperation during invalidateRegion");
} catch (UnsupportedOperationException ee) {
// expected
}
try {
pr.localClear();
fail("Should have thrown UnsupportedOperation during localInvalidateRegion");
} catch (UnsupportedOperationException ee) {
// expected
}
try {
r.clear();
fail("Should have thrown UnsupportedOperationInTransactionException during invalidateRegion");
} catch (UnsupportedOperationInTransactionException ee) {
// expected
}
try {
r.localClear();
fail("Should have thrown UnsupportedOperationInTransactionException during localInvalidateRegion");
} catch (UnsupportedOperationInTransactionException ee) {
// expected
}
ctm.commit();
// now we aren't in tx so these shouldn't throw
pr.invalidateRegion();
r.invalidateRegion();
}
use of org.apache.geode.cache.UnsupportedOperationInTransactionException in project geode by apache.
the class Bug34387DUnitTest method doCommitOtherVm.
private void doCommitOtherVm(final boolean doDestroy) {
VM vm = getOtherVm();
vm.invoke(new CacheSerializableRunnable("create root") {
public void run2() throws CacheException {
AttributesFactory af = new AttributesFactory();
af.setScope(Scope.DISTRIBUTED_ACK);
af.setConcurrencyChecksEnabled(true);
Region r1 = createRootRegion("r1", af.create());
CacheTransactionManager ctm = getCache().getCacheTransactionManager();
ctm.begin();
r1.create("createKey", "createValue");
if (doDestroy) {
try {
r1.localDestroy("createKey");
fail("expected exception not thrown");
} catch (UnsupportedOperationInTransactionException e) {
assertEquals(e.getMessage(), LocalizedStrings.TXStateStub_LOCAL_DESTROY_NOT_ALLOWED_IN_TRANSACTION.toLocalizedString());
}
} else {
try {
r1.localInvalidate("createKey");
fail("expected exception not thrown");
} catch (UnsupportedOperationInTransactionException e) {
assertEquals(e.getMessage(), LocalizedStrings.TXStateStub_LOCAL_INVALIDATE_NOT_ALLOWED_IN_TRANSACTION.toLocalizedString());
}
}
ctm.commit();
}
});
}
use of org.apache.geode.cache.UnsupportedOperationInTransactionException in project geode by apache.
the class DistTXStateProxyImplOnCoordinator method rollback.
@Override
public void rollback() {
if (logger.isDebugEnabled()) {
logger.debug("DistTXStateProxyImplOnCoordinator.rollback Going for rollback ");
}
boolean finalResult = false;
final GemFireCacheImpl cache = GemFireCacheImpl.getExisting("Applying Dist TX Rollback");
final DM dm = cache.getDistributionManager();
try {
// Create Tx Participants
Set<DistributedMember> txRemoteParticpants = getTxRemoteParticpants(dm);
// create processor and rollback message
DistTXRollbackMessage.DistTxRollbackReplyProcessor processor = new DistTXRollbackMessage.DistTxRollbackReplyProcessor(this.getTxId(), dm, txRemoteParticpants, target2realDeals);
// TODO [DISTTX} whats ack threshold?
processor.enableSevereAlertProcessing();
final DistTXRollbackMessage rollbackMsg = new DistTXRollbackMessage(this.getTxId(), this.onBehalfOfClientMember, processor);
// send rollback message to remote nodes
for (DistributedMember remoteNode : txRemoteParticpants) {
DistTXCoordinatorInterface remoteTXStateStub = target2realDeals.get(remoteNode);
if (remoteTXStateStub.isTxState()) {
throw new UnsupportedOperationInTransactionException(LocalizedStrings.DISTTX_TX_EXPECTED.toLocalizedString("DistPeerTXStateStub", remoteTXStateStub.getClass().getSimpleName()));
}
try {
remoteTXStateStub.setRollbackMessage(rollbackMsg, dm);
remoteTXStateStub.rollback();
} finally {
remoteTXStateStub.setRollbackMessage(null, null);
remoteTXStateStub.finalCleanup();
}
if (logger.isDebugEnabled()) {
// TODO - make this trace level
logger.debug("DistTXStateProxyImplOnCoordinator.rollback target = " + remoteNode);
}
}
// Do rollback on local node
DistTXCoordinatorInterface localTXState = target2realDeals.get(dm.getId());
if (localTXState != null) {
if (!localTXState.isTxState()) {
throw new UnsupportedOperationInTransactionException(LocalizedStrings.DISTTX_TX_EXPECTED.toLocalizedString("DistTXStateOnCoordinator", localTXState.getClass().getSimpleName()));
}
localTXState.rollback();
boolean localResult = localTXState.getRollbackResponse();
if (logger.isDebugEnabled()) {
logger.debug("DistTXStateProxyImplOnCoordinator.rollback local = " + dm.getId() + " ,result= " + localResult + " ,finalResult-old= " + finalResult);
}
finalResult = finalResult && localResult;
}
/*
* [DISTTX] TODO Any test hooks
*/
// if (internalAfterIndividualSend != null) {
// internalAfterIndividualSend.run();
// }
/*
* [DISTTX] TODO see how to handle exception
*/
/*
* [DISTTX] TODO Any test hooks
*/
// if (internalAfterIndividualCommitProcess != null) {
// // Testing callback
// internalAfterIndividualCommitProcess.run();
// }
{
// Wait for results
dm.getCancelCriterion().checkCancelInProgress(null);
processor.waitForPrecommitCompletion();
// [DISTTX} TODO Handle stats
// dm.getStats().incCommitWaits();
Map<DistributedMember, Boolean> remoteResults = processor.getRollbackResponseMap();
for (Entry<DistributedMember, Boolean> e : remoteResults.entrySet()) {
DistributedMember target = e.getKey();
Boolean remoteResult = e.getValue();
if (logger.isDebugEnabled()) {
// TODO - make this trace level
logger.debug("DistTXStateProxyImplOnCoordinator.rollback target = " + target + " ,result= " + remoteResult + " ,finalResult-old= " + finalResult);
}
finalResult = finalResult && remoteResult;
}
}
} finally {
inProgress = false;
if (this.synchRunnable != null) {
this.synchRunnable.abort();
}
}
if (logger.isDebugEnabled()) {
logger.debug("DistTXStateProxyImplOnCoordinator.rollback finalResult= " + finalResult);
}
}
Aggregations