Search in sources :

Example 1 with StaticByteBuffer

use of com.thinkaurelius.titan.diskstorage.util.StaticByteBuffer in project titan by thinkaurelius.

the class KeyColumnValueStoreTest method loadLowerTriangularValues.

/**
 * Load a bunch of key-column-values in a way that vaguely resembles a lower
 * triangular matrix.
 * <p/>
 * Iterate over key values {@code k} in the half-open long interval
 * {@code [offset, offset + dimension -1)}. For each {@code k}, iterate over
 * the column values {@code c} in the half-open integer interval
 * {@code [offset, k]}.
 * <p/>
 * For each key-column coordinate specified by a {@code (k, c} pair in the
 *iteration, write a value one byte long with all bits set (unsigned -1 or
 *signed 255).
 *
 * @param dimension size of loaded data (must be positive)
 * @param offset    offset (must be positive)
 * @throws StorageException unexpected failure
 */
public void loadLowerTriangularValues(int dimension, int offset) throws StorageException {
    Preconditions.checkArgument(0 < dimension);
    ByteBuffer val = ByteBuffer.allocate(1);
    val.put((byte) -1);
    StaticBuffer staticVal = new StaticByteBuffer(val);
    List<Entry> rowAdditions = new ArrayList<Entry>(dimension);
    for (int k = 0; k < dimension; k++) {
        rowAdditions.clear();
        ByteBuffer key = ByteBuffer.allocate(8);
        key.putInt(0);
        key.putInt(k + offset);
        key.flip();
        StaticBuffer staticKey = new StaticByteBuffer(key);
        for (int c = 0; c <= k; c++) {
            ByteBuffer col = ByteBuffer.allocate(4);
            col.putInt(c + offset);
            col.flip();
            StaticBuffer staticCol = new StaticByteBuffer(col);
            rowAdditions.add(new StaticBufferEntry(staticCol, staticVal));
        }
        store.mutate(staticKey, rowAdditions, Collections.<StaticBuffer>emptyList(), tx);
    }
}
Also used : StaticByteBuffer(com.thinkaurelius.titan.diskstorage.util.StaticByteBuffer) ArrayList(java.util.ArrayList) ByteBuffer(java.nio.ByteBuffer) StaticByteBuffer(com.thinkaurelius.titan.diskstorage.util.StaticByteBuffer)

Example 2 with StaticByteBuffer

use of com.thinkaurelius.titan.diskstorage.util.StaticByteBuffer in project titan by thinkaurelius.

the class KeyColumnValueStoreTest method loadValues.

public void loadValues(String[][] values, int shiftEveryNthRow, int shiftSliceLength) throws StorageException {
    for (int i = 0; i < values.length; i++) {
        List<Entry> entries = new ArrayList<Entry>();
        for (int j = 0; j < values[i].length; j++) {
            StaticBuffer col;
            if (0 < shiftEveryNthRow && 0 == i % /* +1 */
            shiftEveryNthRow) {
                ByteBuffer bb = ByteBuffer.allocate(shiftSliceLength + 9);
                for (int s = 0; s < shiftSliceLength; s++) {
                    bb.put((byte) -1);
                }
                bb.put(KeyValueStoreUtil.getBuffer(j + 1).asByteBuffer());
                bb.flip();
                col = new StaticByteBuffer(bb);
            // col = KeyValueStoreUtil.getBuffer(j + values[i].length +
            // 100);
            } else {
                col = KeyValueStoreUtil.getBuffer(j);
            }
            entries.add(new StaticBufferEntry(col, KeyValueStoreUtil.getBuffer(values[i][j])));
        }
        store.mutate(KeyValueStoreUtil.getBuffer(i), entries, KeyColumnValueStore.NO_DELETIONS, tx);
    }
}
Also used : StaticByteBuffer(com.thinkaurelius.titan.diskstorage.util.StaticByteBuffer) ArrayList(java.util.ArrayList) ByteBuffer(java.nio.ByteBuffer) StaticByteBuffer(com.thinkaurelius.titan.diskstorage.util.StaticByteBuffer)

Example 3 with StaticByteBuffer

use of com.thinkaurelius.titan.diskstorage.util.StaticByteBuffer in project titan by thinkaurelius.

the class ConsistentKeyLockerSerializer method fromLockColumn.

public TimestampRid fromLockColumn(StaticBuffer lockKey) {
    ReadBuffer r = lockKey.asReadBuffer();
    int len = r.length();
    long tsNS = r.getLong();
    len -= 8;
    byte[] curRid = new byte[len];
    for (int i = 0; r.hasRemaining(); i++) {
        curRid[i] = r.getByte();
    }
    StaticBuffer rid = new StaticByteBuffer(curRid);
    return new TimestampRid(tsNS, rid);
}
Also used : ReadBuffer(com.thinkaurelius.titan.diskstorage.ReadBuffer) StaticByteBuffer(com.thinkaurelius.titan.diskstorage.util.StaticByteBuffer) StaticBuffer(com.thinkaurelius.titan.diskstorage.StaticBuffer)

Example 4 with StaticByteBuffer

use of com.thinkaurelius.titan.diskstorage.util.StaticByteBuffer in project titan by thinkaurelius.

the class MockIDAuthority method getLocalIDPartition.

@Override
public StaticBuffer[] getLocalIDPartition() throws StorageException {
    ByteBuffer lower = ByteBuffer.allocate(4);
    ByteBuffer upper = ByteBuffer.allocate(4);
    lower.putInt(localPartition[0]);
    upper.putInt(localPartition[1]);
    lower.rewind();
    upper.rewind();
    Preconditions.checkArgument(ByteBufferUtil.isSmallerThan(lower, upper), Arrays.toString(localPartition));
    return new StaticBuffer[] { new StaticByteBuffer(lower), new StaticByteBuffer(upper) };
}
Also used : StaticByteBuffer(com.thinkaurelius.titan.diskstorage.util.StaticByteBuffer) StaticBuffer(com.thinkaurelius.titan.diskstorage.StaticBuffer) StaticByteBuffer(com.thinkaurelius.titan.diskstorage.util.StaticByteBuffer) ByteBuffer(java.nio.ByteBuffer)

Example 5 with StaticByteBuffer

use of com.thinkaurelius.titan.diskstorage.util.StaticByteBuffer in project titan by thinkaurelius.

the class KeyColumnValueStoreUtil method longToByteBuffer.

// TODO rename as "longToBuffer" after syntax errors are resolved
public static StaticBuffer longToByteBuffer(long l) {
    ByteBuffer b = ByteBuffer.allocate(8).putLong(l);
    b.flip();
    return new StaticByteBuffer(b);
}
Also used : StaticByteBuffer(com.thinkaurelius.titan.diskstorage.util.StaticByteBuffer) StaticByteBuffer(com.thinkaurelius.titan.diskstorage.util.StaticByteBuffer) ByteBuffer(java.nio.ByteBuffer)

Aggregations

StaticByteBuffer (com.thinkaurelius.titan.diskstorage.util.StaticByteBuffer)6 ByteBuffer (java.nio.ByteBuffer)5 StaticBuffer (com.thinkaurelius.titan.diskstorage.StaticBuffer)2 ArrayList (java.util.ArrayList)2 ReadBuffer (com.thinkaurelius.titan.diskstorage.ReadBuffer)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1