Search in sources :

Example 11 with IntIndexedContainer

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);
                    }
                }
            }
        }
    }
}
Also used : IntCursor(com.carrotsearch.hppc.cursors.IntCursor) IntIndexedContainer(com.carrotsearch.hppc.IntIndexedContainer) TreeMap(java.util.TreeMap) Map(java.util.Map)

Example 12 with IntIndexedContainer

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));
}
Also used : MergePhase(io.crate.execution.dsl.phases.MergePhase) Routing(io.crate.metadata.Routing) Collection(java.util.Collection) IntIndexedContainer(com.carrotsearch.hppc.IntIndexedContainer) NodeOperation(io.crate.execution.dsl.phases.NodeOperation) ExecutionPhase(io.crate.execution.dsl.phases.ExecutionPhase) TreeMap(java.util.TreeMap) UUID(java.util.UUID) RoutedCollectPhase(io.crate.execution.dsl.phases.RoutedCollectPhase) Test(org.junit.Test)

Example 13 with IntIndexedContainer

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);
}
Also used : ShardRouting(org.elasticsearch.cluster.routing.ShardRouting) Routing(io.crate.metadata.Routing) IntIndexedContainer(com.carrotsearch.hppc.IntIndexedContainer) TreeMap(java.util.TreeMap) ShardRouting(org.elasticsearch.cluster.routing.ShardRouting) IntArrayList(com.carrotsearch.hppc.IntArrayList) Map(java.util.Map) TreeMap(java.util.TreeMap)

Example 14 with IntIndexedContainer

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()));
}
Also used : StreamInput(org.elasticsearch.common.io.stream.StreamInput) IntIndexedContainer(com.carrotsearch.hppc.IntIndexedContainer) TreeMap(java.util.TreeMap) TreeMap(java.util.TreeMap) Map(java.util.Map) BytesStreamOutput(org.elasticsearch.common.io.stream.BytesStreamOutput) Test(org.junit.Test)

Example 15 with IntIndexedContainer

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);
}
Also used : IntIndexedContainer(com.carrotsearch.hppc.IntIndexedContainer) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) ArgumentsSource(org.junit.jupiter.params.provider.ArgumentsSource)

Aggregations

IntIndexedContainer (com.carrotsearch.hppc.IntIndexedContainer)30 Map (java.util.Map)17 IntCursor (com.carrotsearch.hppc.cursors.IntCursor)10 ArrayList (java.util.ArrayList)10 TreeMap (java.util.TreeMap)7 Index (org.elasticsearch.index.Index)7 IntArrayList (com.carrotsearch.hppc.IntArrayList)6 RelationName (io.crate.metadata.RelationName)6 List (java.util.List)6 CompletableFuture (java.util.concurrent.CompletableFuture)6 IndexMetadata (org.elasticsearch.cluster.metadata.IndexMetadata)6 Metadata (org.elasticsearch.cluster.metadata.Metadata)6 ShardId (org.elasticsearch.index.shard.ShardId)6 Test (org.junit.Test)6 Routing (io.crate.metadata.Routing)5 ClusterService (org.elasticsearch.cluster.service.ClusterService)5 IndexNotFoundException (org.elasticsearch.index.IndexNotFoundException)5 ShardCollectorProvider (io.crate.execution.engine.collect.ShardCollectorProvider)4 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)4 IllegalIndexShardStateException (org.elasticsearch.index.shard.IllegalIndexShardStateException)4