Skip to content

Commit afc4823

Browse files
AntonKozlovgeoand
authored andcommitted
Add initial support of Project CRaC
1 parent 8bda19e commit afc4823

File tree

8 files changed

+68
-1
lines changed

8 files changed

+68
-1
lines changed

bom/application/pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,7 @@
198198
<strimzi-oauth.version>0.10.0</strimzi-oauth.version>
199199
<strimzi-oauth.nimbus.version>9.22</strimzi-oauth.nimbus.version>
200200
<java-buildpack-client.version>0.0.6</java-buildpack-client.version>
201+
<org-crac.version>0.1.1</org-crac.version>
201202
</properties>
202203

203204
<dependencyManagement>
@@ -5544,6 +5545,11 @@
55445545
<artifactId>quarkus-awt-deployment</artifactId>
55455546
<version>${project.version}</version>
55465547
</dependency>
5548+
<dependency>
5549+
<groupId>io.github.crac</groupId>
5550+
<artifactId>org-crac</artifactId>
5551+
<version>${org-crac.version}</version>
5552+
</dependency>
55475553

55485554
<!-- Relocations -->
55495555
<dependency>

core/runtime/pom.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,8 @@
223223
<runnerParentFirstArtifact>org.wildfly.common:wildfly-common</runnerParentFirstArtifact>
224224
<!-- This is needed because it contains some jar handling classes -->
225225
<runnerParentFirstArtifact>io.smallrye.common:smallrye-common-io</runnerParentFirstArtifact>
226+
<!-- QuarkusEntryPoint needs org-crac class definition -->
227+
<runnerParentFirstArtifact>io.github.crac:org-crac</runnerParentFirstArtifact>
226228
</runnerParentFirstArtifacts>
227229
<excludedArtifacts>
228230
<excludedArtifact>io.smallrye:smallrye-config</excludedArtifact>

extensions/vertx-http/runtime/pom.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,10 @@
6666
<artifactId>svm</artifactId>
6767
<scope>provided</scope>
6868
</dependency>
69+
<dependency>
70+
<groupId>io.github.crac</groupId>
71+
<artifactId>org-crac</artifactId>
72+
</dependency>
6973
<!-- Test dependencies -->
7074
<dependency>
7175
<groupId>org.junit.jupiter</groupId>

extensions/vertx-http/runtime/src/main/java/io/quarkus/vertx/http/runtime/VertxHttpRecorder.java

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737

3838
import javax.enterprise.event.Event;
3939

40+
import org.crac.Resource;
4041
import org.jboss.logging.Logger;
4142
import org.wildfly.common.cpu.ProcessorInfo;
4243

@@ -1039,7 +1040,7 @@ public GracefulShutdownFilter createGracefulShutdownHandler() {
10391040
return new GracefulShutdownFilter();
10401041
}
10411042

