Search in sources :

Example 21 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, MessageSendPartition> all, MessageType type) {
    MessageStat messageWritten = new MessageStat();
    List<Future<?>> futures = new ArrayList<>(all.size());
    // Sort and send the last buffer
    for (Map.Entry<Integer, MessageSendPartition> entry : all.entrySet()) {
        int partitionId = entry.getKey();
        MessageSendPartition partition = entry.getValue();
        /*
             * If the last buffer has already been sorted and sent (empty),
             * there is no need to send again here
             */
        for (WriteBuffers buffer : partition.buffers()) {
            if (!buffer.isEmpty()) {
                buffer.prepareSorting();
                futures.add(this.sortThenSend(partitionId, type, buffer));
            }
        }
        // Record total message count & bytes
        messageWritten.increase(partition.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 22 with ComputerException

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

the class MessageSendManager method sendVertex.

/**
 * There will multiple threads calling the method
 */
public void sendVertex(Vertex vertex) {
    this.checkException();
    int partitionId = this.partitioner.partitionId(vertex.id());
    WriteBuffers buffer = this.buffers.get(partitionId);
    this.sortIfTargetBufferIsFull(buffer, partitionId, MessageType.VERTEX);
    try {
        // Write vertex to buffer
        buffer.writeVertex(vertex);
    } catch (IOException e) {
        throw new ComputerException("Failed to write vertex '%s'", e, vertex.id());
    }
}
Also used : IOException(java.io.IOException) ComputerException(com.baidu.hugegraph.computer.core.common.exception.ComputerException)

Example 23 with ComputerException

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

the class MessageSendManager method sendEdge.

public void sendEdge(Vertex vertex) {
    this.checkException();
    int partitionId = this.partitioner.partitionId(vertex.id());
    WriteBuffers buffer = this.buffers.get(partitionId);
    this.sortIfTargetBufferIsFull(buffer, partitionId, MessageType.EDGE);
    try {
        // Write edge to buffer
        buffer.writeEdges(vertex);
    } catch (IOException e) {
        throw new ComputerException("Failed to write edges of " + "vertex '%s'", e, vertex.id());
    }
}
Also used : IOException(java.io.IOException) ComputerException(com.baidu.hugegraph.computer.core.common.exception.ComputerException)

Example 24 with ComputerException

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

the class EntriesUtil method kvEntryWithFirstSubKv.

public static KvEntryWithFirstSubKv kvEntryWithFirstSubKv(KvEntry entry) {
    try {
        BytesInput input = IOFactory.createBytesInput(entry.value().bytes());
        // Read sub-entry size
        long subKvNum = input.readFixedInt();
        KvEntry firstSubKv = EntriesUtil.subKvEntryFromInput(input, true);
        return new KvEntryWithFirstSubKv(entry.key(), entry.value(), firstSubKv, subKvNum);
    } catch (IOException e) {
        throw new ComputerException(e.getMessage(), e);
    }
}
Also used : BytesInput(com.baidu.hugegraph.computer.core.io.BytesInput) IOException(java.io.IOException) ComputerException(com.baidu.hugegraph.computer.core.common.exception.ComputerException)

Example 25 with ComputerException

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

the class LoaderFileInputSplitFetcher method scanHdfsPaths.

private List<String> scanHdfsPaths(HDFSSource hdfsSource) {
    List<String> paths = new ArrayList<>();
    try {
        Configuration configuration = this.loadConfiguration(hdfsSource);
        this.enableKerberos(hdfsSource, configuration);
        try (FileSystem hdfs = FileSystem.get(configuration)) {
            Path path = new Path(hdfsSource.path());
            FileFilter filter = hdfsSource.filter();
            if (hdfs.getFileStatus(path).isFile()) {
                if (!filter.reserved(path.getName())) {
                    throw new ComputerException("Please check path name and extensions, ensure " + "that at least one path is available for reading");
                }
                paths.add(path.toString());
            } else {
                assert hdfs.getFileStatus(path).isDirectory();
                FileStatus[] statuses = hdfs.listStatus(path);
                Path[] subPaths = FileUtil.stat2Paths(statuses);
                for (Path subPath : subPaths) {
                    if (filter.reserved(subPath.getName())) {
                        paths.add(subPath.toString());
                    }
                }
            }
        }
    } catch (Throwable throwable) {
        throw new ComputerException("Failed to scanPaths", throwable);
    }
    return paths;
}
Also used : Path(org.apache.hadoop.fs.Path) FileStatus(org.apache.hadoop.fs.FileStatus) Configuration(org.apache.hadoop.conf.Configuration) FileSystem(org.apache.hadoop.fs.FileSystem) ArrayList(java.util.ArrayList) FileFilter(com.baidu.hugegraph.loader.source.file.FileFilter) 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