ifesdjeen commented on code in PR #243: URL: https://github.com/apache/cassandra-accord/pull/243#discussion_r2285138262
########## accord-core/src/main/java/accord/local/MaxDecidedRX.java: ########## @@ -22,103 +22,198 @@ import accord.api.RoutingKey; import accord.api.VisibleForImplementation; import accord.primitives.Range; +import accord.primitives.Ranges; import accord.primitives.Routable.Domain; import accord.primitives.Routables; import accord.primitives.TxnId; import accord.primitives.Unseekable; import accord.primitives.Unseekables; import accord.utils.Invariants; -import static accord.primitives.TxnId.maxIfNull; -import static accord.primitives.TxnId.noneIfNull; - -import accord.primitives.Ranges; import accord.utils.ReducingRangeMap; -public class MaxDecidedRX extends ReducingRangeMap<TxnId> +import static accord.primitives.Timestamp.Flag.HLC_BOUND; + +public class MaxDecidedRX extends ReducingRangeMap<MaxDecidedRX.DecidedRX> { + public static final class DecidedRX + { + static final DecidedRX NONE = new DecidedRX(TxnId.NONE, TxnId.NONE); + static final DecidedRX MAX = new DecidedRX(TxnId.MAX, TxnId.MAX); + + public final TxnId any; + public final TxnId hlcBound; + + public DecidedRX(TxnId any, TxnId hlcBound) + { + this.any = any; + this.hlcBound = hlcBound; + } + + @Override + public String toString() + { + return "{any=" + any + ",hlcBound=" + hlcBound + "}"; + } + + public boolean includeDecided(TxnId txnId) + { + if (txnId.isSyncPoint()) + return txnId.compareTo(any) >= 0; + return txnId.compareTo(hlcBound) >= 0; + } + + public boolean includeDecided(long hlc) + { + return hlc >= hlcBound.hlc(); + } + + public boolean excludeDecided(long hlc) + { + return hlc < hlcBound.hlc(); + } + + public boolean excludeDecided(TxnId txnId) + { + return !includeDecided(txnId); + } + + DecidedRX min(DecidedRX that) + { + TxnId any = TxnId.min(this.any, that.any); + TxnId hlcBound = TxnId.mergeMin(this.hlcBound, that.hlcBound, TxnId::fromValues); + return selectOrCreate(any, hlcBound, this, that); + } + + static DecidedRX nonNullOrMin(DecidedRX a, DecidedRX b) + { + if (a == null || b == null) + return a == null ? b : a; + return a.min(b); + } + + DecidedRX max(DecidedRX that) + { + TxnId any = TxnId.max(this.any, that.any); + TxnId hlcBound = TxnId.max(this.hlcBound, that.hlcBound); + return selectOrCreate(any, hlcBound, this, that); + } + + static DecidedRX nonNullOrMax(DecidedRX a, DecidedRX b) + { + if (a == null || b == null) + return a == null ? b : a; + return a.max(b); + } + + static DecidedRX selectOrCreate(TxnId any, TxnId hlcBound, DecidedRX a, DecidedRX b) + { + if (any == a.any && hlcBound == a.hlcBound) + return a; + if (any == b.any && hlcBound == b.hlcBound) + return b; + return new DecidedRX(any, hlcBound); + } + } + public static final MaxDecidedRX EMPTY = new MaxDecidedRX(); private MaxDecidedRX() { super(); } - private MaxDecidedRX(boolean inclusiveEnds, RoutingKey[] starts, TxnId[] values) + private MaxDecidedRX(boolean inclusiveEnds, RoutingKey[] starts, DecidedRX[] values) { super(inclusiveEnds, starts, values); } - TxnId min(Routables<?> keysOrRanges) + DecidedRX min(Routables<?> keysOrRanges) { - return noneIfNull(foldlWithDefault(keysOrRanges, TxnId::nonNullOrMin, null, TxnId.NONE)); + DecidedRX result = foldlWithDefault(keysOrRanges, DecidedRX::nonNullOrMin, DecidedRX.NONE, null); + return result == null ? DecidedRX.NONE : result; } - TxnId max(Routables<?> keysOrRanges) + DecidedRX max(Routables<?> keysOrRanges) { - return maxIfNull(foldlWithDefault(keysOrRanges, TxnId::nonNullOrMax, null, TxnId.MAX)); + DecidedRX result = foldlWithDefault(keysOrRanges, DecidedRX::nonNullOrMax, DecidedRX.MAX, null); + return result == null ? DecidedRX.NONE : result; } - TxnId min(Range range) - { - return noneIfNull(foldlWithDefault(Ranges.of(range), TxnId::nonNullOrMin, null, TxnId.NONE)); - } - - TxnId max(Range range) - { - return maxIfNull(foldlWithDefault(Ranges.of(range), TxnId::nonNullOrMax, null, TxnId.MAX)); - } - public @Nullable TxnId minDecidedDependencyId(Unseekables<?> keysOrRanges, TxnId txnId) +// +// TxnId minAny(Routables<?> keysOrRanges) +// { +// return noneIfNull(foldlWithDefault(keysOrRanges, Entry::minAny, null, TxnId.NONE)); +// } +// +// TxnId maxAny(Routables<?> keysOrRanges) +// { Review Comment: nit: commented code -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: pr-unsubscr...@cassandra.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: pr-unsubscr...@cassandra.apache.org For additional commands, e-mail: pr-h...@cassandra.apache.org