Add feature to automatically remove supervisor based on retention period#11200
Add feature to automatically remove supervisor based on retention period#11200maytasm merged 7 commits intoapache:masterfrom
Conversation
| |`druid.coordinator.period.metadataStoreManagementPeriod`|How often to run metadata management tasks in [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) duration format. |No | `PT1H`| | ||
| |`druid.coordinator.kill.supervisor.on`| Boolean value for whether to enable automatic deletion of terminated supervisors. If set to true, Coordinator will periodically remove terminated supervisors from the supervisor table in metadata storage.| No | False| | ||
| |`druid.coordinator.kill.supervisor.period`| How often to do automatic deletion of terminated supervisor in [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) duration format. Value must be greater than `druid.coordinator.period.metadataStoreManagementPeriod`. Only applies if `druid.coordinator.kill.supervisor.on` is set to True.| No| `P1D`| | ||
| |`druid.coordinator.kill.supervisor.durationToRetain`| Duration of terminated supervisor to be retained from created time in [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) duration format. Only applies if `druid.coordinator.kill.supervisor.on` is set to True.| Yes if `druid.coordinator.kill.supervisor.on` is set to True| None| |
There was a problem hiding this comment.
The code has 1S for durationToRetain default: PT-1s
There was a problem hiding this comment.
The default in the code is used to fail cluster startup if the value is not set by the user. Basically code check for the value being positive (meaning that the user must set it and override the default value). For documentation simplicity sake, the default value in the code is the same effect as None and that the user must set the value.
| |--------|-----------|---------|-------| | ||
| |`druid.coordinator.period.metadataStoreManagementPeriod`|How often to run metadata management tasks in [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) duration format. |No | `PT1H`| | ||
| |`druid.coordinator.kill.supervisor.on`| Boolean value for whether to enable automatic deletion of terminated supervisors. If set to true, Coordinator will periodically remove terminated supervisors from the supervisor table in metadata storage.| No | False| | ||
| |`druid.coordinator.kill.supervisor.period`| How often to do automatic deletion of terminated supervisor in [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) duration format. Value must be greater than `druid.coordinator.period.metadataStoreManagementPeriod`. Only applies if `druid.coordinator.kill.supervisor.on` is set to True.| No| `P1D`| |
There was a problem hiding this comment.
| |`druid.coordinator.kill.supervisor.period`| How often to do automatic deletion of terminated supervisor in [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) duration format. Value must be greater than `druid.coordinator.period.metadataStoreManagementPeriod`. Only applies if `druid.coordinator.kill.supervisor.on` is set to True.| No| `P1D`| | |
| |`druid.coordinator.kill.supervisor.period`| How often to do automatic deletion of terminated supervisor in [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) duration format. Value must be equal to or greater than `druid.coordinator.period.metadataStoreManagementPeriod`. Only applies if `druid.coordinator.kill.supervisor.on` is set to "True".| No| `P1D`| |
| |`druid.coordinator.period.metadataStoreManagementPeriod`|How often to run metadata management tasks in [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) duration format. |No | `PT1H`| | ||
| |`druid.coordinator.kill.supervisor.on`| Boolean value for whether to enable automatic deletion of terminated supervisors. If set to true, Coordinator will periodically remove terminated supervisors from the supervisor table in metadata storage.| No | False| | ||
| |`druid.coordinator.kill.supervisor.period`| How often to do automatic deletion of terminated supervisor in [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) duration format. Value must be greater than `druid.coordinator.period.metadataStoreManagementPeriod`. Only applies if `druid.coordinator.kill.supervisor.on` is set to True.| No| `P1D`| | ||
| |`druid.coordinator.kill.supervisor.durationToRetain`| Duration of terminated supervisor to be retained from created time in [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) duration format. Only applies if `druid.coordinator.kill.supervisor.on` is set to True.| Yes if `druid.coordinator.kill.supervisor.on` is set to True| None| |
There was a problem hiding this comment.
| |`druid.coordinator.kill.supervisor.durationToRetain`| Duration of terminated supervisor to be retained from created time in [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) duration format. Only applies if `druid.coordinator.kill.supervisor.on` is set to True.| Yes if `druid.coordinator.kill.supervisor.on` is set to True| None| | |
| |`druid.coordinator.kill.supervisor.durationToRetain`| Duration of terminated supervisor to be retained from created time in [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) duration format. Only applies if `druid.coordinator.kill.supervisor.on` is set to "True".| Yes if `druid.coordinator.kill.supervisor.on` is set to "True"| None| |
| |`interval/skipCompact/count`|Total number of intervals of this datasource that are skipped (not eligible for auto compaction) by the auto compaction.|datasource.|Varies.| | ||
| |`coordinator/time`|Approximate Coordinator duty runtime in milliseconds. The duty dimension is the string alias of the Duty that is being run.|duty.|Varies.| | ||
| |`coordinator/global/time`|Approximate runtime of a full coordination cycle in milliseconds. The `dutyGroup` dimension indicates what type of coordination this run was. i.e. Historical Management vs Indexing|`dutyGroup`|Varies.| | ||
| |`metadata/kill/supervisor/count`|Total number of terminated supervisors automatically deleted from metadata store supervisor table per each Coordinator kill supervisor duty run. This metric can help adjust `druid.coordinator.kill.supervisor.durationToRetain` configuration based on if more or less terminated supervisors need to be deleted per cycle. Note that this metric is only emitted when `druid.coordinator.kill.supervisor.on` is set to true.| |Varies.| |
There was a problem hiding this comment.
| |`metadata/kill/supervisor/count`|Total number of terminated supervisors automatically deleted from metadata store supervisor table per each Coordinator kill supervisor duty run. This metric can help adjust `druid.coordinator.kill.supervisor.durationToRetain` configuration based on if more or less terminated supervisors need to be deleted per cycle. Note that this metric is only emitted when `druid.coordinator.kill.supervisor.on` is set to true.| |Varies.| | |
| |`metadata/kill/supervisor/count`|Total number of terminated supervisors that were automatically deleted from metadata store per each Coordinator kill supervisor duty run. This metric can help adjust `druid.coordinator.kill.supervisor.durationToRetain` configuration based on whether more or less terminated supervisors need to be deleted per cycle. Note that this metric is only emitted when `druid.coordinator.kill.supervisor.on` is set to true.| |Varies.| |
| Map<String, SupervisorSpec> getLatest(); | ||
|
|
||
| /** | ||
| * Remove terminated supervisor created older than the given timestamp. |
There was a problem hiding this comment.
| * Remove terminated supervisor created older than the given timestamp. | |
| * Remove terminated supervisors created before the given timestamp. |
| Map<String, SupervisorSpec> supervisors = getLatest(); | ||
| for (Map.Entry<String, SupervisorSpec> supervisor : supervisors.entrySet()) { | ||
| final SupervisorSpec spec = supervisor.getValue(); | ||
| if (spec instanceof NoopSupervisorSpec) { |
There was a problem hiding this comment.
does this mean that it is a terminated supervisor? can you add a comment clarifying this bit
There was a problem hiding this comment.
Yep. Terminated supervisor will have it's latest supervisorSpec as NoopSupervisorSpec. (Basically NoopSupervisorSpec is used as a tombstone indicator)
| handle -> { | ||
| Update sql = handle.createStatement( | ||
| StringUtils.format( | ||
| "DELETE FROM %1$s WHERE spec_id = :spec_id AND created_date < :date_time", |
There was a problem hiding this comment.
does it make sense to delete in batch than doing one by one which will be slow?
| import org.apache.druid.server.coordinator.DruidCoordinatorConfig; | ||
| import org.apache.druid.server.coordinator.DruidCoordinatorRuntimeParams; | ||
|
|
||
| public class KillSupervisors implements CoordinatorDuty |
abhishekagarwal87
left a comment
There was a problem hiding this comment.
LGTM @maytasm. Does this PR need a "release notes" label?
Add feature to automatically remove supervisors based on retention period
Description
We currently already have tasklog auto cleanup (#3677) and audit logs auto cleanup (#11084). This PR adds a similar auto cleanup based on duration (time to retained) but for the supervisor table to auto clean up terminated supervisors
This is useful when Druid user has a high churn of task / datasource in a short amount of time causing the metadata store size to grow uncontrollably.
This PR has: