Search in sources :

Example 1 with BufferDecoratedKey

use of org.apache.cassandra.db.BufferDecoratedKey in project cassandra by apache.

the class WriteCallbackInfoTest method testShouldHint.

private void testShouldHint(Verb verb, ConsistencyLevel cl, boolean allowHints, boolean expectHint) throws Exception {
    Object payload = verb == Verb.PAXOS_COMMIT ? new Commit(UUID.randomUUID(), new PartitionUpdate(MockSchema.newTableMetadata("", ""), ByteBufferUtil.EMPTY_BYTE_BUFFER, RegularAndStaticColumns.NONE, 1)) : new Mutation("", new BufferDecoratedKey(new Murmur3Partitioner.LongToken(0), ByteBufferUtil.EMPTY_BYTE_BUFFER));
    WriteCallbackInfo wcbi = new WriteCallbackInfo(InetAddress.getByName("192.168.1.1"), null, new MessageOut(verb, payload, null), null, cl, allowHints);
    Assert.assertEquals(expectHint, wcbi.shouldHint());
    if (expectHint) {
        Assert.assertNotNull(wcbi.mutation());
    } else {
        boolean fail = false;
        try {
            wcbi.mutation();
        } catch (Throwable t) {
            fail = true;
        }
        Assert.assertTrue(fail);
    }
}
Also used : Commit(org.apache.cassandra.service.paxos.Commit) BufferDecoratedKey(org.apache.cassandra.db.BufferDecoratedKey) Mutation(org.apache.cassandra.db.Mutation) Murmur3Partitioner(org.apache.cassandra.dht.Murmur3Partitioner) PartitionUpdate(org.apache.cassandra.db.partitions.PartitionUpdate)

Example 2 with BufferDecoratedKey

use of org.apache.cassandra.db.BufferDecoratedKey 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<MessageOut> outgoingMessageSink = registerOutgoingMessageSink();
    InetAddress remote = InetAddress.getByName("127.0.0.2");
    ColumnFamilyStore cfs = Keyspace.open(keyspace).getColumnFamilyStore(columnFamily);
    Validator validator = new Validator(desc, remote, 0);
    MerkleTrees tree = new MerkleTrees(partitioner);
    tree.addMerkleTrees((int) Math.pow(2, 15), validator.desc.ranges);
    validator.prepare(cfs, tree);
    // and confirm that the tree was split
    assertTrue(tree.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 tree was validated
    Token min = tree.partitioner().getMinimumToken();
    assertNotNull(tree.hash(new Range<>(min, min)));
    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());
    assertNotNull(((ValidationComplete) m).trees);
}
Also used : MerkleTrees(org.apache.cassandra.utils.MerkleTrees) RepairMessage(org.apache.cassandra.repair.messages.RepairMessage) ColumnFamilyStore(org.apache.cassandra.db.ColumnFamilyStore) Token(org.apache.cassandra.dht.Token) BufferDecoratedKey(org.apache.cassandra.db.BufferDecoratedKey) Range(org.apache.cassandra.dht.Range) MessageOut(org.apache.cassandra.net.MessageOut) InetAddress(java.net.InetAddress) CompactionsTest(org.apache.cassandra.db.compaction.CompactionsTest) Test(org.junit.Test)

Example 3 with BufferDecoratedKey

use of org.apache.cassandra.db.BufferDecoratedKey in project cassandra by apache.

the class TokenTreeTest method dk.

private static DecoratedKey dk(Long token) {
    ByteBuffer buf = ByteBuffer.allocate(8);
    buf.putLong(token);
    buf.flip();
    Long hashed = MurmurHash.hash2_64(buf, buf.position(), buf.remaining(), 0);
    return new BufferDecoratedKey(new Murmur3Partitioner.LongToken(hashed), buf);
}
Also used : BufferDecoratedKey(org.apache.cassandra.db.BufferDecoratedKey) Murmur3Partitioner(org.apache.cassandra.dht.Murmur3Partitioner) ByteBuffer(java.nio.ByteBuffer)

Aggregations

BufferDecoratedKey (org.apache.cassandra.db.BufferDecoratedKey)3 Murmur3Partitioner (org.apache.cassandra.dht.Murmur3Partitioner)2 InetAddress (java.net.InetAddress)1 ByteBuffer (java.nio.ByteBuffer)1 ColumnFamilyStore (org.apache.cassandra.db.ColumnFamilyStore)1 Mutation (org.apache.cassandra.db.Mutation)1 CompactionsTest (org.apache.cassandra.db.compaction.CompactionsTest)1 PartitionUpdate (org.apache.cassandra.db.partitions.PartitionUpdate)1 Range (org.apache.cassandra.dht.Range)1 Token (org.apache.cassandra.dht.Token)1 MessageOut (org.apache.cassandra.net.MessageOut)1 RepairMessage (org.apache.cassandra.repair.messages.RepairMessage)1 Commit (org.apache.cassandra.service.paxos.Commit)1 MerkleTrees (org.apache.cassandra.utils.MerkleTrees)1 Test (org.junit.Test)1