This is an automated email from the ASF dual-hosted git repository. markt pushed a commit to branch 8.5.x in repository https://gitbox.apache.org/repos/asf/tomcat.git
commit 0bbaf88a748c52d2a56e1736dfb5ecd109f5954f Author: Mark Thomas <ma...@apache.org> AuthorDate: Tue May 21 22:35:16 2019 +0100 Fix https://bz.apache.org/bugzilla/show_bug.cgi?id=62841 BackupManager Expand the fix to the BackupManager by refactoring the locking into the DeltaSession and ensuring that the session is not locked during serialization. --- .../apache/catalina/ha/session/DeltaSession.java | 51 +++++++++++++++++----- 1 file changed, 41 insertions(+), 10 deletions(-) diff --git a/java/org/apache/catalina/ha/session/DeltaSession.java b/java/org/apache/catalina/ha/session/DeltaSession.java index 9609e24..b5fa5a2 100644 --- a/java/org/apache/catalina/ha/session/DeltaSession.java +++ b/java/org/apache/catalina/ha/session/DeltaSession.java @@ -137,12 +137,29 @@ public class DeltaSession extends StandardSession implements Externalizable,Clus */ @Override public byte[] getDiff() throws IOException { - lockInternal(); - try { - return getDeltaRequest().serialize(); - } finally{ - unlockInternal(); + SynchronizedStack<DeltaRequest> deltaRequestPool = null; + DeltaRequest newDeltaRequest = null; + + if (manager instanceof ClusterManagerBase) { + deltaRequestPool = ((ClusterManagerBase) manager).getDeltaRequestPool(); + newDeltaRequest = deltaRequestPool.pop(); } + if (newDeltaRequest == null) { + newDeltaRequest = new DeltaRequest(); + } + + DeltaRequest oldDeltaRequest = replaceDeltaRequest(newDeltaRequest); + + byte[] result = oldDeltaRequest.serialize(); + + if (deltaRequestPool != null) { + // Only need to reset the old request if it is going to be pooled. + // Otherwise let GC do its thing. + oldDeltaRequest.reset(); + deltaRequestPool.push(oldDeltaRequest); + } + + return result; } public ClassLoader[] getClassLoaders() { @@ -182,32 +199,46 @@ public class DeltaSession extends StandardSession implements Externalizable,Clus } /** - * Resets the current diff state and resets the dirty flag + * {@inheritDoc} + * <p> + * This implementation is a NO-OP. The diff is reset in {@link #getDiff()}. */ @Override public void resetDiff() { resetDeltaRequest(); } + /** + * {@inheritDoc} + * <p> + * This implementation is a NO-OP. Any required locking takes place in the + * methods that make modifications. + */ @Override public void lock() { - lockInternal(); + // NO-OP } + /** + * {@inheritDoc} + * <p> + * This implementation is a NO-OP. Any required unlocking takes place in the + * methods that make modifications. + */ @Override public void unlock() { - unlockInternal(); + // NO-OP } /** - * Lock during serialization + * Lock during serialization. */ private void lockInternal() { diffLock.lock(); } /** - * Unlock after serialization + * Unlock after serialization. */ private void unlockInternal() { diffLock.unlock(); --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org