Search in sources :

Example 91 with InetAddressAndPort

use of org.apache.cassandra.locator.InetAddressAndPort 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)

Example 92 with InetAddressAndPort

use of org.apache.cassandra.locator.InetAddressAndPort in project cassandra by apache.

the class ValidatorTest method testSizeLimiting.

/*
     * Test for CASSANDRA-14096 size limiting. We:
     * 1. Limit the size of a repair session
     * 2. Submit a validation
     * 3. Check that the resulting tree is of limited depth
     */
@Test
public void testSizeLimiting() throws Exception {
    Keyspace ks = Keyspace.open(keyspace);
    ColumnFamilyStore cfs = ks.getColumnFamilyStore(columnFamily);
    cfs.clearUnsafe();
    DatabaseDescriptor.setRepairSessionSpaceInMiB(1);
    // disable compaction while flushing
    cfs.disableAutoCompaction();
    // 2 ** 14 rows would normally use 2^14 leaves, but with only 1 meg we should only use 2^12
    CompactionsTest.populate(keyspace, columnFamily, 0, 1 << 14, 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);
    MerkleTrees trees = ((ValidationResponse) message.payload).trees;
    Iterator<Map.Entry<Range<Token>, MerkleTree>> iterator = trees.iterator();
    int numTrees = 0;
    while (iterator.hasNext()) {
        assertEquals(1 << 12, iterator.next().getValue().size(), 0.0);
        numTrees++;
    }
    assertEquals(1, numTrees);
    assertEquals(trees.rowCount(), 1 << 14);
}
Also used : MerkleTrees(org.apache.cassandra.utils.MerkleTrees) 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) CompactionsTest(org.apache.cassandra.db.compaction.CompactionsTest) Test(org.junit.Test)

Example 93 with InetAddressAndPort

use of org.apache.cassandra.locator.InetAddressAndPort in project cassandra by apache.

the class ValidatorTest method testRangeSplittingTreeSizeLimit.

/*
     * Test for CASSANDRA-11390. When there are multiple subranges the trees should
     * automatically size down to make each subrange fit in the provided memory
     * 1. Limit the size of all the trees
     * 2. Submit a validation against more than one range
     * 3. Check that we have the right number and sizes of trees
     */
@Test
public void testRangeSplittingTreeSizeLimit() throws Exception {
    Keyspace ks = Keyspace.open(keyspace);
    ColumnFamilyStore cfs = ks.getColumnFamilyStore(columnFamily);
    cfs.clearUnsafe();
    DatabaseDescriptor.setRepairSessionSpaceInMiB(1);
    // disable compaction while flushing
    cfs.disableAutoCompaction();
    // 2 ** 14 rows would normally use 2^14 leaves, but with only 1 meg we should only use 2^12
    CompactionsTest.populate(keyspace, columnFamily, 0, 1 << 14, 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();
    List<Range<Token>> ranges = splitHelper(new Range<>(sstable.first.getToken(), sstable.last.getToken()), 2);
    final RepairJobDesc desc = new RepairJobDesc(repairSessionId, UUIDGen.getTimeUUID(), cfs.keyspace.getName(), cfs.getTableName(), ranges);
    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);
    MerkleTrees trees = ((ValidationResponse) message.payload).trees;
    // Should have 4 trees each with a depth of on average 10 (since each range should have gotten 0.25 mebibytes)
    Iterator<Map.Entry<Range<Token>, MerkleTree>> iterator = trees.iterator();
    int numTrees = 0;
    double totalResolution = 0;
    while (iterator.hasNext()) {
        long size = iterator.next().getValue().size();
        // So it turns out that sstable range estimates are pretty variable, depending on the sampling we can
        // get a wide range of values here. So we just make sure that we're smaller than in the single range
        // case and have the right total size.
        assertTrue(size <= (1 << 11));
        assertTrue(size >= (1 << 9));
        totalResolution += size;
        numTrees += 1;
    }
    assertEquals(trees.rowCount(), 1 << 14);
    assertEquals(4, numTrees);
    // With a single tree and a mebibyte we should had a total resolution of 2^12 leaves; with multiple
    // ranges we should get similar overall resolution, but not more.
    assertTrue(totalResolution > (1 << 11) && totalResolution < (1 << 13));
}
Also used : MerkleTrees(org.apache.cassandra.utils.MerkleTrees) 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) CompactionsTest(org.apache.cassandra.db.compaction.CompactionsTest) Test(org.junit.Test)

