Search in sources :

Example 86 with SSTableReader

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();
}
Also used : SSTableReader(org.apache.cassandra.io.sstable.format.SSTableReader) ArrayList(java.util.ArrayList) Range(org.apache.cassandra.dht.Range) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 87 with SSTableReader

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;
}
Also used : StatsMetadata(org.apache.cassandra.io.sstable.metadata.StatsMetadata) SSTableReader(org.apache.cassandra.io.sstable.format.SSTableReader) AlwaysPresentFilter(org.apache.cassandra.utils.AlwaysPresentFilter) RandomAccessFile(java.io.RandomAccessFile) Descriptor(org.apache.cassandra.io.sstable.Descriptor) DatabaseDescriptor(org.apache.cassandra.config.DatabaseDescriptor) IOException(java.io.IOException) Component(org.apache.cassandra.io.sstable.Component) MetadataCollector(org.apache.cassandra.io.sstable.metadata.MetadataCollector) RandomAccessFile(java.io.RandomAccessFile) File(java.io.File)

Example 88 with SSTableReader

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);
}
Also used : MerkleTrees(org.apache.cassandra.utils.MerkleTrees) ValidationComplete(org.apache.cassandra.repair.messages.ValidationComplete) Token(org.apache.cassandra.dht.Token) Range(org.apache.cassandra.dht.Range) MessageOut(org.apache.cassandra.net.MessageOut) RepairMessage(org.apache.cassandra.repair.messages.RepairMessage) SSTableReader(org.apache.cassandra.io.sstable.format.SSTableReader) Keyspace(org.apache.cassandra.db.Keyspace) ColumnFamilyStore(org.apache.cassandra.db.ColumnFamilyStore) UUID(java.util.UUID)

Example 89 with SSTableReader

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()));
    }
}
Also used : java.util(java.util) BeforeClass(org.junit.BeforeClass) SSTableSet(org.apache.cassandra.db.lifecycle.SSTableSet) Range(org.apache.cassandra.dht.Range) SSTableReader(org.apache.cassandra.io.sstable.format.SSTableReader) InetAddress(java.net.InetAddress) Token(org.apache.cassandra.dht.Token) ConfigurationException(org.apache.cassandra.exceptions.ConfigurationException) TokenMetadata(org.apache.cassandra.locator.TokenMetadata) Refs(org.apache.cassandra.utils.concurrent.Refs) DatabaseDescriptor(org.apache.cassandra.config.DatabaseDescriptor) Keyspace(org.apache.cassandra.db.Keyspace) RowUpdateBuilder(org.apache.cassandra.db.RowUpdateBuilder) Before(org.junit.Before) FBUtilities(org.apache.cassandra.utils.FBUtilities) KeyspaceParams(org.apache.cassandra.schema.KeyspaceParams) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) Sets(com.google.common.collect.Sets) ExecutionException(java.util.concurrent.ExecutionException) SchemaLoader(org.apache.cassandra.SchemaLoader) AbstractReplicationStrategy(org.apache.cassandra.locator.AbstractReplicationStrategy) ColumnFamilyStore(org.apache.cassandra.db.ColumnFamilyStore) Assert.assertFalse(org.junit.Assert.assertFalse) Assert.assertEquals(org.junit.Assert.assertEquals) View(org.apache.cassandra.db.lifecycle.View) SSTableReader(org.apache.cassandra.io.sstable.format.SSTableReader) ColumnFamilyStore(org.apache.cassandra.db.ColumnFamilyStore) Range(org.apache.cassandra.dht.Range) Test(org.junit.Test)

Example 90 with SSTableReader

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));
}
Also used : SSTableReader(org.apache.cassandra.io.sstable.format.SSTableReader) UUID(java.util.UUID) Test(org.junit.Test)

Aggregations

SSTableReader (org.apache.cassandra.io.sstable.format.SSTableReader)289 Test (org.junit.Test)159 ColumnFamilyStore (org.apache.cassandra.db.ColumnFamilyStore)91 LifecycleTransaction (org.apache.cassandra.db.lifecycle.LifecycleTransaction)55 Keyspace (org.apache.cassandra.db.Keyspace)49 File (java.io.File)45 UUID (java.util.UUID)28 Range (org.apache.cassandra.dht.Range)28 Directories (org.apache.cassandra.db.Directories)27 Token (org.apache.cassandra.dht.Token)24 RandomAccessFile (java.io.RandomAccessFile)22 AbstractTransactionalTest (org.apache.cassandra.utils.concurrent.AbstractTransactionalTest)20 ArrayList (java.util.ArrayList)18 ByteBuffer (java.nio.ByteBuffer)17 HashSet (java.util.HashSet)16 SchemaLoader.createKeyspace (org.apache.cassandra.SchemaLoader.createKeyspace)16 DecoratedKey (org.apache.cassandra.db.DecoratedKey)16 RowUpdateBuilder (org.apache.cassandra.db.RowUpdateBuilder)16 CompactionController (org.apache.cassandra.db.compaction.CompactionController)14 CompactionIterator (org.apache.cassandra.db.compaction.CompactionIterator)13