Skip to content

Commit

Permalink
Fix test failures
Browse files Browse the repository at this point in the history
  • Loading branch information
belliottsmith committed Aug 13, 2024
1 parent 4b09c27 commit 734d7f7
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 36 deletions.
11 changes: 8 additions & 3 deletions accord-core/src/main/java/accord/topology/Topology.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
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;
Expand Down Expand Up @@ -267,6 +268,7 @@ Topology forSubset(int[] newSubset)
{
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];
Expand All @@ -288,15 +290,18 @@ Topology forSubset(int[] newSubset)
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);
}

Expand Down Expand Up @@ -515,7 +520,7 @@ public boolean contains(Id id)

public List<Shard> shards()
{
return new AbstractList<Shard>()
return new AbstractList<>()
{
@Override
public Shard get(int i)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,36 +128,6 @@ else if (c.compare(accessor.end(ranges, start), startKey) <= 0)
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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public SearchableRangeList(Range[] ranges, int[] lowerBounds, int[] headers, int
}

@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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ public void testRandom()
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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
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;
Expand Down Expand Up @@ -122,9 +123,11 @@ public TopologyAssert isShardsEqualTo(List<Shard> shards)
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;
}
Expand Down

0 comments on commit 734d7f7

Please sign in to comment.