You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cassandra.apache.org by be...@apache.org on 2024/08/13 21:35:55 UTC
(cassandra-accord) 01/01: Fix test failures
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 734d7f7a1e9e5261fc4f5bfeb0265765a97374c1
Author: Benedict Elliott Smith <be...@apache.org>
AuthorDate: Tue Aug 13 21:13:00 2024 +0100
Fix test failures
---
.../src/main/java/accord/topology/Topology.java | 11 +++++---
.../java/accord/utils/CheckpointIntervalArray.java | 30 ----------------------
.../java/accord/utils/SearchableRangeList.java | 2 +-
.../test/java/accord/primitives/RangeDepsTest.java | 2 +-
.../test/java/accord/utils/ExtendedAssertions.java | 5 +++-
5 files changed, 14 insertions(+), 36 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..d442d2d3 100644
--- a/accord-core/src/main/java/accord/topology/Topology.java
+++ b/accord-core/src/main/java/accord/topology/Topology.java
@@ -45,6 +45,7 @@ import accord.utils.IndexedConsumer;
import accord.utils.IndexedIntFunction;
import accord.utils.IndexedTriFunction;
import accord.utils.SimpleBitSet;
+import accord.utils.SortedArrays;
import accord.utils.SortedArrays.SortedArrayList;
import accord.utils.Utils;
import org.agrona.collections.Int2ObjectHashMap;
@@ -267,6 +268,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 +290,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 +520,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..8979ec2e 100644
--- a/accord-core/src/main/java/accord/utils/CheckpointIntervalArray.java
+++ b/accord-core/src/main/java/accord/utils/CheckpointIntervalArray.java
@@ -128,36 +128,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: commits-unsubscribe@cassandra.apache.org
For additional commands, e-mail: commits-help@cassandra.apache.org