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));
}
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));
}
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);
}
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;
}
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());
}
Aggregations