Search in sources :

Example 56 with ComputerException

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

the class HdfsOutput method write.

@Override
public void write(Vertex vertex) {
    try {
        if (!this.filter(vertex)) {
            return;
        }
        this.writeString(vertex.id().toString());
        this.writeString(this.delimiter);
        this.writeString(this.constructValueString(vertex));
        this.writeString(System.lineSeparator());
    } catch (IOException e) {
        throw new ComputerException("Failed to write vertex: {}", vertex.toString(), e);
    }
}
Also used : IOException(java.io.IOException) ComputerException(com.baidu.hugegraph.computer.core.common.exception.ComputerException)

Example 57 with ComputerException

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

the class MessageSendManager method sendControlMessageToWorkers.

private void sendControlMessageToWorkers(Set<Integer> workerIds, MessageType type) {
    List<CompletableFuture<Void>> futures = new ArrayList<>();
    try {
        for (Integer workerId : workerIds) {
            futures.add(this.sender.send(workerId, type));
        }
    } catch (InterruptedException e) {
        throw new ComputerException("Interrupted when waiting to " + "send message async");
    }
    long timeout = type == MessageType.FINISH ? this.transportConf.timeoutFinishSession() : this.transportConf.timeoutSyncRequest();
    try {
        for (CompletableFuture<Void> future : futures) {
            future.get(timeout, TimeUnit.MILLISECONDS);
        }
    } catch (TimeoutException e) {
        throw new ComputerException("Timeout(%sms) to wait for " + "controling message(%s) to finished", e, timeout, type);
    } catch (InterruptedException | ExecutionException e) {
        throw new ComputerException("Failed to wait for controling " + "message(%s) to finished", e, type);
    }
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) ArrayList(java.util.ArrayList) ExecutionException(java.util.concurrent.ExecutionException) ComputerException(com.baidu.hugegraph.computer.core.common.exception.ComputerException) TimeoutException(java.util.concurrent.TimeoutException)

Example 58 with ComputerException

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

the class MessageSendManager method sendMessage.

public void sendMessage(Id targetId, Value value) {
    this.checkException();
    int partitionId = this.partitioner.partitionId(targetId);
    WriteBuffers buffer = this.buffers.get(partitionId);
    this.sortIfTargetBufferIsFull(buffer, partitionId, MessageType.MSG);
    try {
        // Write message to buffer
        buffer.writeMessage(targetId, value);
    } catch (IOException e) {
        throw new ComputerException("Failed to write message", e);
    }
}
Also used : IOException(java.io.IOException) ComputerException(com.baidu.hugegraph.computer.core.common.exception.ComputerException)

Example 59 with ComputerException

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

the class MessageSendManager method sortAndSendLastBuffer.

private MessageStat sortAndSendLastBuffer(Map<Integer, WriteBuffers> all, MessageType type) {
    MessageStat messageWritten = new MessageStat();
    List<Future<?>> futures = new ArrayList<>(all.size());
    // Sort and send the last buffer
    for (Map.Entry<Integer, WriteBuffers> entry : all.entrySet()) {
        int partitionId = entry.getKey();
        WriteBuffers buffer = entry.getValue();
        /*
             * If the last buffer has already been sorted and sent (empty),
             * there is no need to send again here
             */
        if (!buffer.isEmpty()) {
            buffer.prepareSorting();
            futures.add(this.sortThenSend(partitionId, type, buffer));
        }
        // Record total message count & bytes
        messageWritten.increase(buffer.messageWritten());
    }
    this.checkException();
    // Wait all future finished
    try {
        for (Future<?> future : futures) {
            future.get(Constants.FUTURE_TIMEOUT, TimeUnit.SECONDS);
        }
    } catch (TimeoutException e) {
        throw new ComputerException("Timed out to wait for sorting task " + "to finished", e);
    } catch (InterruptedException | ExecutionException e) {
        throw new ComputerException("Failed to wait for sorting task " + "to finished", e);
    }
    return messageWritten;
}
Also used : MessageStat(com.baidu.hugegraph.computer.core.receiver.MessageStat) ArrayList(java.util.ArrayList) ComputerException(com.baidu.hugegraph.computer.core.common.exception.ComputerException) CompletableFuture(java.util.concurrent.CompletableFuture) Future(java.util.concurrent.Future) ExecutionException(java.util.concurrent.ExecutionException) Map(java.util.Map) TimeoutException(java.util.concurrent.TimeoutException)

Example 60 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)

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