This is an automated email from the ASF dual-hosted git repository. markt pushed a commit to branch 7.0.x in repository https://gitbox.apache.org/repos/asf/tomcat.git
commit 3a34cfb3bad9b3ef26d11fbb16916b96146aeab2 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 08f0cd2..35d17d8 100644 --- a/java/org/apache/catalina/ha/session/DeltaSession.java +++ b/java/org/apache/catalina/ha/session/DeltaSession.java @@ -138,12 +138,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() { @@ -188,32 +205,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