Search in sources :

Example 1 with ByteableLongArrayValues

use of net.openhft.chronicle.wire.ByteableLongArrayValues in project Chronicle-Queue by OpenHFT.

the class Indexer method recordAddress.

/**
 * records every 64th addressForRead in the index2index
 *
 * @param index   the index of the Excerpts which we are going to record
 * @param address the addressForRead of the Excerpts which we are going to record
 */
private void recordAddress(long index, long address) {
    if (index % 64 != 0)
        return;
    final ByteableLongArrayValues array = this.array.get();
    final long index2Index = chronicle.indexToIndex();
    chronicle.wire().readDocument(index2Index, rootIndex -> {
        rootIndex.read(() -> "index").int64array(array, longArrayValues -> {
        });
        long secondaryAddress = array.getValueAt(toAddress0(index));
        if (secondaryAddress == UNINITIALISED) {
            array.setValueAt(index, secondaryAddress = chronicle.newIndex());
        }
        chronicle.wire().readDocument(secondaryAddress, secondaryIndex -> {
            secondaryIndex.read(() -> "index").int64array(array, longArrayValues -> {
            });
            array.setValueAt(toAddress1(index), address);
        }, null);
    }, null);
}
Also used : ByteableLongArrayValues(net.openhft.chronicle.wire.ByteableLongArrayValues)

Example 2 with ByteableLongArrayValues

use of net.openhft.chronicle.wire.ByteableLongArrayValues in project Chronicle-Queue by OpenHFT.

the class SingleChronicleQueue method newIndex.

/**
 * Creates a new Excerpt containing and index which will be 1L << 17L bytes long, This method is used for creating
 * both the primary and secondary indexes. Chronicle Queue uses a root primary index ( each entry in the primary
 * index points to a unique a secondary index. The secondary index only records the addressForRead of every 64th except,
 * the except are linearly scanned from there on.
 *
 * @return the addressForRead of the Excerpt containing the usable index, just after the header
 */
long newIndex() {
    final ByteableLongArrayValues array = longArray.get();
    final long size = array.sizeInBytes(NUMBER_OF_ENTRIES_IN_EACH_INDEX);
    final Bytes buffer = NativeBytes.nativeBytes(size);
    buffer.zeroOut(0, size);
    final Wire wire = WireUtil.createWire(this.builder.wireType(), buffer);
    wire.write(() -> "index").int64array(NUMBER_OF_ENTRIES_IN_EACH_INDEX);
    buffer.flip();
    return appendMetaDataReturnAddress(buffer);
}
Also used : ByteableLongArrayValues(net.openhft.chronicle.wire.ByteableLongArrayValues) Wire(net.openhft.chronicle.wire.Wire)

Aggregations

ByteableLongArrayValues (net.openhft.chronicle.wire.ByteableLongArrayValues)2 Wire (net.openhft.chronicle.wire.Wire)1