Search in sources :

Example 1 with ValidationResponse

use of org.apache.cassandra.repair.messages.ValidationResponse in project cassandra by apache.

the class Validator method respond.

private void respond(ValidationResponse response) {
    if (initiatorIsRemote()) {
        MessagingService.instance().send(Message.out(VALIDATION_RSP, response), initiator);
        return;
    }
    /*
         * For local initiators, DO NOT send the message to self over loopback. This is a wasted ser/de loop
         * and a ton of garbage. Instead, move the trees off heap and invoke message handler. We could do it
         * directly, since this method will only be called from {@code Stage.ANTI_ENTROPY}, but we do instead
         * execute a {@code Runnable} on the stage - in case that assumption ever changes by accident.
         */
    Stage.ANTI_ENTROPY.execute(() -> {
        ValidationResponse movedResponse = response;
        try {
            movedResponse = response.tryMoveOffHeap();
        } catch (IOException e) {
            logger.error("Failed to move local merkle tree for {} off heap", desc, e);
        }
        ActiveRepairService.instance.handleMessage(Message.out(VALIDATION_RSP, movedResponse));
    });
}
Also used : ValidationResponse(org.apache.cassandra.repair.messages.ValidationResponse) IOException(java.io.IOException)

Example 2 with ValidationResponse

use of org.apache.cassandra.repair.messages.ValidationResponse in project cassandra by apache.

the class Validator method run.

/**
 * Called after the validation lifecycle to respond with the now valid tree. Runs in Stage.ANTIENTROPY.
 */
public void run() {
    if (initiatorIsRemote()) {
        logger.info("{} Sending completed merkle tree to {} for {}.{}", previewKind.logPrefix(desc.sessionId), initiator, desc.keyspace, desc.columnFamily);
        Tracing.traceRepair("Sending completed merkle tree to {} for {}.{}", initiator, desc.keyspace, desc.columnFamily);
    } else {
        logger.info("{} Local completed merkle tree for {} for {}.{}", previewKind.logPrefix(desc.sessionId), initiator, desc.keyspace, desc.columnFamily);
        Tracing.traceRepair("Local completed merkle tree for {} for {}.{}", initiator, desc.keyspace, desc.columnFamily);
    }
    respond(new ValidationResponse(desc, trees));
}
Also used : ValidationResponse(org.apache.cassandra.repair.messages.ValidationResponse)

Example 3 with ValidationResponse

use of org.apache.cassandra.repair.messages.ValidationResponse in project cassandra by apache.

the class ValidatorTest method testValidatorFailed.

@Test
public void testValidatorFailed() throws Throwable {
    Range<Token> range = new Range<>(partitioner.getMinimumToken(), partitioner.getRandomToken());
    final RepairJobDesc desc = new RepairJobDesc(UUID.randomUUID(), UUID.randomUUID(), keyspace, columnFamily, Arrays.asList(range));
    final CompletableFuture<Message> outgoingMessageSink = registerOutgoingMessageSink();
    InetAddressAndPort remote = InetAddressAndPort.getByName("127.0.0.2");
    Validator validator = new Validator(desc, remote, 0, PreviewKind.NONE);
    validator.fail();
    Message message = outgoingMessageSink.get(TEST_TIMEOUT, TimeUnit.SECONDS);
    assertEquals(Verb.VALIDATION_RSP, message.verb());
    ValidationResponse m = (ValidationResponse) message.payload;
    assertEquals(desc, m.desc);
    assertFalse(m.success());
    assertNull(m.trees);
}
Also used : InetAddressAndPort(org.apache.cassandra.locator.InetAddressAndPort) Message(org.apache.cassandra.net.Message) ValidationResponse(org.apache.cassandra.repair.messages.ValidationResponse) Token(org.apache.cassandra.dht.Token) Range(org.apache.cassandra.dht.Range) CompactionsTest(org.apache.cassandra.db.compaction.CompactionsTest) Test(org.junit.Test)

Example 4 with ValidationResponse

use of org.apache.cassandra.repair.messages.ValidationResponse in project cassandra by apache.

the class ValidatorTest method testValidatorComplete.

