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