From 1782b3faaa0e6f11d86b4b97bcc95a37456e0977 Mon Sep 17 00:00:00 2001 From: Hellblazer Date: Sat, 27 Apr 2024 20:45:25 -0700 Subject: [PATCH] hallelujah! build runs green View change protocol now stable. --- .../apollo/choam/support/Bootstrapper.java | 14 +++++++++++--- .../salesforce/apollo/choam/support/Store.java | 12 +++++++----- .../salesforce/apollo/choam/Transactioneer.java | 2 +- .../apollo/choam/support/BootstrapperTest.java | 1 + choam/src/test/resources/logback-test.xml | 4 ++-- sql-state/pom.xml | 8 ++++++++ .../apollo/state/AbstractLifecycleTest.java | 17 +++++++++++++---- .../com/salesforce/apollo/state/CHOAMTest.java | 8 +++++++- .../salesforce/apollo/state/Transactioneer.java | 13 +++++++------ sql-state/src/test/resources/logback-test.xml | 10 +++++----- 10 files changed, 62 insertions(+), 27 deletions(-) diff --git a/choam/src/main/java/com/salesforce/apollo/choam/support/Bootstrapper.java b/choam/src/main/java/com/salesforce/apollo/choam/support/Bootstrapper.java index bd1bf5072..a47e4438d 100644 --- a/choam/src/main/java/com/salesforce/apollo/choam/support/Bootstrapper.java +++ b/choam/src/main/java/com/salesforce/apollo/choam/support/Bootstrapper.java @@ -143,7 +143,13 @@ private void checkpointCompletion(int threshold, Initial mostRecent) { .filter(cb -> cb.getBlock().hasReconfigure()) .map(cb -> new HashedCertifiedBlock(params.digestAlgorithm(), cb)) .forEach(reconfigure -> store.put(reconfigure)); - scheduleViewChainCompletion(new AtomicReference<>(checkpointView.height()), ULong.valueOf(0)); + var lastReconfig = ULong.valueOf(checkpointView.block.getHeader().getLastReconfig()); + var zero = ULong.valueOf(0); + if (lastReconfig.equals(zero)) { + viewChainSynchronized.complete(true); + } else { + scheduleViewChainCompletion(new AtomicReference<>(lastReconfig), zero); + } } private boolean completeAnchor(Optional futureSailor, AtomicReference start, ULong end, @@ -214,7 +220,9 @@ private Blocks completeViewChain(Terminal link, AtomicReference start, UL long seed = Entropy.nextBitsStreamLong(); ULongBloomFilter blocksBff = new BloomFilter.ULongBloomFilter(seed, params.bootstrap().maxViewBlocks() * 2, params.combine().falsePositiveRate()); - start.set(store.lastViewChainFrom(start.get())); + var lastViewChain = store.lastViewChainFrom(start.get()); + assert lastViewChain != null : "last view chain from: " + start.get() + " is null"; + start.set(lastViewChain); store.viewChainFrom(start.get(), end).forEachRemaining(h -> blocksBff.add(h)); BlockReplication replication = BlockReplication.newBuilder() .setBlocksBff(blocksBff.toBff()) @@ -468,7 +476,7 @@ private void validateAnchor() { try { store.validate(anchor.height(), to); anchorSynchronized.complete(true); - log.info("Anchor chain to checkpoint synchronized on: {}", params.member().getId()); + log.info("Anchor chain to checkpoint synchronized to: {} on: {}", to, params.member().getId()); } catch (Throwable e) { log.error("Anchor chain from: {} to: {} does not validate on: {}", anchor.height(), to, params.member().getId(), e); diff --git a/choam/src/main/java/com/salesforce/apollo/choam/support/Store.java b/choam/src/main/java/com/salesforce/apollo/choam/support/Store.java index 11c0a07f5..e15df2bb2 100644 --- a/choam/src/main/java/com/salesforce/apollo/choam/support/Store.java +++ b/choam/src/main/java/com/salesforce/apollo/choam/support/Store.java @@ -72,7 +72,7 @@ public byte[] block(ULong height) { public Iterator blocksFrom(ULong from, ULong to, int max) { return new Iterator<>() { ULong next; - int remaining = max; + int remaining = max; { next = from == null ? ULong.valueOf(0) : from; @@ -247,7 +247,7 @@ public ULong lastViewChainFrom(ULong height) { } next = viewChain.get(next); } - return last; + return next == null ? last : next; } public void put(HashedCertifiedBlock cb) { @@ -353,8 +353,8 @@ public Iterator viewChainFrom(ULong from, ULong to) { ULong next; { - next = viewChain.get(from); - if (!viewChain.containsKey(next)) { + next = from; + if (!viewChain.containsKey(from)) { next = null; } } @@ -412,10 +412,12 @@ private void put(Digest hash, Block block) { hashes.put(height, hash); hashToHeight.put(hash, height); if (block.hasReconfigure() || block.hasGenesis()) { + log.trace("insert view chain: {}:{}", height, hash); viewChain.put(ULong.valueOf(block.getHeader().getHeight()), ULong.valueOf(block.getHeader().getLastReconfig())); + } else { + log.trace("insert: {}:{}", height, hash); } - log.trace("insert: {}:{}", height, hash); } private T transactionally(Callable action) throws ExecutionException { diff --git a/choam/src/test/java/com/salesforce/apollo/choam/Transactioneer.java b/choam/src/test/java/com/salesforce/apollo/choam/Transactioneer.java index 18bd101a8..7466042b8 100644 --- a/choam/src/test/java/com/salesforce/apollo/choam/Transactioneer.java +++ b/choam/src/test/java/com/salesforce/apollo/choam/Transactioneer.java @@ -24,7 +24,7 @@ class Transactioneer { private final static Random entropy = new Random(); private final static Logger log = LoggerFactory.getLogger(Transactioneer.class); - private final Executor executor = Executors.newVirtualThreadPerTaskExecutor(); + private final static Executor executor = Executors.newVirtualThreadPerTaskExecutor(); private final ScheduledExecutorService scheduler; private final AtomicInteger completed = new AtomicInteger(); private final CountDownLatch countdown; diff --git a/choam/src/test/java/com/salesforce/apollo/choam/support/BootstrapperTest.java b/choam/src/test/java/com/salesforce/apollo/choam/support/BootstrapperTest.java index 0275f948c..e0a2b6233 100644 --- a/choam/src/test/java/com/salesforce/apollo/choam/support/BootstrapperTest.java +++ b/choam/src/test/java/com/salesforce/apollo/choam/support/BootstrapperTest.java @@ -63,6 +63,7 @@ public void smoke() throws Exception { var context = new StaticContext(DigestAlgorithm.DEFAULT.getOrigin(), 0.2, members, 3); TestChain testChain = new TestChain(bootstrapStore); testChain.genesis() + .checkpoint() .userBlocks(10) .viewChange() .userBlocks(10) diff --git a/choam/src/test/resources/logback-test.xml b/choam/src/test/resources/logback-test.xml index b0a99fb23..830a6923d 100644 --- a/choam/src/test/resources/logback-test.xml +++ b/choam/src/test/resources/logback-test.xml @@ -29,11 +29,11 @@ - + - + diff --git a/sql-state/pom.xml b/sql-state/pom.xml index 1e73a795c..890ebc727 100644 --- a/sql-state/pom.xml +++ b/sql-state/pom.xml @@ -84,6 +84,14 @@ org.codehaus.mojo build-helper-maven-plugin + + org.apache.maven.plugins + maven-surefire-plugin + + 1 + false + + diff --git a/sql-state/src/test/java/com/salesforce/apollo/state/AbstractLifecycleTest.java b/sql-state/src/test/java/com/salesforce/apollo/state/AbstractLifecycleTest.java index 8a6820c5c..45343e6de 100644 --- a/sql-state/src/test/java/com/salesforce/apollo/state/AbstractLifecycleTest.java +++ b/sql-state/src/test/java/com/salesforce/apollo/state/AbstractLifecycleTest.java @@ -42,6 +42,8 @@ import java.time.Duration; import java.util.*; import java.util.concurrent.CountDownLatch; +import java.util.concurrent.Executors; +import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicReference; import java.util.function.Function; @@ -81,9 +83,10 @@ abstract public class AbstractLifecycleTest { protected SigningMember testSubject; protected int toleranceLevel; DynamicContextImpl context; - private File baseDir; - private File checkpointDirBase; - private List transactioneers; + private File baseDir; + private File checkpointDirBase; + private List transactioneers; + private ScheduledExecutorService scheduler; { var txns = MigrationTest.initializeBookSchema(); @@ -115,6 +118,10 @@ public void after() throws Exception { choams.values().forEach(e -> e.stop()); choams = null; } + if (scheduler != null) { + scheduler.shutdownNow(); + scheduler = null; + } updaters.values().forEach(up -> up.close()); updaters.clear(); parameters.clear(); @@ -125,6 +132,7 @@ public void after() throws Exception { @BeforeEach public void before() throws Exception { + scheduler = Executors.newScheduledThreadPool(10); checkpointOccurred = new CountDownLatch(CARDINALITY); checkpointDirBase = new File("target/ct-chkpoints-" + Entropy.nextBitsStreamLong()); Utils.clean(checkpointDirBase); @@ -301,7 +309,8 @@ protected void pre() throws Exception { .toList())); var mutator = txneer.getMutator(choams.get(members.getLast().getId()).getSession()); - transactioneers.add(new Transactioneer(() -> update(entropy, mutator), mutator, timeout, 1, countdown)); + transactioneers.add( + new Transactioneer(scheduler, () -> update(entropy, mutator), mutator, timeout, 1, countdown)); System.out.println("Transaction member: " + members.getLast().getId()); System.out.println("Starting txns"); transactioneers.stream().forEach(e -> e.start()); diff --git a/sql-state/src/test/java/com/salesforce/apollo/state/CHOAMTest.java b/sql-state/src/test/java/com/salesforce/apollo/state/CHOAMTest.java index 1e264a6f7..433ef9acb 100644 --- a/sql-state/src/test/java/com/salesforce/apollo/state/CHOAMTest.java +++ b/sql-state/src/test/java/com/salesforce/apollo/state/CHOAMTest.java @@ -81,6 +81,7 @@ public class CHOAMTest { private List members; private MetricRegistry registry; private Map routers; + private ScheduledExecutorService scheduler; private static Txn initialInsert() { return Txn.newBuilder() @@ -102,6 +103,10 @@ public void after() throws Exception { choams.values().forEach(e -> e.stop()); choams = null; } + if (scheduler != null) { + scheduler.shutdownNow(); + scheduler = null; + } updaters.values().forEach(up -> up.close()); updaters.clear(); members = null; @@ -117,6 +122,7 @@ public void after() throws Exception { @BeforeEach public void before() throws Exception { + scheduler = Executors.newScheduledThreadPool(10); registry = new MetricRegistry(); checkpointDirBase = new File("target/ct-chkpoints-" + Entropy.nextBitsStreamLong()); Utils.clean(checkpointDirBase); @@ -184,7 +190,7 @@ public void submitMultiplTxn() throws Exception { var mutator = e.getValue().getMutator(choams.get(e.getKey().getId()).getSession()); for (int i = 0; i < clientCount; i++) { transactioneers.add( - new Transactioneer(() -> update(entropy, mutator), mutator, timeout, max, countdown)); + new Transactioneer(scheduler, () -> update(entropy, mutator), mutator, timeout, max, countdown)); } }); System.out.println("Starting txns"); diff --git a/sql-state/src/test/java/com/salesforce/apollo/state/Transactioneer.java b/sql-state/src/test/java/com/salesforce/apollo/state/Transactioneer.java index 19c3ded10..8140fb295 100644 --- a/sql-state/src/test/java/com/salesforce/apollo/state/Transactioneer.java +++ b/sql-state/src/test/java/com/salesforce/apollo/state/Transactioneer.java @@ -21,12 +21,11 @@ import java.util.function.Supplier; class Transactioneer { - private final static Random entropy = new Random(); - private final static Logger log = LoggerFactory.getLogger(Transactioneer.class); - private final static ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1, Thread.ofVirtual() - .factory()); + private final static Random entropy = new Random(); + private final static Logger log = LoggerFactory.getLogger(Transactioneer.class); + private final static Executor executor = Executors.newVirtualThreadPerTaskExecutor(); - private final Executor executor = Executors.newVirtualThreadPerTaskExecutor(); + private final ScheduledExecutorService scheduler; private final AtomicInteger completed = new AtomicInteger(); private final CountDownLatch countdown; private final AtomicReference inFlight = new AtomicReference<>(); @@ -36,7 +35,9 @@ class Transactioneer { private final Supplier update; private final AtomicBoolean finished = new AtomicBoolean(); - public Transactioneer(Supplier update, Mutator mutator, Duration timeout, int max, CountDownLatch countdown) { + public Transactioneer(ScheduledExecutorService scheduler, Supplier update, Mutator mutator, Duration timeout, + int max, CountDownLatch countdown) { + this.scheduler = scheduler; this.update = update; this.timeout = timeout; this.max = max; diff --git a/sql-state/src/test/resources/logback-test.xml b/sql-state/src/test/resources/logback-test.xml index ed5f0398c..e65c45614 100644 --- a/sql-state/src/test/resources/logback-test.xml +++ b/sql-state/src/test/resources/logback-test.xml @@ -24,7 +24,7 @@ - + @@ -36,15 +36,15 @@ - + - + - + @@ -60,7 +60,7 @@ - +