1042-
private static class WebDeploymentVerticle extends AbstractVerticle {
1043+
private static class WebDeploymentVerticle extends AbstractVerticle implements Resource {
10431044

10441045
private HttpServer httpServer;
10451046
private HttpServer httpsServer;
@@ -1065,6 +1066,7 @@ public WebDeploymentVerticle(HttpServerOptions httpOptions, HttpServerOptions ht
10651066
this.insecureRequests = insecureRequests;
10661067
this.quarkusConfig = quarkusConfig;
10671068
this.connectionCount = connectionCount;
1069+
org.crac.Core.getGlobalContext().register(this);
10681070
}
10691071

10701072
@Override
@@ -1294,6 +1296,24 @@ public void stop(Promise<Void> stopFuture) {
12941296
private String propertyWithProfilePrefix(String portPropertyName) {
12951297
return "%" + launchMode.getDefaultProfile() + "." + portPropertyName;
12961298
}
1299+
1300+
@Override
1301+
public void beforeCheckpoint(org.crac.Context<? extends Resource> context) throws Exception {
1302+
Promise<Void> p = Promise.promise();
1303+
stop(p);
1304+
CountDownLatch latch = new CountDownLatch(1);
1305+
p.future().onComplete(event -> latch.countDown());
1306+
latch.await();
1307+
}
1308+
1309+
@Override
1310+
public void afterRestore(org.crac.Context<? extends Resource> context) throws Exception {
1311+
Promise<Void> p = Promise.promise();
1312+
start(p);
1313+
CountDownLatch latch = new CountDownLatch(1);
1314+
p.future().onComplete(event -> latch.countDown());
1315+
latch.await();
1316+
}
12971317
}
12981318

12991319
protected static ServerBootstrap virtualBootstrap;

independent-projects/bootstrap/bom/pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,11 @@
343343
<artifactId>jsoup</artifactId>
344344
<version>${jsoup.version}</version>
345345
</dependency>
346+
<dependency>
347+
<groupId>io.github.crac</groupId>
348+
<artifactId>org-crac</artifactId>
349+
<version>${org-crac.version}</version>
350+
</dependency>
346351
<!-- Smallrye Common dependencies, imported as a BOM -->
347352
<dependency>
348353
<groupId>io.smallrye.common</groupId>

independent-projects/bootstrap/pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@
6767
<smallrye-common.version>1.11.0</smallrye-common.version>
6868
<gradle-tooling.version>7.4.2</gradle-tooling.version>
6969
<quarkus-fs-util.version>0.0.9</quarkus-fs-util.version>
70+
<org-crac.version>0.1.1</org-crac.version>
7071
</properties>
7172
<modules>
7273
<module>bom</module>

independent-projects/bootstrap/runner/pom.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@
5050
<groupId>org.jboss.logging</groupId>
5151
<artifactId>jboss-logging</artifactId>
5252
</dependency>
53+
<dependency>
54+
<groupId>io.github.crac</groupId>
55+
<artifactId>org-crac</artifactId>
56+
</dependency>
5357
<dependency>
5458
<groupId>org.junit.jupiter</groupId>
5559
<artifactId>junit-jupiter</artifactId>

independent-projects/bootstrap/runner/src/main/java/io/quarkus/bootstrap/runner/RunnerClassLoader.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
import java.util.List;
88
import java.util.Map;
99
import java.util.Set;
10+
import org.crac.Context;
11+
import org.crac.Resource;
1012

1113
/**
1214
* Classloader used with the fast-jar package type.
@@ -41,6 +43,8 @@ public final class RunnerClassLoader extends ClassLoader {
4143
//Protected by synchronization on the above field, as they are related.
4244
private boolean postBootPhase = false;
4345

46+
private final CracResource resource;
47+
4448
RunnerClassLoader(ClassLoader parent, Map<String, ClassLoadingResource[]> resourceDirectoryMap,
4549
Set<String> parentFirstPackages, Set<String> nonExistentResources,
4650
List<String> fullyIndexedDirectories, Map<String, ClassLoadingResource[]> directlyIndexedResourcesIndexMap) {
@@ -50,6 +54,9 @@ public final class RunnerClassLoader extends ClassLoader {
5054
this.nonExistentResources = nonExistentResources;
5155
this.fullyIndexedDirectories = fullyIndexedDirectories;
5256
this.directlyIndexedResourcesIndexMap = directlyIndexedResourcesIndexMap;
57+
58+
resource = new CracResource();
59+
org.crac.Core.getGlobalContext().register(resource);
5360
}
5461

5562
@Override
@@ -290,4 +297,22 @@ public void resetInternalCaches() {
290297
this.postBootPhase = true;
291298
}
292299
}
300+
301+
class CracResource implements Resource {
302+
@Override
303+
public void beforeCheckpoint(Context<? extends Resource> ctx) {
304+
synchronized (currentlyBufferedResources) {
305+
for (int i = 0; i < currentlyBufferedResources.length; ++i) {
306+
if (currentlyBufferedResources[i] != null) {
307+
currentlyBufferedResources[i].resetInternalCaches();
308+
currentlyBufferedResources[i] = null;
309+
}
310+
}
311+
}
312+
}
313+
314+
@Override
315+
public void afterRestore(Context<? extends Resource> ctx) {
316+
}
317+
}
293318
}

0 commit comments

Comments
 (0)