Search in sources :

Example 46 with Keyspace

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

the class IndexSummaryManagerTest method testChangeMaxIndexInterval.

@Test
public void testChangeMaxIndexInterval() throws IOException {
    String ksname = KEYSPACE1;
    // index interval of 8, no key caching
    String cfname = CF_STANDARDLOWiINTERVAL;
    Keyspace keyspace = Keyspace.open(ksname);
    ColumnFamilyStore cfs = keyspace.getColumnFamilyStore(cfname);
    int numSSTables = 1;
    int numRows = 256;
    createSSTables(ksname, cfname, numSSTables, numRows);
    List<SSTableReader> sstables = new ArrayList<>(cfs.getLiveSSTables());
    for (SSTableReader sstable : sstables) sstable.overrideReadMeter(new RestorableMeter(100.0, 100.0));
    try (LifecycleTransaction txn = cfs.getTracker().tryModify(sstables, OperationType.UNKNOWN)) {
        redistributeSummaries(Collections.EMPTY_LIST, of(cfs.metadata.id, txn), 10);
    }
    sstables = new ArrayList<>(cfs.getLiveSSTables());
    for (SSTableReader sstable : sstables) assertEquals(cfs.metadata().params.maxIndexInterval, sstable.getEffectiveIndexInterval(), 0.01);
    // halve the max_index_interval
    MigrationManager.announceTableUpdate(cfs.metadata().unbuild().maxIndexInterval(cfs.metadata().params.maxIndexInterval / 2).build(), true);
    try (LifecycleTransaction txn = cfs.getTracker().tryModify(sstables, OperationType.UNKNOWN)) {
        redistributeSummaries(Collections.EMPTY_LIST, of(cfs.metadata.id, txn), 1);
    }
    sstables = new ArrayList<>(cfs.getLiveSSTables());
    for (SSTableReader sstable : sstables) {
        assertEquals(cfs.metadata().params.maxIndexInterval, sstable.getEffectiveIndexInterval(), 0.01);
        assertEquals(numRows / cfs.metadata().params.maxIndexInterval, sstable.getIndexSummarySize());
    }
    // return max_index_interval to its original value
    MigrationManager.announceTableUpdate(cfs.metadata().unbuild().maxIndexInterval(cfs.metadata().params.maxIndexInterval * 2).build(), true);
    try (LifecycleTransaction txn = cfs.getTracker().tryModify(sstables, OperationType.UNKNOWN)) {
        redistributeSummaries(Collections.EMPTY_LIST, of(cfs.metadata.id, txn), 1);
    }
    for (SSTableReader sstable : cfs.getLiveSSTables()) {
        assertEquals(cfs.metadata().params.maxIndexInterval, sstable.getEffectiveIndexInterval(), 0.01);
        assertEquals(numRows / cfs.metadata().params.maxIndexInterval, sstable.getIndexSummarySize());
    }
}
Also used : RestorableMeter(org.apache.cassandra.metrics.RestorableMeter) SSTableReader(org.apache.cassandra.io.sstable.format.SSTableReader) Keyspace(org.apache.cassandra.db.Keyspace) ColumnFamilyStore(org.apache.cassandra.db.ColumnFamilyStore) LifecycleTransaction(org.apache.cassandra.db.lifecycle.LifecycleTransaction) Test(org.junit.Test)

Example 47 with Keyspace

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

the class IndexSummaryManagerTest method afterTest.

@After
public void afterTest() {
    for (CompactionInfo.Holder holder : CompactionMetrics.getCompactions()) {
        holder.stop();
    }
    String ksname = KEYSPACE1;
    // index interval of 8, no key caching
    String cfname = CF_STANDARDLOWiINTERVAL;
    Keyspace keyspace = Keyspace.open(ksname);
    ColumnFamilyStore cfs = keyspace.getColumnFamilyStore(cfname);
    MigrationManager.announceTableUpdate(cfs.metadata().unbuild().minIndexInterval(originalMinIndexInterval).build(), true);
    MigrationManager.announceTableUpdate(cfs.metadata().unbuild().maxIndexInterval(originalMaxIndexInterval).build(), true);
    IndexSummaryManager.instance.setMemoryPoolCapacityInMB(originalCapacity);
}
Also used : Keyspace(org.apache.cassandra.db.Keyspace) ColumnFamilyStore(org.apache.cassandra.db.ColumnFamilyStore) CompactionInfo(org.apache.cassandra.db.compaction.CompactionInfo) After(org.junit.After)

