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();
}
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);
}
}
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);
}
}
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;
}
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;
}
Aggregations