use of org.apache.cassandra.io.sstable.format.SSTableReader in project cassandra by apache.
the class PendingAntiCompactionTest method acquisitionSuccess.
@Test
public void acquisitionSuccess() throws Exception {
cfs.disableAutoCompaction();
makeSSTables(6);
List<SSTableReader> sstables = new ArrayList<>(cfs.getLiveSSTables());
List<SSTableReader> expected = sstables.subList(0, 3);
Collection<Range<Token>> ranges = new HashSet<>();
for (SSTableReader sstable : expected) {
ranges.add(new Range<>(sstable.first.getToken(), sstable.last.getToken()));
}
PendingAntiCompaction.AcquisitionCallable acquisitionCallable = new PendingAntiCompaction.AcquisitionCallable(cfs, ranges, UUIDGen.getTimeUUID());
logger.info("SSTables: {}", sstables);
logger.info("Expected: {}", expected);
PendingAntiCompaction.AcquireResult result = acquisitionCallable.call();
Assert.assertNotNull(result);
logger.info("Originals: {}", result.txn.originals());
Assert.assertEquals(3, result.txn.originals().size());
for (SSTableReader sstable : expected) {
logger.info("Checking {}", sstable);
Assert.assertTrue(result.txn.originals().contains(sstable));
}
Assert.assertEquals(Transactional.AbstractTransactional.State.IN_PROGRESS, result.txn.state());
result.abort();
}
use of org.apache.cassandra.io.sstable.format.SSTableReader in project cassandra by apache.
the class MockSchema method sstable.
public static SSTableReader sstable(int generation, int size, boolean keepRef, ColumnFamilyStore cfs) {
Descriptor descriptor = new Descriptor(cfs.getDirectories().getDirectoryForNewSSTables(), cfs.keyspace.getName(), cfs.getTableName(), generation, SSTableFormat.Type.BIG);
Set<Component> components = ImmutableSet.of(Component.DATA, Component.PRIMARY_INDEX, Component.FILTER, Component.TOC);
for (Component component : components) {
File file = new File(descriptor.filenameFor(component));
try {
file.createNewFile();
} catch (IOException e) {
}
}
if (size > 0) {
try {
File file = new File(descriptor.filenameFor(Component.DATA));
try (RandomAccessFile raf = new RandomAccessFile(file, "rw")) {
raf.setLength(size);
}
} catch (IOException e) {
throw new RuntimeException(e);
}
}
SerializationHeader header = SerializationHeader.make(cfs.metadata(), Collections.emptyList());
StatsMetadata metadata = (StatsMetadata) new MetadataCollector(cfs.metadata().comparator).finalizeMetadata(cfs.metadata().partitioner.getClass().getCanonicalName(), 0.01f, -1, null, header).get(MetadataType.STATS);
SSTableReader reader = SSTableReader.internalOpen(descriptor, components, cfs.metadata, RANDOM_ACCESS_READER_FACTORY.sharedCopy(), RANDOM_ACCESS_READER_FACTORY.sharedCopy(), indexSummary.sharedCopy(), new AlwaysPresentFilter(), 1L, metadata, SSTableReader.OpenReason.NORMAL, header);
reader.first = reader.last = readerBounds(generation);
if (!keepRef)
reader.selfRef().release();
return reader;
}
use of org.apache.cassandra.io.sstable.format.SSTableReader in project cassandra by apache.
the class ValidatorTest method simpleValidationTest.
/**
* Test for CASSANDRA-5263
* 1. Create N rows
* 2. Run validation compaction
* 3. Expect merkle tree with size 2^(log2(n))
*/
public void simpleValidationTest(int n) throws Exception {
Keyspace ks = Keyspace.open(keyspace);
ColumnFamilyStore cfs = ks.getColumnFamilyStore(columnFamily);
cfs.clearUnsafe();
// disable compaction while flushing
cfs.disableAutoCompaction();
//ttl=3s
CompactionsTest.populate(keyspace, columnFamily, 0, n, 0);
cfs.forceBlockingFlush();
assertEquals(1, cfs.getLiveSSTables().size());
// wait enough to force single compaction
TimeUnit.SECONDS.sleep(5);
SSTableReader sstable = cfs.getLiveSSTables().iterator().next();
UUID repairSessionId = UUIDGen.getTimeUUID();
final RepairJobDesc desc = new RepairJobDesc(repairSessionId, UUIDGen.getTimeUUID(), cfs.keyspace.getName(), cfs.getTableName(), Collections.singletonList(new Range<>(sstable.first.getToken(), sstable.last.getToken())));
ActiveRepairService.instance.registerParentRepairSession(repairSessionId, FBUtilities.getBroadcastAddress(), Collections.singletonList(cfs), desc.ranges, false, ActiveRepairService.UNREPAIRED_SSTABLE, false);
final CompletableFuture<MessageOut> outgoingMessageSink = registerOutgoingMessageSink();
Validator validator = new Validator(desc, FBUtilities.getBroadcastAddress(), 0, true, false);
CompactionManager.instance.submitValidation(cfs, validator);
MessageOut message = outgoingMessageSink.get(TEST_TIMEOUT, TimeUnit.SECONDS);
assertEquals(MessagingService.Verb.REPAIR_MESSAGE, message.verb);
RepairMessage m = (RepairMessage) message.payload;
assertEquals(RepairMessage.Type.VALIDATION_COMPLETE, m.messageType);
assertEquals(desc, m.desc);
assertTrue(((ValidationComplete) m).success());
MerkleTrees trees = ((ValidationComplete) m).trees;
Iterator<Map.Entry<Range<Token>, MerkleTree>> iterator = trees.iterator();
while (iterator.hasNext()) {
assertEquals(Math.pow(2, Math.ceil(Math.log(n) / Math.log(2))), iterator.next().getValue().size(), 0.0);
}
assertEquals(trees.rowCount(), n);
}
use of org.apache.cassandra.io.sstable.format.SSTableReader in project cassandra by apache.
the class ActiveRepairServiceTest method testSnapshotAddSSTables.
@Test
public void testSnapshotAddSSTables() throws Exception {
ColumnFamilyStore store = prepareColumnFamilyStore();
UUID prsId = UUID.randomUUID();
Set<SSTableReader> original = Sets.newHashSet(store.select(View.select(SSTableSet.CANONICAL, (s) -> !s.isRepaired())).sstables);
ActiveRepairService.instance.registerParentRepairSession(prsId, FBUtilities.getBroadcastAddress(), Collections.singletonList(store), Collections.singleton(new Range<>(store.getPartitioner().getMinimumToken(), store.getPartitioner().getMinimumToken())), true, System.currentTimeMillis(), true);
ActiveRepairService.instance.getParentRepairSession(prsId).maybeSnapshot(store.metadata.id, prsId);
UUID prsId2 = UUID.randomUUID();
ActiveRepairService.instance.registerParentRepairSession(prsId2, FBUtilities.getBroadcastAddress(), Collections.singletonList(store), Collections.singleton(new Range<>(store.getPartitioner().getMinimumToken(), store.getPartitioner().getMinimumToken())), true, System.currentTimeMillis(), true);
createSSTables(store, 2);
ActiveRepairService.instance.getParentRepairSession(prsId).maybeSnapshot(store.metadata.id, prsId);
try (Refs<SSTableReader> refs = store.getSnapshotSSTableReaders(prsId.toString())) {
assertEquals(original, Sets.newHashSet(refs.iterator()));
}
}
use of org.apache.cassandra.io.sstable.format.SSTableReader in project cassandra by apache.
the class StreamSessionTest method incrementalSSTableSelection.
@Test
public void incrementalSSTableSelection() throws Exception {
// make 3 tables, 1 unrepaired, 2 pending repair with different repair ids, and 1 repaired
SSTableReader sstable1 = createSSTable(() -> QueryProcessor.executeInternal(String.format("INSERT INTO %s.%s (k, v) VALUES (1, 1)", keyspace, table)));
SSTableReader sstable2 = createSSTable(() -> QueryProcessor.executeInternal(String.format("INSERT INTO %s.%s (k, v) VALUES (2, 2)", keyspace, table)));
SSTableReader sstable3 = createSSTable(() -> QueryProcessor.executeInternal(String.format("INSERT INTO %s.%s (k, v) VALUES (3, 3)", keyspace, table)));
SSTableReader sstable4 = createSSTable(() -> QueryProcessor.executeInternal(String.format("INSERT INTO %s.%s (k, v) VALUES (4, 4)", keyspace, table)));
UUID pendingRepair = UUIDGen.getTimeUUID();
long repairedAt = System.currentTimeMillis();
mutateRepaired(sstable2, ActiveRepairService.UNREPAIRED_SSTABLE, pendingRepair);
mutateRepaired(sstable3, ActiveRepairService.UNREPAIRED_SSTABLE, UUIDGen.getTimeUUID());
mutateRepaired(sstable4, repairedAt, ActiveRepairService.NO_PENDING_REPAIR);
// no pending repair should return all sstables
Assert.assertEquals(Sets.newHashSet(sstable1, sstable2, sstable3, sstable4), selectReaders(ActiveRepairService.NO_PENDING_REPAIR));
// a pending repair arg should only return sstables with the same pending repair id
Assert.assertEquals(Sets.newHashSet(sstable2), selectReaders(pendingRepair));
}
Aggregations