Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TransactionServiceImp optimisations #199

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@

import java.util.HashMap;
import java.util.HashSet;
import java.util.Hashtable;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
import java.util.Stack;
import java.util.concurrent.ConcurrentHashMap;

import com.atomikos.finitestates.FSMEnterEvent;
import com.atomikos.finitestates.FSMEnterListener;
Expand Down Expand Up @@ -55,7 +55,7 @@ public class TransactionServiceImp implements TransactionServiceProvider,

private long maxTimeout_;
private Object[] rootLatches_ = null;
private Hashtable<String,CompositeTransaction> tidToTransactionMap_ = null;
private Map<String,CompositeTransaction> tidToTransactionMap_;
private Map<String, CoordinatorImp> recreatedCoordinatorsByRootId = new HashMap<>();
private Map<String, CoordinatorImp> allCoordinatorsByCoordinatorId = new HashMap<>();
private boolean shutdownInProgress_ = false;
Expand Down Expand Up @@ -91,7 +91,7 @@ public class TransactionServiceImp implements TransactionServiceProvider,
* configurations that do not support orphan detection.
* @param single_threaded_2pc
* Whether 2PC commit should happen in the same thread that started the tx.
* @param recoveryLog2
* @param recoveryLog
*
*/

Expand All @@ -105,7 +105,7 @@ public TransactionServiceImp ( String name ,
initialized_ = false;
recoverymanager_ = recoverymanager;
tidmgr_ = tidmgr;
tidToTransactionMap_ = new Hashtable<String,CompositeTransaction>();
tidToTransactionMap_ = new ConcurrentHashMap<>();
rootLatches_ = new Object[NUMLATCHES];
for (int i = 0; i < NUMLATCHES; i++) {
rootLatches_[i] = new Object();
Expand Down Expand Up @@ -144,12 +144,10 @@ private Object getLatch ( String root )
private void setTidToTx ( String tid , CompositeTransaction ct )
throws IllegalStateException
{
synchronized ( tidToTransactionMap_ ) {
if ( tidToTransactionMap_.containsKey ( tid.intern () ) )
throw new IllegalStateException ( "Already mapped: " + tid );
tidToTransactionMap_.put ( tid.intern (), ct );
ct.addSubTxAwareParticipant(this); // for GC purposes
}
if (tidToTransactionMap_.containsKey(tid.intern()))
throw new IllegalStateException("Already mapped: " + tid);
tidToTransactionMap_.put(tid.intern(), ct);
ct.addSubTxAwareParticipant(this); // for GC purposes
}

/**
Expand Down Expand Up @@ -215,11 +213,9 @@ private CompositeTransactionImp createCT ( String tid ,
*
* @param recoveryDomainName The recovery domain of the superior of this coordinator.
*
* @param RecoveryCoordinator
* @param adaptor
* An existing coordinator for the given root. Null if not a
* subtx, or an <b>adaptor</b> in other cases.
* @param lineage
* The ancestor information.
* @param root
* The root id.
* @param timeout
Expand All @@ -232,7 +228,7 @@ private CompositeTransactionImp createCT ( String tid ,
private CoordinatorImp createCC (String recoveryDomainName, RecoveryCoordinator adaptor ,
String root, long timeout )
{
CoordinatorImp cc = null;
CoordinatorImp cc;

if (maxTimeout_ > 0 && timeout > maxTimeout_ ) {
timeout = maxTimeout_;
Expand Down Expand Up @@ -387,7 +383,7 @@ public Participant getParticipant ( String root ) throws SysException
}

/**
* @see FSMEnterListener.
* @see FSMEnterListener
*/

public void entered ( FSMEnterEvent event )
Expand Down Expand Up @@ -426,13 +422,7 @@ public void rolledback ( CompositeTransaction tx )

public CompositeTransaction getCompositeTransaction ( String tid )
{
CompositeTransaction ret = null;

synchronized ( tidToTransactionMap_ ) {
ret = (CompositeTransaction) tidToTransactionMap_.get ( tid.intern () );
}

return ret;
return tidToTransactionMap_.get(tid.intern());
}


Expand All @@ -447,7 +437,7 @@ public CompositeTransaction getCompositeTransaction ( String tid )
CompositeTransaction createSubTransaction ( CompositeTransaction parent )
{
if (Configuration.getConfigProperties().getAllowSubTransactions()) {
CompositeTransactionImp ret = null;
CompositeTransactionImp ret;
Stack<CompositeTransaction> lineage = (Stack<CompositeTransaction>) parent.getLineage ().clone ();
lineage.push ( parent );
String tid = tidmgr_.get ();
Expand Down Expand Up @@ -484,8 +474,8 @@ public synchronized CompositeTransaction recreateCompositeTransaction (Propagati
throw new IllegalStateException (
"Max number of active transactions reached:" + maxNumberOfActiveTransactions_ );

CoordinatorImp cc = null;
CompositeTransaction ct = null;
CoordinatorImp cc;
CompositeTransaction ct;

try {
String tid = tidmgr_.get ();
Expand Down Expand Up @@ -634,7 +624,7 @@ public CompositeTransaction createCompositeTransaction ( long timeout ) throws S
}

String tid = tidmgr_.get ();
Stack<CompositeTransaction> lineage = new Stack<CompositeTransaction>();
Stack<CompositeTransaction> lineage = new Stack<>();
// create a CC with heuristic preference set to false,
// since it does not really matter anyway (since we are
// creating a root)
Expand Down