Search in sources :

Example 1 with BytesToken

use of org.apache.cassandra.dht.ByteOrderedPartitioner.BytesToken in project cassandra by apache.

the class AntiCompactionTest method antiCompactOne.

private void antiCompactOne(long repairedAt, UUID pendingRepair) throws Exception {
    assert repairedAt != UNREPAIRED_SSTABLE || pendingRepair != null;
    ColumnFamilyStore store = prepareColumnFamilyStore();
    Collection<SSTableReader> sstables = getUnrepairedSSTables(store);
    assertEquals(store.getLiveSSTables().size(), sstables.size());
    Range<Token> range = new Range<Token>(new BytesToken("0".getBytes()), new BytesToken("4".getBytes()));
    List<Range<Token>> ranges = Arrays.asList(range);
    int repairedKeys = 0;
    int pendingKeys = 0;
    int nonRepairedKeys = 0;
    try (LifecycleTransaction txn = store.getTracker().tryModify(sstables, OperationType.ANTICOMPACTION);
        Refs<SSTableReader> refs = Refs.ref(sstables)) {
        if (txn == null)
            throw new IllegalStateException();
        UUID parentRepairSession = UUID.randomUUID();
        CompactionManager.instance.performAnticompaction(store, ranges, refs, txn, repairedAt, pendingRepair, parentRepairSession);
    }
    assertEquals(2, store.getLiveSSTables().size());
    for (SSTableReader sstable : store.getLiveSSTables()) {
        try (ISSTableScanner scanner = sstable.getScanner()) {
            while (scanner.hasNext()) {
                UnfilteredRowIterator row = scanner.next();
                if (sstable.isRepaired() || sstable.isPendingRepair()) {
                    assertTrue(range.contains(row.partitionKey().getToken()));
                    repairedKeys += sstable.isRepaired() ? 1 : 0;
                    pendingKeys += sstable.isPendingRepair() ? 1 : 0;
                } else {
                    assertFalse(range.contains(row.partitionKey().getToken()));
                    nonRepairedKeys++;
                }
            }
        }
    }
    for (SSTableReader sstable : store.getLiveSSTables()) {
        assertFalse(sstable.isMarkedCompacted());
        assertEquals(1, sstable.selfRef().globalCount());
    }
    assertEquals(0, store.getTracker().getCompacting().size());
    assertEquals(repairedKeys, repairedAt != UNREPAIRED_SSTABLE ? 4 : 0);
    assertEquals(pendingKeys, pendingRepair != NO_PENDING_REPAIR ? 4 : 0);
    assertEquals(nonRepairedKeys, 6);
}
Also used : UnfilteredRowIterator(org.apache.cassandra.db.rows.UnfilteredRowIterator) LifecycleTransaction(org.apache.cassandra.db.lifecycle.LifecycleTransaction) BytesToken(org.apache.cassandra.dht.ByteOrderedPartitioner.BytesToken) Token(org.apache.cassandra.dht.Token) Range(org.apache.cassandra.dht.Range) SSTableReader(org.apache.cassandra.io.sstable.format.SSTableReader) BytesToken(org.apache.cassandra.dht.ByteOrderedPartitioner.BytesToken) UUID(java.util.UUID)

Example 2 with BytesToken

use of org.apache.cassandra.dht.ByteOrderedPartitioner.BytesToken in project cassandra by apache.

the class AntiCompactionTest method shouldSkipAntiCompactionForNonIntersectingRange.

@Test
public void shouldSkipAntiCompactionForNonIntersectingRange() throws InterruptedException, IOException {
    Keyspace keyspace = Keyspace.open(KEYSPACE1);
    ColumnFamilyStore store = keyspace.getColumnFamilyStore(CF);
    store.disableAutoCompaction();
    for (int table = 0; table < 10; table++) {
        generateSStable(store, Integer.toString(table));
    }
    Collection<SSTableReader> sstables = getUnrepairedSSTables(store);
    assertEquals(store.getLiveSSTables().size(), sstables.size());
    Range<Token> range = new Range<Token>(new BytesToken("-1".getBytes()), new BytesToken("-10".getBytes()));
    List<Range<Token>> ranges = Arrays.asList(range);
    UUID parentRepairSession = UUID.randomUUID();
    try (LifecycleTransaction txn = store.getTracker().tryModify(sstables, OperationType.ANTICOMPACTION);
        Refs<SSTableReader> refs = Refs.ref(sstables)) {
        CompactionManager.instance.performAnticompaction(store, ranges, refs, txn, 1, NO_PENDING_REPAIR, parentRepairSession);
    }
    assertThat(store.getLiveSSTables().size(), is(10));
    assertThat(Iterables.get(store.getLiveSSTables(), 0).isRepaired(), is(false));
}
Also used : LifecycleTransaction(org.apache.cassandra.db.lifecycle.LifecycleTransaction) BytesToken(org.apache.cassandra.dht.ByteOrderedPartitioner.BytesToken) Token(org.apache.cassandra.dht.Token) Range(org.apache.cassandra.dht.Range) SSTableReader(org.apache.cassandra.io.sstable.format.SSTableReader) BytesToken(org.apache.cassandra.dht.ByteOrderedPartitioner.BytesToken) UUID(java.util.UUID) Test(org.junit.Test)

