kfaraz commented on code in PR #16799:
URL: https://github.com/apache/druid/pull/16799#discussion_r1694580881


##########
server/src/main/java/org/apache/druid/rpc/indexing/OverlordClient.java:
##########
@@ -180,15 +181,13 @@ ListenableFuture<CloseableIterator<TaskStatusPlus>> 
taskStatuses(
   ListenableFuture<CloseableIterator<SupervisorStatus>> supervisorStatuses();
 
   /**
-   * Returns a list of intervals locked by higher priority conflicting lock 
types
+   * Returns a list of Locks of higher priority with conflicting intervals

Review Comment:
   ```suggestion
      * Returns a list of locks of higher priority with conflicting intervals
   ```



##########
indexing-service/src/main/java/org/apache/druid/indexing/overlord/TaskQueryTool.java:
##########
@@ -85,28 +86,12 @@ public TaskQueryTool(
   }
 
   /**
-   * @param lockFilterPolicies Requests for conflicing lock intervals for 
various datasources
-   * @return Map from datasource to intervals locked by tasks that have a 
conflicting lock type that cannot be revoked
+   * @param lockFilterPolicies Requests for conflicing locks for various 
datasources
+   * @return Map from datasource to conflicting lock infos
    */
-  public Map<String, List<Interval>> getLockedIntervals(List<LockFilterPolicy> 
lockFilterPolicies)
+  public Map<String, List<TaskLockInfo>> 
getConflictingLockInfos(List<LockFilterPolicy> lockFilterPolicies)

Review Comment:
   Rename all the methods named `getConflictingLockInfos()` to 
`getActiveTaskLocks()`.
   These APIs are just returning active locks which satisfy certain conditions.
   
   The fact whether they conflict with something else or not is the caller's 
concern. 



##########
indexing-service/src/main/java/org/apache/druid/indexing/overlord/http/OverlordResource.java:
##########
@@ -241,33 +242,18 @@ public Response isLeader()
     }
   }
 
-  @Deprecated
-  @POST
-  @Path("/lockedIntervals")
-  @Produces(MediaType.APPLICATION_JSON)
-  @ResourceFilters(StateResourceFilter.class)
-  public Response getDatasourceLockedIntervals(Map<String, Integer> 
minTaskPriority)
-  {
-    if (minTaskPriority == null || minTaskPriority.isEmpty()) {
-      return Response.status(Status.BAD_REQUEST).entity("No Datasource 
provided").build();
-    }
-
-    // Build the response
-    return 
Response.ok(taskQueryTool.getLockedIntervals(minTaskPriority)).build();
-  }
-
   @POST
-  @Path("/lockedIntervals/v2")
+  @Path("/conflictingLocks")

Review Comment:
   Call the new API `/activeLocks`.



##########
indexing-service/src/main/java/org/apache/druid/indexing/overlord/http/OverlordResource.java:
##########
@@ -241,33 +242,18 @@ public Response isLeader()
     }
   }
 
-  @Deprecated
-  @POST
-  @Path("/lockedIntervals")
-  @Produces(MediaType.APPLICATION_JSON)
-  @ResourceFilters(StateResourceFilter.class)
-  public Response getDatasourceLockedIntervals(Map<String, Integer> 
minTaskPriority)
-  {
-    if (minTaskPriority == null || minTaskPriority.isEmpty()) {
-      return Response.status(Status.BAD_REQUEST).entity("No Datasource 
provided").build();
-    }
-
-    // Build the response
-    return 
Response.ok(taskQueryTool.getLockedIntervals(minTaskPriority)).build();
-  }
-
   @POST
-  @Path("/lockedIntervals/v2")

Review Comment:
   Let's retain this API as it is not deprecated yet. We can mark it deprecated 
as a part of the changes in this PR.



##########
indexing-service/src/main/java/org/apache/druid/indexing/common/TaskLock.java:
##########
@@ -77,4 +78,9 @@ default void assertNotRevoked()
           .build("Lock of type[%s] for interval[%s] was revoked", getType(), 
getInterval());
     }
   }
