Skip to content

Commit

Permalink
genesis/reassembly unblocking. use phaser instead of countdownlatch
Browse files Browse the repository at this point in the history
  • Loading branch information
Hellblazer committed Apr 6, 2024
1 parent 8898f0b commit 8df28c5
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
6 changes: 6 additions & 0 deletions choam/src/main/java/com/salesforce/apollo/choam/CHOAM.java
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,11 @@ public String logState() {
if (c == null) {
return "No committee on: %s".formatted(params.member().getId());
}
if (h.block == null) {
return "block is null, committee: %s state: %s on: %s ".formatted(c.getClass().getSimpleName(),
transitions.fsm().getCurrentState(),
params.member().getId());
}
return "block: %s hash: %s height: %s committee: %s state: %s on: %s ".formatted(h.block.getBodyCase(), h.hash,
h.height(),
c.getClass().getSimpleName(),
Expand Down Expand Up @@ -908,6 +913,7 @@ private void synchronize(SynchronizedState state) {
try {
linear.execute(Utils.wrapped(() -> {
transitions.regenerated();
transitions.combine();
}, log));
} catch (RejectedExecutionException e) {
// ignore
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ public class GenesisAssembly implements Genesis {
private final Transitions transitions;
private final ViewContext view;
private final Map<Member, Validate> witnesses = new ConcurrentHashMap<>();
private final OneShot ds;
private volatile Thread blockingThread;
private volatile OneShot ds;
private volatile HashedBlock reconfiguration;

public GenesisAssembly(ViewContext vc, CommonCommunications<Terminal, ?> comms, ViewMember genesisMember,
Expand Down Expand Up @@ -115,7 +115,6 @@ public void certify() {
var validate = view.generateValidation(reconfiguration);
log.debug("Certifying genesis block: {} for: {} count: {} on: {}", reconfiguration.hash, view.context().getId(),
slate.size(), params().member().getId());
ds = new OneShot();
ds.setValue(validate.toByteString());
}

Expand Down Expand Up @@ -168,7 +167,6 @@ public void gather(List<ByteString> preblock, boolean last) {

@Override
public void nominate() {
ds = new OneShot();
var validations = Validations.newBuilder();
proposals.values()
.stream()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,18 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.concurrent.CountDownLatch;
import java.util.concurrent.Phaser;
import java.util.function.Supplier;

public class OneShot implements Supplier<ByteString> {
private static final Logger log = LoggerFactory.getLogger(OneShot.class);

private final CountDownLatch latch = new CountDownLatch(1);
private volatile ByteString value;
private final Phaser phaser = new Phaser(1);
private volatile ByteString value;

@Override
public ByteString get() {
try {
latch.await();
} catch (InterruptedException e) {
return ByteString.EMPTY;
}
phaser.register();
final var current = value;
log.trace("providing value: " + (current == null ? "null" : String.valueOf(current.size())));
value = null;
Expand All @@ -35,6 +31,6 @@ public ByteString get() {
public void setValue(ByteString value) {
log.trace("resetting value: " + (value == null ? "null" : String.valueOf(value.size())));
this.value = value;
latch.countDown();
phaser.arriveAndDeregister();
}
}

0 comments on commit 8df28c5

Please sign in to comment.