maytasm commented on a change in pull request #11009:
URL: https://github.com/apache/druid/pull/11009#discussion_r597224953



##########
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:
       Done




-- 
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]

Reply via email to