maytasm commented on a change in pull request #11164:
URL: https://github.com/apache/druid/pull/11164#discussion_r622703819



##########
File path: 
server/src/main/java/org/apache/druid/metadata/SQLMetadataRuleManager.java
##########
@@ -421,8 +422,35 @@ public Void inTransaction(Handle handle, TransactionStatus 
transactionStatus) th
     return true;
   }
 
+  @Override
+  public int removeRulesOlderThan(long timestamp)
+  {
+    DateTime dateTime = DateTimes.utc(timestamp);
+    synchronized (lock) {
+      return dbi.withHandle(
+          handle -> {
+            Update sql = handle.createStatement(
+                StringUtils.format(
+                    "DELETE FROM %1$s WHERE datasource NOT IN (SELECT DISTINCT 
datasource from %2$s) and datasource!=:default_rule and version < :date_time",

Review comment:
       Regarding the query `"DELETE FROM %1$s WHERE datasource NOT IN (SELECT 
DISTINCT datasource from %2$s) and datasource!=:default_rule and version < 
:date_time"`, I think since it’s run very infrequent (by default once a day) 
and the inner query on segment table is a READ (no locking), it should be ok. 
Also, adding an index on datasource column in the segment table (for the 
alternative approach suggested) puts additional overhead on the database 
operation which is probably not worth it for a query that is run once a day.




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