Example 94 with InetAddressAndPort

use of org.apache.cassandra.locator.InetAddressAndPort in project cassandra by apache.

the class NeighborsAndRangesTest method forceFilterCommonIncrementalRanges.

@Test
public void forceFilterCommonIncrementalRanges() {
    CommonRange cr1 = new CommonRange(Sets.newHashSet(PARTICIPANT1, PARTICIPANT2), Collections.emptySet(), Sets.newHashSet(RANGE1));
    CommonRange cr2 = new CommonRange(Sets.newHashSet(PARTICIPANT1, PARTICIPANT2, PARTICIPANT3), Collections.emptySet(), Sets.newHashSet(RANGE3));
    CommonRange cr3 = new CommonRange(Sets.newHashSet(PARTICIPANT2, PARTICIPANT3), Collections.emptySet(), Sets.newHashSet(RANGE2));
    // PARTICIPANT1 is excluded
    Set<InetAddressAndPort> liveEndpoints = Sets.newHashSet(PARTICIPANT2, PARTICIPANT3);
    List<CommonRange> initial = Lists.newArrayList(cr1, cr2, cr3);
    List<CommonRange> expected = Lists.newArrayList(new CommonRange(Sets.newHashSet(PARTICIPANT2), Collections.emptySet(), Sets.newHashSet(RANGE1), true), new CommonRange(Sets.newHashSet(PARTICIPANT2, PARTICIPANT3), Collections.emptySet(), Sets.newHashSet(RANGE3), true), new CommonRange(Sets.newHashSet(PARTICIPANT2, PARTICIPANT3), Collections.emptySet(), Sets.newHashSet(RANGE2), false));
    NeighborsAndRanges nr = new NeighborsAndRanges(true, liveEndpoints, initial);
    List<CommonRange> actual = nr.filterCommonRanges(null, null);
    Assert.assertEquals(expected, actual);
}
Also used : InetAddressAndPort(org.apache.cassandra.locator.InetAddressAndPort) NeighborsAndRanges(org.apache.cassandra.repair.RepairRunnable.NeighborsAndRanges) Test(org.junit.Test)

Example 95 with InetAddressAndPort

use of org.apache.cassandra.locator.InetAddressAndPort in project cassandra by apache.

the class ProxyHandlerConnectionsTest method doTestManual.