@Test
public void testValidatorComplete() throws Throwable {
    Range<Token> range = new Range<>(partitioner.getMinimumToken(), partitioner.getRandomToken());
    final RepairJobDesc desc = new RepairJobDesc(UUID.randomUUID(), UUID.randomUUID(), keyspace, columnFamily, Arrays.asList(range));
    final CompletableFuture<Message> outgoingMessageSink = registerOutgoingMessageSink();
    InetAddressAndPort remote = InetAddressAndPort.getByName("127.0.0.2");
    ColumnFamilyStore cfs = Keyspace.open(keyspace).getColumnFamilyStore(columnFamily);
    Validator validator = new Validator(desc, remote, 0, PreviewKind.NONE);
    MerkleTrees trees = new MerkleTrees(partitioner);
    trees.addMerkleTrees((int) Math.pow(2, 15), validator.desc.ranges);
    validator.prepare(cfs, trees);
    // and confirm that the trees were split
    assertTrue(trees.size() > 1);
    // add a row
    Token mid = partitioner.midpoint(range.left, range.right);
    validator.add(EmptyIterators.unfilteredRow(cfs.metadata(), new BufferDecoratedKey(mid, ByteBufferUtil.bytes("inconceivable!")), false));
    validator.complete();
    // confirm that the trees were validated
    Token min = trees.partitioner().getMinimumToken();
    assertNotNull(trees.hash(new Range<>(min, min)));
    Message message = outgoingMessageSink.get(TEST_TIMEOUT, TimeUnit.SECONDS);
    assertEquals(Verb.VALIDATION_RSP, message.verb());
    ValidationResponse m = (ValidationResponse) message.payload;
    assertEquals(desc, m.desc);
    assertTrue(m.success());
    assertNotNull(m.trees);
}
Also used : MerkleTrees(org.apache.cassandra.utils.MerkleTrees) InetAddressAndPort(org.apache.cassandra.locator.InetAddressAndPort) Message(org.apache.cassandra.net.Message) ValidationResponse(org.apache.cassandra.repair.messages.ValidationResponse) ColumnFamilyStore(org.apache.cassandra.db.ColumnFamilyStore) Token(org.apache.cassandra.dht.Token) BufferDecoratedKey(org.apache.cassandra.db.BufferDecoratedKey) Range(org.apache.cassandra.dht.Range) CompactionsTest(org.apache.cassandra.db.compaction.CompactionsTest) Test(org.junit.Test)

Example 5 with ValidationResponse

use of org.apache.cassandra.repair.messages.ValidationResponse 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())));
    InetAddressAndPort host = InetAddressAndPort.getByName("127.0.0.2");
    ActiveRepairService.instance.registerParentRepairSession(repairSessionId, host, Collections.singletonList(cfs), desc.ranges, false, ActiveRepairService.UNREPAIRED_SSTABLE, false, PreviewKind.NONE);
    final CompletableFuture<Message> outgoingMessageSink = registerOutgoingMessageSink();
    Validator validator = new Validator(desc, host, 0, true, false, PreviewKind.NONE);
    ValidationManager.instance.submitValidation(cfs, validator);
    Message message = outgoingMessageSink.get(TEST_TIMEOUT, TimeUnit.SECONDS);
    assertEquals(Verb.VALIDATION_RSP, message.verb());
    ValidationResponse m = (ValidationResponse) message.payload;
    assertEquals(desc, m.desc);
    assertTrue(m.success());
    Iterator<Map.Entry<Range<Token>, MerkleTree>> iterator = m.trees.iterator();
    while (iterator.hasNext()) {
        assertEquals(Math.pow(2, Math.ceil(Math.log(n) / Math.log(2))), iterator.next().getValue().size(), 0.0);
    }
    assertEquals(m.trees.rowCount(), n);
}
Also used : InetAddressAndPort(org.apache.cassandra.locator.InetAddressAndPort) Message(org.apache.cassandra.net.Message) Token(org.apache.cassandra.dht.Token) Range(org.apache.cassandra.dht.Range) SSTableReader(org.apache.cassandra.io.sstable.format.SSTableReader) ValidationResponse(org.apache.cassandra.repair.messages.ValidationResponse) Keyspace(org.apache.cassandra.db.Keyspace) ColumnFamilyStore(org.apache.cassandra.db.ColumnFamilyStore) UUID(java.util.UUID)

Aggregations

ValidationResponse (org.apache.cassandra.repair.messages.ValidationResponse)8 Range (org.apache.cassandra.dht.Range)5 Token (org.apache.cassandra.dht.Token)5 InetAddressAndPort (org.apache.cassandra.locator.InetAddressAndPort)5 Message (org.apache.cassandra.net.Message)5 ColumnFamilyStore (org.apache.cassandra.db.ColumnFamilyStore)4 CompactionsTest (org.apache.cassandra.db.compaction.CompactionsTest)4 MerkleTrees (org.apache.cassandra.utils.MerkleTrees)4 Test (org.junit.Test)4 UUID (java.util.UUID)3 Keyspace (org.apache.cassandra.db.Keyspace)3 SSTableReader (org.apache.cassandra.io.sstable.format.SSTableReader)3 IOException (java.io.IOException)1 BufferDecoratedKey (org.apache.cassandra.db.BufferDecoratedKey)1 RepairJobDesc (org.apache.cassandra.repair.RepairJobDesc)1 RepairSession (org.apache.cassandra.repair.RepairSession)1 RepairMessage (org.apache.cassandra.repair.messages.RepairMessage)1 SyncResponse (org.apache.cassandra.repair.messages.SyncResponse)1