capistrant opened a new pull request, #12599:
URL: https://github.com/apache/druid/pull/12599

   <!-- Thanks for trying to help us make Apache Druid be the best it can be! 
Please fill out as much of the following information as is possible (where 
relevant, and remove it when irrelevant) to help make the intention and scope 
of this PR clear in order to ease review. -->
   
   <!-- Please read the doc for contribution 
(https://github.com/apache/druid/blob/master/CONTRIBUTING.md) before making 
this PR. Also, once you open a PR, please _avoid using force pushes and 
rebasing_ since these make it difficult for reviewers to see what you've 
changed in response to their reviews. See [the 'If your pull request shows 
conflicts with master' 
section](https://github.com/apache/druid/blob/master/CONTRIBUTING.md#if-your-pull-request-shows-conflicts-with-master)
 for more details. -->
   
   This PR addresses part of the proposal in #12526 
   
   <!-- Replace XXXX with the id of the issue fixed in this PR. Remove this 
section if there is no corresponding issue. Don't reference the issue in the 
title of this pull-request. -->
   
   <!-- If you are a committer, follow the PR action item checklist for 
committers:
   
https://github.com/apache/druid/blob/master/dev/committer-instructions.md#pr-and-issue-action-item-checklist-for-committers.
 -->
   
   ### Description
   
   <!-- Describe the goal of this PR, what problem are you fixing. If there is 
a corresponding issue (referenced above), it's not necessary to repeat the 
description here, however, you may choose to keep one summary sentence. -->
   
   <!-- Describe your patch: what did you change in code? How did you fix the 
problem? -->
   
   <!-- If there are several relatively logically separate changes in this PR, 
create a mini-section for each of them. For example: -->
   
   #### Made an incompatible change to druid_segments table
   
   Added a new column, `last_used VARCHAR(255)` to the druid_segments table. 
When creating the druid_segments table from scratch, this column is not 
nullable. However, to more easily facilitate an upgrade to a version of Druid 
with this code, the migration steps to ALTER druid_segments allow the column to 
have null values. Perhaps we can document an optional post upgrade step to 
ALTER the table to not allow nulls that is contingent upon completing the 
existing optional post-upgrade step to populate last_used for already unused 
rows.
   
   This column is a UTC date string corresponding to the last time that the 
`used` column was modified.
   
   #### Added a configuration to the `druid.coordinator.kill.` family, 
`druid.coordinator.kill.bufferPeriod`
   
   `druid.coordinator.kill.bufferPeriod` is a Duration that defines the amount 
of time that a segment must have been unused for before KillUnusedSegments will 
potentially kill it. For example, with the default `PT24H`. If I mark a segment 
X unused at `2022-06-01T00:05:00.000Z`. By rule, this segment cannot be killed 
until at or after `2022-06-02T00:05:00.000Z`.
   
   The most prominent use of this new configuration is to prevent deletion of 
data from Druid by mistake. It can be thought of like the trash folder in HDFS. 
Marking segments unused is the `rm`. Without trash, the data is just gone. With 
trash, we can recover. The period is the amount of time before pending trash 
sent away for good.
   
   <!--
   In each section, please describe design decisions made, including:
    - Choice of algorithms
    - Behavioral aspects. What configuration values are acceptable? How are 
corner cases and error conditions handled, such as when there are insufficient 
resources?
    - Class organization and design (how the logic is split between classes, 
inheritance, composition, design patterns)
    - Method organization and design (how the logic is split between methods, 
parameters and return types)
    - Naming (class, method, API, configuration, HTTP endpoint, names of 
emitted metrics)
   -->
   
   
   <!-- It's good to describe an alternative design (or mention an alternative 
name) for every design (or naming) decision point and compare the alternatives 
with the designs that you've implemented (or the names you've chosen) to 
highlight the advantages of the chosen designs and names. -->
   
   #### Alternative Design
   
   Alternatively, I could have embedded last_used within the payload. The 
functionality at the end of the day would be the same, but I have listed some 
pros and cons below.
   
   Pros
   * No table schema change needed to upgrade Druid, making life easier for an 
operator.
   
   Cons
   * If you were adding this feature in the initial pre-release development of 
Druid, you'd probably steer away from accumulating too much in the payload 
column and instead create native columns in the database table
     * embedding it in this column is almost hiding it. Or at least making it 
harder for others to discover and understand. 
   * You need to pull the payload back in the query for unused segments. 
