Search in sources :

Example 6 with KeyRange

use of com.thinkaurelius.titan.diskstorage.keycolumnvalue.KeyRange in project titan by thinkaurelius.

the class CassandraHelper method transformRange.

public static KeyRange transformRange(Token leftKeyExclusive, Token rightKeyInclusive) {
    if (!(leftKeyExclusive instanceof BytesToken))
        throw new UnsupportedOperationException();
    // if left part is BytesToken, right part should be too, otherwise there is no sense in the ring
    assert rightKeyInclusive instanceof BytesToken;
    // l is exclusive, r is inclusive
    BytesToken l = (BytesToken) leftKeyExclusive;
    BytesToken r = (BytesToken) rightKeyInclusive;
    byte[] leftTokenValue = l.getTokenValue();
    byte[] rightTokenValue = r.getTokenValue();
    Preconditions.checkArgument(leftTokenValue.length == rightTokenValue.length, "Tokens have unequal length");
    int tokenLength = leftTokenValue.length;
    byte[][] tokens = new byte[][] { leftTokenValue, rightTokenValue };
    byte[][] plusOne = new byte[2][tokenLength];
    for (int j = 0; j < 2; j++) {
        boolean carry = true;
        for (int i = tokenLength - 1; i >= 0; i--) {
            byte b = tokens[j][i];
            if (carry) {
                b++;
                carry = false;
            }
            if (b == 0)
                carry = true;
            plusOne[j][i] = b;
        }
    }
    StaticBuffer lb = StaticArrayBuffer.of(plusOne[0]);
    StaticBuffer rb = StaticArrayBuffer.of(plusOne[1]);
    Preconditions.checkArgument(lb.length() == tokenLength, lb.length());
    Preconditions.checkArgument(rb.length() == tokenLength, rb.length());
    return new KeyRange(lb, rb);
}
Also used : KeyRange(com.thinkaurelius.titan.diskstorage.keycolumnvalue.KeyRange) BytesToken(org.apache.cassandra.dht.BytesToken) StaticBuffer(com.thinkaurelius.titan.diskstorage.StaticBuffer)

Example 7 with KeyRange

use of com.thinkaurelius.titan.diskstorage.keycolumnvalue.KeyRange in project titan by thinkaurelius.

the class PartitionIDRangeTest method convert.

public static List<KeyRange> convert(long lower, long upper, int bitwidth) {
    StaticBuffer lowerBuffer = BufferUtil.getLongBuffer(convert(lower, bitwidth));
    StaticBuffer upperBuffer = BufferUtil.getLongBuffer(convert(upper, bitwidth));
    //        Preconditions.checkArgument(lowerBuffer.compareTo(upperBuffer) < 0, "%s vs %s",lowerBuffer,upperBuffer);
    return Lists.newArrayList(new KeyRange(lowerBuffer, upperBuffer));
}
Also used : KeyRange(com.thinkaurelius.titan.diskstorage.keycolumnvalue.KeyRange) StaticBuffer(com.thinkaurelius.titan.diskstorage.StaticBuffer)

Example 8 with KeyRange

use of com.thinkaurelius.titan.diskstorage.keycolumnvalue.KeyRange in project titan by thinkaurelius.

the class PartitionIDRange method getIDRanges.

public static List<PartitionIDRange> getIDRanges(final int partitionBits, final List<KeyRange> locals) {
    Preconditions.checkArgument(partitionBits > 0 && partitionBits < (Integer.SIZE - 1));
    Preconditions.checkArgument(locals != null && !locals.isEmpty(), "KeyRanges are empty");
    final int partitionIdBound = (1 << (partitionBits));
    final int backShift = Integer.SIZE - partitionBits;
    List<PartitionIDRange> partitionRanges = Lists.newArrayList();
    for (KeyRange local : locals) {
        Preconditions.checkArgument(local.getStart().length() >= 4);
        Preconditions.checkArgument(local.getEnd().length() >= 4);
        if (local.getStart().equals(local.getEnd())) {
            //Start=End => Partition spans entire range
            partitionRanges.add(new PartitionIDRange(0, partitionIdBound, partitionIdBound));
            continue;
        }
        int startInt = local.getStart().getInt(0);
        int lowerID = startInt >>> backShift;
        assert lowerID >= 0 && lowerID < partitionIdBound;
        //Lower id must be inclusive, so check that we did not truncate anything!
        boolean truncatedBits = (lowerID << backShift) != startInt;
        StaticBuffer start = local.getAt(0);
        for (int i = 4; i < start.length() && !truncatedBits; i++) {
            if (start.getByte(i) != 0)
                truncatedBits = true;
        }
        //adjust to make sure we are inclusive
        if (truncatedBits)
            lowerID += 1;
        //upper id is exclusive
        int upperID = local.getEnd().getInt(0) >>> backShift;
        //Check that we haven't jumped order indicating that the interval was too small
        if ((local.getStart().compareTo(local.getEnd()) < 0 && lowerID >= upperID)) {
            discardRange(local);
            continue;
        }
        //ensure that lowerID remains within range
        lowerID = lowerID % partitionIdBound;
        if (lowerID == upperID) {
            //After re-normalizing, check for interval colision
            discardRange(local);
            continue;
        }
        partitionRanges.add(new PartitionIDRange(lowerID, upperID, partitionIdBound));
    }
    return partitionRanges;
}
Also used : KeyRange(com.thinkaurelius.titan.diskstorage.keycolumnvalue.KeyRange) StaticBuffer(com.thinkaurelius.titan.diskstorage.StaticBuffer)

Aggregations

KeyRange (com.thinkaurelius.titan.diskstorage.keycolumnvalue.KeyRange)8 StaticBuffer (com.thinkaurelius.titan.diskstorage.StaticBuffer)5 BiMap (com.google.common.collect.BiMap)4 ImmutableBiMap (com.google.common.collect.ImmutableBiMap)4 ImmutableMap (com.google.common.collect.ImmutableMap)4 HashMap (java.util.HashMap)4 Map (java.util.Map)4 NavigableMap (java.util.NavigableMap)4 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)4 ConcurrentMap (java.util.concurrent.ConcurrentMap)4 ServerName (org.apache.hadoop.hbase.ServerName)4 IOException (java.io.IOException)2 LinkedList (java.util.LinkedList)2 HRegionInfo (org.apache.hadoop.hbase.HRegionInfo)2 MasterNotRunningException (org.apache.hadoop.hbase.MasterNotRunningException)2 ZooKeeperConnectionException (org.apache.hadoop.hbase.ZooKeeperConnectionException)2 HTable (org.apache.hadoop.hbase.client.HTable)2 BackendException (com.thinkaurelius.titan.diskstorage.BackendException)1 CTConnection (com.thinkaurelius.titan.diskstorage.cassandra.thrift.thriftpool.CTConnection)1 ArrayList (java.util.ArrayList)1