use of org.apache.geode.cache.UnsupportedOperationInTransactionException in project geode by apache.
the class DistTXCommitMessage method operateOnTx.
@Override
protected boolean operateOnTx(TXId txId, DistributionManager dm) throws RemoteOperationException {
if (logger.isDebugEnabled()) {
logger.debug("DistTXCommitMessage.operateOnTx: Tx {}", txId);
}
InternalCache cache = GemFireCacheImpl.getInstance();
TXManagerImpl txMgr = cache.getTXMgr();
final TXStateProxy txStateProxy = txMgr.getTXState();
TXCommitMessage cmsg = null;
try {
// do the actual commit, only if it was not done before
if (txMgr.isHostedTxRecentlyCompleted(txId)) {
if (logger.isDebugEnabled()) {
logger.debug("DistTXCommitMessage.operateOnTx: found a previously committed transaction:{}", txId);
}
cmsg = txMgr.getRecentlyCompletedMessage(txId);
if (txMgr.isExceptionToken(cmsg)) {
throw txMgr.getExceptionForToken(cmsg, txId);
}
} else {
// that don't start remote TX) then ignore
if (txStateProxy != null) {
/*
* [DISTTX] TODO See how other exceptions are caught and send on wire, than throwing?
*
* This can be spared since it will be programming bug
*/
if (!txStateProxy.isDistTx() || txStateProxy.isCreatedOnDistTxCoordinator()) {
throw new UnsupportedOperationInTransactionException(LocalizedStrings.DISTTX_TX_EXPECTED.toLocalizedString("DistTXStateProxyImplOnDatanode", txStateProxy.getClass().getSimpleName()));
}
if (logger.isDebugEnabled()) {
logger.debug("DistTXCommitMessage.operateOnTx Commiting {} " + " incoming entryEventList:{} coming from {} ", txId, DistTXStateProxyImplOnCoordinator.printEntryEventList(this.entryStateList), this.getSender().getId());
}
// Set Member's ID to all entry states
String memberID = this.getSender().getId();
for (ArrayList<DistTxThinEntryState> esList : this.entryStateList) {
for (DistTxThinEntryState es : esList) {
es.setMemberID(memberID);
}
}
((DistTXStateProxyImplOnDatanode) txStateProxy).populateDistTxEntryStates(this.entryStateList);
txStateProxy.setCommitOnBehalfOfRemoteStub(true);
txMgr.commit();
cmsg = txStateProxy.getCommitMessage();
}
}
} finally {
txMgr.removeHostedTXState(txId);
}
DistTXCommitReplyMessage.send(getSender(), getProcessorId(), cmsg, getReplySender(dm));
/*
* return false so there isn't another reply
*/
return false;
}
use of org.apache.geode.cache.UnsupportedOperationInTransactionException in project geode by apache.
the class TXStateStub method destroyExistingEntry.
/*
* (non-Javadoc)
*
* @see
* org.apache.geode.internal.cache.TXStateInterface#destroyExistingEntry(org.apache.geode.internal
* .cache.EntryEventImpl, boolean, java.lang.Object)
*/
public void destroyExistingEntry(EntryEventImpl event, boolean cacheWrite, Object expectedOldValue) throws EntryNotFoundException {
if (event.getOperation().isLocal()) {
throw new UnsupportedOperationInTransactionException(LocalizedStrings.TXStateStub_LOCAL_DESTROY_NOT_ALLOWED_IN_TRANSACTION.toLocalizedString());
}
TXRegionStub rs = getTXRegionStub(event.getRegion());
rs.destroyExistingEntry(event, cacheWrite, expectedOldValue);
}
use of org.apache.geode.cache.UnsupportedOperationInTransactionException in project geode by apache.
the class TXJUnitTest method testDestroyRegionNotSupported.
/**
* make sure that we throw an UnsupportedOperationInTransactionException
*
* @throws Exception
*/
@Test
public void testDestroyRegionNotSupported() 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());
List list = new ArrayList();
list.add("stuff");
list.add("stuff2");
ctm.begin();
try {
pr.destroyRegion();
fail("Should have thrown UnsupportedOperationInTransactionException during destroyRegion");
} catch (UnsupportedOperationInTransactionException ee) {
// expected
}
try {
pr.localDestroyRegion();
fail("Should have thrown UnsupportedOperationInTransactionException during localDestroyRegion");
} catch (UnsupportedOperationInTransactionException ee) {
// expected
}
try {
r.destroyRegion();
fail("Should have thrown UnsupportedOperationInTransactionException during destroyRegion");
} catch (UnsupportedOperationInTransactionException ee) {
// expected
}
try {
r.localDestroyRegion();
fail("Should have thrown UnsupportedOperationInTransactionException during localDestroyRegion");
} catch (UnsupportedOperationInTransactionException ee) {
// expected
}
assertTrue(!pr.isDestroyed());
assertTrue(!r.isDestroyed());
ctm.commit();
// now we aren't in tx so these shouldn't throw
pr.destroyRegion();
r.destroyRegion();
}
use of org.apache.geode.cache.UnsupportedOperationInTransactionException in project geode by apache.
the class TXJUnitTest method testInvalidateRegionNotSupported.
/**
* make sure that we throw an UnsupportedOperationInTransactionException
*
* @throws Exception
*/
@Test
public void testInvalidateRegionNotSupported() 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.invalidateRegion();
fail("Should have thrown UnsupportedOperationInTransactionException during invalidateRegion");
} catch (UnsupportedOperationInTransactionException ee) {
// expected
}
try {
pr.localInvalidateRegion();
fail("Should have thrown UnsupportedOperationInTransactionException during localInvalidateRegion");
} catch (UnsupportedOperationInTransactionException ee) {
// expected
}
try {
r.invalidateRegion();
fail("Should have thrown UnsupportedOperationInTransactionException during invalidateRegion");
} catch (UnsupportedOperationInTransactionException ee) {
// expected
}
try {
r.localInvalidateRegion();
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 ExecutionHandlerContext method executeWithTransaction.
private void executeWithTransaction(ChannelHandlerContext ctx, final Executor exec, Command command) throws Exception {
CacheTransactionManager txm = cache.getCacheTransactionManager();
TransactionId transactionId = getTransactionID();
txm.resume(transactionId);
try {
exec.executeCommand(command, this);
} catch (UnsupportedOperationInTransactionException e) {
command.setResponse(Coder.getErrorResponse(this.byteBufAllocator, RedisConstants.ERROR_UNSUPPORTED_OPERATION_IN_TRANSACTION));
} catch (TransactionException e) {
command.setResponse(Coder.getErrorResponse(this.byteBufAllocator, RedisConstants.ERROR_TRANSACTION_EXCEPTION));
} catch (Exception e) {
ByteBuf response = getExceptionResponse(ctx, e);
command.setResponse(response);
}
getTransactionQueue().add(command);
transactionId = txm.suspend();
setTransactionID(transactionId);
}
Aggregations