commit f854f1897ee2c6536157d227c1cc5f9ba09011a1 Author: Edwin Kempin Date: Fri Oct 2 11:11:12 2020 +0200 LoggingContext: Remove duplicated comments about copying perf logs between threads Signed-off-by: Edwin Kempin Change-Id: I0afc5437bf332988e30e514d735e486fb310f341 diff --git a/java/com/google/gerrit/server/logging/LoggingContext.java b/java/com/google/gerrit/server/logging/LoggingContext.java index 36c7e9e..671c224 100644 --- a/java/com/google/gerrit/server/logging/LoggingContext.java +++ b/java/com/google/gerrit/server/logging/LoggingContext.java @@ -42,6 +42,15 @@ public class LoggingContext extends com.google.common.flogger.backend.system.Log private static final ThreadLocal tags = new ThreadLocal<>(); private static final ThreadLocal forceLogging = new ThreadLocal<>(); private static final ThreadLocal performanceLogging = new ThreadLocal<>(); + + /** + * When copying the logging context to a new thread we need to ensure that the performance log + * records that are added in the new thread are added to the same {@link + * MutablePerformanceLogRecords} instance (see {@link LoggingContextAwareRunnable} and {@link + * LoggingContextAwareCallable}). This is important since performance log records are processed + * only at the end of the request and performance log records that are created in another thread + * should not get lost. + */ private static final ThreadLocal performanceLogRecords = new ThreadLocal<>(); @@ -57,11 +66,6 @@ public class LoggingContext extends com.google.common.flogger.backend.system.Log return runnable; } - // Pass the MutablePerformanceLogRecords instance into the LoggingContextAwareRunnable - // constructor so that performance log records that are created in the wrapped runnable are - // added to this MutablePerformanceLogRecords instance. This is important since performance - // log records are processed only at the end of the request and performance log records that - // are created in another thread should not get lost. return new LoggingContextAwareRunnable( runnable, getInstance().getMutablePerformanceLogRecords()); } @@ -71,11 +75,6 @@ public class LoggingContext extends com.google.common.flogger.backend.system.Log return callable; } - // Pass the MutablePerformanceLogRecords instance into the LoggingContextAwareCallable - // constructor so that performance log records that are created in the wrapped runnable are - // added to this MutablePerformanceLogRecords instance. This is important since performance - // log records are processed only at the end of the request and performance log records that - // are created in another thread should not get lost. return new LoggingContextAwareCallable<>( callable, getInstance().getMutablePerformanceLogRecords()); } @@ -233,12 +232,7 @@ public class LoggingContext extends com.google.common.flogger.backend.system.Log *

Attention: The passed in {@link MutablePerformanceLogRecords} instance is * directly stored in the logging context. * - *

This method is intended to be only used when the logging context is copied to a new thread - * to ensure that the performance log records that are added in the new thread are added to the - * same {@link MutablePerformanceLogRecords} instance (see {@link LoggingContextAwareRunnable} and - * {@link LoggingContextAwareCallable}). This is important since performance log records are - * processed only at the end of the request and performance log records that are created in - * another thread should not get lost. + *

This method is intended to be only used when the logging context is copied to a new thread. * * @param mutablePerformanceLogRecords the {@link MutablePerformanceLogRecords} instance in which * performance log records should be stored diff --git a/java/com/google/gerrit/server/logging/LoggingContextAwareCallable.java b/java/com/google/gerrit/server/logging/LoggingContextAwareCallable.java index d2701d7..1adee1b 100644 --- a/java/com/google/gerrit/server/logging/LoggingContextAwareCallable.java +++ b/java/com/google/gerrit/server/logging/LoggingContextAwareCallable.java @@ -75,13 +75,6 @@ class LoggingContextAwareCallable implements Callable { loggingCtx.setTags(tags); loggingCtx.forceLogging(forceLogging); loggingCtx.performanceLogging(performanceLogging); - - // For the performance log records use the {@link MutablePerformanceLogRecords} instance from - // the logging context of the calling thread in the logging context of the new thread. This way - // performance log records that are created from the new thread are available from the logging - // context of the calling thread. This is important since performance log records are processed - // only at the end of the request and performance log records that are created in another thread - // should not get lost. loggingCtx.setMutablePerformanceLogRecords(mutablePerformanceLogRecords); try { return callable.call(); diff --git a/java/com/google/gerrit/server/logging/LoggingContextAwareRunnable.java b/java/com/google/gerrit/server/logging/LoggingContextAwareRunnable.java index 23162b1..d0559cc 100644 --- a/java/com/google/gerrit/server/logging/LoggingContextAwareRunnable.java +++ b/java/com/google/gerrit/server/logging/LoggingContextAwareRunnable.java @@ -98,13 +98,6 @@ public class LoggingContextAwareRunnable implements Runnable { loggingCtx.setTags(tags); loggingCtx.forceLogging(forceLogging); loggingCtx.performanceLogging(performanceLogging); - - // For the performance log records use the {@link MutablePerformanceLogRecords} instance from - // the logging context of the calling thread in the logging context of the new thread. This way - // performance log records that are created from the new thread are available from the logging - // context of the calling thread. This is important since performance log records are processed - // only at the end of the request and performance log records that are created in another thread - // should not get lost. loggingCtx.setMutablePerformanceLogRecords(mutablePerformanceLogRecords); try { runnable.run();