Search in sources :

Example 31 with ComputerException

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

the class SerializeUtil method fromBytes.

public static <V extends Readable> List<V> fromBytes(byte[] bytes, Supplier<V> supplier) {
    try (BytesInput bai = IOFactory.createBytesInput(bytes)) {
        int size = bai.readInt();
        List<V> list = new ArrayList<>(size);
        for (int i = 0; i < size; i++) {
            V obj = supplier.get();
            obj.read(bai);
            list.add(obj);
        }
        return list;
    } catch (IOException e) {
        throw new ComputerException("Failed to read from byte array", e);
    }
}
Also used : BytesInput(com.baidu.hugegraph.computer.core.io.BytesInput) ArrayList(java.util.ArrayList) IOException(java.io.IOException) ComputerException(com.baidu.hugegraph.computer.core.common.exception.ComputerException)

Example 32 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 33 with ComputerException

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

the class EntriesUtil method subKvEntryFromInput.

public static KvEntry subKvEntryFromInput(RandomAccessInput input, RandomAccessInput userAccessInput, boolean useInlinePointer) {
    try {
        Pointer key, value;
        if (useInlinePointer) {
            byte[] keyBytes = input.readBytes(input.readFixedInt());
            key = new InlinePointer(keyBytes);
            byte[] valueBytes = input.readBytes(input.readFixedInt());
            value = new InlinePointer(valueBytes);
        } else {
            int keyLength = input.readFixedInt();
            key = new CachedPointer(userAccessInput, input.position(), keyLength);
            input.skip(keyLength);
            int valueLength = input.readFixedInt();
            value = new CachedPointer(userAccessInput, input.position(), valueLength);
            input.skip(valueLength);
        }
        return new DefaultKvEntry(key, value);
    } catch (IOException e) {
        throw new ComputerException(e.getMessage(), e);
    }
}
Also used : IOException(java.io.IOException) ComputerException(com.baidu.hugegraph.computer.core.common.exception.ComputerException)

Example 34 with ComputerException

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

the class MockWorkerInputManager method loadEdgeInputSplitData.

public int loadEdgeInputSplitData() {
    if (this.edgeInputSplit == null) {
        throw new ComputerException("Should fetch edge input split meta " + "before load");
    }
    if (this.edgeInputSplit.equals(InputSplit.END_SPLIT)) {
        throw new ComputerException("Can't load edge input split data, " + "because it has been exhausted");
    }
    EdgeFetcher edgeFetcher = this.fetcher.edgeFetcher();
    edgeFetcher.prepareLoadInputSplit(this.edgeInputSplit);
    int count = 0;
    while (edgeFetcher.hasNext()) {
        Edge edge = edgeFetcher.next();
        // Write edge to buffer
        Assert.assertNotNull(edge);
        count++;
    }
    return count;
}
Also used : Edge(com.baidu.hugegraph.structure.graph.Edge) ComputerException(com.baidu.hugegraph.computer.core.common.exception.ComputerException)

Example 35 with ComputerException

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

the class MockWorkerInputManager method loadVertexInputSplitData.

public int loadVertexInputSplitData() {
    if (this.vertexInputSplit == null) {
        throw new ComputerException("Should fetch vertex input split " + "meta before load");
    }
    if (this.vertexInputSplit.equals(InputSplit.END_SPLIT)) {
        throw new ComputerException("Can't load vertex input split data, " + "because it has been exhausted");
    }
    VertexFetcher vertexFetcher = this.fetcher.vertexFetcher();
    vertexFetcher.prepareLoadInputSplit(this.vertexInputSplit);
    int count = 0;
    while (vertexFetcher.hasNext()) {
        Vertex vertex = vertexFetcher.next();
        // Write vertex to buffer
        Assert.assertNotNull(vertex);
        count++;
    }
    return count;
}
Also used : Vertex(com.baidu.hugegraph.structure.graph.Vertex) 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