use of org.apache.geode.internal.cache.TXStateProxy in project geode by apache.
the class JCALocalTransaction method commit.
@Override
public void commit() throws ResourceException {
LogWriter logger = this.cache.getLogger();
if (logger.fineEnabled()) {
logger.fine("JCALocalTransaction:invoked commit");
}
TXStateProxy tsp = this.gfTxMgr.getTXState();
if (tsp != null && this.tid != tsp.getTransactionId()) {
throw new IllegalStateException("Local Transaction associated with Tid = " + this.tid + " attempting to commit a different transaction");
}
try {
this.gfTxMgr.commit();
this.tid = null;
} catch (Exception e) {
// TODO: consider wrapping the cause
throw new LocalTransactionException(e.toString());
}
}
use of org.apache.geode.internal.cache.TXStateProxy in project geode by apache.
the class JCALocalTransaction method rollback.
@Override
public void rollback() throws ResourceException {
TXStateProxy tsp = this.gfTxMgr.getTXState();
if (tsp != null && this.tid != tsp.getTransactionId()) {
throw new IllegalStateException("Local Transaction associated with Tid = " + this.tid + " attempting to commit a different transaction");
}
LogWriter logger = this.cache.getLogger();
if (logger.fineEnabled()) {
logger.fine("JCALocalTransaction:invoked rollback");
}
try {
this.gfTxMgr.rollback();
} catch (IllegalStateException ise) {
// It is possible that the GFE transaction has already been rolled back.
if (ise.getMessage().equals(LocalizedStrings.TXManagerImpl_THREAD_DOES_NOT_HAVE_AN_ACTIVE_TRANSACTION.toLocalizedString())) {
// ignore
} else {
throw new ResourceException(ise);
}
} catch (RuntimeException e) {
throw new ResourceException(e);
} finally {
this.tid = null;
}
}
use of org.apache.geode.internal.cache.TXStateProxy in project geode by apache.
the class ServerRegionProxy method recordTXOperation.
/** test hook */
private void recordTXOperation(ServerRegionOperation op, Object key, Object... arguments) {
if (ClientTXStateStub.transactionRecordingEnabled()) {
TXStateProxy tx = TXManagerImpl.getCurrentTXState();
if (tx == null) {
return;
}
tx.recordTXOperation(this, op, key, arguments);
}
}
use of org.apache.geode.internal.cache.TXStateProxy in project geode by apache.
the class OpExecutorImpl method executeWithServerAffinity.
/**
* execute the given op on the given server. If the server cannot be reached, sends a
* TXFailoverOp, then retries the given op
*
* @param loc the server to execute the op on
* @param op the op to execute
* @return the result of execution
*/
private Object executeWithServerAffinity(ServerLocation loc, Op op) {
try {
Object retVal = executeOnServer(loc, op, true, false);
affinityRetryCount.set(0);
return retVal;
} catch (ServerConnectivityException e) {
if (logger.isDebugEnabled()) {
logger.debug("caught exception while executing with affinity:{}", e.getMessage(), e);
}
if (!this.serverAffinityFailover || e instanceof ServerOperationException) {
affinityRetryCount.set(0);
throw e;
}
int retryCount = affinityRetryCount.get();
if ((retryAttempts != -1 && retryCount >= retryAttempts) || retryCount > TX_RETRY_ATTEMPT) {
// prevent
// stack
// overflow
// fixes
// bug
// 46535
affinityRetryCount.set(0);
throw e;
}
affinityRetryCount.set(retryCount + 1);
}
this.affinityServerLocation.set(null);
if (logger.isDebugEnabled()) {
logger.debug("reset server affinity: attempting txFailover");
}
// send TXFailoverOp, so that new server can
// do bootstrapping, then re-execute original op
AbstractOp absOp = (AbstractOp) op;
absOp.getMessage().setIsRetry();
int transactionId = absOp.getMessage().getTransactionId();
// so set it explicitly for TXFailoverOp
try {
TXFailoverOp.execute(this.pool, transactionId);
} catch (TransactionException e) {
// If this is the first operation in the transaction then
// do not throw TransactionDataNodeHasDeparted back to the
// user, re-try the op instead. fixes bug 44375. NOTE: TXFailoverOp
// is sent even after first op, as it is not known if the first
// operation has established a TXState already
TXStateProxy txState = TXManagerImpl.getCurrentTXState();
if (txState == null) {
throw e;
} else if (txState.operationCount() > 1) {
throw e;
}
}
if (op instanceof ExecuteRegionFunctionOpImpl) {
op = new ExecuteRegionFunctionOpImpl((ExecuteRegionFunctionOpImpl) op, (byte) 1, /* isReExecute */
new HashSet<String>());
((ExecuteRegionFunctionOpImpl) op).getMessage().setTransactionId(transactionId);
} else if (op instanceof ExecuteFunctionOpImpl) {
op = new ExecuteFunctionOpImpl((ExecuteFunctionOpImpl) op, (byte) 1);
((ExecuteFunctionOpImpl) op).getMessage().setTransactionId(transactionId);
}
return this.pool.execute(op);
}
use of org.apache.geode.internal.cache.TXStateProxy in project geode by apache.
the class IndexManager method processAction.
/**
* @param opCode one of IndexProtocol.OTHER_OP, BEFORE_UPDATE_OP, AFTER_UPDATE_OP.
*/
private void processAction(RegionEntry entry, int action, int opCode) throws QueryException {
final long startPA = getCachePerfStats().startIndexUpdate();
DefaultQuery.setPdxReadSerialized(this.region.getCache(), true);
TXStateProxy tx = null;
if (!((InternalCache) this.region.getCache()).isClient()) {
tx = ((TXManagerImpl) this.region.getCache().getCacheTransactionManager()).internalSuspend();
}
try {
// creation thread
if (IndexManager.testHook != null) {
if (logger.isDebugEnabled()) {
logger.debug("IndexManager TestHook is set.");
}
// ConcurrentIndexInitOnOverflowRegionDUnitTest
testHook.hook(6);
}
long start = 0;
boolean indexLockAcquired = false;
switch(action) {
case ADD_ENTRY:
{
if (IndexManager.testHook != null) {
if (logger.isDebugEnabled()) {
logger.debug("IndexManager TestHook in ADD_ENTRY.");
}
testHook.hook(5);
}
// this action is only called after update
assert opCode == IndexProtocol.OTHER_OP;
// Asif The behaviour can arise if an index creation has already
// acted upon a newly added entry , but by the time callback
// occurs , the index is added to the map & thus
// the add operation will now have an effect of update.
// so we need to remove the mapping even if it is an Add action
// as otherwise the new results will get added into the
// old results instead of replacement
Iterator iter = this.indexes.values().iterator();
while (iter.hasNext()) {
Object ind = iter.next();
// the index is in create phase.
if (ind instanceof FutureTask) {
continue;
}
IndexProtocol index = (IndexProtocol) ind;
if (((AbstractIndex) index).isPopulated() && index.getType() != IndexType.PRIMARY_KEY) {
// apply IMQ on it
if (!index.containsEntry(entry)) {
if (logger.isDebugEnabled()) {
logger.debug("Adding to index: {}{} value: {}", index.getName(), this.region.getFullPath(), entry.getKey());
}
start = ((AbstractIndex) index).updateIndexUpdateStats();
index.addIndexMapping(entry);
((AbstractIndex) index).updateIndexUpdateStats(start);
}
}
}
break;
}
case UPDATE_ENTRY:
{
if (IndexManager.testHook != null) {
if (logger.isDebugEnabled()) {
logger.debug("IndexManager TestHook in UPDATE_ENTRY.");
}
testHook.hook(5);
// QueryDataInconsistencyDUnitTest
testHook.hook(9);
}
// this action is only called with opCode AFTER_UPDATE_OP
assert opCode == IndexProtocol.AFTER_UPDATE_OP;
Iterator iter = this.indexes.values().iterator();
while (iter.hasNext()) {
Object ind = iter.next();
// the index is in create phase.
if (ind instanceof FutureTask) {
continue;
}
IndexProtocol index = (IndexProtocol) ind;
if (((AbstractIndex) index).isPopulated() && index.getType() != IndexType.PRIMARY_KEY) {
if (logger.isDebugEnabled()) {
logger.debug("Updating index: {}{} value: {}", index.getName(), this.region.getFullPath(), entry.getKey());
}
start = ((AbstractIndex) index).updateIndexUpdateStats();
index.addIndexMapping(entry);
((AbstractIndex) index).updateIndexUpdateStats(start);
}
}
break;
}
case REMOVE_ENTRY:
{
if (IndexManager.testHook != null) {
if (logger.isDebugEnabled()) {
logger.debug("IndexManager TestHook in REMOVE_ENTRY.");
}
testHook.hook(5);
testHook.hook(10);
}
Iterator iter = this.indexes.values().iterator();
while (iter.hasNext()) {
Object ind = iter.next();
// the index is in create phase.
if (ind instanceof FutureTask) {
continue;
}
IndexProtocol index = (IndexProtocol) ind;
if (((AbstractIndex) index).isPopulated() && index.getType() != IndexType.PRIMARY_KEY) {
AbstractIndex abstractIndex = (AbstractIndex) index;
if (logger.isDebugEnabled()) {
logger.debug("Removing from index: {}{} value: {}", index.getName(), this.region.getFullPath(), entry.getKey());
}
start = ((AbstractIndex) index).updateIndexUpdateStats();
index.removeIndexMapping(entry, opCode);
((AbstractIndex) index).updateIndexUpdateStats(start);
}
}
break;
}
default:
{
throw new IndexMaintenanceException(LocalizedStrings.IndexManager_INVALID_ACTION.toLocalizedString());
}
}
} finally {
DefaultQuery.setPdxReadSerialized(this.region.getCache(), false);
if (tx != null) {
((TXManagerImpl) this.region.getCache().getCacheTransactionManager()).internalResume(tx);
}
getCachePerfStats().endIndexUpdate(startPA);
}
}
Aggregations