Example 48 with Keyspace

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

the class IndexSummaryManagerTest method testCancelIndex.

@Test
public void testCancelIndex() throws Exception {
    String ksname = KEYSPACE1;
    // index interval of 8, no key caching
    String cfname = CF_STANDARDLOWiINTERVAL;
    Keyspace keyspace = Keyspace.open(ksname);
    final ColumnFamilyStore cfs = keyspace.getColumnFamilyStore(cfname);
    final int numSSTables = 4;
    int numRows = 256;
    createSSTables(ksname, cfname, numSSTables, numRows);
    final List<SSTableReader> sstables = new ArrayList<>(cfs.getLiveSSTables());
    for (SSTableReader sstable : sstables) sstable.overrideReadMeter(new RestorableMeter(100.0, 100.0));
    final long singleSummaryOffHeapSpace = sstables.get(0).getIndexSummaryOffHeapSize();
    // everything should get cut in half
    final AtomicReference<CompactionInterruptedException> exception = new AtomicReference<>();
    // barrier to control when redistribution runs
    final CountDownLatch barrier = new CountDownLatch(1);
    Thread t = NamedThreadFactory.createThread(new Runnable() {

        public void run() {
            try {
                // Don't leave enough space for even the minimal index summaries
                try (LifecycleTransaction txn = cfs.getTracker().tryModify(sstables, OperationType.UNKNOWN)) {
                    IndexSummaryManager.redistributeSummaries(new ObservableRedistribution(Collections.EMPTY_LIST, of(cfs.metadata.id, txn), singleSummaryOffHeapSpace, barrier));
                }
            } catch (CompactionInterruptedException ex) {
                exception.set(ex);
            } catch (IOException ignored) {
            }
        }
    });
    t.start();
    while (CompactionManager.instance.getActiveCompactions() == 0 && t.isAlive()) Thread.sleep(1);
    // to ensure that the stop condition check in IndexSummaryRedistribution::redistributeSummaries
    // is made *after* the halt request is made to the CompactionManager, don't allow the redistribution
    // to proceed until stopCompaction has been called.
    CompactionManager.instance.stopCompaction("INDEX_SUMMARY");
    // allows the redistribution to proceed
    barrier.countDown();
    t.join();
    assertNotNull("Expected compaction interrupted exception", exception.get());
    assertTrue("Expected no active compactions", CompactionMetrics.getCompactions().isEmpty());
    Set<SSTableReader> beforeRedistributionSSTables = new HashSet<>(sstables);
    Set<SSTableReader> afterCancelSSTables = new HashSet<>(cfs.getLiveSSTables());
    Set<SSTableReader> disjoint = Sets.symmetricDifference(beforeRedistributionSSTables, afterCancelSSTables);
    assertTrue(String.format("Mismatched files before and after cancelling redistribution: %s", Joiner.on(",").join(disjoint)), disjoint.isEmpty());
    validateData(cfs, numRows);
}
Also used : CompactionInterruptedException(org.apache.cassandra.db.compaction.CompactionInterruptedException) LifecycleTransaction(org.apache.cassandra.db.lifecycle.LifecycleTransaction) AtomicReference(java.util.concurrent.atomic.AtomicReference) IOException(java.io.IOException) RestorableMeter(org.apache.cassandra.metrics.RestorableMeter) SSTableReader(org.apache.cassandra.io.sstable.format.SSTableReader) Keyspace(org.apache.cassandra.db.Keyspace) ColumnFamilyStore(org.apache.cassandra.db.ColumnFamilyStore) Test(org.junit.Test)

Example 49 with Keyspace

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

the class IndexSummaryManagerTest method testJMXFunctions.

