You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@druid.apache.org by GitBox <gi...@apache.org> on 2021/03/18 07:27:36 UTC

[GitHub] [druid] abhishekagarwal87 commented on a change in pull request #11009: Auto-compaction with segment granularity should skip segments that already have the configured segmentGranularity

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:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org