Search in sources :

Example 31 with KvEntry

use of com.baidu.hugegraph.computer.core.store.entry.KvEntry in project hugegraph-computer by hugegraph.

the class MessageInputTest method testMessageInput.

@Test
public void testMessageInput() throws IOException {
    MessageRecvManager receiveManager = this.managers.get(MessageRecvManager.NAME);
    receiveManager.onStarted(this.connectionId);
    // Superstep 0
    receiveManager.beforeSuperstep(this.config, 0);
    receiveManager.onStarted(this.connectionId);
    addMessages((NetworkBuffer buffer) -> {
        receiveManager.handle(MessageType.MSG, 0, buffer);
    });
    receiveManager.onFinished(this.connectionId);
    PeekableIterator<KvEntry> it = receiveManager.messagePartitions().get(0);
    MessageInput<IdList> input = new MessageInput<>(context(), it);
    Map<Id, List<IdList>> expectedMessages = expectedMessages();
    checkMessages(expectedMessages, input);
}
Also used : MessageRecvManager(com.baidu.hugegraph.computer.core.receiver.MessageRecvManager) KvEntry(com.baidu.hugegraph.computer.core.store.entry.KvEntry) NetworkBuffer(com.baidu.hugegraph.computer.core.network.buffer.NetworkBuffer) ArrayList(java.util.ArrayList) IdList(com.baidu.hugegraph.computer.core.graph.value.IdList) List(java.util.List) IdListList(com.baidu.hugegraph.computer.core.graph.value.IdListList) Id(com.baidu.hugegraph.computer.core.graph.id.Id) BytesId(com.baidu.hugegraph.computer.core.graph.id.BytesId) ConnectionId(com.baidu.hugegraph.computer.core.network.ConnectionId) IdList(com.baidu.hugegraph.computer.core.graph.value.IdList) Test(org.junit.Test)

Example 32 with KvEntry

use of com.baidu.hugegraph.computer.core.store.entry.KvEntry 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;
}
Also used : KvEntry(com.baidu.hugegraph.computer.core.store.entry.KvEntry) ComputerException(com.baidu.hugegraph.computer.core.common.exception.ComputerException) 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) PeekableIterator(com.baidu.hugegraph.computer.core.sort.flusher.PeekableIterator) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) Map(java.util.Map)

Example 33 with KvEntry

use of com.baidu.hugegraph.computer.core.store.entry.KvEntry in project hugegraph-computer by hugegraph.

the class FileGraphPartition method writeEdges.

private void writeEdges(Pointer vid, PeekableIterator<KvEntry> edges, BufferedFileOutput edgeOut) throws IOException {
    byte[] vidBytes = vid.bytes();
    while (edges.hasNext()) {
        KvEntry entry = edges.peek();
        Pointer key = entry.key();
        int matched = vid.compareTo(key);
        if (matched < 0) {
            return;
        }
        edges.next();
        if (matched > 0) {
            // Skip stale edges
            continue;
        }
        assert matched == 0;
        edgeOut.writeFixedInt(vidBytes.length);
        edgeOut.write(vidBytes);
        long valuePosition = edgeOut.position();
        edgeOut.writeFixedInt(0);
        this.edgeCount += entry.numSubEntries();
        edgeOut.writeFixedInt((int) entry.numSubEntries());
        EntryIterator subKvIt = EntriesUtil.subKvIterFromEntry(entry);
        while (subKvIt.hasNext()) {
            KvEntry subEntry = subKvIt.next();
            // Not write sub-key length
            edgeOut.write(subEntry.key().bytes());
            // Not write sub-value length
            edgeOut.write(subEntry.value().bytes());
        }
        long valueLength = edgeOut.position() - valuePosition - Constants.INT_LEN;
        edgeOut.writeFixedInt(valuePosition, (int) valueLength);
    }
}
Also used : KvEntry(com.baidu.hugegraph.computer.core.store.entry.KvEntry) Pointer(com.baidu.hugegraph.computer.core.store.entry.Pointer) EntryIterator(com.baidu.hugegraph.computer.core.store.EntryIterator)

