jon-wei commented on a change in pull request #7547: Add support minor 
compaction with segment locking
URL: https://github.com/apache/incubator-druid/pull/7547#discussion_r297910522
 
 

 ##########
 File path: 
indexing-service/src/main/java/org/apache/druid/indexing/common/SegmentLock.java
 ##########
 @@ -0,0 +1,237 @@
+/*
+ * 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.indexing.common;
+
+import com.fasterxml.jackson.annotation.JsonCreator;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.google.common.base.Preconditions;
+import org.apache.druid.indexing.overlord.LockRequest;
+import org.apache.druid.indexing.overlord.LockRequestForNewSegment;
+import org.apache.druid.indexing.overlord.SpecificSegmentLockRequest;
+import org.apache.druid.indexing.overlord.TimeChunkLockRequest;
+import org.apache.druid.java.util.common.ISE;
+import org.joda.time.Interval;
+
+import java.util.Objects;
+
+/**
+ * Lock for set of segments. Should be unique for (dataSource, interval, 
version, partitionId).
+ */
+public class SegmentLock implements TaskLock
+{
+  static final String TYPE = "segment";
+
+  private final TaskLockType lockType;
+  private final String groupId;
+  private final String dataSource;
+  private final Interval interval;
+  private final String version;
+  private final int partitionId;
+  private final int priority;
+  private final boolean revoked;
+
+  @JsonCreator
+  public SegmentLock(
+      @JsonProperty("lockType") TaskLockType lockType,
+      @JsonProperty("groupId") String groupId,
+      @JsonProperty("dataSource") String dataSource,
+      @JsonProperty("interval") Interval interval,
+      @JsonProperty("version") String version,
+      @JsonProperty("partitionId") int partitionId,
+      @JsonProperty("priority") int priority,
+      @JsonProperty("revoked") boolean revoked
+  )
+  {
+    this.lockType = Preconditions.checkNotNull(lockType, "lockType");
+    this.groupId = Preconditions.checkNotNull(groupId, "groupId");
+    this.dataSource = Preconditions.checkNotNull(dataSource, "dataSource");
+    this.interval = Preconditions.checkNotNull(interval, "interval");
+    this.version = Preconditions.checkNotNull(version, "version");
+    this.partitionId = partitionId;
+    this.priority = priority;
+    this.revoked = revoked;
+  }
+
+  public SegmentLock(
+      TaskLockType lockType,
+      String groupId,
+      String dataSource,
+      Interval interval,
+      String version,
+      int partitionId,
+      int priority
+  )
+  {
+    this(lockType, groupId, dataSource, interval, version, partitionId, 
priority, false);
+  }
+
+  @JsonProperty
+  @Override
+  public String getType()
+  {
+    return TYPE;
+  }
+
+  @Override
+  public TaskLock revokedCopy()
+  {
+    return new SegmentLock(lockType, groupId, dataSource, interval, version, 
partitionId, priority, true);
+  }
+
+  @Override
+  public TaskLock withPriority(int newPriority)
+  {
+    return new SegmentLock(lockType, groupId, dataSource, interval, version, 
partitionId, newPriority, revoked);
+  }
+
+  @Override
+  public LockGranularity getGranularity()
+  {
+    return LockGranularity.SEGMENT;
+  }
+
+  @JsonProperty
+  @Override
+  public TaskLockType getLockType()
+  {
+    return lockType;
+  }
+
+  @JsonProperty
+  @Override
+  public String getGroupId()
+  {
+    return groupId;
+  }
+
+  @JsonProperty
+  @Override
+  public String getDataSource()
+  {
+    return dataSource;
+  }
+
+  @JsonProperty
+  @Override
+  public Interval getInterval()
+  {
+    return interval;
+  }
+
+  @JsonProperty
+  public int getPartitionId()
+  {
+    return partitionId;
+  }
+
+  @JsonProperty
+  @Override
+  public String getVersion()
+  {
+    return version;
+  }
+
+  @JsonProperty
+  @Override
+  public Integer getPriority()
+  {
+    return priority;
+  }
+
+  @Override
+  public int getNonNullPriority()
+  {
+    return priority;
+  }
+
+  @JsonProperty
+  @Override
+  public boolean isRevoked()
+  {
+    return revoked;
+  }
+
+  @Override
+  public boolean conflict(LockRequest request)
+  {
+    if (request instanceof TimeChunkLockRequest) {
 
 Review comment:
   I think this method would be more readable if it checked for `instanceof 
LockRequestForNewSegment` first and then 
`!dataSource.equals(request.getDataSource()` as separate checks that return 
`false` (i.e., the cases that will never conflict), before going to the 
`TimeChunkLockRequest` and `SpecificSegmentLockRequest` blocks
   

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


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to