Search in sources :

Example 36 with ComputerException

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

the class DegreeCentrality method compute0.

@Override
public void compute0(ComputationContext context, Vertex vertex) {
    if (!this.calculateByWeightProperty) {
        vertex.value(new DoubleValue(vertex.numEdges()));
    } else {
        /*
             *  TODO: Here we use doubleValue type now, we will use BigDecimal
             *  and output "BigDecimalValue" to resolve double type overflow
             *  int the future;
             */
        double totalWeight = 0.0;
        Iterator<Edge> edges = vertex.edges().iterator();
        while (edges.hasNext()) {
            Edge edge = edges.next();
            double weight = weightValue(edge.property(this.weightProperty));
            totalWeight += weight;
            if (Double.isInfinite(totalWeight)) {
                throw new ComputerException("Calculate weight overflow," + "current is %s, edge '%s' " + "is %s", totalWeight, edge, weight);
            }
        }
        vertex.value(new DoubleValue(totalWeight));
    }
    vertex.inactivate();
}
Also used : DoubleValue(com.baidu.hugegraph.computer.core.graph.value.DoubleValue) Edge(com.baidu.hugegraph.computer.core.graph.edge.Edge) ComputerException(com.baidu.hugegraph.computer.core.common.exception.ComputerException)

Example 37 with ComputerException

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

the class DataClientManager method connect.

public void connect(int workerId, String hostname, int dataPort) {
    try {
        TransportClient client = this.connManager.getOrCreateClient(hostname, dataPort);
        LOG.info("Successfully connect to worker: {}({}:{})", workerId, hostname, dataPort);
        this.sender.addWorkerClient(workerId, client);
    } catch (TransportException e) {
        throw new ComputerException("Failed to connect to worker: %s(%s:%s)", workerId, hostname, dataPort);
    }
}
Also used : TransportException(com.baidu.hugegraph.computer.core.common.exception.TransportException) ComputerException(com.baidu.hugegraph.computer.core.common.exception.ComputerException)

Example 38 with ComputerException

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

the class TransportUtil method getLocalIPAddress.

public static List<String> getLocalIPAddress() {
    List<String> ips = new ArrayList<>();
    try {
        Enumeration<NetworkInterface> allNetInterfaces = NetworkInterface.getNetworkInterfaces();
        InetAddress ip;
        while (allNetInterfaces.hasMoreElements()) {
            NetworkInterface netInterface = allNetInterfaces.nextElement();
            if (!netInterface.isLoopback() && !netInterface.isVirtual() && netInterface.isUp()) {
                Enumeration<InetAddress> addresses = netInterface.getInetAddresses();
                while (addresses.hasMoreElements()) {
                    ip = addresses.nextElement();
                    if (ip instanceof Inet4Address) {
                        ips.add(ip.getHostAddress());
                    }
                }
            }
        }
        return ips;
    } catch (Exception e) {
        throw new ComputerException("Failed to getLocalIPAddress", e);
    }
}
Also used : Inet4Address(java.net.Inet4Address) ArrayList(java.util.ArrayList) NetworkInterface(java.net.NetworkInterface) InetAddress(java.net.InetAddress) UnknownHostException(java.net.UnknownHostException) ComputerException(com.baidu.hugegraph.computer.core.common.exception.ComputerException) ComputerException(com.baidu.hugegraph.computer.core.common.exception.ComputerException)

Example 39 with ComputerException

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

the class FileRegionBuffer method transformFromChannel.

/**
 * Use zero-copy transform from socket channel to file
 * @param channel
 * @param targetPath
 * @return channelFuture
 */