Increased db I/O, network, druid memory and compute demands
   * You need to process the payloads in Druid code instead of simply filtering 
on the column value if it were native to the metastore table
   
   #### Upgrade Plan
   
   Requiring a database table alteration is a breaking change. It introduces an 
extra requirement for an operator to upgrade from an older version of Druid. I 
have done my best to limit the complexity of upgrading and provide as much 
assistance as possible to the Druid operators out there.
   
   ##### No work necessary case
   
   There is a case where there is no extra work necessary for the Druid 
operator to upgrade. If the operator has used the default of `true` for 
`druid.metadata.storage.connector.createTables`, and their metastore user has 
DDL privs, the table will automatically be altered at startup if the 
`last_used` column is missing from the druid_segments table.
   
   The coordinator and overlord will startup just fine. And all future changes 
to the used column (plus new segment creation) will populate `last_used`. For 
existing segments who match `used = true`, the value of `last_used` will be 
`null`. I have coded up the logic for finding segments to kill in a way that 
ignores the bufferPeriod for these segments with `null` column values. This 
means that `KillUnusedSegments` will use the same logic as pre-upgrade when 
looking for killable segments in the metadata store.
   
   ##### Some work necessary case
   
   If the operator has either:
   * set `druid.metadata.storage.connector.createTables` to false
   * not given their metastore user DDL privs
   
   They will need to execute an ALTER statement themselves before the upgrade. 
To make things easy for them, I have created a new Druid cli tool called 
UpdateTables that can perform this for them by executing the same alter table 
code path as the no work necessary case described above. This tool, as well as 
the actual ALTER command - in case the operator wants to do it themselves - is 
documented in a new upgrade-prep.md resource.
   
   ##### Optional post upgrade action
   
   If the operator is interested in populating all of their legacy unused 
segments with a last_used date string following the upgrade, I have included 
another action in the new UpdateTables cli tool that will do so. Again, I have 
documented the tool and provided the actual UPDATE statement that they could 
use manually. This step is completely optional and only needed if the operator 
desires that their legacy unused segments come under the purview of the new 
bufferPeriod config post-upgrade.
   
   <!-- If there was a discussion of the design of the feature implemented in 
this PR elsewhere (e. g. a "Proposal" issue, any other issue, or a thread in 
the development mailing list), link to that discussion from this PR description 
and explain what have changed in your final design compared to your original 
proposal or the consensus version in the end of the discussion. If something 
hasn't changed since the original discussion, you can omit a detailed 
discussion of those aspects of the design here, perhaps apart from brief 
mentioning for the sake of readability of this PR description. -->
   
   <!-- Some of the aspects mentioned above may be omitted for simple and small 
changes. -->
   
   <hr>
   
   ##### Key changed/added classes in this PR
    * MetadataStorageConnector - added 2 methods to interface
    * IndexerSQLMetadataStorageCoordinator - create new segments with last_used 
column populated
    * SQLMetadataConnector - code for altering and validating the 
druid_segments table
    * SQLMetadataSegmentPublisher - publish segments with last_used column 
populated
    * SegmentsMetadataManager - update signature of interface method
    * SqlSegmentsMetadataManager - manage and use last_used column properly
    * SqlSegmentsMetadataQuery.java - manage last_used properly
    * DruidCoordinatorConfig - new config
    * Main - new cli tool
    * UpdateTables - new cli tool
   <hr>
   
   <!-- Check the items by putting "x" in the brackets for the done things. Not 
all of these items apply to every PR. Remove the items which are not done or 
not relevant to the PR. None of the items from the checklist below are strictly 
necessary, but it would be very helpful if you at least self-review the PR. -->
   
   This PR has:
   - [ ] been self-reviewed.
   - [ ] added documentation for new or modified features or behaviors.
   - [ ] added Javadocs for most classes and all non-trivial methods. Linked 
related entities via Javadoc links.
   - [ ] added or updated version, license, or notice information in 
[licenses.yaml](https://github.com/apache/druid/blob/master/dev/license.md)
   - [ ] added comments explaining the "why" and the intent of the code 
wherever would not be obvious for an unfamiliar reader.
   - [ ] added unit tests or modified existing tests to cover new code paths, 
ensuring the threshold for [code 
coverage](https://github.com/apache/druid/blob/master/dev/code-review/code-coverage.md)
 is met.
   - [ ] added integration tests.
   - [ ] been tested in a test Druid cluster.
   


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

To unsubscribe, e-mail: [email protected]

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