Skip to content

Commit 696afe9

Browse files
committed
Add new compaction policy to prioritize fragmented intervals
1 parent 2d7cd69 commit 696afe9

File tree

8 files changed

+346
-52
lines changed

8 files changed

+346
-52
lines changed

server/src/main/java/org/apache/druid/server/compaction/BaseCandidateSearchPolicy.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ public final int compareCandidates(CompactionCandidate o1, CompactionCandidate o
6666
@Override
6767
public boolean isEligibleForCompaction(
6868
CompactionCandidate candidate,
69-
CompactionStatus currentCompactionStatus,
7069
CompactionTaskStatus latestTaskStatus
7170
)
7271
{

server/src/main/java/org/apache/druid/server/compaction/CompactionCandidate.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,20 @@ public CompactionStatistics getStats()
137137
return CompactionStatistics.create(totalBytes, numSegments(), numIntervals);
138138
}
139139

140+
@Nullable
141+
public CompactionStatistics getCompactedStats()
142+
{
143+
return (currentStatus == null || currentStatus.getCompactedStats() == null)
144+
? null : currentStatus.getCompactedStats();
145+
}
146+
147+
@Nullable
148+
public CompactionStatistics getUncompactedStats()
149+
{
150+
return (currentStatus == null || currentStatus.getUncompactedStats() == null)
151+
? null : currentStatus.getUncompactedStats();
152+
}
153+
140154
/**
141155
* Current compaction status of the time chunk corresponding to this candidate.
142156
*/

server/src/main/java/org/apache/druid/server/compaction/CompactionCandidateSearchPolicy.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@
2929
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "type")
3030
@JsonSubTypes(value = {
3131
@JsonSubTypes.Type(name = "newestSegmentFirst", value = NewestSegmentFirstPolicy.class),
32-
@JsonSubTypes.Type(name = "fixedIntervalOrder", value = FixedIntervalOrderPolicy.class)
32+
@JsonSubTypes.Type(name = "fixedIntervalOrder", value = FixedIntervalOrderPolicy.class),
33+
@JsonSubTypes.Type(name = "mostFragmentedFirst", value = MostFragmentedIntervalFirstPolicy.class)
3334
})
3435
public interface CompactionCandidateSearchPolicy
3536
{
@@ -50,7 +51,6 @@ public interface CompactionCandidateSearchPolicy
5051
*/
5152
boolean isEligibleForCompaction(
5253
CompactionCandidate candidate,
53-
CompactionStatus currentCompactionStatus,
5454
CompactionTaskStatus latestTaskStatus
5555
);
5656
}

server/src/main/java/org/apache/druid/server/compaction/CompactionStatistics.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,4 +65,14 @@ public void decrement(CompactionStatistics other)
6565
numIntervals -= other.getNumIntervals();
6666
numSegments -= other.getNumSegments();
6767
}
68+
69+
@Override
70+
public String toString()
71+
{
72+
return "CompactionStatistics{" +
73+
"totalBytes=" + totalBytes +
74+
", numSegments=" + numSegments +
75+
", numIntervals=" + numIntervals +
76+
'}';
77+
}
6878
}

0 commit comments

Comments
 (0)