Skip to content

Commit

Permalink
serialize via single threaded executor
Browse files Browse the repository at this point in the history
  • Loading branch information
Hellblazer committed Jun 23, 2024
1 parent 6d6bd30 commit 129fa49
Showing 1 changed file with 4 additions and 15 deletions.
19 changes: 4 additions & 15 deletions choam/src/main/java/com/salesforce/apollo/choam/Producer.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,7 @@
import org.slf4j.LoggerFactory;

import java.util.*;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ConcurrentSkipListMap;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.Semaphore;
import java.util.concurrent.*;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicReference;

Expand All @@ -54,7 +51,8 @@ public class Producer {
private final Transitions transitions;
private final ViewContext view;
private final Digest nextViewId;
private final Semaphore serialize = new Semaphore(1);
private final Executor serialize = Executors.newSingleThreadExecutor(
Thread.ofVirtual().factory());
private final ViewAssembly assembly;
private final int maxEpoch;
private volatile boolean assembled = false;
Expand Down Expand Up @@ -351,22 +349,13 @@ private void reconfigure() {
}

private void serial(List<ByteString> preblock, Boolean last) {
try {
serialize.acquire();
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
return;
}
Thread.ofVirtual().start(() -> {
serialize.execute(() -> {
try {
create(preblock, last);
} catch (Throwable t) {
log.error("Error processing preblock last: {} on: {}", last, params().member().getId(), t);
} finally {
serialize.release();
}
});

}

private PendingBlock validate(Validate v) {
Expand Down

0 comments on commit 129fa49

Please sign in to comment.