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