public ChannelFuture transformFromChannel(SocketChannel channel, String targetPath) {
    assert channel.eventLoop().inEventLoop();
    ChannelPromise channelPromise = channel.newPromise();
    try {
        if (channel instanceof EpollSocketChannel) {
            // Use splice zero-copy if io mode is epoll
            FileDescriptor fd = FileDescriptor.from(targetPath);
            try {
                ((EpollSocketChannel) channel).spliceTo(fd, 0, this.length, channelPromise);
                channelPromise.addListener(future -> fd.close());
            } catch (Throwable throwable) {
                fd.close();
                throw throwable;
            }
        } else {
            // Use memory map zero-copy if io mode is not epoll
            try (RandomAccessFile file = new RandomAccessFile(targetPath, Constants.FILE_MODE_WRITE)) {
                FileChannel fileChannel = file.getChannel();
                NioSocketChannel nioChannel = (NioSocketChannel) channel;
                ReadableByteChannel javaChannel = (ReadableByteChannel) nioChannel.unsafe().ch();
                fileChannel.transferFrom(javaChannel, 0, this.length);
                channelPromise.setSuccess();
                fileChannel.close();
            }
        }
        this.path = targetPath;
    } catch (Throwable throwable) {
        channelPromise.setFailure(throwable);
        throw new ComputerException("Failed to transform from socket to file, " + "targetPath:%s, remoteAddress:%s", throwable, targetPath, TransportUtil.remoteAddress(channel));
    }
    return channelPromise;
}
Also used : NioSocketChannel(io.netty.channel.socket.nio.NioSocketChannel) ReadableByteChannel(java.nio.channels.ReadableByteChannel) RandomAccessFile(java.io.RandomAccessFile) FileChannel(java.nio.channels.FileChannel) EpollSocketChannel(io.netty.channel.epoll.EpollSocketChannel) ChannelPromise(io.netty.channel.ChannelPromise) FileDescriptor(io.netty.channel.unix.FileDescriptor) ComputerException(com.baidu.hugegraph.computer.core.common.exception.ComputerException)

Example 40 with ComputerException

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

the class ComputeManager method compute.

public WorkerStat compute(WorkerContext context, int superstep) {
    this.sendManager.startSend(MessageType.MSG);
    WorkerStat workerStat = new WorkerStat();
    Map<Integer, PartitionStat> stats = new ConcurrentHashMap<>();
    /*
         * Remark: The main thread can perceive the partition compute exception
         * only after all partition compute completed, and only record the last
         * exception.
         */
    Consumers<FileGraphPartition> consumers = new Consumers<>(this.computeExecutor, partition -> {
        PartitionStat stat = partition.compute(context, superstep);
        stats.put(stat.partitionId(), stat);
    });
    consumers.start("partition-compute");
    try {
        for (FileGraphPartition partition : this.partitions.values()) {
            consumers.provide(partition);
        }
        consumers.await();
    } catch (Throwable t) {
        throw new ComputerException("An exception occurred when " + "partition parallel compute", t);
    }
    this.sendManager.finishSend(MessageType.MSG);
    // After compute and send finish signal.
    Map<Integer, MessageStat> recvStats = this.recvManager.messageStats();
    for (Map.Entry<Integer, PartitionStat> entry : stats.entrySet()) {
        PartitionStat partStat = entry.getValue();
        int partitionId = partStat.partitionId();
        MessageStat sendStat = this.sendManager.messageStat(partitionId);
        partStat.mergeSendMessageStat(sendStat);
        MessageStat recvStat = recvStats.get(partitionId);
        if (recvStat != null) {
            partStat.mergeRecvMessageStat(recvStat);
        }
        workerStat.add(partStat);
    }
    return workerStat;
}
Also used : MessageStat(com.baidu.hugegraph.computer.core.receiver.MessageStat) Consumers(com.baidu.hugegraph.computer.core.util.Consumers) ComputerException(com.baidu.hugegraph.computer.core.common.exception.ComputerException) PartitionStat(com.baidu.hugegraph.computer.core.graph.partition.PartitionStat) WorkerStat(com.baidu.hugegraph.computer.core.worker.WorkerStat) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) Map(java.util.Map)

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