Skip to content

Commit

Permalink
use tolerance + 1 for majority, rather than 2/3+1 in DHT/iterations.
Browse files Browse the repository at this point in the history
  • Loading branch information
Hellblazer committed Jun 11, 2024
1 parent f191845 commit a2c3a9f
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 32 deletions.
52 changes: 26 additions & 26 deletions fireflies/src/main/java/com/salesforce/apollo/fireflies/View.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,34 +82,34 @@
* @since 220
*/
public class View {
private static final String FINALIZE_VIEW_CHANGE = "FINALIZE VIEW CHANGE";
private static final Logger log = LoggerFactory.getLogger(
View.class);
private static final String SCHEDULED_VIEW_CHANGE = "Scheduled View Change";
final CommonCommunications<Fireflies, Service> comm;
final AtomicBoolean started = new AtomicBoolean();
private final CommonCommunications<Entrance, Service> approaches;
private final DynamicContext<Participant> context;
private final DigestAlgorithm digestAlgo;
private final RingCommunications<Participant, Fireflies> gossiper;
private final AtomicBoolean introduced = new AtomicBoolean();
private final List<BiConsumer<Context, Digest>> viewChangeListeners = new CopyOnWriteArrayList<>();
private final Executor viewNotificationQueue = Executors.newSingleThreadExecutor(
private static final String FINALIZE_VIEW_CHANGE = "FINALIZE VIEW CHANGE";
private static final Logger log = LoggerFactory.getLogger(View.class);
private static final String SCHEDULED_VIEW_CHANGE = "Scheduled View Change";

final CommonCommunications<Fireflies, Service> comm;
final AtomicBoolean started = new AtomicBoolean();
private final CommonCommunications<Entrance, Service> approaches;
private final DynamicContext<Participant> context;
private final DigestAlgorithm digestAlgo;
private final RingCommunications<Participant, Fireflies> gossiper;
private final AtomicBoolean introduced = new AtomicBoolean();
private final List<BiConsumer<Context, Digest>> viewChangeListeners = new CopyOnWriteArrayList<>();
private final Executor viewNotificationQueue = Executors.newSingleThreadExecutor(
Thread.ofVirtual().factory());
private final FireflyMetrics metrics;
private final Node node;
private final Map<Digest, SignedViewChange> observations = new ConcurrentSkipListMap<>();
private final Parameters params;
private final ConcurrentMap<Digest, RoundScheduler.Timer> pendingRebuttals = new ConcurrentSkipListMap<>();
private final RoundScheduler roundTimers;
private final Set<Digest> shunned = new ConcurrentSkipListSet<>();
private final Map<String, RoundScheduler.Timer> timers = new HashMap<>();
private final ReadWriteLock viewChange = new ReentrantReadWriteLock(
private final FireflyMetrics metrics;
private final Node node;
private final Map<Digest, SignedViewChange> observations = new ConcurrentSkipListMap<>();
private final Parameters params;
private final ConcurrentMap<Digest, RoundScheduler.Timer> pendingRebuttals = new ConcurrentSkipListMap<>();
private final RoundScheduler roundTimers;
private final Set<Digest> shunned = new ConcurrentSkipListSet<>();
private final Map<String, RoundScheduler.Timer> timers = new HashMap<>();
private final ReadWriteLock viewChange = new ReentrantReadWriteLock(
true);
private final ViewManagement viewManagement;
private final EventValidation validation;
private final Verifiers verifiers;
private volatile ScheduledFuture<?> futureGossip;
private final ViewManagement viewManagement;
private final EventValidation validation;
private final Verifiers verifiers;
private volatile ScheduledFuture<?> futureGossip;

public View(DynamicContext<Participant> context, ControlledIdentifierMember member, String endpoint,
EventValidation validation, Verifiers verifiers, Router communications, Parameters params,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ private void proceed(Digest key, final boolean allow, Runnable onMajority, Runna
member.getId());
} else {
if (onMajority != null && !majoritySucceed) {
if (tally.get() >= context.majority()) {
if (tally.get() > context.toleranceLevel()) {
majoritySucceed = true;
log.debug("Obtained: {} majority of: {} for digest: {} tally: {} on: {}", current, key,
context.getId(), tally.get(), member.getId());
Expand Down
10 changes: 5 additions & 5 deletions thoth/src/main/java/com/salesforce/apollo/thoth/KerlDHT.java
Original file line number Diff line number Diff line change
Expand Up @@ -778,7 +778,7 @@ private <T> void completeIt(CompletableFuture<T> result, HashMultiset<T> gathere
.stream()
.max(Ordering.natural().onResultOf(Multiset.Entry::getCount))
.orElse(null);
var majority = context.size() == 1 ? 1 : context.majority();
var majority = context.size() == 1 ? 1 : context.toleranceLevel() + 1;
if (max != null) {
if (max.getCount() >= majority) {
try {
Expand All @@ -796,10 +796,10 @@ private <T> void completeIt(CompletableFuture<T> result, HashMultiset<T> gathere

private boolean failedMajority(CompletableFuture<?> result, int maxAgree, String operation) {
log.debug("Unable to achieve majority read: {}, max: {} required: {} on: {}", operation, maxAgree,
context.majority(), member.getId());
context.toleranceLevel() + 1, member.getId());
return result.completeExceptionally(new CompletionException(
"Unable to achieve majority read: " + operation + ", max: " + maxAgree + " required: " + context.majority()
+ " on: " + member.getId()));
"Unable to achieve majority read: " + operation + ", max: " + maxAgree + " required: "
+ context.toleranceLevel() + 1 + " on: " + member.getId()));
}

private void initializeSchema() {
Expand Down Expand Up @@ -877,7 +877,7 @@ private <T> boolean read(CompletableFuture<T> result, HashMultiset<T> gathered,
var max = max(gathered);
if (max != null) {
tally.set(max.getCount());
var ctxMajority = context.size() == 1 ? 1 : context.majority();
var ctxMajority = context.size() == 1 ? 1 : context.toleranceLevel() + 1;
final var majority = tally.get() >= ctxMajority;
if (majority) {
result.complete(max.getElement());
Expand Down

0 comments on commit a2c3a9f

Please sign in to comment.