use of com.baidu.hugegraph.computer.core.common.exception.ComputerException in project hugegraph-computer by hugegraph.
the class ComputeManager method input.
public WorkerStat input() {
WorkerStat workerStat = new WorkerStat();
this.recvManager.waitReceivedAllMessages();
Map<Integer, PeekableIterator<KvEntry>> vertices = this.recvManager.vertexPartitions();
Map<Integer, PeekableIterator<KvEntry>> edges = this.recvManager.edgePartitions();
// TODO: parallel input process
for (Map.Entry<Integer, PeekableIterator<KvEntry>> entry : vertices.entrySet()) {
int partition = entry.getKey();
PeekableIterator<KvEntry> vertexIter = entry.getValue();
PeekableIterator<KvEntry> edgesIter = edges.getOrDefault(partition, PeekableIterator.emptyIterator());
FileGraphPartition part = new FileGraphPartition(this.context, this.managers, partition);
PartitionStat partitionStat = null;
ComputerException inputException = null;
try {
partitionStat = part.input(vertexIter, edgesIter);
} catch (ComputerException e) {
inputException = e;
} finally {
try {
vertexIter.close();
edgesIter.close();
} catch (Exception e) {
String message = "Failed to close vertex or edge file " + "iterator";
ComputerException closeException = new ComputerException(message, e);
if (inputException != null) {
inputException.addSuppressed(closeException);
} else {
throw closeException;
}
}
if (inputException != null) {
throw inputException;
}
}
workerStat.add(partitionStat);
this.partitions.put(partition, part);
}
return workerStat;
}
use of com.baidu.hugegraph.computer.core.common.exception.ComputerException in project hugegraph-computer by hugegraph.
the class FileGraphPartition method compute.
protected PartitionStat compute(WorkerContext context, int superstep) {
LOG.info("Partition {} begin compute in superstep {}", this.partition, superstep);
try {
this.beforeCompute(superstep);
} catch (IOException e) {
throw new ComputerException("Error occurred when beforeCompute at superstep %s", e, superstep);
}
long activeVertexCount;
try {
this.computation.beforeSuperstep(context);
activeVertexCount = superstep == 0 ? this.compute0(context) : this.compute1(context);
this.computation.afterSuperstep(context);
} catch (Exception e) {
throw new ComputerException("Error occurred when compute at superstep %s", e, superstep);
}
try {
this.afterCompute(superstep);
} catch (Exception e) {
throw new ComputerException("Error occurred when afterCompute at superstep %s", e, superstep);
}
LOG.info("Partition {} finish compute in superstep {}", this.partition, superstep);
return new PartitionStat(this.partition, this.vertexCount, this.edgeCount, this.vertexCount - activeVertexCount);
}
use of com.baidu.hugegraph.computer.core.common.exception.ComputerException in project hugegraph-computer by hugegraph.
the class FileGraphPartition method readVertexStatusAndValue.
private void readVertexStatusAndValue(Vertex vertex, Value result) {
try {
boolean activate = this.preStatusInput.readBoolean();
if (activate) {
vertex.reactivate();
} else {
vertex.inactivate();
}
} catch (IOException e) {
throw new ComputerException("Failed to read status of vertex '%s'", e, vertex);
}
try {
result.read(this.preValueInput);
vertex.value(result);
} catch (IOException e) {
throw new ComputerException("Failed to read value of vertex '%s'", e, vertex);
}
}
use of com.baidu.hugegraph.computer.core.common.exception.ComputerException in project hugegraph-computer by hugegraph.
the class FileGraphPartition method compute0.
private long compute0(ComputationContext context) {
long activeVertexCount = 0L;
while (this.vertexInput.hasNext()) {
Vertex vertex = this.vertexInput.next();
vertex.reactivate();
Edges edges = this.edgesInput.edges(this.vertexInput.idPointer());
vertex.edges(edges);
this.computation.compute0(context, vertex);
if (vertex.active()) {
activeVertexCount++;
}
try {
this.saveVertexStatusAndValue(vertex);
} catch (IOException e) {
throw new ComputerException("Error occurred when saveVertex: %s", e, vertex);
}
}
return activeVertexCount;
}
use of com.baidu.hugegraph.computer.core.common.exception.ComputerException in project hugegraph-computer by hugegraph.
the class EtcdClient method waitAndPrefixGetFromPutEvent.
/**
* Wait at most expected eventCount events triggered in timeout ms.
* This method wait at most timeout ms regardless whether expected
* eventCount events triggered.
* @param existedKeyValues readonly
*/
private List<byte[]> waitAndPrefixGetFromPutEvent(ByteSequence prefixSeq, int count, List<KeyValue> existedKeyValues, long revision, long timeout, long logInterval) throws InterruptedException {
Map<ByteSequence, ByteSequence> keyValues = new ConcurrentHashMap<>();
for (KeyValue kv : existedKeyValues) {
keyValues.put(kv.getKey(), kv.getValue());
}
WaitEvent<List<byte[]>> barrierEvent = new WaitEvent<>();
Consumer<WatchResponse> consumer = watchResponse -> {
List<WatchEvent> events = watchResponse.getEvents();
for (WatchEvent event : events) {
if (EventType.PUT.equals(event.getEventType())) {
KeyValue keyValue = event.getKeyValue();
keyValues.put(keyValue.getKey(), keyValue.getValue());
if (keyValues.size() == count) {
List<byte[]> result = new ArrayList<>(count);
for (ByteSequence byteSequence : keyValues.values()) {
result.add(byteSequence.getBytes());
}
barrierEvent.signalAll(result);
}
} else if (EventType.DELETE.equals(event.getEventType())) {
keyValues.remove(event.getKeyValue().getKey());
} else {
throw new ComputerException("Unexpected event type '%s'", event.getEventType());
}
}
};
WatchOption watchOption = WatchOption.newBuilder().withPrefix(prefixSeq).withRevision(revision).build();
try (Watch.Watcher watcher = this.watch.watch(prefixSeq, watchOption, consumer)) {
return barrierEvent.await(timeout, logInterval, () -> {
LOG.info("Wait for keys with prefix '{}' and timeout {}ms, " + "expect {} keys but actual got {} keys", prefixSeq.toString(ENCODING), timeout, count, keyValues.size());
});
}
}
Aggregations