You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by ri...@apache.org on 2006/10/03 08:47:30 UTC
svn commit: r452323 - in
/incubator/qpid/trunk/qpid/java/broker/src/org/apache/qpid/server:
AMQChannel.java queue/AMQMessage.java txn/TxnBuffer.java
Author: ritchiem
Date: Mon Oct 2 23:47:30 2006
New Revision: 452323
URL: http://svn.apache.org/viewvc?view=rev&rev=452323
Log:
Optimised Transaction handling.
When using a a transaction don't start a store transaction on a commit UNLESS a persistent message has been sent. As non-persistent messages are not stored.
Modified:
incubator/qpid/trunk/qpid/java/broker/src/org/apache/qpid/server/AMQChannel.java
incubator/qpid/trunk/qpid/java/broker/src/org/apache/qpid/server/queue/AMQMessage.java
incubator/qpid/trunk/qpid/java/broker/src/org/apache/qpid/server/txn/TxnBuffer.java
Modified: incubator/qpid/trunk/qpid/java/broker/src/org/apache/qpid/server/AMQChannel.java
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/broker/src/org/apache/qpid/server/AMQChannel.java?view=diff&rev=452323&r1=452322&r2=452323
==============================================================================
--- incubator/qpid/trunk/qpid/java/broker/src/org/apache/qpid/server/AMQChannel.java (original)
+++ incubator/qpid/trunk/qpid/java/broker/src/org/apache/qpid/server/AMQChannel.java Mon Oct 2 23:47:30 2006
@@ -199,6 +199,12 @@
{
if (_transactional)
{
+ //don't create a transaction unless needed
+ if(_currentMessage.isPersistent())
+ {
+ _txnBuffer.setPersistentMessageRecevied();
+ }
+
//don't route this until commit
_txnBuffer.enlist(new Publish(_currentMessage));
_currentMessage = null;
@@ -603,6 +609,11 @@
Publish(AMQMessage msg)
{
_msg = msg;
+ }
+
+ public boolean isPersistent() throws AMQException
+ {
+ return _msg.isPersistent();
}
public void commit() throws AMQException
Modified: incubator/qpid/trunk/qpid/java/broker/src/org/apache/qpid/server/queue/AMQMessage.java
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/broker/src/org/apache/qpid/server/queue/AMQMessage.java?view=diff&rev=452323&r1=452322&r2=452323
==============================================================================
--- incubator/qpid/trunk/qpid/java/broker/src/org/apache/qpid/server/queue/AMQMessage.java (original)
+++ incubator/qpid/trunk/qpid/java/broker/src/org/apache/qpid/server/queue/AMQMessage.java Mon Oct 2 23:47:30 2006
@@ -337,6 +337,8 @@
{
throw new AMQException("Cannot determine delivery mode of message. Content header not found.");
}
+
+ //todo remove literal values to a constant file such as AMQConstants in common
return _contentHeaderBody.properties instanceof BasicContentHeaderProperties
&&((BasicContentHeaderProperties) _contentHeaderBody.properties).getDeliveryMode() == 2;
}
Modified: incubator/qpid/trunk/qpid/java/broker/src/org/apache/qpid/server/txn/TxnBuffer.java
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/broker/src/org/apache/qpid/server/txn/TxnBuffer.java?view=diff&rev=452323&r1=452322&r2=452323
==============================================================================
--- incubator/qpid/trunk/qpid/java/broker/src/org/apache/qpid/server/txn/TxnBuffer.java (original)
+++ incubator/qpid/trunk/qpid/java/broker/src/org/apache/qpid/server/txn/TxnBuffer.java Mon Oct 2 23:47:30 2006
@@ -17,6 +17,7 @@
*/
package org.apache.qpid.server.txn;
+import org.apache.log4j.Logger;
import org.apache.qpid.AMQException;
import org.apache.qpid.server.store.MessageStore;
@@ -25,21 +26,32 @@
public class TxnBuffer
{
+ private boolean _persistentMessageRecevied = false;
private final MessageStore _store;
private final List<TxnOp> _ops = new ArrayList<TxnOp>();
+ private static final Logger _log = Logger.getLogger(TxnBuffer.class);
public TxnBuffer(MessageStore store)
{
_store = store;
}
+ public void setPersistentMessageRecevied()
+ {
+ _persistentMessageRecevied = true;
+ }
+
public void commit() throws AMQException
{
- _store.beginTran();
+ if (_persistentMessageRecevied)
+ {
+ _log.info("Begin Transaction.");
+ _store.beginTran();
+ }
boolean failed = true;
try
{
- for(TxnOp op : _ops)
+ for (TxnOp op : _ops)
{
op.commit();
}
@@ -48,20 +60,25 @@
}
finally
{
- if(failed)
- {
- _store.abortTran();
- }
- else
+ if (_persistentMessageRecevied)
{
- _store.commitTran();
+ if (failed)
+ {
+ _log.info("Transaction Failed");
+ _store.abortTran();
+ }
+ else
+ {
+ _log.info("Transaction Succeeded");
+ _store.commitTran();
+ }
}
}
}
public void rollback() throws AMQException
{
- for(TxnOp op : _ops)
+ for (TxnOp op : _ops)
{
op.rollback();
}