use of org.apache.cassandra.db.compaction.CompactionInfo in project cassandra by apache.
the class PendingAntiCompactionTest method testRetries.
@Test
public void testRetries() throws InterruptedException, ExecutionException {
ColumnFamilyStore cfs = MockSchema.newCFS();
cfs.addSSTable(MockSchema.sstable(1, true, cfs));
CountDownLatch cdl = new CountDownLatch(5);
ExecutorPlus es = executorFactory().sequential("test");
CompactionInfo.Holder holder = new CompactionInfo.Holder() {
public CompactionInfo getCompactionInfo() {
return new CompactionInfo(cfs.metadata(), OperationType.ANTICOMPACTION, 0, 0, UUID.randomUUID(), cfs.getLiveSSTables());
}
public boolean isGlobal() {
return false;
}
};
try {
PendingAntiCompaction.AntiCompactionPredicate acp = new PendingAntiCompaction.AntiCompactionPredicate(FULL_RANGE, UUID.randomUUID()) {
@Override
public boolean apply(SSTableReader sstable) {
cdl.countDown();
if (cdl.getCount() > 0)
throw new PendingAntiCompaction.SSTableAcquisitionException("blah");
return true;
}
};
CompactionManager.instance.active.beginCompaction(holder);
PendingAntiCompaction.AcquisitionCallable acquisitionCallable = new PendingAntiCompaction.AcquisitionCallable(cfs, UUID.randomUUID(), 10, 1, acp);
Future f = es.submit(acquisitionCallable);
cdl.await();
assertNotNull(f.get());
} finally {
es.shutdown();
CompactionManager.instance.active.finishCompaction(holder);
}
}
use of org.apache.cassandra.db.compaction.CompactionInfo in project cassandra by apache.
the class PendingAntiCompactionTest method testRetriesTimeout.
@Test
public void testRetriesTimeout() throws InterruptedException, ExecutionException {
ColumnFamilyStore cfs = MockSchema.newCFS();
cfs.addSSTable(MockSchema.sstable(1, true, cfs));
ExecutorPlus es = executorFactory().sequential("test");
CompactionInfo.Holder holder = new CompactionInfo.Holder() {
public CompactionInfo getCompactionInfo() {
return new CompactionInfo(cfs.metadata(), OperationType.ANTICOMPACTION, 0, 0, UUID.randomUUID(), cfs.getLiveSSTables());
}
public boolean isGlobal() {
return false;
}
};
try {
PendingAntiCompaction.AntiCompactionPredicate acp = new PendingAntiCompaction.AntiCompactionPredicate(FULL_RANGE, UUID.randomUUID()) {
@Override
public boolean apply(SSTableReader sstable) {
throw new PendingAntiCompaction.SSTableAcquisitionException("blah");
}
};
CompactionManager.instance.active.beginCompaction(holder);
PendingAntiCompaction.AcquisitionCallable acquisitionCallable = new PendingAntiCompaction.AcquisitionCallable(cfs, UUID.randomUUID(), 2, 1000, acp);
Future fut = es.submit(acquisitionCallable);
assertNull(fut.get());
} finally {
es.shutdown();
CompactionManager.instance.active.finishCompaction(holder);
}
}
use of org.apache.cassandra.db.compaction.CompactionInfo in project cassandra by apache.
the class CompactionStatsTest method testCompactionStats.
@Test
public void testCompactionStats() {
createTable("CREATE TABLE %s (pk int, ck int, PRIMARY KEY (pk, ck))");
ColumnFamilyStore cfs = getCurrentColumnFamilyStore();
long bytesCompacted = 123;
long bytesTotal = 123456;
UUID compactionId = UUID.randomUUID();
List<SSTableReader> sstables = IntStream.range(0, 10).mapToObj(i -> MockSchema.sstable(i, i * 10L, i * 10L + 9, cfs)).collect(Collectors.toList());
CompactionInfo.Holder compactionHolder = new CompactionInfo.Holder() {
public CompactionInfo getCompactionInfo() {
return new CompactionInfo(cfs.metadata(), OperationType.COMPACTION, bytesCompacted, bytesTotal, compactionId, sstables);
}
public boolean isGlobal() {
return false;
}
};
CompactionManager.instance.active.beginCompaction(compactionHolder);
ToolRunner.ToolResult tool = ToolRunner.invokeNodetool("compactionstats");
tool.assertOnCleanExit();
String stdout = tool.getStdout();
assertThat(stdout).contains("pending tasks: 1");
Assertions.assertThat(stdout).containsPattern("keyspace\\s+table\\s+task id\\s+completion ratio\\s+kind\\s+progress\\s+sstables\\s+total\\s+unit");
String expectedStatsPattern = String.format("%s\\s+%s\\s+%s\\s+%.2f%%\\s+%s\\s+%s\\s+%s\\s+%s\\s+%s", CQLTester.KEYSPACE, currentTable(), compactionId, (double) bytesCompacted / bytesTotal * 100, OperationType.COMPACTION, bytesCompacted, sstables.size(), bytesTotal, CompactionInfo.Unit.BYTES);
Assertions.assertThat(stdout).containsPattern(expectedStatsPattern);
CompactionManager.instance.active.finishCompaction(compactionHolder);
tool = ToolRunner.invokeNodetool("compactionstats");
tool.assertOnCleanExit();
stdout = tool.getStdout();
assertThat(stdout).contains("pending tasks: 0");
}
use of org.apache.cassandra.db.compaction.CompactionInfo in project cassandra by apache.
the class CompactionStatsTest method testCompactionStatsHumanReadable.
@Test
public void testCompactionStatsHumanReadable() {
createTable("CREATE TABLE %s (pk int, ck int, PRIMARY KEY (pk, ck))");
ColumnFamilyStore cfs = getCurrentColumnFamilyStore();
long bytesCompacted = 123;
long bytesTotal = 123456;
UUID compactionId = UUID.randomUUID();
List<SSTableReader> sstables = IntStream.range(0, 10).mapToObj(i -> MockSchema.sstable(i, i * 10L, i * 10L + 9, cfs)).collect(Collectors.toList());
CompactionInfo.Holder compactionHolder = new CompactionInfo.Holder() {
public CompactionInfo getCompactionInfo() {
return new CompactionInfo(cfs.metadata(), OperationType.COMPACTION, bytesCompacted, bytesTotal, compactionId, sstables);
}
public boolean isGlobal() {
return false;
}
};
CompactionManager.instance.active.beginCompaction(compactionHolder);
ToolRunner.ToolResult tool = ToolRunner.invokeNodetool("compactionstats", "--human-readable");
tool.assertOnCleanExit();
String stdout = tool.getStdout();
assertThat(stdout).contains("pending tasks: 1");
Assertions.assertThat(stdout).containsPattern("keyspace\\s+table\\s+task id\\s+completion ratio\\s+kind\\s+progress\\s+sstables\\s+total\\s+unit");
String expectedStatsPattern = String.format("%s\\s+%s\\s+%s\\s+%.2f%%\\s+%s\\s+%s\\s+%s\\s+%s\\s+%s", CQLTester.KEYSPACE, currentTable(), compactionId, (double) bytesCompacted / bytesTotal * 100, OperationType.COMPACTION, "123 bytes", sstables.size(), "120.56 KiB", CompactionInfo.Unit.BYTES);
Assertions.assertThat(stdout).containsPattern(expectedStatsPattern);
CompactionManager.instance.active.finishCompaction(compactionHolder);
tool = ToolRunner.invokeNodetool("compactionstats", "--human-readable");
tool.assertOnCleanExit();
stdout = tool.getStdout();
assertThat(stdout).contains("pending tasks: 0");
}
use of org.apache.cassandra.db.compaction.CompactionInfo in project cassandra by apache.
the class SSTableTasksTableTest method testSelectAll.
@Test
public void testSelectAll() throws Throwable {
createTable("CREATE TABLE %s (pk int, ck int, PRIMARY KEY (pk, ck))");
ColumnFamilyStore cfs = getCurrentColumnFamilyStore();
long bytesCompacted = 123;
long bytesTotal = 123456;
UUID compactionId = UUID.randomUUID();
List<SSTableReader> sstables = IntStream.range(0, 10).mapToObj(i -> MockSchema.sstable(i, i * 10L, i * 10L + 9, cfs)).collect(Collectors.toList());
CompactionInfo.Holder compactionHolder = new CompactionInfo.Holder() {
public CompactionInfo getCompactionInfo() {
return new CompactionInfo(cfs.metadata(), OperationType.COMPACTION, bytesCompacted, bytesTotal, compactionId, sstables);
}
public boolean isGlobal() {
return false;
}
};
CompactionManager.instance.active.beginCompaction(compactionHolder);
UntypedResultSet result = execute("SELECT * FROM vts.sstable_tasks");
assertRows(result, row(CQLTester.KEYSPACE, currentTable(), compactionId, 1.0 * bytesCompacted / bytesTotal, OperationType.COMPACTION.toString().toLowerCase(), bytesCompacted, sstables.size(), bytesTotal, CompactionInfo.Unit.BYTES.toString()));
CompactionManager.instance.active.finishCompaction(compactionHolder);
result = execute("SELECT * FROM vts.sstable_tasks");
assertEmpty(result);
}
Aggregations