Search in sources :

Example 11 with Pointer

use of com.baidu.hugegraph.computer.core.store.entry.Pointer 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)

Example 12 with Pointer

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

the class CombineSubKvOuterSortFlusher method flush.

@Override
public void flush(EntryIterator entries, KvEntryFileWriter writer) throws IOException {
    E.checkArgument(entries.hasNext(), "Parameter entries can't be empty");
    PeekableIterator<KvEntry> kvEntries = PeekableIteratorAdaptor.of(entries);
    SubKvSorter sorter = new SubKvSorter(kvEntries, this.sources);
    KvEntry currentKv = sorter.currentKv();
    while (true) {
        currentKv.key().write(this.output);
        long position = this.output.position();
        // Write total sub-entry length placeholder
        this.output.writeFixedInt(0);
        // Write sub-entry count placeholder
        this.output.writeFixedInt(0);
        int writtenCount = 0;
        // Iterate subKv of currentKv
        KvEntry lastSubKv = sorter.next();
        Pointer lastSubValue = lastSubKv.value();
        while (true) {
            KvEntry current = null;
            if (sorter.hasNext()) {
                current = sorter.next();
                if (lastSubKv.compareTo(current) == 0) {
                    lastSubValue = this.combiner.combine(lastSubValue, current.value());
                    continue;
                }
            }
            lastSubKv.key().write(this.output);
            lastSubValue.write(this.output);
            writtenCount++;
            /*
                 * Fill placeholder if the number of subkvs with different
                 * keys is equal to the subKvFlushThreshold.
                 */
            if (current == null || writtenCount == this.subKvFlushThreshold) {
                long currentPosition = this.output.position();
                this.output.seek(position);
                this.output.writeFixedInt((int) (currentPosition - position - Integer.BYTES));
                this.output.writeFixedInt(writtenCount);
                this.output.seek(currentPosition);
                // Write kvEntry to file.
                RandomAccessInput input = EntriesUtil.inputFromOutput(this.output);
                writer.write(EntriesUtil.kvEntryFromInput(input, true, true));
                this.output.seek(0);
                if (current == null) {
                    break;
                }
                currentKv.key().write(this.output);
                position = this.output.position();
                // Write value length placeholder
                this.output.writeFixedInt(0);
                // Write subKv count placeholder
                this.output.writeFixedInt(0);
                writtenCount = 0;
            }
            lastSubKv = current;
            lastSubValue = lastSubKv.value();
        }
        sorter.reset();
        // Get next KV
        if ((currentKv = sorter.currentKv()) == null) {
            break;
        }
    }
    writer.finish();
}
Also used : RandomAccessInput(com.baidu.hugegraph.computer.core.io.RandomAccessInput) SubKvSorter(com.baidu.hugegraph.computer.core.sort.sorter.SubKvSorter) KvEntry(com.baidu.hugegraph.computer.core.store.entry.KvEntry) Pointer(com.baidu.hugegraph.computer.core.store.entry.Pointer)

Aggregations

Pointer (com.baidu.hugegraph.computer.core.store.entry.Pointer)12 KvEntry (com.baidu.hugegraph.computer.core.store.entry.KvEntry)9 BytesOutput (com.baidu.hugegraph.computer.core.io.BytesOutput)5 Test (org.junit.Test)5 Config (com.baidu.hugegraph.computer.core.config.Config)4 BytesInput (com.baidu.hugegraph.computer.core.io.BytesInput)4 InlinePointer (com.baidu.hugegraph.computer.core.store.entry.InlinePointer)4 Properties (com.baidu.hugegraph.computer.core.graph.properties.Properties)3 LongValue (com.baidu.hugegraph.computer.core.graph.value.LongValue)3 RandomAccessInput (com.baidu.hugegraph.computer.core.io.RandomAccessInput)3 GraphFactory (com.baidu.hugegraph.computer.core.graph.GraphFactory)2 DoubleValue (com.baidu.hugegraph.computer.core.graph.value.DoubleValue)2 DefaultKvEntry (com.baidu.hugegraph.computer.core.store.entry.DefaultKvEntry)2 IOException (java.io.IOException)2 IntValueSumCombiner (com.baidu.hugegraph.computer.core.combiner.IntValueSumCombiner)1 PointerCombiner (com.baidu.hugegraph.computer.core.combiner.PointerCombiner)1 Constants (com.baidu.hugegraph.computer.core.common.Constants)1 ComputerException (com.baidu.hugegraph.computer.core.common.exception.ComputerException)1 ComputerOptions (com.baidu.hugegraph.computer.core.config.ComputerOptions)1 BytesId (com.baidu.hugegraph.computer.core.graph.id.BytesId)1