abhishekagarwal87 commented on a change in pull request #11009:
URL: https://github.com/apache/druid/pull/11009#discussion_r596606358
##########
File path:
server/src/main/java/org/apache/druid/server/coordinator/duty/NewestSegmentFirstIterator.java
##########
@@ -397,20 +398,29 @@ private boolean
needsCompaction(DataSourceCompactionConfig config, SegmentsToCom
needsCompaction = true;
}
- // Only checks for segmentGranularity as auto compaction currently only
supports segmentGranularity
- final Granularity segmentGranularity =
lastCompactionState.getGranularitySpec() != null ?
-
objectMapper.convertValue(lastCompactionState.getGranularitySpec(),
GranularitySpec.class).getSegmentGranularity() :
- null;
-
- if (config.getGranularitySpec() != null &&
- config.getGranularitySpec().getSegmentGranularity() != null &&
-
!config.getGranularitySpec().getSegmentGranularity().equals(segmentGranularity))
{
- log.info(
- "Configured granularitySpec[%s] is different from the one[%s] of
segments. Needs compaction",
- config.getGranularitySpec(),
- segmentGranularity
- );
- needsCompaction = true;
+ if (config.getGranularitySpec() != null &&
config.getGranularitySpec().getSegmentGranularity() != null) {
+ // Only checks for segmentGranularity as auto compaction currently only
supports segmentGranularity
+ final Granularity existingSegmentGranularity =
lastCompactionState.getGranularitySpec() != null ?
+
objectMapper.convertValue(lastCompactionState.getGranularitySpec(),
GranularitySpec.class).getSegmentGranularity() :
+ null;
+ if (existingSegmentGranularity == null) {
+ // Candidate segments were all compacted without segment granularity
set.
+ // We need to check if all segments have the same segment granularity
and if it is the same
+ // as the configured segment granularity.
+ Set<Granularity> segmentGranularities = candidates.segments.stream()
+
.map(segment ->
GranularityType.fromPeriod(segment.getInterval().toPeriod()).getDefaultGranularity())
+
.collect(Collectors.toSet());
+ if (segmentGranularities.size() != 1 ||
!segmentGranularities.contains(config.getGranularitySpec().getSegmentGranularity()))
{
+ needsCompaction = true;
Review comment:
do we need a log statement here as well?
##########
File path:
server/src/main/java/org/apache/druid/server/coordinator/duty/NewestSegmentFirstIterator.java
##########
@@ -397,20 +398,29 @@ private boolean
needsCompaction(DataSourceCompactionConfig config, SegmentsToCom
needsCompaction = true;
}
- // Only checks for segmentGranularity as auto compaction currently only
supports segmentGranularity
- final Granularity segmentGranularity =
lastCompactionState.getGranularitySpec() != null ?
-
objectMapper.convertValue(lastCompactionState.getGranularitySpec(),
GranularitySpec.class).getSegmentGranularity() :
- null;
-
- if (config.getGranularitySpec() != null &&
- config.getGranularitySpec().getSegmentGranularity() != null &&
-
!config.getGranularitySpec().getSegmentGranularity().equals(segmentGranularity))
{
- log.info(
- "Configured granularitySpec[%s] is different from the one[%s] of
segments. Needs compaction",
- config.getGranularitySpec(),
- segmentGranularity
- );
- needsCompaction = true;
+ if (config.getGranularitySpec() != null &&
config.getGranularitySpec().getSegmentGranularity() != null) {
+ // Only checks for segmentGranularity as auto compaction currently only
supports segmentGranularity
+ final Granularity existingSegmentGranularity =
lastCompactionState.getGranularitySpec() != null ?
+
objectMapper.convertValue(lastCompactionState.getGranularitySpec(),
GranularitySpec.class).getSegmentGranularity() :
+ null;
+ if (existingSegmentGranularity == null) {
+ // Candidate segments were all compacted without segment granularity
set.
+ // We need to check if all segments have the same segment granularity
and if it is the same
+ // as the configured segment granularity.
+ Set<Granularity> segmentGranularities = candidates.segments.stream()
+
.map(segment ->
GranularityType.fromPeriod(segment.getInterval().toPeriod()).getDefaultGranularity())
+
.collect(Collectors.toSet());
+ if (segmentGranularities.size() != 1 ||
!segmentGranularities.contains(config.getGranularitySpec().getSegmentGranularity()))
{
+ needsCompaction = true;
+ }
+ } else if
(!config.getGranularitySpec().getSegmentGranularity().equals(existingSegmentGranularity))
{
+ log.info(
+ "Configured granularitySpec[%s] is different from the one[%s] of
segments. Needs compaction",
Review comment:
nit: maybe you can just log the segment granularity instead of the
granularity spec?
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]