@Test
public void testJMXFunctions() throws IOException {
    IndexSummaryManager manager = IndexSummaryManager.instance;
    // resize interval
    manager.setResizeIntervalInMinutes(-1);
    assertNull(manager.getTimeToNextResize(TimeUnit.MINUTES));
    manager.setResizeIntervalInMinutes(10);
    assertEquals(10, manager.getResizeIntervalInMinutes());
    assertEquals(10, manager.getTimeToNextResize(TimeUnit.MINUTES), 1);
    manager.setResizeIntervalInMinutes(15);
    assertEquals(15, manager.getResizeIntervalInMinutes());
    assertEquals(15, manager.getTimeToNextResize(TimeUnit.MINUTES), 2);
    // memory pool capacity
    assertTrue(manager.getMemoryPoolCapacityInMB() >= 0);
    manager.setMemoryPoolCapacityInMB(10);
    assertEquals(10, manager.getMemoryPoolCapacityInMB());
    String ksname = KEYSPACE1;
    // index interval of 8, no key caching
    String cfname = CF_STANDARDLOWiINTERVAL;
    Keyspace keyspace = Keyspace.open(ksname);
    ColumnFamilyStore cfs = keyspace.getColumnFamilyStore(cfname);
    cfs.truncateBlocking();
    cfs.disableAutoCompaction();
    ByteBuffer value = ByteBuffer.wrap(new byte[100]);
    int numSSTables = 2;
    int numRows = 10;
    for (int sstable = 0; sstable < numSSTables; sstable++) {
        for (int row = 0; row < numRows; row++) {
            String key = String.format("%3d", row);
            new RowUpdateBuilder(cfs.metadata(), 0, key).clustering("column").add("val", value).build().applyUnsafe();
        }
        cfs.forceBlockingFlush();
    }
    assertTrue(manager.getAverageIndexInterval() >= cfs.metadata().params.minIndexInterval);
    Map<String, Integer> intervals = manager.getIndexIntervals();
    for (Map.Entry<String, Integer> entry : intervals.entrySet()) if (entry.getKey().contains(CF_STANDARDLOWiINTERVAL))
        assertEquals(cfs.metadata().params.minIndexInterval, entry.getValue(), 0.001);
    manager.setMemoryPoolCapacityInMB(0);
    manager.redistributeSummaries();
    assertTrue(manager.getAverageIndexInterval() > cfs.metadata().params.minIndexInterval);
    intervals = manager.getIndexIntervals();
    for (Map.Entry<String, Integer> entry : intervals.entrySet()) {
        if (entry.getKey().contains(CF_STANDARDLOWiINTERVAL))
            assertTrue(entry.getValue() >= cfs.metadata().params.minIndexInterval);
    }
}
Also used : RowUpdateBuilder(org.apache.cassandra.db.RowUpdateBuilder) Keyspace(org.apache.cassandra.db.Keyspace) ColumnFamilyStore(org.apache.cassandra.db.ColumnFamilyStore) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Example 50 with Keyspace

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

the class IndexSummaryManagerTest method beforeTest.

@Before
public void beforeTest() {
    String ksname = KEYSPACE1;
    // index interval of 8, no key caching
    String cfname = CF_STANDARDLOWiINTERVAL;
    Keyspace keyspace = Keyspace.open(ksname);
    ColumnFamilyStore cfs = keyspace.getColumnFamilyStore(cfname);
    originalMinIndexInterval = cfs.metadata().params.minIndexInterval;
    originalMaxIndexInterval = cfs.metadata().params.maxIndexInterval;
    originalCapacity = IndexSummaryManager.instance.getMemoryPoolCapacityInMB();
}
Also used : Keyspace(org.apache.cassandra.db.Keyspace) ColumnFamilyStore(org.apache.cassandra.db.ColumnFamilyStore) Before(org.junit.Before)

Aggregations

Keyspace (org.apache.cassandra.db.Keyspace)69 ColumnFamilyStore (org.apache.cassandra.db.ColumnFamilyStore)63 SSTableReader (org.apache.cassandra.io.sstable.format.SSTableReader)48 Test (org.junit.Test)42 LifecycleTransaction (org.apache.cassandra.db.lifecycle.LifecycleTransaction)23 RowUpdateBuilder (org.apache.cassandra.db.RowUpdateBuilder)17 CompactionController (org.apache.cassandra.db.compaction.CompactionController)13 CompactionIterator (org.apache.cassandra.db.compaction.CompactionIterator)12 DecoratedKey (org.apache.cassandra.db.DecoratedKey)11 ByteBuffer (java.nio.ByteBuffer)10 File (java.io.File)5 Directories (org.apache.cassandra.db.Directories)5 SystemKeyspace (org.apache.cassandra.db.SystemKeyspace)5 RestorableMeter (org.apache.cassandra.metrics.RestorableMeter)5 ArrayList (java.util.ArrayList)4 AbstractCompactionStrategy (org.apache.cassandra.db.compaction.AbstractCompactionStrategy)4 Range (org.apache.cassandra.dht.Range)4 Token (org.apache.cassandra.dht.Token)4 Descriptor (org.apache.cassandra.io.sstable.Descriptor)4 PrintStream (java.io.PrintStream)3