Search in sources :

Example 1 with ComputerException

use of com.baidu.hugegraph.computer.core.common.exception.ComputerException in project hugegraph-computer by hugegraph.

the class HgkvFileImpl method readFooter.

private void readFooter() throws IOException {
    File file = new File(this.path);
    // The footerLength occupied 4 bytes, versionLength 2 * 2 bytes
    long versionOffset = file.length() - Short.BYTES * 2 - Integer.BYTES;
    try (RandomAccessInput input = IOFactory.createFileInput(file)) {
        input.seek(versionOffset);
        // Read version
        short majorVersion = input.readShort();
        short minorVersion = input.readShort();
        String version = version(majorVersion, minorVersion);
        // Read footerLength
        int footerLength = input.readFixedInt();
        switch(version) {
            case "1.0":
                this.readFooterV1d0(input, file.length() - footerLength);
                break;
            default:
                throw new ComputerException("Illegal HgkvFile version '%s'", version);
        }
    }
}
Also used : RandomAccessInput(com.baidu.hugegraph.computer.core.io.RandomAccessInput) File(java.io.File) ComputerException(com.baidu.hugegraph.computer.core.common.exception.ComputerException)

Example 2 with ComputerException

use of com.baidu.hugegraph.computer.core.common.exception.ComputerException in project hugegraph-computer by hugegraph.

the class NettyTransportClientTest method testTransportPerformance.

