surekhasaharan commented on a change in pull request #7490: Add reload by 
interval API
URL: https://github.com/apache/incubator-druid/pull/7490#discussion_r276856491
 
 

 ##########
 File path: 
server/src/main/java/org/apache/druid/server/http/DataSourcesResource.java
 ##########
 @@ -700,4 +704,85 @@ static boolean 
isSegmentLoaded(Iterable<ImmutableSegmentLoadInfo> serverView, Se
     }
     return false;
   }
+
+  @PUT
+  @Path("/{dataSourceName}/markUsed")
+  @Produces(MediaType.APPLICATION_JSON)
+  @ResourceFilters(DatasourceResourceFilter.class)
+  public Response enableDatasourceSegments(
+      @PathParam("dataSourceName") String dataSourceName,
+      MarkDatasourceSegmentsPayload payload
+  )
+  {
+    if (payload == null || !payload.isValid()) {
+      return Response.status(Response.Status.BAD_REQUEST).entity(
+          ImmutableMap.of(
+              "error",
+              "Either interval or segments can be specified"
+          )
+      ).build();
+    }
+
+    final ImmutableDruidDataSource dataSource = getDataSource(dataSourceName);
+    if (dataSource == null) {
+      return Response.noContent().build();
+    }
+
+    boolean success;
+    try {
+      if (payload.getInterval() != null) {
+        success = databaseSegmentManager.enableSegments(dataSource.getName(), 
payload.getInterval());
+      } else {
+        success = databaseSegmentManager.enableSegments(dataSource.getName(), 
payload.getSegmentIds());
+      }
+    }
+    catch (Exception e) {
+      return Response.serverError().entity(
+          ImmutableMap.of(
+              "error",
+              "Exception occurred.",
+              "message",
+              e.toString()
+          )
+      ).build();
+    }
+
+    if (!success) {
+      return Response.noContent().build();
+    }
+
+    return Response.ok().build();
+  }
+
+  @VisibleForTesting
+  protected static class MarkDatasourceSegmentsPayload
+  {
+    private final Interval interval;
+    private final Set<String> segmentIds;
+
+    @JsonCreator
+    public MarkDatasourceSegmentsPayload(
+        @JsonProperty("interval") Interval interval,
+        @JsonProperty("segments") Set<String> segmentIds
+    )
+    {
+      this.interval = interval;
+      this.segmentIds = segmentIds;
+    }
+
+    public Interval getInterval()
+    {
+      return interval;
+    }
+
+    public Set<String> getSegmentIds()
+    {
+      return segmentIds;
+    }
+
+    public boolean isValid()
+    {
+      return interval == null ^ segmentIds == null;
 
 Review comment:
   Nice trick !

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