From 9726ca14993d6ba68d18f94960fc215e5fb98f99 Mon Sep 17 00:00:00 2001 From: Hellblazer Date: Fri, 5 Jan 2024 13:38:00 -0800 Subject: [PATCH] Configure DHT URL template, rather than hard-wire --- .../apollo/model/ProcessDomain.java | 22 +++++++++++-------- .../apollo/model/ContainmentDomainTest.java | 6 ++--- .../salesforce/apollo/model/DomainTest.java | 6 ++--- .../apollo/model/FireFliesTest.java | 16 ++++++-------- 4 files changed, 26 insertions(+), 24 deletions(-) diff --git a/model/src/main/java/com/salesforce/apollo/model/ProcessDomain.java b/model/src/main/java/com/salesforce/apollo/model/ProcessDomain.java index 1f574cbc9..ff2d3199f 100644 --- a/model/src/main/java/com/salesforce/apollo/model/ProcessDomain.java +++ b/model/src/main/java/com/salesforce/apollo/model/ProcessDomain.java @@ -43,10 +43,12 @@ */ public class ProcessDomain extends Domain { - private final static Logger log = LoggerFactory.getLogger(ProcessDomain.class); - protected final KerlDHT dht; - protected final View foundation; - private final UUID listener; + private final static String DEFAULT_DHT_DB_URL_TEMPLATE = "jdbc:h2:mem:%s-%s;DB_CLOSE_DELAY=-1"; + private final static Logger log = LoggerFactory.getLogger(ProcessDomain.class); + + protected final KerlDHT dht; + protected final View foundation; + private final UUID listener; public ProcessDomain(Digest group, ControlledIdentifierMember member, ProcessDomainParameters parameters, Builder builder, Parameters.RuntimeParameters.Builder runtime, InetSocketAddress endpoint, @@ -57,9 +59,10 @@ public ProcessDomain(Digest group, ControlledIdentifierMember member, ProcessDom .setpByz(parameters.dhtPbyz) .setId(group) .build(); - final var dhtUrl = String.format("jdbc:h2:mem:%s-%s;DB_CLOSE_DELAY=-1", member.getId(), UUID.randomUUID()); + var template = parameters.dhtDbUrlTemplate == null ? DEFAULT_DHT_DB_URL_TEMPLATE : parameters.dhtDbUrlTemplate; + final var dhtUrl = String.format(template, member.getId(), UUID.randomUUID()); JdbcConnectionPool connectionPool = JdbcConnectionPool.create(dhtUrl, "", ""); - connectionPool.setMaxConnections(10); + connectionPool.setMaxConnections(parameters.jdbcMaxConnections()); dht = new KerlDHT(parameters.dhtOpsFrequency, params.context(), member, connectionPool, params.digestAlgorithm(), params.communications(), parameters.dhtOperationsTimeout, parameters.dhtFpr, stereotomyMetrics); @@ -124,8 +127,9 @@ protected void stopServices() { dht.stop(); } - public record ProcessDomainParameters(String dbURL, Duration dhtOperationsTimeout, Path checkpointBaseDir, - Duration dhtOpsFrequency, double dhtFpr, Duration dhtEventValidTO, - int dhtBias, int jdbcMaxConnections, double dhtPbyz) { + public record ProcessDomainParameters(String dbURL, Duration dhtOperationsTimeout, String dhtDbUrlTemplate, + Path checkpointBaseDir, Duration dhtOpsFrequency, double dhtFpr, + Duration dhtEventValidTO, int dhtBias, int jdbcMaxConnections, + double dhtPbyz) { } } diff --git a/model/src/test/java/com/salesforce/apollo/model/ContainmentDomainTest.java b/model/src/test/java/com/salesforce/apollo/model/ContainmentDomainTest.java index a33746955..30ed6d221 100644 --- a/model/src/test/java/com/salesforce/apollo/model/ContainmentDomainTest.java +++ b/model/src/test/java/com/salesforce/apollo/model/ContainmentDomainTest.java @@ -85,9 +85,9 @@ public void before() throws Exception { final var member = new ControlledIdentifierMember(id); var localRouter = new LocalServer(prefix, member).router(ServerConnectionCache.newBuilder().setTarget(30)); routers.add(localRouter); - var dbUrl = String.format("jdbc:h2:mem:%s-%s;DB_CLOSE_DELAY=-1", member.getId(), UUID.randomUUID()); - var pdParams = new ProcessDomain.ProcessDomainParameters(dbUrl, Duration.ofMinutes(1), checkpointDirBase, - Duration.ofMillis(10), 0.00125, + var dbUrl = String.format("jdbc:h2:mem:sql-%s-%s;DB_CLOSE_DELAY=-1", member.getId(), UUID.randomUUID()); + var pdParams = new ProcessDomain.ProcessDomainParameters(dbUrl, Duration.ofMinutes(1), null, + checkpointDirBase, Duration.ofMillis(10), 0.00125, Duration.ofMinutes(1), 3, 10, 0.1); var domain = new ProcessContainerDomain(group, member, pdParams, params, RuntimeParameters.newBuilder() .setFoundation( diff --git a/model/src/test/java/com/salesforce/apollo/model/DomainTest.java b/model/src/test/java/com/salesforce/apollo/model/DomainTest.java index 25a714c97..acb806ff3 100644 --- a/model/src/test/java/com/salesforce/apollo/model/DomainTest.java +++ b/model/src/test/java/com/salesforce/apollo/model/DomainTest.java @@ -215,9 +215,9 @@ public void before() throws Exception { final var member = new ControlledIdentifierMember(id); var localRouter = new LocalServer(prefix, member).router(ServerConnectionCache.newBuilder().setTarget(30)); routers.add(localRouter); - var dbUrl = String.format("jdbc:h2:mem:%s-%s;DB_CLOSE_DELAY=-1", member.getId(), UUID.randomUUID()); - var pdParams = new ProcessDomain.ProcessDomainParameters(dbUrl, Duration.ofMinutes(1), checkpointDirBase, - Duration.ofMillis(10), 0.00125, + var dbUrl = String.format("jdbc:h2:mem:sql-%s-%s;DB_CLOSE_DELAY=-1", member.getId(), UUID.randomUUID()); + var pdParams = new ProcessDomain.ProcessDomainParameters(dbUrl, Duration.ofMinutes(1), null, + checkpointDirBase, Duration.ofMillis(10), 0.00125, Duration.ofMinutes(1), 3, 10, 0.1); var domain = new ProcessDomain(group, member, pdParams, params, RuntimeParameters.newBuilder() .setFoundation(sealed) diff --git a/model/src/test/java/com/salesforce/apollo/model/FireFliesTest.java b/model/src/test/java/com/salesforce/apollo/model/FireFliesTest.java index b7aab9b7c..751966814 100644 --- a/model/src/test/java/com/salesforce/apollo/model/FireFliesTest.java +++ b/model/src/test/java/com/salesforce/apollo/model/FireFliesTest.java @@ -86,9 +86,9 @@ public void before() throws Exception { var context = new ContextImpl<>(DigestAlgorithm.DEFAULT.getLast(), CARDINALITY, 0.2, 3); final var member = new ControlledIdentifierMember(id); var localRouter = new LocalServer(prefix, member).router(ServerConnectionCache.newBuilder().setTarget(30)); - var dbUrl = String.format("jdbc:h2:mem:%s-%s;DB_CLOSE_DELAY=-1", member.getId(), UUID.randomUUID()); - var pdParams = new ProcessDomain.ProcessDomainParameters(dbUrl, Duration.ofSeconds(5), checkpointDirBase, - Duration.ofMillis(10), 0.00125, + var dbUrl = String.format("jdbc:h2:mem:sql-%s-%s;DB_CLOSE_DELAY=-1", member.getId(), UUID.randomUUID()); + var pdParams = new ProcessDomain.ProcessDomainParameters(dbUrl, Duration.ofSeconds(5), null, + checkpointDirBase, Duration.ofMillis(10), 0.00125, Duration.ofSeconds(5), 3, 10, 0.1); var node = new ProcessDomain(group, member, pdParams, params, RuntimeParameters.newBuilder() .setFoundation(sealed) @@ -116,14 +116,12 @@ public void smokin() throws Exception { public void viewChange(Context context, Digest viewId, List joins, List leaves) { if (context.totalCount() == CARDINALITY) { - System.out.println( - String.format("Full view: %s members: %s on: %s", viewId, context.totalCount(), - d.getMember().getId())); + System.out.printf("Full view: %s members: %s on: %s%n", viewId, context.totalCount(), + d.getMember().getId()); countdown.countDown(); } else { - System.out.println( - String.format("Members joining: %s members: %s on: %s", viewId, context.totalCount(), - d.getMember().getId())); + System.out.printf("Members joining: %s members: %s on: %s%n", viewId, context.totalCount(), + d.getMember().getId()); } } };