use of org.apache.cassandra.db.compaction.AbstractStrategyHolder.TaskSupplier in project cassandra by apache.
the class CompactionStrategyManager method getNextBackgroundTask.
/**
* Return the next background task
*
* Returns a task for the compaction strategy that needs it the most (most estimated remaining tasks)
*/
public AbstractCompactionTask getNextBackgroundTask(int gcBefore) {
maybeReloadDiskBoundaries();
readLock.lock();
try {
if (!isEnabled())
return null;
int numPartitions = getNumTokenPartitions();
// first try to promote/demote sstables from completed repairs
AbstractCompactionTask repairFinishedTask;
repairFinishedTask = pendingRepairs.getNextRepairFinishedTask();
if (repairFinishedTask != null)
return repairFinishedTask;
repairFinishedTask = transientRepairs.getNextRepairFinishedTask();
if (repairFinishedTask != null)
return repairFinishedTask;
// sort compaction task suppliers by remaining tasks descending
List<TaskSupplier> suppliers = new ArrayList<>(numPartitions * holders.size());
for (AbstractStrategyHolder holder : holders) suppliers.addAll(holder.getBackgroundTaskSuppliers(gcBefore));
Collections.sort(suppliers);
// return the first non-null task
for (TaskSupplier supplier : suppliers) {
AbstractCompactionTask task = supplier.getTask();
if (task != null)
return task;
}
return null;
} finally {
readLock.unlock();
}
}
Aggregations