Skip to content

Commit

Permalink
Close GRPC server during CRaC snapshotting
Browse files Browse the repository at this point in the history
Signed-off-by: Radim Vansa <[email protected]>
  • Loading branch information
rvansa committed Mar 30, 2023
1 parent 1a8ca80 commit d43d690
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
5 changes: 5 additions & 0 deletions vertx-grpc/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,11 @@
<version>${project.version}</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>io.github.crac</groupId>
<artifactId>org-crac</artifactId>
<version>0.1.3</version>
</dependency>
</dependencies>

<build>
Expand Down
28 changes: 27 additions & 1 deletion vertx-grpc/src/main/java/io/vertx/grpc/VertxServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@
import io.vertx.core.net.impl.SslContextProvider;
import io.vertx.core.net.impl.VertxEventLoopGroup;
import io.vertx.core.spi.transport.Transport;
import org.crac.Context;
import org.crac.Core;
import org.crac.Resource;

import java.io.IOException;
import java.util.ArrayList;
Expand All @@ -51,7 +54,7 @@
/**
* @author <a href="mailto:[email protected]">Julien Viet</a>
*/
public class VertxServer extends Server {
public class VertxServer extends Server implements Resource {

private static final ConcurrentMap<ServerID, ActualServer> map = new ConcurrentHashMap<>();

Expand Down Expand Up @@ -166,6 +169,7 @@ void stop(ContextInternal context, Promise<Void> promise) {
this.builder = builder;
this.context = context;
this.commandDecorator = commandDecorator;
Core.getGlobalContext().register(this);
}

@Override
Expand Down Expand Up @@ -236,4 +240,26 @@ public void awaitTermination() throws InterruptedException {
public Server getRawServer() {
return actual.server;
}

@Override
public void beforeCheckpoint(Context<? extends Resource> context) throws Exception {
Promise<Void> promise = Promise.promise();
this.context.runOnContext(ignored -> {
if (actual != null) {
shutdown(promise);
}
});
promise.future().toCompletionStage().toCompletableFuture().get();
}

@Override
public void afterRestore(Context<? extends Resource> context) throws Exception {
Promise<Void> promise = Promise.promise();
this.context.runOnContext(ignored -> {
if (actual != null) {
start(promise);
}
});
promise.future().toCompletionStage().toCompletableFuture().get();
}
}

0 comments on commit d43d690

Please sign in to comment.