You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by rj...@apache.org on 2009/01/19 11:16:52 UTC
svn commit: r735645 - in /tomcat/sandbox/tomcat-oacc/trunk:
docs/changelog.xml
src/share/org/apache/catalina/cluster/deploy/FileMessageFactory.java
src/share/org/apache/catalina/cluster/deploy/WarWatcher.java
Author: rjung
Date: Mon Jan 19 02:16:51 2009
New Revision: 735645
URL: http://svn.apache.org/viewvc?rev=735645&view=rev
Log:
Backport r717903 from Tomcat 6.0:
Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=45851
Fix out of order message processing issues
Backport r717906 from Tomcat 6.0:
Fix small memory leak found by find bugs.
Modified:
tomcat/sandbox/tomcat-oacc/trunk/docs/changelog.xml
tomcat/sandbox/tomcat-oacc/trunk/src/share/org/apache/catalina/cluster/deploy/FileMessageFactory.java
tomcat/sandbox/tomcat-oacc/trunk/src/share/org/apache/catalina/cluster/deploy/WarWatcher.java
Modified: tomcat/sandbox/tomcat-oacc/trunk/docs/changelog.xml
URL: http://svn.apache.org/viewvc/tomcat/sandbox/tomcat-oacc/trunk/docs/changelog.xml?rev=735645&r1=735644&r2=735645&view=diff
==============================================================================
--- tomcat/sandbox/tomcat-oacc/trunk/docs/changelog.xml (original)
+++ tomcat/sandbox/tomcat-oacc/trunk/docs/changelog.xml Mon Jan 19 02:16:51 2009
@@ -32,6 +32,13 @@
<section name="Tomcat OACC 6.0.19 (rjung)">
<subsection name="Cluster">
<changelog>
+ <fix>
+ Fix small memory leak in FarmWarDeployer. Backport from Tomcat 6.0. (rjung)
+ </fix>
+ <fix>
+ <bug>45851</bug>: Fix out of order message processing issues with the
+ FarmWarDeployer. Backport from Tomcat 6.0. (rjung)
+ </fix>
<update>
Add ManagerBase session getLastAccessedTimestamp and
getCreationTimestamp for better remote JMX access.
Modified: tomcat/sandbox/tomcat-oacc/trunk/src/share/org/apache/catalina/cluster/deploy/FileMessageFactory.java
URL: http://svn.apache.org/viewvc/tomcat/sandbox/tomcat-oacc/trunk/src/share/org/apache/catalina/cluster/deploy/FileMessageFactory.java?rev=735645&r1=735644&r2=735645&view=diff
==============================================================================
--- tomcat/sandbox/tomcat-oacc/trunk/src/share/org/apache/catalina/cluster/deploy/FileMessageFactory.java (original)
+++ tomcat/sandbox/tomcat-oacc/trunk/src/share/org/apache/catalina/cluster/deploy/FileMessageFactory.java Mon Jan 19 02:16:51 2009
@@ -22,6 +22,9 @@
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.FileNotFoundException;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.atomic.AtomicLong;
/**
* This factory is used to read files and write files by splitting them up into
@@ -75,7 +78,7 @@
protected FileOutputStream out;
/**
- * The number of messages we have read or written
+ * The number of messages we have written
*/
protected int nrOfMessagesProcessed = 0;
@@ -88,6 +91,19 @@
* The total number of packets that we split this file into
*/
protected long totalNrOfMessages = 0;
+
+ /**
+ * The number of the last message procssed. Message IDs are 1 based.
+ */
+ protected AtomicLong lastMessageProcessed = new AtomicLong(0);
+
+ /**
+ * Messages received out of order are held in the buffer until required. If
+ * everything is worked as expected, messages will spend very little time in
+ * the buffer.
+ */
+ protected Map<Long, FileMessage> msgBuffer =
+ new ConcurrentHashMap<Long, FileMessage>();
/**
* The bytes that we hold the data in, not thread safe.
@@ -95,6 +111,12 @@
protected byte[] data = new byte[READ_SIZE];
/**
+ * Flag that indicates if a thread is writing messages to disk. Access to
+ * this flag must be synchronised.
+ */
+ protected boolean isWriting = false;
+
+ /**
* Private constructor, either instantiates a factory to read or write. <BR>
* When openForWrite==true, then a the file, f, will be created and an
* output stream is opened to write to it. <BR>
@@ -206,25 +228,65 @@
if (log.isDebugEnabled())
log.debug("Message " + msg + " data " + msg.getData()
+ " data length " + msg.getDataLength() + " out " + out);
- if (out != null) {
- out.write(msg.getData(), 0, msg.getDataLength());
- nrOfMessagesProcessed++;
+
+ if (msg.getMessageNumber() <= lastMessageProcessed.get()) {
+ // Duplicate of message already processed
+ log.warn("Receive Message again -- Sender ActTimeout too short [ path: "
+ + msg.getContextPath()
+ + " war: "
+ + msg.getFileName()
+ + " data: "
+ + msg.getData()
+ + " data length: " + msg.getDataLength() + " ]");
+ return false;
+ }
+
+ FileMessage previous =
+ msgBuffer.put(new Long(msg.getMessageNumber()), msg);
+ if (previous !=null) {
+ // Duplicate of message not yet processed
+ log.warn("Receive Message again -- Sender ActTimeout too short [ path: "
+ + msg.getContextPath()
+ + " war: "
+ + msg.getFileName()
+ + " data: "
+ + msg.getData()
+ + " data length: " + msg.getDataLength() + " ]");
+ return false;
+ }
+
+ FileMessage next = null;
+ synchronized (this) {
+ if (!isWriting) {
+ next = msgBuffer.get(new Long(lastMessageProcessed.get() + 1));
+ if (next != null) {
+ isWriting = true;
+ } else {
+ return false;
+ }
+ } else {
+ return false;
+ }
+ }
+
+ while (next != null) {
+ out.write(next.getData(), 0, next.getDataLength());
+ lastMessageProcessed.incrementAndGet();
out.flush();
- if (msg.getMessageNumber() == msg.getTotalNrOfMsgs()) {
+ if (next.getMessageNumber() == next.getTotalNrOfMsgs()) {
out.close();
cleanup();
return true;
- }//end if
- } else {
- if (log.isWarnEnabled())
- log.warn("Receive Message again -- Sender ActTimeout to short [ path: "
- + msg.getContextPath()
- + " war: "
- + msg.getFileName()
- + " data: "
- + msg.getData()
- + " data length: " + msg.getDataLength() + " ]");
+ }
+ synchronized(this) {
+ next =
+ msgBuffer.get(new Long(lastMessageProcessed.get() + 1));
+ if (next == null) {
+ isWriting = false;
+ }
+ }
}
+
return false;
}//writeMessage
@@ -249,6 +311,8 @@
data = null;
nrOfMessagesProcessed = 0;
totalNrOfMessages = 0;
+ msgBuffer.clear();
+ lastMessageProcessed = null;
}
/**
Modified: tomcat/sandbox/tomcat-oacc/trunk/src/share/org/apache/catalina/cluster/deploy/WarWatcher.java
URL: http://svn.apache.org/viewvc/tomcat/sandbox/tomcat-oacc/trunk/src/share/org/apache/catalina/cluster/deploy/WarWatcher.java?rev=735645&r1=735644&r2=735645&view=diff
==============================================================================
--- tomcat/sandbox/tomcat-oacc/trunk/src/share/org/apache/catalina/cluster/deploy/WarWatcher.java (original)
+++ tomcat/sandbox/tomcat-oacc/trunk/src/share/org/apache/catalina/cluster/deploy/WarWatcher.java Mon Jan 19 02:16:51 2009
@@ -93,7 +93,7 @@
} else if (check == -1) {
listener.fileRemoved(info.getWar());
//no need to keep in memory
- currentStatus.remove(info.getWar());
+ currentStatus.remove(info.getWar().getAbsolutePath());
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org