Skip to content

Commit

Permalink
Print JVM restoration time in DefaultLifecycleProcessor
Browse files Browse the repository at this point in the history
Closes gh-31252
  • Loading branch information
sdeleuze committed Sep 18, 2023
1 parent 2fbcff8 commit 4128f4d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
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;
Expand All @@ -59,10 +60,13 @@
* <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 {
Expand Down Expand Up @@ -554,8 +558,10 @@ public void afterRestore(org.crac.Context<? extends org.crac.Resource> context)
// 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() {
Expand Down

0 comments on commit 4128f4d

Please sign in to comment.