Browse Source

Print JVM restoration time in DefaultLifecycleProcessor

Closes gh-31252
pull/31253/head
Sébastien Deleuze 1 year ago
parent
commit
4128f4d5c9
  1. 2
      framework-docs/modules/ROOT/pages/integration/checkpoint-restore.adoc
  2. 12
      spring-context/src/main/java/org/springframework/context/support/DefaultLifecycleProcessor.java

2
framework-docs/modules/ROOT/pages/integration/checkpoint-restore.adoc

@ -6,7 +6,7 @@ The Spring Framework integrates with checkpoint/restore as implemented by https: @@ -6,7 +6,7 @@ The Spring Framework integrates with checkpoint/restore as implemented by https:
Using this feature requires:
* A checkpoint/restore enabled JVM (Linux only for now).
* The presence in the classpath of the https://github.com/CRaC/org.crac[`org.crac:crac`] library.
* The presence in the classpath of the https://github.com/CRaC/org.crac[`org.crac:crac`] library (version `1.4.0` and above are supported).
* Specifying the required `java` command line parameters like `-XX:CRaCCheckpointTo=PATH` or `-XX:CRaCRestoreFrom=PATH`.
WARNING: The files generated in the path specified by `-XX:CRaCCheckpointTo=PATH` when a checkpoint is requested contain a representation of the memory of the running JVM, which may contain secrets and other sensitive data. Using this feature should be done with the assumption that any value "seen" by the JVM, such as configuration properties coming from the environment, will be stored in those CRaC files. As a consequence, the security implications of where and how those files are generated, stored and accessed should be carefully assessed.

12
spring-context/src/main/java/org/springframework/context/support/DefaultLifecycleProcessor.java

@ -37,6 +37,7 @@ import org.apache.commons.logging.LogFactory; @@ -37,6 +37,7 @@ import org.apache.commons.logging.LogFactory;
import org.crac.CheckpointException;
import org.crac.Core;
import org.crac.RestoreException;
import org.crac.management.CRaCMXBean;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.BeanFactoryAware;
@ -59,10 +60,13 @@ import org.springframework.util.ClassUtils; @@ -59,10 +60,13 @@ import org.springframework.util.ClassUtils;
* <p>Provides interaction with {@link Lifecycle} and {@link SmartLifecycle} beans in
* groups for specific phases, on startup/shutdown as well as for explicit start/stop
* interactions on a {@link org.springframework.context.ConfigurableApplicationContext}.
* As of 6.1, this also includes support for JVM checkpoint/restore (Project CRaC).
*
* <p>As of 6.1, this also includes support for JVM checkpoint/restore (Project CRaC)
* when the {@code org.crac:crac} dependency on the classpath.
*
* @author Mark Fisher
* @author Juergen Hoeller
* @author Sebastien Deleuze
* @since 3.0
*/
public class DefaultLifecycleProcessor implements LifecycleProcessor, BeanFactoryAware {
@ -554,8 +558,10 @@ public class DefaultLifecycleProcessor implements LifecycleProcessor, BeanFactor @@ -554,8 +558,10 @@ public class DefaultLifecycleProcessor implements LifecycleProcessor, BeanFactor
// Barrier for prevent-shutdown thread not needed anymore
this.barrier = null;
Duration timeTakenToRestart = Duration.ofNanos(System.nanoTime() - restartTime);
logger.info("Spring-managed lifecycle restart completed in " + timeTakenToRestart.toMillis() + " ms");
long timeTakenToRestart = Duration.ofNanos(System.nanoTime() - restartTime).toMillis();
long timeTakenToRestoreJvm = CRaCMXBean.getCRaCMXBean().getUptimeSinceRestore();
logger.info("Spring-managed lifecycle restart completed in " + timeTakenToRestart
+ " ms (restored JVM running for " + timeTakenToRestoreJvm + " ms)");
}
private void awaitPreventShutdownBarrier() {

Loading…
Cancel
Save