Search in sources :

Example 36 with KvEntry

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

the class SubKvSorter method reset.

public void reset() {
    if (!this.entries.hasNext()) {
        this.currentEntry = null;
        return;
    }
    this.subKvMergeSources.clear();
    assert this.subKvSortPathNum > 0;
    KvEntry entry;
    while (true) {
        entry = this.entries.next();
        this.subKvMergeSources.add(new MergePath(this.entries, entry));
        KvEntry next = this.entries.peek();
        if (this.subKvMergeSources.size() == this.subKvSortPathNum || next == null || entry.key().compareTo(next.key()) != 0) {
            break;
        }
    }
    this.subKvSorting = new LoserTreeInputsSorting<>(this.subKvMergeSources);
    this.currentEntry = entry;
}
Also used : KvEntry(com.baidu.hugegraph.computer.core.store.entry.KvEntry)

Example 37 with KvEntry

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

Example 38 with KvEntry

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

the class KvOuterSortFlusher method flush.

@Override
public void flush(EntryIterator entries, KvEntryFileWriter writer) throws IOException {
    E.checkArgument(entries.hasNext(), "Parameter entries can't be empty");
    while (entries.hasNext()) {
        KvEntry entry = entries.next();
        writer.write(entry);
    }
    writer.finish();
}
Also used : KvEntry(com.baidu.hugegraph.computer.core.store.entry.KvEntry)

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