use of org.apache.geode.internal.cache.TXEntryState.DistTxThinEntryState in project geode by apache.
the class DistTXStateProxyImplOnCoordinator method doPrecommit.
private boolean doPrecommit() {
boolean finalResult = true;
final GemFireCacheImpl cache = GemFireCacheImpl.getExisting("Applying Dist TX Precommit");
final DM dm = cache.getDistributionManager();
Set<DistributedMember> txRemoteParticpants = getTxRemoteParticpants(dm);
// create processor and precommit message
DistTXPrecommitMessage.DistTxPrecommitReplyProcessor processor = new DistTXPrecommitMessage.DistTxPrecommitReplyProcessor(this.getTxId(), dm, txRemoteParticpants, target2realDeals);
// TODO [DISTTX} whats ack threshold?
processor.enableSevereAlertProcessing();
final DistTXPrecommitMessage precommitMsg = new DistTXPrecommitMessage(this.getTxId(), this.onBehalfOfClientMember, processor);
// send precommit 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.setPrecommitMessage(precommitMsg, dm);
remoteTXStateStub.precommit();
} finally {
remoteTXStateStub.setPrecommitMessage(null, null);
}
if (logger.isDebugEnabled()) {
logger.debug("DistTXStateProxyImplOnCoordinator.doPrecommit Sent Message to target = " + remoteNode);
}
}
// Do precommit on local node
TreeSet<String> sortedRegionName = new TreeSet<>();
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.precommit();
boolean localResult = localTXState.getPreCommitResponse();
TreeMap<String, ArrayList<DistTxThinEntryState>> entryStateSortedMap = new TreeMap<String, ArrayList<DistTxThinEntryState>>();
ArrayList<ArrayList<DistTxThinEntryState>> entryEventList = null;
if (localResult) {
localResult = ((DistTXStateOnCoordinator) localTXState).populateDistTxEntryStateList(entryStateSortedMap);
if (localResult) {
entryEventList = new ArrayList<ArrayList<DistTxThinEntryState>>(entryStateSortedMap.values());
populateEntryEventMap(dm.getId(), entryEventList, sortedRegionName);
}
}
if (logger.isDebugEnabled()) {
logger.debug("DistTXStateProxyImplOnCoordinator.doPrecommit local = " + dm.getId() + " ,entryEventList=" + printEntryEventList(entryEventList) + " ,txRegionVersionsMap=" + printEntryEventMap(this.txEntryEventMap) + " ,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, DistTxPrecommitResponse> remoteResults = processor.getCommitResponseMap();
for (Entry<DistributedMember, DistTxPrecommitResponse> e : remoteResults.entrySet()) {
DistributedMember target = e.getKey();
DistTxPrecommitResponse remoteResponse = e.getValue();
ArrayList<ArrayList<DistTxThinEntryState>> entryEventList = remoteResponse.getDistTxEntryEventList();
populateEntryEventMap(target, entryEventList, sortedRegionName);
if (logger.isDebugEnabled()) {
logger.debug("DistTXStateProxyImplOnCoordinator.doPrecommit got reply from target = " + target + " ,sortedRegions" + sortedRegionName + " ,entryEventList=" + printEntryEventList(entryEventList) + " ,txEntryEventMap=" + printEntryEventMap(this.txEntryEventMap) + " ,result= " + remoteResponse.getCommitState() + " ,finalResult-old= " + finalResult);
}
finalResult = finalResult && remoteResponse.getCommitState();
}
}
if (logger.isDebugEnabled()) {
logger.debug("DistTXStateProxyImplOnCoordinator.doPrecommit finalResult= " + finalResult);
}
return finalResult;
}
use of org.apache.geode.internal.cache.TXEntryState.DistTxThinEntryState 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.internal.cache.TXEntryState.DistTxThinEntryState in project geode by apache.
the class TXRegionState method populateDistTxEntryStateList.
public boolean populateDistTxEntryStateList(ArrayList<DistTxThinEntryState> entryStateList) {
String regionFullPath = this.getRegion().getFullPath();
try {
if (!this.entryMods.isEmpty()) {
// [DISTTX] TODO Sort this first
for (Entry<Object, TXEntryState> em : this.entryMods.entrySet()) {
Object mKey = em.getKey();
TXEntryState txes = em.getValue();
DistTxThinEntryState thinEntryState = txes.getDistTxEntryStates();
entryStateList.add(thinEntryState);
if (logger.isDebugEnabled()) {
logger.debug("TXRegionState.populateDistTxEntryStateList Added " + thinEntryState + " for key=" + mKey + " ,op=" + txes.opToString() + " ,region=" + regionFullPath);
}
}
}
return true;
} catch (RegionDestroyedException ex) {
// region was destroyed out from under us; after conflict checking
// passed. So act as if the region destroy happened right after the
// commit. We act this way by doing nothing; including distribution
// of this region's commit data.
} catch (CancelException ex) {
// cache was closed out from under us; after conflict checking
// passed. So do nothing.
}
if (logger.isDebugEnabled()) {
logger.debug("TXRegionState.populateDistTxEntryStateList Got exception for region " + regionFullPath);
}
return false;
}
use of org.apache.geode.internal.cache.TXEntryState.DistTxThinEntryState in project geode by apache.
the class TXRegionState method setDistTxEntryStates.
public void setDistTxEntryStates(ArrayList<DistTxThinEntryState> entryEventList) {
String regionFullPath = this.getRegion().getFullPath();
int entryModsSize = this.entryMods.size();
int entryEventListSize = entryEventList.size();
if (entryModsSize != entryEventListSize) {
throw new UnsupportedOperationInTransactionException(LocalizedStrings.DISTTX_TX_EXPECTED.toLocalizedString("entry size of " + entryModsSize + " for region " + regionFullPath, entryEventListSize));
}
int index = 0;
// [DISTTX] TODO Sort this first
for (Entry<Object, TXEntryState> em : this.entryMods.entrySet()) {
Object mKey = em.getKey();
TXEntryState txes = em.getValue();
DistTxThinEntryState thinEntryState = entryEventList.get(index++);
txes.setDistTxEntryStates(thinEntryState);
if (logger.isDebugEnabled()) {
logger.debug("TxRegionState.setDistTxEntryStates Added " + thinEntryState + " for key=" + mKey + " ,op=" + txes.opToString() + " ,region=" + regionFullPath);
}
}
}
Aggregations