bdeggleston commented on code in PR #65: URL: https://github.com/apache/cassandra-accord/pull/65#discussion_r1319184875
########## accord-core/src/main/java/accord/coordinate/TopologyMismatch.java: ########## @@ -0,0 +1,77 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package accord.coordinate; + +import java.util.EnumSet; + +import javax.annotation.Nullable; + +import accord.api.RoutingKey; +import accord.primitives.Routables; +import accord.primitives.Seekables; +import accord.primitives.TxnId; +import accord.topology.Topology; + +public class TopologyMismatch extends CoordinationFailed +{ + public final Topology topology; + public final Seekables<?, ?> keysOrRanges; + private final EnumSet<Reason> reasons; + + public enum Reason { HOME_KEY, KEYS_OR_RANGES } + + private TopologyMismatch(EnumSet<Reason> reasons, Topology topology, TxnId txnId, RoutingKey homeKey, Seekables<?, ?> keysOrRanges) + { + super(txnId, homeKey, buildMessage(reasons, topology, homeKey, keysOrRanges)); + this.reasons = reasons; + this.topology = topology; + this.keysOrRanges = keysOrRanges; + } + + private static String buildMessage(EnumSet<Reason> reason, Topology topology, RoutingKey homeKey, Seekables<?, ?> keysOrRanges) + { + StringBuilder sb = new StringBuilder(); + if (reason.contains(Reason.KEYS_OR_RANGES)) + sb.append(String.format("Txn attempted to access keys or ranges %s that are not longer valid globally (%d -> %s)", keysOrRanges, topology.epoch(), topology.ranges())); + if (reason.contains(Reason.HOME_KEY)) + { + if (sb.length() != 0) + sb.append('\n'); + sb.append(String.format("HomeKey %s exists for a range that is no longer globally valid (%d -> %s)", homeKey, topology.epoch(), topology.ranges())); + } + return sb.toString(); + } + + @Nullable + public static TopologyMismatch checkForMismatch(Topology t, TxnId txnId, RoutingKey homeKey, Seekables<?, ?> keysOrRanges) + { + EnumSet<TopologyMismatch.Reason> reasons = EnumSet.noneOf(TopologyMismatch.Reason.class); Review Comment: Can we set this to null and only allocate the EnumSet if we encounter a problem? ########## accord-core/src/main/java/accord/impl/InMemoryCommandStore.java: ########## @@ -92,6 +94,11 @@ public abstract class InMemoryCommandStore extends CommandStore private final TreeMap<TxnId, RangeCommand> rangeCommands = new TreeMap<>(); private final TreeMap<TxnId, Ranges> historicalRangeCommands = new TreeMap<>(); + /** + * Since this cache is fully in-memory the store does not hit states that most stores will; that data is not in-memory! + * To simulate such behaviors, a "cache" is used to state what is in-memory vs what needs to be loaded. + */ + private final Set<Object> cache = new LinkedHashSet<>(); Review Comment: I think the SafeCommandStore/SafeCommand would mostly address this coverage? It should throw if you attempt to load something that wasn't included in the PreLoadContext ########## accord-core/src/main/java/accord/messages/WaitUntilApplied.java: ########## @@ -170,6 +170,7 @@ private ReadNack apply(SafeCommandStore safeStore, SafeCommand safeCommand) } else { + // TODO (debug): this will cause us to send a Nack back, so why are we listening? Review Comment: reminder to remove ########## accord-core/src/main/java/accord/utils/async/AsyncChains.java: ########## @@ -363,6 +477,11 @@ protected void checkNextIsHead() Invariants.checkState(next instanceof Head<?>, "Next is not an instance of AsyncChains.Head (it is %s); was map/flatMap called on the same object multiple times?", next.getClass()); } + public static AsyncChain<?> detectLeak(Consumer<Throwable> onLeak, Runnable onCall) Review Comment: this is cool, WDYT about adding a flag to include this in every chain that can be used in testing? -- 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: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]

