suneet-s commented on a change in pull request #11227: URL: https://github.com/apache/druid/pull/11227#discussion_r629564966
########## File path: server/src/main/java/org/apache/druid/metadata/IndexerSQLMetadataStorageCoordinator.java ########## @@ -1423,4 +1424,40 @@ public boolean insertDataSourceMetadata(String dataSource, DataSourceMetadata me .execute() ); } + + @Override + public int removeDataSourceMetadataOlderThan(long timestamp, @Nullable Set<String> excludeDatasources) + { + DateTime dateTime = DateTimes.utc(timestamp); + List<String> datasources = connector.getDBI().withHandle( + handle -> handle + .createQuery( + StringUtils.format( + "SELECT dataSource FROM %1$s WHERE created_date < '%2$s'", + dbTables.getDataSourceTable(), + dateTime.toString() + ) + ) + .mapTo(String.class) + .list() + ); + return connector.getDBI().withHandle( + handle -> { + final PreparedBatch batch = handle.prepareBatch( + StringUtils.format( + "DELETE FROM %1$s WHERE dataSource = :dataSource AND created_date < '%2$s'", + dbTables.getDataSourceTable(), + dateTime.toString() + ) + ); + for (String datasourceMetadataInDb : datasources) { + if (!excludeDatasources.contains(datasourceMetadataInDb)) { Review comment: possible NPE - `excludeDatasources` is marked as nullable in the function definition -- 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: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@druid.apache.org For additional commands, e-mail: commits-h...@druid.apache.org