Example 3 with BytesToken

use of org.apache.cassandra.dht.ByteOrderedPartitioner.BytesToken in project cassandra by apache.

the class SystemKeyspaceTest method testNonLocalToken.

@Test
public void testNonLocalToken() throws UnknownHostException {
    BytesToken token = new BytesToken(ByteBufferUtil.bytes("token3"));
    InetAddress address = InetAddress.getByName("127.0.0.2");
    SystemKeyspace.updateTokens(address, Collections.<Token>singletonList(token));
    assert SystemKeyspace.loadTokens().get(address).contains(token);
    SystemKeyspace.removeEndpoint(address);
    assert !SystemKeyspace.loadTokens().containsValue(token);
}
Also used : BytesToken(org.apache.cassandra.dht.ByteOrderedPartitioner.BytesToken) InetAddress(java.net.InetAddress) Test(org.junit.Test)

Example 4 with BytesToken

use of org.apache.cassandra.dht.ByteOrderedPartitioner.BytesToken in project cassandra by apache.

the class RowCacheTest method testRowCacheCleanup.

@Test
public void testRowCacheCleanup() throws Exception {
    StorageService.instance.initServer(0);
    CacheService.instance.setRowCacheCapacityInMB(1);
    rowCacheLoad(100, Integer.MAX_VALUE, 1000);
    ColumnFamilyStore store = Keyspace.open(KEYSPACE_CACHED).getColumnFamilyStore(CF_CACHED);
    assertEquals(CacheService.instance.rowCache.size(), 100);
    store.cleanupCache();
    assertEquals(CacheService.instance.rowCache.size(), 100);
    TokenMetadata tmd = StorageService.instance.getTokenMetadata();
    byte[] tk1, tk2;
    tk1 = "key1000".getBytes();
    tk2 = "key1050".getBytes();
    tmd.updateNormalToken(new BytesToken(tk1), InetAddress.getByName("127.0.0.1"));
    tmd.updateNormalToken(new BytesToken(tk2), InetAddress.getByName("127.0.0.2"));
    store.cleanupCache();
    assertEquals(50, CacheService.instance.rowCache.size());
    CacheService.instance.setRowCacheCapacityInMB(0);
}
Also used : BytesToken(org.apache.cassandra.dht.ByteOrderedPartitioner.BytesToken) TokenMetadata(org.apache.cassandra.locator.TokenMetadata) Test(org.junit.Test)

Example 5 with BytesToken

use of org.apache.cassandra.dht.ByteOrderedPartitioner.BytesToken in project cassandra by apache.

the class SystemKeyspaceTest method testLocalTokens.

@Test
public void testLocalTokens() {
    // Remove all existing tokens
    Collection<Token> current = SystemKeyspace.loadTokens().asMap().get(FBUtilities.getLocalAddress());
    if (current != null && !current.isEmpty())
        SystemKeyspace.updateTokens(current);
    List<Token> tokens = new ArrayList<Token>() {

        {
            for (int i = 0; i < 9; i++) add(new BytesToken(ByteBufferUtil.bytes(String.format("token%d", i))));
        }
    };
    SystemKeyspace.updateTokens(tokens);
    int count = 0;
    for (Token tok : SystemKeyspace.getSavedTokens()) assert tokens.get(count++).equals(tok);
}
Also used : BytesToken(org.apache.cassandra.dht.ByteOrderedPartitioner.BytesToken) BytesToken(org.apache.cassandra.dht.ByteOrderedPartitioner.BytesToken) Token(org.apache.cassandra.dht.Token) Test(org.junit.Test)

Aggregations

BytesToken (org.apache.cassandra.dht.ByteOrderedPartitioner.BytesToken)12 Test (org.junit.Test)9 Token (org.apache.cassandra.dht.Token)6 SSTableReader (org.apache.cassandra.io.sstable.format.SSTableReader)6 UUID (java.util.UUID)5 LifecycleTransaction (org.apache.cassandra.db.lifecycle.LifecycleTransaction)5 Range (org.apache.cassandra.dht.Range)5 TokenMetadata (org.apache.cassandra.locator.TokenMetadata)4 UnfilteredRowIterator (org.apache.cassandra.db.rows.UnfilteredRowIterator)2 InetAddress (java.net.InetAddress)1 RowFilter (org.apache.cassandra.db.filter.RowFilter)1 BigIntegerToken (org.apache.cassandra.dht.RandomPartitioner.BigIntegerToken)1 ColumnMetadata (org.apache.cassandra.schema.ColumnMetadata)1 Ignore (org.junit.Ignore)1