use of com.carrotsearch.hppc.IntIndexedContainer in project crate by crate.
the class Routing method writeTo.
@Override
public void writeTo(StreamOutput out) throws IOException {
out.writeVInt(locations.size());
for (Map.Entry<String, Map<String, IntIndexedContainer>> entry : locations.entrySet()) {
out.writeString(entry.getKey());
Map<String, IntIndexedContainer> shardsByIndex = entry.getValue();
if (shardsByIndex == null) {
out.writeVInt(0);
} else {
out.writeVInt(shardsByIndex.size());
for (Map.Entry<String, IntIndexedContainer> innerEntry : shardsByIndex.entrySet()) {
out.writeString(innerEntry.getKey());
IntIndexedContainer shardIds = innerEntry.getValue();
if (shardIds == null || shardIds.size() == 0) {
out.writeVInt(0);
} else {
out.writeVInt(shardIds.size());
for (IntCursor shardId : shardIds) {
out.writeVInt(shardId.value);
}
}
}
}
}
}
use of com.carrotsearch.hppc.IntIndexedContainer in project crate by crate.
the class ExecutionPhasesRootTaskTest method testGroupByServer.
@Test
public void testGroupByServer() throws Exception {
var routingMap = new TreeMap<String, Map<String, IntIndexedContainer>>();
routingMap.put("node1", Map.of("t1", IntArrayList.from(1, 2)));
routingMap.put("node2", Map.of("t1", IntArrayList.from(3, 4)));
Routing twoNodeRouting = new Routing(routingMap);
UUID jobId = UUID.randomUUID();
RoutedCollectPhase c1 = new RoutedCollectPhase(jobId, 1, "c1", twoNodeRouting, RowGranularity.DOC, List.of(), List.of(), WhereClause.MATCH_ALL.queryOrFallback(), DistributionInfo.DEFAULT_BROADCAST);
MergePhase m1 = new MergePhase(jobId, 2, "merge1", 2, 1, Set.of("node3", "node4"), List.of(), List.of(), DistributionInfo.DEFAULT_BROADCAST, null);
MergePhase m2 = new MergePhase(jobId, 3, "merge2", 2, 1, Set.of("node1", "node3"), List.of(), List.of(), DistributionInfo.DEFAULT_BROADCAST, null);
NodeOperation n1 = NodeOperation.withDownstream(c1, m1, (byte) 0);
NodeOperation n2 = NodeOperation.withDownstream(m1, m2, (byte) 0);
NodeOperation n3 = NodeOperation.withDownstream(m2, mock(ExecutionPhase.class), (byte) 0);
Map<String, Collection<NodeOperation>> groupByServer = NodeOperationGrouper.groupByServer(List.of(n1, n2, n3));
assertThat(groupByServer.containsKey("node1"), is(true));
assertThat(groupByServer.get("node1"), Matchers.containsInAnyOrder(n1, n3));
assertThat(groupByServer.containsKey("node2"), is(true));
assertThat(groupByServer.get("node2"), Matchers.containsInAnyOrder(n1));
assertThat(groupByServer.containsKey("node3"), is(true));
assertThat(groupByServer.get("node3"), Matchers.containsInAnyOrder(n2, n3));
assertThat(groupByServer.containsKey("node4"), is(true));
assertThat(groupByServer.get("node4"), Matchers.containsInAnyOrder(n2));
}
use of com.carrotsearch.hppc.IntIndexedContainer in project crate by crate.
the class DocLevelCollectTest method routing.
private Routing routing(String table) {
Map<String, Map<String, IntIndexedContainer>> locations = new TreeMap<>();
for (final ShardRouting shardRouting : clusterService().state().routingTable().allShards(table)) {
Map<String, IntIndexedContainer> shardIds = locations.get(shardRouting.currentNodeId());
if (shardIds == null) {
shardIds = new TreeMap<>();
locations.put(shardRouting.currentNodeId(), shardIds);
}
IntIndexedContainer shardIdSet = shardIds.get(shardRouting.getIndexName());
if (shardIdSet == null) {
shardIdSet = new IntArrayList();
shardIds.put(shardRouting.index().getName(), shardIdSet);
}
shardIdSet.add(shardRouting.id());
}
return new Routing(locations);
}
use of com.carrotsearch.hppc.IntIndexedContainer in project crate by crate.
the class RoutingTest method testStreamingWithLocations.
@Test
public void testStreamingWithLocations() throws Exception {
Map<String, Map<String, IntIndexedContainer>> locations = new TreeMap<>();
Map<String, IntIndexedContainer> indexMap = new TreeMap<>();
indexMap.put("index-0", IntArrayList.from(1, 2));
locations.put("node-0", indexMap);
BytesStreamOutput out = new BytesStreamOutput();
Routing routing1 = new Routing(locations);
routing1.writeTo(out);
StreamInput in = out.bytes().streamInput();
Routing routing2 = new Routing(in);
assertThat(routing1.locations(), is(routing2.locations()));
}
use of com.carrotsearch.hppc.IntIndexedContainer in project graphhopper by graphhopper.
the class RoutingAlgorithmTest method testRekeyBugOfIntBinHeap.
@ParameterizedTest
@ArgumentsSource(FixtureProvider.class)
public void testRekeyBugOfIntBinHeap(Fixture f) {
// using Dijkstra + IntBinHeap then rekey loops endlessly
GraphHopperStorage matrixGraph = f.createGHStorage();
initMatrixALikeGraph(matrixGraph, f.carEncoder);
Path p = f.calcPath(matrixGraph, 36, 91);
assertEquals(12, p.calcNodes().size());
IntIndexedContainer nodes = p.calcNodes();
if (!nodes(36, 46, 56, 66, 76, 86, 85, 84, 94, 93, 92, 91).equals(nodes) && !nodes(36, 46, 56, 66, 76, 86, 85, 84, 83, 82, 92, 91).equals(nodes)) {
fail("wrong locations: " + nodes.toString());
}
assertEquals(66f, p.getDistance(), 1e-3);
testBug1(f, matrixGraph);
testCorrectWeight(f, matrixGraph);
}
Aggregations