Search in sources :

Example 1 with ValidationComplete

use of org.apache.cassandra.repair.messages.ValidationComplete 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)

Aggregations

UUID (java.util.UUID)1 ColumnFamilyStore (org.apache.cassandra.db.ColumnFamilyStore)1 Keyspace (org.apache.cassandra.db.Keyspace)1 Range (org.apache.cassandra.dht.Range)1 Token (org.apache.cassandra.dht.Token)1 SSTableReader (org.apache.cassandra.io.sstable.format.SSTableReader)1 MessageOut (org.apache.cassandra.net.MessageOut)1 RepairMessage (org.apache.cassandra.repair.messages.RepairMessage)1 ValidationComplete (org.apache.cassandra.repair.messages.ValidationComplete)1 MerkleTrees (org.apache.cassandra.utils.MerkleTrees)1