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