gianm commented on code in PR #19151:
URL: https://github.com/apache/druid/pull/19151#discussion_r2932634229
##########
server/src/main/java/org/apache/druid/client/indexing/ClientCompactionIntervalSpec.java:
##########
@@ -20,83 +20,52 @@
package org.apache.druid.client.indexing;
import com.fasterxml.jackson.annotation.JsonCreator;
-import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.apache.druid.java.util.common.IAE;
-import org.apache.druid.query.SegmentDescriptor;
import org.joda.time.Interval;
import javax.annotation.Nullable;
-import java.util.List;
import java.util.Objects;
-import java.util.stream.Collectors;
/**
* InputSpec for {@link ClientCompactionIOConfig}.
* <p>
* Should be synchronized with
org.apache.druid.indexing.common.task.CompactionIntervalSpec and
org.apache.druid.indexing.common.task.UncompactedInputSpec.
*/
-public class ClientCompactionIntervalSpec
+public class ClientCompactionIntervalSpec implements ClientCompactionInputSpec
{
- private static final String TYPE_ALL_SEGMENTS = "interval";
- private static final String TYPE_UNCOMPACTED_SEGMENTS_ONLY = "uncompacted";
+ public static final String TYPE = "interval";
private final Interval interval;
@Nullable
- private final List<SegmentDescriptor> uncompactedSegments;
- @Nullable
private final String sha256OfSortedSegmentIds;
@JsonCreator
public ClientCompactionIntervalSpec(
@JsonProperty("interval") Interval interval,
- @JsonProperty("uncompactedSegments") @Nullable List<SegmentDescriptor>
uncompactedSegments,
@JsonProperty("sha256OfSortedSegmentIds") @Nullable String
sha256OfSortedSegmentIds
)
{
if (interval != null && interval.toDurationMillis() == 0) {
throw new IAE("Interval[%s] is empty, must specify a nonempty interval",
interval);
}
this.interval = interval;
- if (uncompactedSegments == null) {
- // perform a full compaction
- } else if (uncompactedSegments.isEmpty()) {
- throw new IAE("Can not supply empty segments as input, please use either
null or non-empty segments.");
- } else if (interval != null) {
- List<SegmentDescriptor> segmentsNotInInterval =
- uncompactedSegments.stream().filter(s ->
!interval.contains(s.getInterval())).collect(Collectors.toList());
- if (!segmentsNotInInterval.isEmpty()) {
- throw new IAE(
- "Can not supply segments outside interval[%s], got segments[%s].",
- interval,
- segmentsNotInInterval
- );
- }
- }
- this.uncompactedSegments = uncompactedSegments;
this.sha256OfSortedSegmentIds = sha256OfSortedSegmentIds;
}
@JsonProperty
public String getType()
Review Comment:
This is now going to conflict with the `type` field added by
`@JsonTypeInfo`. I think you can remove it.
##########
server/src/main/java/org/apache/druid/server/compaction/Eligibility.java:
##########
@@ -0,0 +1,121 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.druid.server.compaction;
+
+import org.apache.druid.error.DruidException;
+import org.apache.druid.java.util.common.StringUtils;
+
+import javax.annotation.Nullable;
+import java.util.Objects;
+
+/**
+ * Describes the eligibility of an interval for compaction.
+ */
+public class Eligibility
+{
+ /**
+ * Denotes that the candidate interval is eligible for a
+ * {@link CompactionMode#ALL_SEGMENTS full} compaction.
+ */
+ public static final Eligibility FULL = new Eligibility(true, null,
CompactionMode.ALL_SEGMENTS);
+
+ private final boolean eligible;
+ private final String reason;
+ @Nullable
+ private final CompactionMode mode;
+
+ private Eligibility(boolean eligible, String reason, @Nullable
CompactionMode mode)
+ {
+ this.eligible = eligible;
+ this.reason = reason;
+ this.mode = mode;
+ }
+
+ public boolean isEligible()
+ {
+ return eligible;
+ }
+
+ public String getReason()
+ {
+ return reason;
+ }
+
+ /**
+ * The mode of compaction (full or minor). This is non-null only when the
+ * candidate is considered to be eligible for compaction by the policy.
+ *
+ * @throws DruidException if {@link #isEligible()} returns false.
+ */
+ public CompactionMode getMode()
+ {
+ if (!isEligible()) {
+ throw DruidException.defensive("Cannot get mode since interval is not
eligible for compaction");
+ }
+ return mode;
+ }
+
+ /**
+ * Denotes that the candidate interval is not eligible for compaction.
+ */
+ public static Eligibility fail(String messageFormat, Object... args)
+ {
+ return new Eligibility(false, StringUtils.format(messageFormat, args),
null);
+ }
+
+ /**
+ * @return {@code Eligibility} denoting that the candidate interval is
+ * eligibile for a {@link CompactionMode#UNCOMPACTED_SEGMENTS_ONLY minor}
Review Comment:
eligible (spelling)
--
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.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]