+
+  default TaskLockInfo toTaskLockInfo()

Review Comment:
   Let's keep the `TaskLock` interface clean.
   
   You can add a static utility method in `TaskLockInfo` class instead. 
Something like `TaskLockInfo.of(TaskLock lock)`.



##########
server/src/main/java/org/apache/druid/metadata/TaskLockInfo.java:
##########
@@ -0,0 +1,108 @@
+/*
+ * 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.metadata;
+
+import com.fasterxml.jackson.annotation.JsonCreator;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import org.joda.time.Interval;
+
+import java.util.Objects;
+
+/**
+ * Contains information about an active task lock for a given datasource

Review Comment:
   If it is always meant to be for an active lock, should we call this class 
`ActiveTaskLockInfo` or maybe just `ActiveTaskLock`?



##########
server/src/main/java/org/apache/druid/metadata/TaskLockInfo.java:
##########
@@ -0,0 +1,108 @@
+/*
+ * 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.metadata;
+
+import com.fasterxml.jackson.annotation.JsonCreator;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import org.joda.time.Interval;
+
+import java.util.Objects;
+
+/**
+ * Contains information about an active task lock for a given datasource
+ */
+public class TaskLockInfo
+{
+  private final String granularity;
+  private final String type;
+  private final int priority;
+  private final Interval interval;
+
+  @JsonCreator
+  public TaskLockInfo(
+      @JsonProperty("granularity") String granularity,
+      @JsonProperty("type") String type,

Review Comment:
   Why are these two fields strings instead of the actual type?



##########
server/src/main/java/org/apache/druid/rpc/indexing/OverlordClient.java:
##########
@@ -180,15 +181,13 @@ ListenableFuture<CloseableIterator<TaskStatusPlus>> 
taskStatuses(
   ListenableFuture<CloseableIterator<SupervisorStatus>> supervisorStatuses();
 
   /**
-   * Returns a list of intervals locked by higher priority conflicting lock 
types
+   * Returns a list of Locks of higher priority with conflicting intervals
    *
    * @param lockFilterPolicies List of all filters for different datasources
-   * @return Map from datasource name to list of intervals locked by tasks 
that have a conflicting lock type with
+   * @return Map from datasource name to list of locks held by tasks that have 
conflicting intervals with
    * priority greater than or equal to the {@code minTaskPriority} for that 
datasource.
    */
-  ListenableFuture<Map<String, List<Interval>>> findLockedIntervals(
-      List<LockFilterPolicy> lockFilterPolicies
-  );
+  ListenableFuture<Map<String, List<TaskLockInfo>>> 
findConflictingLockInfos(List<LockFilterPolicy> lockFilterPolicies);

Review Comment:
   ```suggestion
     ListenableFuture<Map<String, List<TaskLockInfo>>> 
findConflictingLocks(List<LockFilterPolicy> lockFilterPolicies);
   ```



##########
server/src/main/java/org/apache/druid/server/http/TaskLockResponse.java:
##########
@@ -0,0 +1,74 @@
+/*
+ * 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.http;
+
+import com.fasterxml.jackson.annotation.JsonCreator;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import org.apache.druid.metadata.TaskLockInfo;
+
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+
+public class TaskLockResponse
+{
+  private final Map<String, List<TaskLockInfo>> taskLocks;
+
+  @JsonCreator
+  public TaskLockResponse(
+      @JsonProperty("taskLocks") final Map<String, List<TaskLockInfo>> 
taskLocks
+  )
+  {
+    this.taskLocks = taskLocks;
+  }
+
+  @JsonProperty
+  public Map<String, List<TaskLockInfo>> getTaskLocks()

Review Comment:
   Nit: either call it `datasourceToTaskLocks` (or similar) or add a javadoc.



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

Reply via email to