This is an automated email from the ASF dual-hosted git repository. benedict pushed a commit to branch trunk in repository https://gitbox.apache.org/repos/asf/cassandra-accord.git
commit 4aa0a8aeb6b12036660695e3fb89c69b5d40f345 Author: Benedict Elliott Smith <[email protected]> AuthorDate: Tue Aug 13 21:13:00 2024 +0100 Fix test failures --- .../src/main/java/accord/topology/Topology.java | 10 ++++--- .../java/accord/utils/CheckpointIntervalArray.java | 31 ---------------------- .../java/accord/utils/SearchableRangeList.java | 2 +- .../test/java/accord/primitives/RangeDepsTest.java | 2 +- .../test/java/accord/utils/ExtendedAssertions.java | 5 +++- 5 files changed, 13 insertions(+), 37 deletions(-) diff --git a/accord-core/src/main/java/accord/topology/Topology.java b/accord-core/src/main/java/accord/topology/Topology.java index 56fb0a10..3d148219 100644 --- a/accord-core/src/main/java/accord/topology/Topology.java +++ b/accord-core/src/main/java/accord/topology/Topology.java @@ -267,6 +267,7 @@ public class Topology { Ranges rangeSubset = ranges.select(newSubset); SimpleBitSet nodes = new SimpleBitSet(nodeIds.size()); + Int2ObjectHashMap<NodeInfo> nodeLookup = new Int2ObjectHashMap<>(nodes.size(), 0.8f); for (int shardIndex : newSubset) { Shard shard = shards[shardIndex]; @@ -288,15 +289,18 @@ public class Topology Topology forSubset(int[] newSubset, Collection<Id> nodes) { Ranges rangeSubset = ranges.select(newSubset); - Id[] nodeIds = nodes.toArray(new Id[nodes.size()]); - Arrays.sort(nodeIds); + Id[] nodeIds = new Id[nodes.size()]; Int2ObjectHashMap<NodeInfo> nodeLookup = new Int2ObjectHashMap<>(nodes.size(), 0.8f); for (Id id : nodes) { NodeInfo info = this.nodeLookup.get(id.id).forSubset(newSubset); if (info.ranges.isEmpty()) continue; + nodeIds[nodeLookup.size()] = id; nodeLookup.put(id.id, info); } + if (nodeLookup.size() != nodeIds.length) + nodeIds = Arrays.copyOf(nodeIds, nodeLookup.size()); + Arrays.sort(nodeIds); return new Topology(global(), epoch, shards, ranges, new SortedArrayList<>(nodeIds), nodeLookup, rangeSubset, newSubset); } @@ -515,7 +519,7 @@ public class Topology public List<Shard> shards() { - return new AbstractList<Shard>() + return new AbstractList<>() { @Override public Shard get(int i) diff --git a/accord-core/src/main/java/accord/utils/CheckpointIntervalArray.java b/accord-core/src/main/java/accord/utils/CheckpointIntervalArray.java index df9ffe1a..d5a60b71 100644 --- a/accord-core/src/main/java/accord/utils/CheckpointIntervalArray.java +++ b/accord-core/src/main/java/accord/utils/CheckpointIntervalArray.java @@ -24,7 +24,6 @@ import accord.utils.CheckpointIntervalArrayBuilder.Accessor; import net.nicoulaj.compilecommand.annotations.Inline; import static accord.utils.SortedArrays.Search.CEIL; -import static accord.utils.SortedArrays.Search.FLOOR; public class CheckpointIntervalArray<Ranges, Range, Key> { @@ -128,36 +127,6 @@ public class CheckpointIntervalArray<Ranges, Range, Key> return forEach(start, end, floor, startKey, 0, forEachScanOrCheckpoint, forEachRange, p1, p2, p3, p4, minIndex); } - public <P1, P2, P3, P4> int forEachKey(Key key, IndexedQuadConsumer<P1, P2, P3, P4> forEachScanOrCheckpoint, IndexedRangeQuadConsumer<P1, P2, P3, P4> forEachRange, P1 p1, P2 p2, P3 p3, P4 p4, int minIndex) - { - if (accessor.size(ranges) == 0 || minIndex == accessor.size(ranges)) - return minIndex; - - var c = accessor.keyComparator(); - int end = accessor.binarySearch(ranges, minIndex, accessor.size(ranges), key, (a, b) -> c.compare(a, accessor.start(b)), FLOOR); - if (end < 0) end = -1 - end; - else ++end; - if (end <= minIndex) return minIndex; - - int floor = accessor.binarySearch(ranges, minIndex, accessor.size(ranges), key, (a, b) -> c.compare(a, accessor.start(b)), CEIL); - int start = floor; - if (floor < 0) - { - // if there's no precise match on start, step backwards; - // if this range does not overlap us, step forwards again for start - // but retain the floor index for performing scan and checkpoint searches from - // as this contains all ranges that might overlap us (whereas those that end - // after us but before the next range's start would be missed by the next range index) - start = floor = -2 - floor; - if (start < 0) - start = floor = 0; - else if (c.compare(accessor.end(ranges, start), key) <= 0) - ++start; - } - - return forEach(start, end, floor, key, 0, forEachScanOrCheckpoint, forEachRange, p1, p2, p3, p4, minIndex); - } - @Inline protected <P1, P2, P3, P4> int forEach(int start, int end, int floor, Key startBound, int cmpStartBoundWithEnd, IndexedQuadConsumer<P1, P2, P3, P4> forEachScanOrCheckpoint, IndexedRangeQuadConsumer<P1, P2, P3, P4> forEachRange, diff --git a/accord-core/src/main/java/accord/utils/SearchableRangeList.java b/accord-core/src/main/java/accord/utils/SearchableRangeList.java index 65e4465f..5e677e82 100644 --- a/accord-core/src/main/java/accord/utils/SearchableRangeList.java +++ b/accord-core/src/main/java/accord/utils/SearchableRangeList.java @@ -86,7 +86,7 @@ public class SearchableRangeList extends CheckpointIntervalArray<Range[], Range, } @Inline - public <P1, P2, P3, P4> int forEach(RoutableKey key, IndexedQuadConsumer<P1, P2, P3, P4> forEachScanOrCheckpoint, IndexedRangeQuadConsumer<P1, P2, P3, P4> forEachRange, P1 p1, P2 p2, P3 p3, P4 p4, int minIndex) + public <P1, P2, P3, P4> int forEachKey(RoutableKey key, IndexedQuadConsumer<P1, P2, P3, P4> forEachScanOrCheckpoint, IndexedRangeQuadConsumer<P1, P2, P3, P4> forEachRange, P1 p1, P2 p2, P3 p3, P4 p4, int minIndex) { if (ranges.length == 0 || minIndex == ranges.length) return minIndex; diff --git a/accord-core/src/test/java/accord/primitives/RangeDepsTest.java b/accord-core/src/test/java/accord/primitives/RangeDepsTest.java index 5d6f0fdb..cf03e41c 100644 --- a/accord-core/src/test/java/accord/primitives/RangeDepsTest.java +++ b/accord-core/src/test/java/accord/primitives/RangeDepsTest.java @@ -247,7 +247,7 @@ public class RangeDepsTest for (int i = 0 ; i < 1000 ; ++i) { long seed = random.nextLong(); -// long seed = -5637243003494330136L; +// long seed = 1953755836248097851L; System.out.println("Seed: " + seed); random.setSeed(seed); generate(random, new GenerateRanges(1000, 0.01f, 0.3f, 0.1f, 1f), 100, 1000) diff --git a/accord-core/src/test/java/accord/utils/ExtendedAssertions.java b/accord-core/src/test/java/accord/utils/ExtendedAssertions.java index 0e4f8543..3546badc 100644 --- a/accord-core/src/test/java/accord/utils/ExtendedAssertions.java +++ b/accord-core/src/test/java/accord/utils/ExtendedAssertions.java @@ -30,6 +30,7 @@ import accord.primitives.Unseekables; import accord.topology.Shard; import accord.topology.Topologies; import accord.topology.Topology; +import accord.utils.SortedArrays.SortedArrayList; import org.agrona.collections.LongArrayList; import org.assertj.core.api.AbstractAssert; import org.assertj.core.api.Assertions; @@ -122,9 +123,11 @@ public class ExtendedAssertions return myself; } - public TopologyAssert isHostsEqualTo(List<Node.Id> nodes) + public TopologyAssert isHostsEqualTo(SortedArrayList<Node.Id> nodes) { isNotNull(); +// Collection<Node.Id> actualNodes = actual.nodes(); +// if (!(actualNodes instanceof SortedArrayList)) actualNodes = SortedArrayList.copyUnsorted(nodes, Node.Id[]::new); objects.assertEqual(info, actual.nodes(), nodes); return myself; } --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
