mirror of https://github.com/apache/activemq.git
Add patch with some tweaks submitted by Bernhard Trummer to clean up the logging for XA TX.
This commit is contained in:
parent
e4af2eb635
commit
8e7556f397
|
@ -40,9 +40,9 @@ import org.apache.activemq.command.TransactionId;
|
|||
import org.apache.activemq.command.TransactionInfo;
|
||||
import org.apache.activemq.command.XATransactionId;
|
||||
import org.apache.activemq.transaction.Synchronization;
|
||||
import org.apache.activemq.transport.failover.FailoverTransport;
|
||||
import org.apache.activemq.util.JMSExceptionSupport;
|
||||
import org.apache.activemq.util.LongSequenceGenerator;
|
||||
import org.apache.activemq.util.XASupport;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
@ -161,7 +161,7 @@ public class TransactionContext implements XAResource {
|
|||
try {
|
||||
synchronizations.get(i).afterRollback();
|
||||
} catch (Throwable t) {
|
||||
LOG.debug("Exception from afterRollback on " + synchronizations.get(i), t);
|
||||
LOG.debug("Exception from afterRollback on {}", synchronizations.get(i), t);
|
||||
if (firstException == null) {
|
||||
firstException = t;
|
||||
}
|
||||
|
@ -184,7 +184,7 @@ public class TransactionContext implements XAResource {
|
|||
try {
|
||||
synchronizations.get(i).afterCommit();
|
||||
} catch (Throwable t) {
|
||||
LOG.debug("Exception from afterCommit on " + synchronizations.get(i), t);
|
||||
LOG.debug("Exception from afterCommit on {}", synchronizations.get(i), t);
|
||||
if (firstException == null) {
|
||||
firstException = t;
|
||||
}
|
||||
|
@ -245,11 +245,9 @@ public class TransactionContext implements XAResource {
|
|||
if (localTransactionEventListener != null) {
|
||||
localTransactionEventListener.beginEvent();
|
||||
}
|
||||
if (LOG.isDebugEnabled()) {
|
||||
LOG.debug("Begin:" + transactionId);
|
||||
}
|
||||
}
|
||||
|
||||
LOG.debug("Begin:{}", transactionId);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -272,11 +270,8 @@ public class TransactionContext implements XAResource {
|
|||
LOG.warn("rollback processing error", canOcurrOnFailover);
|
||||
}
|
||||
if (transactionId != null) {
|
||||
if (LOG.isDebugEnabled()) {
|
||||
LOG.debug("Rollback: " + transactionId
|
||||
+ " syncCount: "
|
||||
+ (synchronizations != null ? synchronizations.size() : 0));
|
||||
}
|
||||
LOG.debug("Rollback: {} syncCount: {}",
|
||||
transactionId, (synchronizations != null ? synchronizations.size() : 0));
|
||||
|
||||
TransactionInfo info = new TransactionInfo(getConnectionId(), transactionId, TransactionInfo.ROLLBACK);
|
||||
this.transactionId = null;
|
||||
|
@ -314,11 +309,8 @@ public class TransactionContext implements XAResource {
|
|||
|
||||
// Only send commit if the transaction was started.
|
||||
if (transactionId != null) {
|
||||
if (LOG.isDebugEnabled()) {
|
||||
LOG.debug("Commit: " + transactionId
|
||||
+ " syncCount: "
|
||||
+ (synchronizations != null ? synchronizations.size() : 0));
|
||||
}
|
||||
LOG.debug("Commit: {} syncCount: {}",
|
||||
transactionId, (synchronizations != null ? synchronizations.size() : 0));
|
||||
|
||||
TransactionInfo info = new TransactionInfo(getConnectionId(), transactionId, TransactionInfo.COMMIT_ONE_PHASE);
|
||||
this.transactionId = null;
|
||||
|
@ -330,7 +322,7 @@ public class TransactionContext implements XAResource {
|
|||
}
|
||||
afterCommit();
|
||||
} catch (JMSException cause) {
|
||||
LOG.info("commit failed for transaction " + info.getTransactionId(), cause);
|
||||
LOG.info("commit failed for transaction {}", info.getTransactionId(), cause);
|
||||
if (localTransactionEventListener != null) {
|
||||
localTransactionEventListener.rollbackEvent();
|
||||
}
|
||||
|
@ -349,11 +341,11 @@ public class TransactionContext implements XAResource {
|
|||
/**
|
||||
* Associates a transaction with the resource.
|
||||
*/
|
||||
@Override
|
||||
public void start(Xid xid, int flags) throws XAException {
|
||||
|
||||
if (LOG.isDebugEnabled()) {
|
||||
LOG.debug("Start: " + xid + ", flags:" + flags);
|
||||
}
|
||||
LOG.debug("Start: {}, flags: {}", xid, XASupport.toString(flags));
|
||||
|
||||
if (isInLocalTransaction()) {
|
||||
throw new XAException(XAException.XAER_PROTO);
|
||||
}
|
||||
|
@ -365,7 +357,7 @@ public class TransactionContext implements XAResource {
|
|||
// if ((flags & TMJOIN) == TMJOIN) {
|
||||
// TODO: verify that the server has seen the xid
|
||||
// // }
|
||||
// if ((flags & TMJOIN) == TMRESUME) {
|
||||
// if ((flags & TMRESUME) == TMRESUME) {
|
||||
// // TODO: verify that the xid was suspended.
|
||||
// }
|
||||
|
||||
|
@ -382,11 +374,10 @@ public class TransactionContext implements XAResource {
|
|||
return connection.getConnectionInfo().getConnectionId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void end(Xid xid, int flags) throws XAException {
|
||||
|
||||
if (LOG.isDebugEnabled()) {
|
||||
LOG.debug("End: " + xid + ", flags:" + flags);
|
||||
}
|
||||
LOG.debug("End: {}, flags: {}", xid, XASupport.toString(flags));
|
||||
|
||||
if (isInLocalTransaction()) {
|
||||
throw new XAException(XAException.XAER_PROTO);
|
||||
|
@ -434,10 +425,9 @@ public class TransactionContext implements XAResource {
|
|||
&& Arrays.equals(xid1.getGlobalTransactionId(), xid2.getGlobalTransactionId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int prepare(Xid xid) throws XAException {
|
||||
if (LOG.isDebugEnabled()) {
|
||||
LOG.debug("Prepare: " + xid);
|
||||
}
|
||||
LOG.debug("Prepare: {}", xid);
|
||||
|
||||
// We allow interleaving multiple transactions, so
|
||||
// we don't limit prepare to the associated xid.
|
||||
|
@ -461,9 +451,7 @@ public class TransactionContext implements XAResource {
|
|||
synchronized(ENDED_XA_TRANSACTION_CONTEXTS) {
|
||||
List<TransactionContext> l = ENDED_XA_TRANSACTION_CONTEXTS.remove(x);
|
||||
if (l != null && !l.isEmpty()) {
|
||||
if (LOG.isDebugEnabled()) {
|
||||
LOG.debug("firing afterCommit callbacks on XA_RDONLY from prepare: " + xid);
|
||||
}
|
||||
LOG.debug("firing afterCommit callbacks on XA_RDONLY from prepare: {}", xid);
|
||||
for (TransactionContext ctx : l) {
|
||||
ctx.afterCommit();
|
||||
}
|
||||
|
@ -481,10 +469,8 @@ public class TransactionContext implements XAResource {
|
|||
try {
|
||||
ctx.afterRollback();
|
||||
} catch (Throwable ignored) {
|
||||
if (LOG.isDebugEnabled()) {
|
||||
LOG.debug("failed to firing afterRollback callbacks on prepare failure, txid: " +
|
||||
x + ", context: " + ctx, ignored);
|
||||
}
|
||||
LOG.debug("failed to firing afterRollback callbacks on prepare " +
|
||||
"failure, txid: {}, context: {}", x, ctx, ignored);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -493,6 +479,7 @@ public class TransactionContext implements XAResource {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void rollback(Xid xid) throws XAException {
|
||||
|
||||
if (LOG.isDebugEnabled()) {
|
||||
|
@ -535,11 +522,10 @@ public class TransactionContext implements XAResource {
|
|||
}
|
||||
|
||||
// XAResource interface
|
||||
@Override
|
||||
public void commit(Xid xid, boolean onePhase) throws XAException {
|
||||
|
||||
if (LOG.isDebugEnabled()) {
|
||||
LOG.debug("Commit: " + xid + ", onePhase=" + onePhase);
|
||||
}
|
||||
LOG.debug("Commit: {}, onePhase={}", xid, onePhase);
|
||||
|
||||
// We allow interleaving multiple transactions, so
|
||||
// we don't limit commit to the associated xid.
|
||||
|
@ -568,7 +554,7 @@ public class TransactionContext implements XAResource {
|
|||
try {
|
||||
ctx.afterCommit();
|
||||
} catch (Exception ignored) {
|
||||
LOG.debug("ignoring exception from after completion on ended transaction: " + ignored, ignored);
|
||||
LOG.debug("ignoring exception from after completion on ended transaction: {}", ignored, ignored);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -584,9 +570,7 @@ public class TransactionContext implements XAResource {
|
|||
try {
|
||||
ctx.afterRollback();
|
||||
} catch (Throwable ignored) {
|
||||
if (LOG.isDebugEnabled()) {
|
||||
LOG.debug("failed to firing afterRollback callbacks commit failure, txid: " + x + ", context: " + ctx, ignored);
|
||||
}
|
||||
LOG.debug("failed to firing afterRollback callbacks commit failure, txid: {}, context: {}", x, ctx, ignored);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -594,13 +578,11 @@ public class TransactionContext implements XAResource {
|
|||
}
|
||||
throw toXAException(e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void forget(Xid xid) throws XAException {
|
||||
if (LOG.isDebugEnabled()) {
|
||||
LOG.debug("Forget: " + xid);
|
||||
}
|
||||
LOG.debug("Forget: {}", xid);
|
||||
|
||||
// We allow interleaving multiple transactions, so
|
||||
// we don't limit forget to the associated xid.
|
||||
|
@ -628,6 +610,7 @@ public class TransactionContext implements XAResource {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSameRM(XAResource xaResource) throws XAException {
|
||||
if (xaResource == null) {
|
||||
return false;
|
||||
|
@ -643,6 +626,7 @@ public class TransactionContext implements XAResource {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Xid[] recover(int flag) throws XAException {
|
||||
LOG.debug("recover({})", flag);
|
||||
|
||||
|
@ -667,10 +651,12 @@ public class TransactionContext implements XAResource {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getTransactionTimeout() throws XAException {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setTransactionTimeout(int seconds) throws XAException {
|
||||
return false;
|
||||
}
|
||||
|
@ -702,9 +688,7 @@ public class TransactionContext implements XAResource {
|
|||
TransactionInfo info = new TransactionInfo(getConnectionId(), transactionId, TransactionInfo.BEGIN);
|
||||
try {
|
||||
this.connection.asyncSendPacket(info);
|
||||
if (LOG.isDebugEnabled()) {
|
||||
LOG.debug("{} started XA transaction {} ", this, transactionId);
|
||||
}
|
||||
LOG.debug("{} started XA transaction {}", this, transactionId);
|
||||
} catch (JMSException e) {
|
||||
disassociate();
|
||||
throw toXAException(e);
|
||||
|
@ -716,9 +700,7 @@ public class TransactionContext implements XAResource {
|
|||
TransactionInfo info = new TransactionInfo(getConnectionId(), transactionId, TransactionInfo.END);
|
||||
try {
|
||||
syncSendPacketWithInterruptionHandling(info);
|
||||
if (LOG.isDebugEnabled()) {
|
||||
LOG.debug("{} ended XA transaction {}", this, transactionId);
|
||||
}
|
||||
} catch (JMSException e) {
|
||||
disassociate();
|
||||
throw toXAException(e);
|
||||
|
@ -814,7 +796,6 @@ public class TransactionContext implements XAResource {
|
|||
return connection;
|
||||
}
|
||||
|
||||
|
||||
// for RAR xa recovery where xaresource connection is per request
|
||||
public ActiveMQConnection setConnection(ActiveMQConnection connection) {
|
||||
ActiveMQConnection existing = this.connection;
|
||||
|
|
|
@ -0,0 +1,89 @@
|
|||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.apache.activemq.util;
|
||||
|
||||
import static javax.transaction.xa.XAResource.TMENDRSCAN;
|
||||
import static javax.transaction.xa.XAResource.TMFAIL;
|
||||
import static javax.transaction.xa.XAResource.TMJOIN;
|
||||
import static javax.transaction.xa.XAResource.TMNOFLAGS;
|
||||
import static javax.transaction.xa.XAResource.TMONEPHASE;
|
||||
import static javax.transaction.xa.XAResource.TMRESUME;
|
||||
import static javax.transaction.xa.XAResource.TMSTARTRSCAN;
|
||||
import static javax.transaction.xa.XAResource.TMSUCCESS;
|
||||
import static javax.transaction.xa.XAResource.TMSUSPEND;
|
||||
|
||||
public class XASupport {
|
||||
|
||||
public static String toString(int flags) {
|
||||
if (flags == TMNOFLAGS) {
|
||||
return "TMNOFLAGS";
|
||||
}
|
||||
|
||||
StringBuilder result = new StringBuilder();
|
||||
if (hasFlag(flags, TMENDRSCAN)) {
|
||||
add(result, "TMENDRSCAN");
|
||||
}
|
||||
if (hasFlag(flags, TMFAIL)) {
|
||||
add(result, "TMFAIL");
|
||||
}
|
||||
if (hasFlag(flags, TMJOIN)) {
|
||||
add(result, "TMJOIN");
|
||||
}
|
||||
if (hasFlag(flags, TMONEPHASE)) {
|
||||
add(result, "TMONEPHASE");
|
||||
}
|
||||
if (hasFlag(flags, TMRESUME)) {
|
||||
add(result, "TMRESUME");
|
||||
}
|
||||
if (hasFlag(flags, TMSTARTRSCAN)) {
|
||||
add(result, "TMSTARTRSCAN");
|
||||
}
|
||||
if (hasFlag(flags, TMSUCCESS)) {
|
||||
add(result, "TMSUCCESS");
|
||||
}
|
||||
if (hasFlag(flags, TMSUSPEND)) {
|
||||
add(result, "TMSUSPEND");
|
||||
}
|
||||
|
||||
int nonStandardFlags = flags
|
||||
& ~TMENDRSCAN
|
||||
& ~TMFAIL
|
||||
& ~TMJOIN
|
||||
& ~TMONEPHASE
|
||||
& ~TMRESUME
|
||||
& ~TMSTARTRSCAN
|
||||
& ~TMSUCCESS
|
||||
& ~TMSUSPEND;
|
||||
|
||||
if (nonStandardFlags != 0) {
|
||||
add(result, String.format("0x%08x", nonStandardFlags));
|
||||
}
|
||||
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
private static boolean hasFlag(int flags, int flag) {
|
||||
return (flags & flag) == flag;
|
||||
}
|
||||
|
||||
private static void add(StringBuilder result, String string) {
|
||||
if (result.length() > 0) {
|
||||
result.append(" | ");
|
||||
}
|
||||
result.append(string);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,82 @@
|
|||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.apache.activemq.util;
|
||||
|
||||
import static javax.transaction.xa.XAResource.TMENDRSCAN;
|
||||
import static javax.transaction.xa.XAResource.TMFAIL;
|
||||
import static javax.transaction.xa.XAResource.TMJOIN;
|
||||
import static javax.transaction.xa.XAResource.TMNOFLAGS;
|
||||
import static javax.transaction.xa.XAResource.TMONEPHASE;
|
||||
import static javax.transaction.xa.XAResource.TMRESUME;
|
||||
import static javax.transaction.xa.XAResource.TMSTARTRSCAN;
|
||||
import static javax.transaction.xa.XAResource.TMSUCCESS;
|
||||
import static javax.transaction.xa.XAResource.TMSUSPEND;
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Parameterized;
|
||||
import org.junit.runners.Parameterized.Parameters;
|
||||
|
||||
@RunWith(Parameterized.class)
|
||||
public class XASupportTest {
|
||||
|
||||
private final int flags;
|
||||
private final String expectedResult;
|
||||
|
||||
public XASupportTest(int flags, String expectedResult) {
|
||||
this.flags = flags;
|
||||
this.expectedResult = expectedResult;
|
||||
}
|
||||
|
||||
@Parameters
|
||||
public static Iterable<Object[]> parameters() {
|
||||
List<Object[]> p = new LinkedList<Object[]>();
|
||||
|
||||
// single values from XAResource
|
||||
add(p, TMENDRSCAN, "TMENDRSCAN");
|
||||
add(p, TMFAIL, "TMFAIL");
|
||||
add(p, TMJOIN, "TMJOIN");
|
||||
add(p, TMNOFLAGS, "TMNOFLAGS");
|
||||
add(p, TMONEPHASE, "TMONEPHASE");
|
||||
add(p, TMRESUME, "TMRESUME");
|
||||
add(p, TMSTARTRSCAN, "TMSTARTRSCAN");
|
||||
add(p, TMSUCCESS, "TMSUCCESS");
|
||||
add(p, TMSUSPEND, "TMSUSPEND");
|
||||
|
||||
// combination of multiple flags
|
||||
add(p, TMONEPHASE | TMSUCCESS, "TMONEPHASE | TMSUCCESS");
|
||||
|
||||
// flags not specified in XAResource
|
||||
add(p, TMSUCCESS | 0x00400000, "TMSUCCESS | 0x00400000");
|
||||
|
||||
return p;
|
||||
}
|
||||
|
||||
private static void add(List<Object[]> p, int flags, String expectedResult) {
|
||||
p.add(new Object[] { flags, expectedResult });
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test() throws Exception {
|
||||
assertThat(XASupport.toString(flags), is(expectedResult));
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue