use of com.baidu.hugegraph.computer.core.common.exception.ComputerException in project hugegraph-computer by hugegraph.
the class HdfsOutput method write.
@Override
public void write(Vertex vertex) {
try {
if (!this.filter(vertex)) {
return;
}
this.writeString(vertex.id().toString());
this.writeString(this.delimiter);
this.writeString(this.constructValueString(vertex));
this.writeString(System.lineSeparator());
} catch (IOException e) {
throw new ComputerException("Failed to write vertex: {}", vertex.toString(), e);
}
}
use of com.baidu.hugegraph.computer.core.common.exception.ComputerException in project hugegraph-computer by hugegraph.
the class MessageSendManager method sendControlMessageToWorkers.
private void sendControlMessageToWorkers(Set<Integer> workerIds, MessageType type) {
List<CompletableFuture<Void>> futures = new ArrayList<>();
try {
for (Integer workerId : workerIds) {
futures.add(this.sender.send(workerId, type));
}
} catch (InterruptedException e) {
throw new ComputerException("Interrupted when waiting to " + "send message async");
}
long timeout = type == MessageType.FINISH ? this.transportConf.timeoutFinishSession() : this.transportConf.timeoutSyncRequest();
try {
for (CompletableFuture<Void> future : futures) {
future.get(timeout, TimeUnit.MILLISECONDS);
}
} catch (TimeoutException e) {
throw new ComputerException("Timeout(%sms) to wait for " + "controling message(%s) to finished", e, timeout, type);
} catch (InterruptedException | ExecutionException e) {
throw new ComputerException("Failed to wait for controling " + "message(%s) to finished", e, type);
}
}
use of com.baidu.hugegraph.computer.core.common.exception.ComputerException in project hugegraph-computer by hugegraph.
the class MessageSendManager method sendMessage.
public void sendMessage(Id targetId, Value value) {
this.checkException();
int partitionId = this.partitioner.partitionId(targetId);
WriteBuffers buffer = this.buffers.get(partitionId);
this.sortIfTargetBufferIsFull(buffer, partitionId, MessageType.MSG);
try {
// Write message to buffer
buffer.writeMessage(targetId, value);
} catch (IOException e) {
throw new ComputerException("Failed to write message", e);
}
}
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, WriteBuffers> all, MessageType type) {
MessageStat messageWritten = new MessageStat();
List<Future<?>> futures = new ArrayList<>(all.size());
// Sort and send the last buffer
for (Map.Entry<Integer, WriteBuffers> entry : all.entrySet()) {
int partitionId = entry.getKey();
WriteBuffers buffer = entry.getValue();
/*
* If the last buffer has already been sorted and sent (empty),
* there is no need to send again here
*/
if (!buffer.isEmpty()) {
buffer.prepareSorting();
futures.add(this.sortThenSend(partitionId, type, buffer));
}
// Record total message count & bytes
messageWritten.increase(buffer.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 EntriesUtil method subKvEntryFromInput.
public static KvEntry subKvEntryFromInput(RandomAccessInput input, RandomAccessInput userAccessInput, boolean useInlinePointer) {
try {
Pointer key, value;
if (useInlinePointer) {
byte[] keyBytes = input.readBytes(input.readFixedInt());
key = new InlinePointer(keyBytes);
byte[] valueBytes = input.readBytes(input.readFixedInt());
value = new InlinePointer(valueBytes);
} else {
int keyLength = input.readFixedInt();
key = new CachedPointer(userAccessInput, input.position(), keyLength);
input.skip(keyLength);
int valueLength = input.readFixedInt();
value = new CachedPointer(userAccessInput, input.position(), valueLength);
input.skip(valueLength);
}
return new DefaultKvEntry(key, value);
} catch (IOException e) {
throw new ComputerException(e.getMessage(), e);
}
}
Aggregations