Search in sources :

Example 1 with BytesToken

use of org.apache.cassandra.dht.BytesToken in project eiger by wlloyd.

the class CleanupTest method testCleanupWithIndexes.

@Test
public void testCleanupWithIndexes() throws IOException, ExecutionException, InterruptedException {
    Table table = Table.open(TABLE1);
    ColumnFamilyStore cfs = table.getColumnFamilyStore(CF1);
    assertEquals(cfs.indexManager.getIndexedColumns().iterator().next(), COLUMN);
    List<Row> rows;
    // insert data and verify we get it back w/ range query
    fillCF(cfs, LOOPS);
    rows = Util.getRangeSlice(cfs);
    assertEquals(LOOPS, rows.size());
    SecondaryIndex index = cfs.indexManager.getIndexForColumn(COLUMN);
    long start = System.currentTimeMillis();
    while (!index.isIndexBuilt(COLUMN) && System.currentTimeMillis() < start + 10000) Thread.sleep(10);
    // verify we get it back w/ index query too
    IndexExpression expr = new IndexExpression(COLUMN, IndexOperator.EQ, VALUE);
    List<IndexExpression> clause = Arrays.asList(expr);
    IFilter filter = new IdentityQueryFilter();
    IPartitioner p = StorageService.getPartitioner();
    Range<RowPosition> range = Util.range("", "");
    rows = table.getColumnFamilyStore(CF1).search(clause, range, Integer.MAX_VALUE, filter);
    assertEquals(LOOPS, rows.size());
    // we don't allow cleanup when the local host has no range to avoid wipping up all data when a node has not join the ring.
    // So to make sure cleanup erase everything here, we give the localhost the tiniest possible range.
    TokenMetadata tmd = StorageService.instance.getTokenMetadata();
    byte[] tk1 = new byte[1], tk2 = new byte[1];
    tk1[0] = 2;
    tk2[0] = 1;
    tmd.updateNormalToken(new BytesToken(tk1), InetAddress.getByName("127.0.0.1"));
    tmd.updateNormalToken(new BytesToken(tk2), InetAddress.getByName("127.0.0.2"));
    CompactionManager.instance.performCleanup(cfs, new NodeId.OneShotRenewer());
    // row data should be gone
    rows = Util.getRangeSlice(cfs);
    assertEquals(0, rows.size());
    // not only should it be gone but there should be no data on disk, not even tombstones
    assert cfs.getSSTables().isEmpty();
    // 2ary indexes should result in no results, too (although tombstones won't be gone until compacted)
    rows = cfs.search(clause, range, Integer.MAX_VALUE, filter);
    assertEquals(0, rows.size());
}
Also used : IndexExpression(org.apache.cassandra.thrift.IndexExpression) TokenMetadata(org.apache.cassandra.locator.TokenMetadata) IdentityQueryFilter(org.apache.cassandra.db.columniterator.IdentityQueryFilter) SecondaryIndex(org.apache.cassandra.db.index.SecondaryIndex) IFilter(org.apache.cassandra.db.filter.IFilter) BytesToken(org.apache.cassandra.dht.BytesToken) NodeId(org.apache.cassandra.utils.NodeId) IPartitioner(org.apache.cassandra.dht.IPartitioner) Test(org.junit.Test)

Example 2 with BytesToken

use of org.apache.cassandra.dht.BytesToken in project eiger by wlloyd.

the class SystemTableTest method testNonLocalToken.

@Test
public void testNonLocalToken() throws UnknownHostException {
    BytesToken token = new BytesToken(ByteBufferUtil.bytes("token3"));
    InetAddress address = InetAddress.getByName("127.0.0.2");
    SystemTable.updateToken(address, token);
    assert SystemTable.loadTokens().get(token).equals(address);
    SystemTable.removeToken(token);
    assert !SystemTable.loadTokens().containsKey(token);
}
Also used : BytesToken(org.apache.cassandra.dht.BytesToken) InetAddress(java.net.InetAddress) Test(org.junit.Test)

Example 3 with BytesToken

use of org.apache.cassandra.dht.BytesToken in project eiger by wlloyd.

