use of org.apache.cassandra.db.compaction.CompactionInfo in project cassandra by apache.
the class ViewBuilder method getCompactionInfo.
public CompactionInfo getCompactionInfo() {
long rangesLeft = 0, rangesTotal = 0;
Token lastToken = prevToken;
// has.
for (Range<Token> range : StorageService.instance.getLocalRanges(baseCfs.keyspace.getName())) {
rangesLeft++;
rangesTotal++;
// end of the method.
if (lastToken == null || range.contains(lastToken))
rangesLeft = 0;
}
return new CompactionInfo(baseCfs.metadata(), OperationType.VIEW_BUILD, rangesLeft, rangesTotal, "ranges", compactionId);
}
use of org.apache.cassandra.db.compaction.CompactionInfo in project cassandra by apache.
the class SSTableTasksTable method data.
public DataSet data() {
SimpleDataSet result = new SimpleDataSet(metadata());
for (CompactionInfo task : CompactionManager.instance.getSSTableTasks()) {
long completed = task.getCompleted();
long total = task.getTotal();
double completionRatio = total == 0L ? 1.0 : (((double) completed) / total);
result.row(task.getKeyspace().orElse("*"), task.getTable().orElse("*"), task.getTaskId()).column(COMPLETION_RATIO, completionRatio).column(KIND, task.getTaskType().toString().toLowerCase()).column(PROGRESS, completed).column(SSTABLES, task.getSSTables().size()).column(TOTAL, total).column(UNIT, task.getUnit().toString().toLowerCase());
}
return result;
}
use of org.apache.cassandra.db.compaction.CompactionInfo in project cassandra by apache.
the class IndexSummaryManagerTest method testCancelIndexHelper.
public void testCancelIndexHelper(Consumer<ColumnFamilyStore> cancelFunction) 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);
cfs.disableAutoCompaction();
final int numSSTables = 8;
int numRows = 256;
createSSTables(ksname, cfname, numSSTables, numRows);
List<SSTableReader> allSSTables = new ArrayList<>(cfs.getLiveSSTables());
List<SSTableReader> sstables = allSSTables.subList(0, 4);
List<SSTableReader> compacting = allSSTables.subList(4, 8);
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);
CompactionInfo.Holder ongoingCompaction = new CompactionInfo.Holder() {
public CompactionInfo getCompactionInfo() {
return new CompactionInfo(cfs.metadata(), OperationType.UNKNOWN, 0, 0, UUID.randomUUID(), compacting);
}
public boolean isGlobal() {
return false;
}
};
try (LifecycleTransaction ignored = cfs.getTracker().tryModify(compacting, OperationType.UNKNOWN)) {
CompactionManager.instance.active.beginCompaction(ongoingCompaction);
Thread t = NamedThreadFactory.createAnonymousThread(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(of(cfs.metadata.id, txn), 0, singleSummaryOffHeapSpace, barrier));
}
} catch (CompactionInterruptedException ex) {
exception.set(ex);
} catch (IOException ignored) {
}
}
});
t.start();
while (CompactionManager.instance.getActiveCompactions() < 2 && 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.
cancelFunction.accept(cfs);
// allows the redistribution to proceed
barrier.countDown();
t.join();
} finally {
CompactionManager.instance.active.finishCompaction(ongoingCompaction);
}
assertNotNull("Expected compaction interrupted exception", exception.get());
assertTrue("Expected no active compactions", CompactionManager.instance.active.getCompactions().isEmpty());
Set<SSTableReader> beforeRedistributionSSTables = new HashSet<>(allSSTables);
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());
assertOnDiskState(cfs, 8);
validateData(cfs, numRows);
}
Aggregations