AMQ-1063: Fixed journaled JDBC checkpoint which would mark inTx eager, which was wrong, as getting the JDBC connection may fail. So the mark inTx should only happen if getting the connection was succesful.

This commit is contained in:
Claus Ibsen 2013-11-03 11:54:14 +01:00
parent af1edf4588
commit d0f48b3ee5
1 changed files with 8 additions and 6 deletions

View File

@ -30,8 +30,6 @@ import org.slf4j.LoggerFactory;
/** /**
* Helps keep track of the current transaction/JDBC connection. * Helps keep track of the current transaction/JDBC connection.
*
*
*/ */
public class TransactionContext { public class TransactionContext {
@ -40,7 +38,7 @@ public class TransactionContext {
private final DataSource dataSource; private final DataSource dataSource;
private final JDBCPersistenceAdapter persistenceAdapter; private final JDBCPersistenceAdapter persistenceAdapter;
private Connection connection; private Connection connection;
private boolean inTx; private volatile boolean inTx;
private PreparedStatement addMessageStatement; private PreparedStatement addMessageStatement;
private PreparedStatement removedMessageStatement; private PreparedStatement removedMessageStatement;
private PreparedStatement updateLastAckStatement; private PreparedStatement updateLastAckStatement;
@ -68,12 +66,14 @@ public class TransactionContext {
IOException ioe = IOExceptionSupport.create(e); IOException ioe = IOExceptionSupport.create(e);
persistenceAdapter.getBrokerService().handleIOException(ioe); persistenceAdapter.getBrokerService().handleIOException(ioe);
throw ioe; throw ioe;
} }
try { try {
connection.setTransactionIsolation(transactionIsolation); connection.setTransactionIsolation(transactionIsolation);
} catch (Throwable e) { } catch (Throwable e) {
// ignore
LOG.trace("Cannot set transaction isolation to " + transactionIsolation + " due " + e.getMessage()
+ ". This exception is ignored.", e);
} }
} }
return connection; return connection;
@ -147,7 +147,8 @@ public class TransactionContext {
connection.close(); connection.close();
} }
} catch (Throwable e) { } catch (Throwable e) {
LOG.warn("Close failed: " + e.getMessage(), e); // ignore
LOG.trace("Closing connection failed due: " + e.getMessage() + ". This exception is ignored.", e);
} finally { } finally {
connection = null; connection = null;
} }
@ -159,8 +160,9 @@ public class TransactionContext {
if (inTx) { if (inTx) {
throw new IOException("Already started."); throw new IOException("Already started.");
} }
inTx = true;
connection = getConnection(); connection = getConnection();
// only mark in tx if we could get a connection
inTx = true;
} }
public void commit() throws IOException { public void commit() throws IOException {