private void doTestManual(ConnectionTest.Settings settings, ManualSendTest test) throws Throwable {
    InetAddressAndPort endpoint = FBUtilities.getBroadcastAddressAndPort();
    InboundConnectionSettings inboundSettings = settings.inbound.apply(new InboundConnectionSettings()).withBindAddress(endpoint).withSocketFactory(factory);
    InboundSockets inbound = new InboundSockets(Collections.singletonList(inboundSettings));
    OutboundConnectionSettings outboundSettings = settings.outbound.apply(new OutboundConnectionSettings(endpoint)).withConnectTo(endpoint).withDefaultReserveLimits().withSocketFactory(factory);
    ResourceLimits.EndpointAndGlobal reserveCapacityInBytes = new ResourceLimits.EndpointAndGlobal(new ResourceLimits.Concurrent(outboundSettings.applicationSendQueueReserveEndpointCapacityInBytes), outboundSettings.applicationSendQueueReserveGlobalCapacityInBytes);
    OutboundConnection outbound = new OutboundConnection(settings.type, outboundSettings, reserveCapacityInBytes);
    try {
        InboundProxyHandler.Controller controller = new InboundProxyHandler.Controller();
        inbound.open(pipeline -> {
            InboundProxyHandler handler = new InboundProxyHandler(controller);
            pipeline.addLast(handler);
        }).sync();
        test.accept(Pair.create(inboundSettings, outboundSettings), inbound, outbound, endpoint, controller);
    } finally {
        outbound.close(false);
        inbound.close().get(30L, SECONDS);
        outbound.close(false).get(30L, SECONDS);
        MessagingService.instance().messageHandlers.clear();
    }
}
Also used : InetAddressAndPort(org.apache.cassandra.locator.InetAddressAndPort) CompactionManager(org.apache.cassandra.db.compaction.CompactionManager) BeforeClass(org.junit.BeforeClass) CommitLog(org.apache.cassandra.db.commitlog.CommitLog) TimeoutException(java.util.concurrent.TimeoutException) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) Supplier(java.util.function.Supplier) ByteBuf(io.netty.buffer.ByteBuf) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Pair(org.apache.cassandra.utils.Pair) InboundProxyHandler(org.apache.cassandra.net.proxy.InboundProxyHandler) Map(java.util.Map) After(org.junit.After) IVersionedAsymmetricSerializer(org.apache.cassandra.io.IVersionedAsymmetricSerializer) DataOutputPlus(org.apache.cassandra.io.util.DataOutputPlus) IVersionedSerializer(org.apache.cassandra.io.IVersionedSerializer) ToLongFunction(java.util.function.ToLongFunction) DatabaseDescriptor(org.apache.cassandra.config.DatabaseDescriptor) Global.approxTime(org.apache.cassandra.utils.MonotonicClock.Global.approxTime) Uninterruptibles(com.google.common.util.concurrent.Uninterruptibles) FBUtilities(org.apache.cassandra.utils.FBUtilities) IOException(java.io.IOException) Test(org.junit.Test) MILLISECONDS(java.util.concurrent.TimeUnit.MILLISECONDS) CRC(org.apache.cassandra.net.OutboundConnectionSettings.Framing.CRC) TimeUnit(java.util.concurrent.TimeUnit) CountDownLatch(java.util.concurrent.CountDownLatch) SETTINGS(org.apache.cassandra.net.ConnectionTest.SETTINGS) DataInputPlus(org.apache.cassandra.io.util.DataInputPlus) Assert(org.junit.Assert) Collections(java.util.Collections) SECONDS(java.util.concurrent.TimeUnit.SECONDS) InetAddressAndPort(org.apache.cassandra.locator.InetAddressAndPort) InboundProxyHandler(org.apache.cassandra.net.proxy.InboundProxyHandler)

Aggregations

InetAddressAndPort (org.apache.cassandra.locator.InetAddressAndPort)281 Test (org.junit.Test)129 Token (org.apache.cassandra.dht.Token)65 TokenMetadata (org.apache.cassandra.locator.TokenMetadata)43 EndpointsForRange (org.apache.cassandra.locator.EndpointsForRange)39 Range (org.apache.cassandra.dht.Range)28 Replica (org.apache.cassandra.locator.Replica)25 ArrayList (java.util.ArrayList)24 ByteBuffer (java.nio.ByteBuffer)23 HashMap (java.util.HashMap)23 UUID (java.util.UUID)22 HashSet (java.util.HashSet)20 Map (java.util.Map)20 Mutation (org.apache.cassandra.db.Mutation)17 PartitionIterator (org.apache.cassandra.db.partitions.PartitionIterator)17 UnfilteredPartitionIterator (org.apache.cassandra.db.partitions.UnfilteredPartitionIterator)16 VersionedValue (org.apache.cassandra.gms.VersionedValue)16 VisibleForTesting (com.google.common.annotations.VisibleForTesting)15 IPartitioner (org.apache.cassandra.dht.IPartitioner)15 BigIntegerToken (org.apache.cassandra.dht.RandomPartitioner.BigIntegerToken)15