suneet-s commented on a change in pull request #11227:
URL: https://github.com/apache/druid/pull/11227#discussion_r629576496



##########
File path: 
server/src/main/java/org/apache/druid/server/coordinator/duty/KillDatasourceMetadata.java
##########
@@ -0,0 +1,110 @@
+/*
+ * 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.coordinator.duty;
+
+import com.google.common.base.Preconditions;
+import com.google.common.base.Strings;
+import com.google.inject.Inject;
+import org.apache.druid.indexing.overlord.IndexerMetadataStorageCoordinator;
+import org.apache.druid.indexing.overlord.supervisor.NoopSupervisorSpec;
+import org.apache.druid.indexing.overlord.supervisor.SupervisorSpec;
+import org.apache.druid.java.util.common.logger.Logger;
+import org.apache.druid.java.util.emitter.service.ServiceEmitter;
+import org.apache.druid.java.util.emitter.service.ServiceMetricEvent;
+import org.apache.druid.metadata.MetadataSupervisorManager;
+import org.apache.druid.server.coordinator.DruidCoordinatorConfig;
+import org.apache.druid.server.coordinator.DruidCoordinatorRuntimeParams;
+
+import java.util.Collection;
+import java.util.Map;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+/**
+ * CoordinatorDuty for automatic deletion of datasource metadata from the 
datasource table in metadata storage.
+ * (Note: datasource metadata only exists for datasource created from 
supervisor).
+ */
+public class KillDatasourceMetadata implements CoordinatorDuty
+{
+  private static final Logger log = new Logger(KillDatasourceMetadata.class);
+
+  private final long period;
+  private final long retainDuration;
+  private long lastKillTime = 0;
+
+  private final IndexerMetadataStorageCoordinator 
indexerMetadataStorageCoordinator;
+  private final MetadataSupervisorManager metadataSupervisorManager;
+
+  @Inject
+  public KillDatasourceMetadata(
+      DruidCoordinatorConfig config,
+      IndexerMetadataStorageCoordinator indexerMetadataStorageCoordinator,
+      MetadataSupervisorManager metadataSupervisorManager
+  )
+  {
+    this.indexerMetadataStorageCoordinator = indexerMetadataStorageCoordinator;
+    this.metadataSupervisorManager = metadataSupervisorManager;
+    this.period = config.getCoordinatorDatasourceKillPeriod().getMillis();
+    Preconditions.checkArgument(
+        this.period >= 
config.getCoordinatorMetadataStoreManagementPeriod().getMillis(),
+        "Coordinator datasource metadata kill period must be >= 
druid.coordinator.period.metadataStoreManagementPeriod"
+    );
+    this.retainDuration = 
config.getCoordinatorDatasourceKillDurationToRetain().getMillis();
+    Preconditions.checkArgument(this.retainDuration >= 0, "Coordinator 
datasource metadata kill retainDuration must be >= 0");
+    log.debug(
+        "Datasource Metadata Kill Task scheduling enabled with period [%s], 
retainDuration [%s]",
+        this.period,
+        this.retainDuration
+    );
+  }
+
+  @Override
+  public DruidCoordinatorRuntimeParams run(DruidCoordinatorRuntimeParams 
params)
+  {
+    if ((lastKillTime + period) < System.currentTimeMillis()) {
+      lastKillTime = System.currentTimeMillis();
+      long timestamp = System.currentTimeMillis() - retainDuration;

Review comment:
       Additional question - I notice this pattern in a few other co-ordinator 
duties.
   
   Are there any additional safeguards we need for a very large 
`retainDuration`? What happens if `timestamp` is calculated to be negative?




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



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

Reply via email to