In order to create a checkpoint using CRaC it is required that all sockets are closed before taking the snapshot.
JAVA-3928 already introduced ways to suspend the ConnectionPool via invalidate(...) and resume if afterwards via `ready`.
Is there a way to access the ConnectionPool to invoke those methods or maybe even provide some public API as outlined below
class MongoClientResource implements org.crac.Resource { MongoClient mongoClient; // ... @Override public void beforeCheckpoint(Context<? extends Resource> context) throws Exception { // mongoClient -> delegate -> cluster -> server -> connectionPool.invalidate(...) client.suspend(); } @Override public void afterRestore(Context<? extends Resource> context) throws Exception { // mongoClient -> delegate -> cluster -> server -> connectionPool.ready() client.resume(); } }
In doing so existing references to the MongoClient as well as obtained MongoDatabase, MongoCollection instances will remain valid, which would not be the case if the client was closed before the checkpoint and recreated from captured MongoClientSettings in the afterRestore method.