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