Search in sources :

Example 6 with BytesToken

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

the class AntiCompactionTest method antiCompactionSizeTest.

@Ignore
@Test
public void antiCompactionSizeTest() throws InterruptedException, IOException {
    Keyspace keyspace = Keyspace.open(KEYSPACE1);
    ColumnFamilyStore cfs = keyspace.getColumnFamilyStore(CF);
    cfs.disableAutoCompaction();
    SSTableReader s = writeFile(cfs, 1000);
    cfs.addSSTable(s);
    Range<Token> range = new Range<Token>(new BytesToken(ByteBufferUtil.bytes(0)), new BytesToken(ByteBufferUtil.bytes(500)));
    Collection<SSTableReader> sstables = cfs.getLiveSSTables();
    UUID parentRepairSession = UUID.randomUUID();
    try (LifecycleTransaction txn = cfs.getTracker().tryModify(sstables, OperationType.ANTICOMPACTION);
        Refs<SSTableReader> refs = Refs.ref(sstables)) {
        CompactionManager.instance.performAnticompaction(cfs, Arrays.asList(range), refs, txn, 12345, NO_PENDING_REPAIR, parentRepairSession);
    }
    long sum = 0;
    long rows = 0;
    for (SSTableReader x : cfs.getLiveSSTables()) {
        sum += x.bytesOnDisk();
        rows += x.getTotalRows();
    }
    assertEquals(sum, cfs.metric.liveDiskSpaceUsed.getCount());
    //See writeFile for how this number is derived
    assertEquals(rows, 1000 * (1000 * 5));
}
Also used : SSTableReader(org.apache.cassandra.io.sstable.format.SSTableReader) BytesToken(org.apache.cassandra.dht.ByteOrderedPartitioner.BytesToken) 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) UUID(java.util.UUID) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 7 with BytesToken

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

the class AntiCompactionTest method shouldMutate.

private void shouldMutate(long repairedAt, UUID pendingRepair) throws InterruptedException, IOException {
    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("9999".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, repairedAt, pendingRepair, parentRepairSession);
    }
    assertThat(store.getLiveSSTables().size(), is(1));
    assertThat(Iterables.get(store.getLiveSSTables(), 0).isRepaired(), is(repairedAt != UNREPAIRED_SSTABLE));
    assertThat(Iterables.get(store.getLiveSSTables(), 0).isPendingRepair(), is(pendingRepair != NO_PENDING_REPAIR));
    assertThat(Iterables.get(store.getLiveSSTables(), 0).selfRef().globalCount(), is(1));
    assertThat(store.getTracker().getCompacting().size(), is(0));
}
Also used : SSTableReader(org.apache.cassandra.io.sstable.format.SSTableReader) BytesToken(org.apache.cassandra.dht.ByteOrderedPartitioner.BytesToken) 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) UUID(java.util.UUID)

Example 8 with BytesToken

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

the class AntiCompactionTest method antiCompactTen.

public void antiCompactTen(String compactionStrategy) 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("0".getBytes()), new BytesToken("4".getBytes()));
    List<Range<Token>> ranges = Arrays.asList(range);
    long repairedAt = 1000;
    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, repairedAt, NO_PENDING_REPAIR, parentRepairSession);
    }
    /*
        Anticompaction will be anti-compacting 10 SSTables but will be doing this two at a time
        so there will be no net change in the number of sstables
         */
    assertEquals(10, store.getLiveSSTables().size());
    int repairedKeys = 0;
    int nonRepairedKeys = 0;
    for (SSTableReader sstable : store.getLiveSSTables()) {
        try (ISSTableScanner scanner = sstable.getScanner()) {
            while (scanner.hasNext()) {
                try (UnfilteredRowIterator row = scanner.next()) {
                    if (sstable.isRepaired()) {
                        assertTrue(range.contains(row.partitionKey().getToken()));
                        assertEquals(repairedAt, sstable.getSSTableMetadata().repairedAt);
                        repairedKeys++;
                    } else {
                        assertFalse(range.contains(row.partitionKey().getToken()));
                        assertEquals(ActiveRepairService.UNREPAIRED_SSTABLE, sstable.getSSTableMetadata().repairedAt);
                        nonRepairedKeys++;
                    }
                }
            }
        }
    }
    assertEquals(repairedKeys, 40);
    assertEquals(nonRepairedKeys, 60);
}
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 9 with BytesToken

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

the class RangeTest method testByteTokensCompare.

@Test
public void testByteTokensCompare() {
    Token t1 = new BytesToken(ByteBuffer.wrap(new byte[] { 1, 2, 3 }));
    Token t2 = new BytesToken(ByteBuffer.wrap(new byte[] { 1, 2, 3 }));
    Token t3 = new BytesToken(ByteBuffer.wrap(new byte[] { 1, 2, 3, 4 }));
    assert t1.compareTo(t2) == 0;
    assert t1.compareTo(t3) < 0;
    assert t3.compareTo(t1) > 0;
    assert t1.compareTo(t1) == 0;
    Token t4 = new BytesToken(new byte[] { 1, 2, 3 });
    Token t5 = new BytesToken(new byte[] { 4, 5, 6, 7 });
    assert t4.compareTo(t5) < 0;
    assert t5.compareTo(t4) > 0;
    assert t1.compareTo(t4) == 0;
}
Also used : BytesToken(org.apache.cassandra.dht.ByteOrderedPartitioner.BytesToken) BytesToken(org.apache.cassandra.dht.ByteOrderedPartitioner.BytesToken) BigIntegerToken(org.apache.cassandra.dht.RandomPartitioner.BigIntegerToken) Test(org.junit.Test)

Example 10 with BytesToken

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

the class CleanupTest method testCleanupWithNewToken.

@Test
public void testCleanupWithNewToken() throws ExecutionException, InterruptedException, UnknownHostException {
    StorageService.instance.getTokenMetadata().clearUnsafe();
    Keyspace keyspace = Keyspace.open(KEYSPACE1);
    ColumnFamilyStore cfs = keyspace.getColumnFamilyStore(CF_STANDARD1);
    // insert data and verify we get it back w/ range query
    fillCF(cfs, "val", LOOPS);
    assertEquals(LOOPS, Util.getAll(Util.cmd(cfs).build()).size());
    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, 2);
    assertEquals(0, Util.getAll(Util.cmd(cfs).build()).size());
}
Also used : BytesToken(org.apache.cassandra.dht.ByteOrderedPartitioner.BytesToken) TokenMetadata(org.apache.cassandra.locator.TokenMetadata) 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