@Test
public void testTransportPerformance() throws IOException, InterruptedException {
    Configurator.setAllLevels("com.baidu.hugegraph", Level.INFO);
    Configurator.setAllLevels("com.baidu.hugegraph.computer.core.network", Level.WARN);
    NettyTransportClient client = (NettyTransportClient) this.oneClient();
    ByteBuffer buffer = ByteBuffer.allocateDirect(50 * 1024);
    AtomicInteger handledCnt = new AtomicInteger(0);
    Mockito.doAnswer(invocationOnMock -> {
        invocationOnMock.callRealMethod();
        BARRIER_EVENT.signalAll();
        return null;
    }).when(clientHandler).sendAvailable(Mockito.any());
    Mockito.doAnswer(invocationOnMock -> {
        invocationOnMock.callRealMethod();
        handledCnt.getAndIncrement();
        return null;
    }).when(serverHandler).handle(Mockito.any(), Mockito.anyInt(), Mockito.any());
    long preTransport = System.nanoTime();
    client.startSession();
    int dataNum = 209716;
    long timout = 10_000L;
    for (int i = 0; i < dataNum; i++) {
        boolean send = client.send(MessageType.MSG, 1, buffer);
        if (!send) {
            LOG.info("Current send unavailable");
            i--;
            if (!BARRIER_EVENT.await(timout)) {
                throw new ComputerException("Timeout(%sms) to wait " + "sendable", timout);
            }
            BARRIER_EVENT.reset();
        }
    }
    client.finishSession();
    long postTransport = System.nanoTime();
    LOG.info("Transport {} data packets total 10GB, cost {}ms", dataNum, (postTransport - preTransport) / 1000_000L);
    Assert.assertEquals(dataNum, handledCnt.get());
    Configurator.setAllLevels("com.baidu.hugegraph.computer.core.network", Level.INFO);
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ByteBuffer(java.nio.ByteBuffer) ComputerException(com.baidu.hugegraph.computer.core.common.exception.ComputerException) Test(org.junit.Test)

Example 3 with ComputerException

use of com.baidu.hugegraph.computer.core.common.exception.ComputerException in project hugegraph-computer by hugegraph.

the class FileGraphPartition method compute1.

private long compute1(ComputationContext context, Computation<M> computation, int superstep) {
    Value result = this.context.config().createObject(ComputerOptions.ALGORITHM_RESULT_CLASS);
    long activeVertexCount = 0L;
    while (this.vertexInput.hasNext()) {
        Vertex vertex = this.vertexInput.next();
        this.readVertexStatusAndValue(vertex, result);
        Iterator<M> messageIter = this.messageInput.iterator(this.vertexInput.idPointer());
        if (messageIter.hasNext()) {
            vertex.reactivate();
        }
        /*
             * If the vertex is inactive, it's edges will be skipped
             * automatically at the next vertex.
             */
        if (vertex.active()) {
            Edges edges = this.edgesInput.edges(this.vertexInput.idPointer());
            vertex.edges(edges);
            computation.compute(context, vertex, messageIter);
        }
        // The vertex status may be changed after computation
        if (vertex.active()) {
            activeVertexCount++;
        }
        try {
            this.saveVertexStatusAndValue(vertex);
        } catch (IOException e) {
            throw new ComputerException("Error occurred when saveVertex", e);
        }
    }
    return activeVertexCount;
}
Also used : Vertex(com.baidu.hugegraph.computer.core.graph.vertex.Vertex) Value(com.baidu.hugegraph.computer.core.graph.value.Value) IOException(java.io.IOException) Edges(com.baidu.hugegraph.computer.core.graph.edge.Edges) ComputerException(com.baidu.hugegraph.computer.core.common.exception.ComputerException)

Example 4 with ComputerException

use of com.baidu.hugegraph.computer.core.common.exception.ComputerException in project hugegraph-computer by hugegraph.

the class FileGraphPartition method compute0.

private long compute0(ComputationContext context, Computation<M> computation) {
    long activeVertexCount = 0L;
    while (this.vertexInput.hasNext()) {
        Vertex vertex = this.vertexInput.next();
        vertex.reactivate();
        Edges edges = this.edgesInput.edges(this.vertexInput.idPointer());
        vertex.edges(edges);
        computation.compute0(context, vertex);
        if (vertex.active()) {
            activeVertexCount++;
        }
        try {
            this.saveVertexStatusAndValue(vertex);
        } catch (IOException e) {
            throw new ComputerException("Error occurred when saveVertex: %s", e, vertex);
        }
    }
    return activeVertexCount;
}
Also used : Vertex(com.baidu.hugegraph.computer.core.graph.vertex.Vertex) IOException(java.io.IOException) Edges(com.baidu.hugegraph.computer.core.graph.edge.Edges) ComputerException(com.baidu.hugegraph.computer.core.common.exception.ComputerException)

Example 5 with ComputerException

use of com.baidu.hugegraph.computer.core.common.exception.ComputerException in project hugegraph-computer by hugegraph.

the class EdgesInputTest method addEdgeBuffer.

private static void addEdgeBuffer(Consumer<ManagedBuffer> consumer, EdgeFrequency freq) throws IOException {
    for (long i = 0L; i < 200L; i++) {
        Vertex vertex = graphFactory().createVertex();
        vertex.id(BytesId.of(i));
        int count = (int) i;
        if (count == 0) {
            continue;
        }
        Edges edges = graphFactory().createEdges(count);
        for (long j = 0; j < count; j++) {
            Edge edge = graphFactory().createEdge();
            switch(freq) {
                case SINGLE:
                    edge.targetId(BytesId.of(j));
                    break;
                case SINGLE_PER_LABEL:
                    edge.label(String.valueOf(j));
                    edge.targetId(BytesId.of(j));
                    break;
                case MULTIPLE:
                    edge.name(String.valueOf(j));
                    edge.label(String.valueOf(j));
                    edge.targetId(BytesId.of(j));
                    break;
                default:
                    throw new ComputerException("Illegal edge frequency %s", freq);
            }
            Properties properties = graphFactory().createProperties();
            properties.put("p1", new LongValue(i));
            edge.properties(properties);
            edges.add(edge);
        }
        vertex.edges(edges);
        ReceiverUtil.consumeBuffer(writeEdges(vertex, freq), consumer);
    }
}
Also used : Vertex(com.baidu.hugegraph.computer.core.graph.vertex.Vertex) LongValue(com.baidu.hugegraph.computer.core.graph.value.LongValue) Properties(com.baidu.hugegraph.computer.core.graph.properties.Properties) Edges(com.baidu.hugegraph.computer.core.graph.edge.Edges) Edge(com.baidu.hugegraph.computer.core.graph.edge.Edge) ComputerException(com.baidu.hugegraph.computer.core.common.exception.ComputerException)

Aggregations

ComputerException (com.baidu.hugegraph.computer.core.common.exception.ComputerException)61 IOException (java.io.IOException)27 ExecutionException (java.util.concurrent.ExecutionException)13 Edges (com.baidu.hugegraph.computer.core.graph.edge.Edges)10 ByteSequence (io.etcd.jetcd.ByteSequence)9 ArrayList (java.util.ArrayList)8 GetResponse (io.etcd.jetcd.kv.GetResponse)7 Vertex (com.baidu.hugegraph.computer.core.graph.vertex.Vertex)6 RandomAccessInput (com.baidu.hugegraph.computer.core.io.RandomAccessInput)6 PartitionStat (com.baidu.hugegraph.computer.core.graph.partition.PartitionStat)5 GetOption (io.etcd.jetcd.options.GetOption)5 Map (java.util.Map)5 Edge (com.baidu.hugegraph.computer.core.graph.edge.Edge)4 BytesInput (com.baidu.hugegraph.computer.core.io.BytesInput)4 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)4 Properties (com.baidu.hugegraph.computer.core.graph.properties.Properties)3 Value (com.baidu.hugegraph.computer.core.graph.value.Value)3 MessageStat (com.baidu.hugegraph.computer.core.receiver.MessageStat)3 KeyValue (io.etcd.jetcd.KeyValue)3 DeleteResponse (io.etcd.jetcd.kv.DeleteResponse)3