Search in sources :

Example 51 with ComputerException

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

the class EdgesInput method edges.

public Edges edges(ReusablePointer vidPointer) {
    try {
        while (this.input.available() > 0) {
            long startPosition = this.input.position();
            this.idPointer.read(this.input);
            int status = vidPointer.compareTo(this.idPointer);
            if (status < 0) {
                // No edges
                /*
                     * The current batch belong to vertex that vertex id is
                     * bigger than specified id.
                     */
                this.input.seek(startPosition);
                return EmptyEdges.instance();
            } else if (status == 0) {
                // Has edges
                this.valuePointer.read(this.input);
                Edges edges = this.readEdges(this.valuePointer.input());
                if (edges.size() < this.flushThreshold) {
                    return edges;
                } else {
                    return new SuperEdges(vidPointer, edges, startPosition);
                }
            } else {
                /*
                     * The current batch belong to vertex that vertex id is
                     * smaller than specified id.
                     */
                int valueLength = this.input.readFixedInt();
                this.input.skip(valueLength);
            }
        }
        return EmptyEdges.instance();
    } catch (IOException e) {
        throw new ComputerException("Can't read from edges input '%s'", e, this.edgeFile.getAbsoluteFile());
    }
}
Also used : IOException(java.io.IOException) Edges(com.baidu.hugegraph.computer.core.graph.edge.Edges) ComputerException(com.baidu.hugegraph.computer.core.common.exception.ComputerException)

Example 52 with ComputerException

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

the class VertexInput method next.

public Vertex next() {
    this.readCount++;
    try {
        this.idPointer.read(this.input);
        this.valuePointer.read(this.input);
        RandomAccessInput valueInput = this.valuePointer.input();
        this.vertex.label(StreamGraphInput.readLabel(valueInput));
        this.properties.read(valueInput);
        this.vertex.id(StreamGraphInput.readId(this.idPointer.input()));
        this.vertex.properties(this.properties);
    } catch (IOException e) {
        throw new ComputerException("Can't read vertex from input '%s'", e, this.vertexFile.getAbsolutePath());
    }
    return this.vertex;
}
Also used : RandomAccessInput(com.baidu.hugegraph.computer.core.io.RandomAccessInput) IOException(java.io.IOException) ComputerException(com.baidu.hugegraph.computer.core.common.exception.ComputerException)

Example 53 with ComputerException

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

the class BytesId method asObject.

@Override
public Object asObject() {
    switch(this.idType) {
        case LONG:
            BytesInput input = IOFactory.createBytesInput(this.bytes, 0, this.length);
            try {
                return input.readLong();
            } catch (IOException e) {
                throw new ComputerException("Failed to read BytesId to " + "Long object");
            }
        case UTF8:
            return CoderUtil.decode(this.bytes, 0, this.length);
        case UUID:
            input = IOFactory.createBytesInput(this.bytes, 0, this.length);
            try {
                long high = input.readLong();
                long low = input.readLong();
                return new UUID(high, low);
            } catch (IOException e) {
                throw new ComputerException("Failed to read BytesId to " + "UUID object");
            }
        default:
            throw new ComputerException("Unexpected IdType %s", this.idType);
    }
}
Also used : BytesInput(com.baidu.hugegraph.computer.core.io.BytesInput) IOException(java.io.IOException) UUID(java.util.UUID) ComputerException(com.baidu.hugegraph.computer.core.common.exception.ComputerException)

Example 54 with ComputerException

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

the class BytesId method of.

public static BytesId of(UUID value) {
    E.checkArgument(value != null, "The value can't be null");
    long high = value.getMostSignificantBits();
    long low = value.getLeastSignificantBits();
    BytesOutput output = IOFactory.createBytesOutput(16);
    try {
        output.writeLong(high);
        output.writeLong(low);
    } catch (IOException e) {
        throw new ComputerException("Failed to write UUID object to " + "BytesId");
    }
    return new BytesId(IdType.UUID, output.buffer(), output.position());
}
Also used : BytesOutput(com.baidu.hugegraph.computer.core.io.BytesOutput) IOException(java.io.IOException) ComputerException(com.baidu.hugegraph.computer.core.common.exception.ComputerException)

Example 55 with ComputerException

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

the class AbstractPointerCombiner method combine.

public Pointer combine(Pointer v1, Pointer v2) {
    try {
        RandomAccessInput input1 = v1.input();
        RandomAccessInput input2 = v2.input();
        input1.seek(v1.offset());
        input2.seek(v2.offset());
        this.v1.read(input1);
        this.v2.read(input2);
        this.combiner.combine(this.v1, this.v2, this.result);
        this.output.seek(0L);
        this.result.write(this.output);
        return new InlinePointer(this.output.buffer(), this.output.position());
    } catch (Exception e) {
        throw new ComputerException("Failed to combine pointer1(offset=%s, length=%s) and " + "pointer2(offset=%s, length=%s)'", e, v1.offset(), v1.length(), v2.offset(), v2.length());
    }
}
Also used : RandomAccessInput(com.baidu.hugegraph.computer.core.io.RandomAccessInput) InlinePointer(com.baidu.hugegraph.computer.core.store.entry.InlinePointer) ComputerException(com.baidu.hugegraph.computer.core.common.exception.ComputerException) 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