Example 34 with KvEntry

use of com.baidu.hugegraph.computer.core.store.entry.KvEntry in project hugegraph-computer by hugegraph.

the class FileGraphPartition method input.

protected PartitionStat input(PeekableIterator<KvEntry> vertices, PeekableIterator<KvEntry> edges) {
    try {
        createFile(this.vertexFile);
        createFile(this.edgeFile);
        BufferedFileOutput vertexOut = new BufferedFileOutput(this.vertexFile);
        BufferedFileOutput edgeOut = new BufferedFileOutput(this.edgeFile);
        while (vertices.hasNext()) {
            KvEntry entry = vertices.next();
            Pointer key = entry.key();
            Pointer value = entry.value();
            this.writeVertex(key, value, vertexOut);
            this.writeEdges(key, edges, edgeOut);
        }
        vertexOut.close();
        edgeOut.close();
    } catch (IOException e) {
        throw new ComputerException("Failed to init FileGraphPartition '%s'", e, this.partition);
    }
    return new PartitionStat(this.partition, this.vertexCount, this.edgeCount, 0L);
}
Also used : BufferedFileOutput(com.baidu.hugegraph.computer.core.io.BufferedFileOutput) PartitionStat(com.baidu.hugegraph.computer.core.graph.partition.PartitionStat) KvEntry(com.baidu.hugegraph.computer.core.store.entry.KvEntry) Pointer(com.baidu.hugegraph.computer.core.store.entry.Pointer) IOException(java.io.IOException) ComputerException(com.baidu.hugegraph.computer.core.common.exception.ComputerException)

Example 35 with KvEntry

use of com.baidu.hugegraph.computer.core.store.entry.KvEntry in project hugegraph-computer by hugegraph.

the class MessageInput method iterator.

public Iterator<T> iterator(ReusablePointer vidPointer) {
    while (this.messages.hasNext()) {
        KvEntry entry = this.messages.peek();
        Pointer key = entry.key();
        int status = vidPointer.compareTo(key);
        if (status < 0) {
            return Collections.emptyIterator();
        } else if (status == 0) {
            break;
        } else {
            this.messages.next();
        }
    }
    return new MessageIterator(vidPointer);
}
Also used : KvEntry(com.baidu.hugegraph.computer.core.store.entry.KvEntry) Pointer(com.baidu.hugegraph.computer.core.store.entry.Pointer)

Aggregations

KvEntry (com.baidu.hugegraph.computer.core.store.entry.KvEntry)38 Test (org.junit.Test)13 BytesId (com.baidu.hugegraph.computer.core.graph.id.BytesId)9 Id (com.baidu.hugegraph.computer.core.graph.id.Id)9 BytesInput (com.baidu.hugegraph.computer.core.io.BytesInput)9 Pointer (com.baidu.hugegraph.computer.core.store.entry.Pointer)9 BytesOutput (com.baidu.hugegraph.computer.core.io.BytesOutput)6 RandomAccessInput (com.baidu.hugegraph.computer.core.io.RandomAccessInput)5 Sorter (com.baidu.hugegraph.computer.core.sort.Sorter)5 ArrayList (java.util.ArrayList)5 IntValueSumCombiner (com.baidu.hugegraph.computer.core.combiner.IntValueSumCombiner)4 PointerCombiner (com.baidu.hugegraph.computer.core.combiner.PointerCombiner)4 IntValue (com.baidu.hugegraph.computer.core.graph.value.IntValue)4 CombineKvOuterSortFlusher (com.baidu.hugegraph.computer.core.sort.flusher.CombineKvOuterSortFlusher)4 DefaultKvEntry (com.baidu.hugegraph.computer.core.store.entry.DefaultKvEntry)4 File (java.io.File)4 IOException (java.io.IOException)4 Properties (com.baidu.hugegraph.computer.core.graph.properties.Properties)3 LongValue (com.baidu.hugegraph.computer.core.graph.value.LongValue)3 OuterSortFlusher (com.baidu.hugegraph.computer.core.sort.flusher.OuterSortFlusher)3