the class SystemTableTest method testLocalToken.

@Test
public void testLocalToken() {
    SystemTable.updateToken(new BytesToken(ByteBufferUtil.bytes("token")));
    assert new String(((BytesToken) SystemTable.getSavedToken()).token, Charsets.UTF_8).equals("token");
    SystemTable.updateToken(new BytesToken(ByteBufferUtil.bytes("token2")));
    assert new String(((BytesToken) SystemTable.getSavedToken()).token, Charsets.UTF_8).equals("token2");
}
Also used : BytesToken(org.apache.cassandra.dht.BytesToken) Test(org.junit.Test)

Example 4 with BytesToken

use of org.apache.cassandra.dht.BytesToken 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 5 with BytesToken

use of org.apache.cassandra.dht.BytesToken in project eiger by wlloyd.

the class SerializationsTest method testStreamRequestMessageWrite.

private void testStreamRequestMessageWrite() throws IOException {
    Collection<Range<Token>> ranges = new ArrayList<Range<Token>>();
    for (int i = 0; i < 5; i++) ranges.add(new Range<Token>(new BytesToken(ByteBufferUtil.bytes(Integer.toString(10 * i))), new BytesToken(ByteBufferUtil.bytes(Integer.toString(10 * i + 5)))));
    List<ColumnFamilyStore> stores = Collections.singletonList(Table.open("Keyspace1").getColumnFamilyStore("Standard1"));
    StreamRequestMessage msg0 = new StreamRequestMessage(FBUtilities.getBroadcastAddress(), ranges, "Keyspace1", stores, 123L, OperationType.RESTORE_REPLICA_COUNT);
    StreamRequestMessage msg1 = new StreamRequestMessage(FBUtilities.getBroadcastAddress(), makePendingFile(true, 100, OperationType.BOOTSTRAP), 124L);
    StreamRequestMessage msg2 = new StreamRequestMessage(FBUtilities.getBroadcastAddress(), makePendingFile(false, 100, OperationType.BOOTSTRAP), 124L);
    DataOutputStream out = getOutput("streaming.StreamRequestMessage.bin");
    StreamRequestMessage.serializer().serialize(msg0, out, getVersion());
    StreamRequestMessage.serializer().serialize(msg1, out, getVersion());
    StreamRequestMessage.serializer().serialize(msg2, out, getVersion());
    messageSerializer.serialize(msg0.getMessage(getVersion()), out, getVersion());
    messageSerializer.serialize(msg1.getMessage(getVersion()), out, getVersion());
    messageSerializer.serialize(msg2.getMessage(getVersion()), out, getVersion());
    out.close();
}
Also used : DataOutputStream(java.io.DataOutputStream) BytesToken(org.apache.cassandra.dht.BytesToken) ColumnFamilyStore(org.apache.cassandra.db.ColumnFamilyStore) BytesToken(org.apache.cassandra.dht.BytesToken) Token(org.apache.cassandra.dht.Token) Range(org.apache.cassandra.dht.Range)

Aggregations

BytesToken (org.apache.cassandra.dht.BytesToken)5 Test (org.junit.Test)3 StaticBuffer (com.thinkaurelius.titan.diskstorage.StaticBuffer)1 KeyRange (com.thinkaurelius.titan.diskstorage.keycolumnvalue.KeyRange)1 DataOutputStream (java.io.DataOutputStream)1 InetAddress (java.net.InetAddress)1 ColumnFamilyStore (org.apache.cassandra.db.ColumnFamilyStore)1 IdentityQueryFilter (org.apache.cassandra.db.columniterator.IdentityQueryFilter)1 IFilter (org.apache.cassandra.db.filter.IFilter)1 SecondaryIndex (org.apache.cassandra.db.index.SecondaryIndex)1 IPartitioner (org.apache.cassandra.dht.IPartitioner)1 Range (org.apache.cassandra.dht.Range)1 Token (org.apache.cassandra.dht.Token)1 TokenMetadata (org.apache.cassandra.locator.TokenMetadata)1 IndexExpression (org.apache.cassandra.thrift.IndexExpression)1 NodeId (org.apache.cassandra.utils.NodeId)1