Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fix][Tiered Storage] Eagerly Delete Offloaded Segments On Topic Deletion #15914

Merged
merged 2 commits into from
Sep 29, 2022

Conversation

dlg99
Copy link
Contributor

@dlg99 dlg99 commented Jun 2, 2022

Fixes #9962

Motivation

Offloaded ledgers can be orphaned on topic deletion.

Modifications

Topic to be truncated before deletion to delete offloaded ledgers properly and fail if truncation fails.

Verifying this change

  • Make sure that the change passes the CI checks.

This change added integration tests

Does this pull request potentially affect one of the following parts:

If yes was chosen, please highlight the changes

Nothing changed in the options but admin CLI will implicitly run truncate before topic delete.

  • Dependencies (does it add or upgrade a dependency): (yes / no)
  • The public API: (yes / no)
  • The schema: (yes / no / don't know)
  • The default values of configurations: (yes / no)
  • The wire protocol: (yes / no)
  • The rest endpoints: (yes / no)
  • The admin cli options: (yes / no)
  • Anything that affects deployment: (yes / no / don't know)

Documentation

Check the box below or label this PR directly.

Need to update docs?

  • doc-required
    (Your PR needs to update docs and you will update later)

  • doc-not-needed
    (Please explain why)

  • doc
    (Your PR contains doc changes)

  • doc-complete
    (Docs have been already added)

@github-actions github-actions bot added the doc-not-needed Your PR changes do not impact docs label Jun 2, 2022
Copy link
Contributor

@eolivelli eolivelli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lgtm.
Great

@hangc0276

@hangc0276
Copy link
Contributor

Even though we should delete the offload data on topic deletion, it has changed the default behavior. We'd better have a proposal to discuss it.

Another one is that it can't prevent orphan ledgers because they offloaded data deletion is async.

@hangc0276
Copy link
Contributor

hangc0276 commented Jun 6, 2022

We need more eyes. @merlimat @codelipenghui @315157973 @Jason918 @zymap @horizonzy

@dlg99
Copy link
Contributor Author

dlg99 commented Jun 6, 2022

@hangc0276

Even though we should delete the offload data on topic deletion, it has changed the default behavior. We'd better have a proposal to discuss it.

I disagree that undocumented silently orphaned data (without tools/automated processes to detect it and clean up) is a "default behavior" one ever expected or wanted. It looks like a bug that just happened.

Another one is that it can't prevent orphan ledgers because they offloaded data deletion is async.

In case of truncate internalTrimLedgers runs with isTruncate == true actual future that completes when trimming is done, and the topic deletion will follow that.
In case of deletion we have isTruncate == false and internalTrimLedgers runs with Futures.NULL_PROMISE.

In case I missed some place where internalTrimLedgers completes the promise before the data deletion is done i'll fix that as long as we agree on overall approach.

// Truncate to ensure the offloaded data is not orphaned.
// Also ensures the BK ledgers are deleted and not just scheduled for deletion
CompletableFuture<Void> truncateFuture = ledger.asyncTruncate();
truncateFuture.whenComplete((ignore, exc) -> {
Copy link
Member

@horizonzy horizonzy Jun 10, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about that move this logic to ledger.asyncDelete(). It can cover more situation.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@horizonzy moved it into ManagedLedgerImpl

@dlg99 dlg99 marked this pull request as draft June 22, 2022 04:07
Copy link
Contributor

@hangc0276 hangc0276 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall LGTM.

My only concern is if the offload data have been used by other systems, for example, a hive table, the topic deletion will delete the table, and other systems won't get the data out from the table.

There is another risk is that after the ledger deletion succeeds, but some ledgers deletion from BookKeeper failed, it won't delete the topic metadata, which will lead to some ledgers has been deleted from storage, but their metadata still can be found from the topic metadata, and the consumer will fetch data failed. We are writing a proposal to solve this issue.

@@ -2687,6 +2687,22 @@ public void deleteLedgerFailed(ManagedLedgerException e, Object ctx) {

@Override
public void asyncDelete(final DeleteLedgerCallback callback, final Object ctx) {
// Truncate to ensure the offloaded data is not orphaned.
// Also ensures the BK ledgers are deleted and not just scheduled for deletion
CompletableFuture<Void> truncateFuture = asyncTruncate();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we use asyncTruncate to trigger delete storage data.
Maybe we should mofidy the code:

if (!factory.isMetadataServiceAvailable()) {
// Defer trimming of ledger if we cannot connect to metadata service
promise.complete(null);
return;
}

When the meta data service is not available, should complete with exception.

@github-actions
Copy link

The pr had no activity for 30 days, mark with Stale label.

@github-actions github-actions bot added the Stale label Jul 26, 2022
@dlg99 dlg99 force-pushed the topic-deletion branch 2 times, most recently from 75c7192 to a912495 Compare September 14, 2022 01:06
@dlg99 dlg99 marked this pull request as ready for review September 15, 2022 21:13
@dlg99
Copy link
Contributor Author

dlg99 commented Sep 16, 2022

@eolivelli @hangc0276 please take another look.
I addressed the case when the topic is unloaded.

@github-actions github-actions bot removed the Stale label Sep 17, 2022
DeleteLedgerCallback callback, Object ctx) {
final CompletableFuture<Map<Long, MLDataFormats.ManagedLedgerInfo.LedgerInfo>>
ledgerInfosFuture = new CompletableFuture<>();
store.getManagedLedgerInfo(managedLedgerName, false, null,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we read ManagedLedgerInfo from store instead of just use info in the parameter list?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

info is org.apache.bookkeeper.mledger.ManagedLedgerInfo, store returns MLDataFormats.ManagedLedgerInfo.LedgerInfo which has some additional info and used in OffloadUtils

Copy link
Contributor

@Jason918 Jason918 Sep 24, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dlg99 This still confuse me. All data in ManagedLedgerInfo comes directly from MLDataFormats.ManagedLedgerInfo.LedgerInfo. I think it's better to just sync all the info to ManagedLedgerInfo.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately ManagedLedgerInfo is part of of the public REST API

for instance here we return it (JSON encoded) to the client

PartitionedManagedLedgerInfo partitionedManagedLedgerInfo = new PartitionedManagedLedgerInfo();

We should not add everything to it.

We have this bad problem in Pulsar that we aren't always aware of what is leaking to the public APIs.

I prefer to keep the patch in this form.
And if we want to change ManagedLedgerInfo we can do it in a follow up work.

As this patch is fixing some kind of "bad problem" (because we are not deleting data that should have been deleted, that has some legal impact in some countries), this patch should be cherry-picked to active branches.
I won't add API changes in a patch that will be ported

Copy link
Contributor

@Jason918 Jason918 Sep 29, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately ManagedLedgerInfo is part of of the public REST API

Sorry, I missed this.

I prefer to keep the patch in this form. And if we want to change ManagedLedgerInfo we can do it in a follow up work.

As this patch is fixing some kind of "bad problem" (because we are not deleting data that should have been deleted, that has some legal impact in some countries), this patch should be cherry-picked to active branches. I won't add API changes in a patch that will be ported

Make sense to me, this patch LGTM

@dlg99
Copy link
Contributor Author

dlg99 commented Sep 22, 2022

@Jason918 I addressed your comments

Copy link
Contributor

@eolivelli eolivelli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@eolivelli
Copy link
Contributor

tests are now failing due to #17736

because "trim" cannot happen if a ManagedLedger is "fenced", and we set "fenced" in "delete".
so there is some code path in which we "delete" and then try to "trim".
we should do the opposite...trim and then delete.

merlimat pushed a commit that referenced this pull request Sep 29, 2022
dlg99 added a commit to dlg99/pulsar that referenced this pull request Oct 4, 2022
…tion (apache#15914)

* Truncate topic before deletion to avoid orphaned offloaded ledgers

* CR feedback

(cherry picked from commit 9026d19)
dlg99 added a commit to dlg99/pulsar that referenced this pull request Oct 4, 2022
…tion (apache#15914)

* Truncate topic before deletion to avoid orphaned offloaded ledgers

* CR feedback

(cherry picked from commit 9026d19)
dlg99 added a commit to dlg99/pulsar that referenced this pull request Oct 21, 2022
…tion (apache#15914)

* Truncate topic before deletion to avoid orphaned offloaded ledgers

* CR feedback

(cherry picked from commit 9026d19)
dlg99 added a commit to datastax/pulsar that referenced this pull request Oct 31, 2022
…tion (apache#17915) (#152)

(cherry picked from commit 0854032)

Fixes apache#9962 

### Motivation

Offloaded ledgers can be orphaned on topic deletion. 

This is a redo of apache#15914 which conflicted with concurrently merged apache#17736 thus resulting in apache#17889 .

apache#17736 made a decision to not allow managed ledger trimming for the fenced mledgers because in many case fencing indicates a problems that should stop all operations on mledger. At the same time fencing is used before deletion starts, so trimming added to the deletion process cannot proceed.
After discussion with @eolivelli I introduced new state, FencedForDeletion, which acts as Fenced state except for the trimming/deletion purposes.

### Modifications

Topic to be truncated before deletion to delete offloaded ledgers properly and fail if truncation fails.

### Verifying this change

local fork tests: dlg99#1

- [ ] Make sure that the change passes the CI checks.

This change added integration tests

### Does this pull request potentially affect one of the following parts:

*If `yes` was chosen, please highlight the changes*

Nothing changed in the options but admin CLI will implicitly run truncate before topic delete. 

  - Dependencies (does it add or upgrade a dependency): (yes / no)
  - The public API: (yes / no)
  - The schema: (yes / no / don't know)
  - The default values of configurations: (yes / no)
  - The wire protocol: (yes / no)
  - The rest endpoints: (yes / no)
  - The admin cli options: (yes / no)
  - Anything that affects deployment: (yes / no / don't know)

### Documentation

Check the box below or label this PR directly.

Need to update docs? 

- [ ] `doc-required` 
(Your PR needs to update docs and you will update later)
  
- [x] `doc-not-needed` 
(Please explain why)
  
- [ ] `doc` 
(Your PR contains doc changes)

- [ ] `doc-complete`
(Docs have been already added)
@congbobo184
Copy link
Contributor

congbobo184 commented Nov 15, 2022

@dlg99 could you please cherry-pick this PR to branch-2.9? thanks.

@congbobo184
Copy link
Contributor

@dlg99 hi, I move this PR to release/2.9.5, if you have any questions, please ping me. thanks.

liangyepianzhou pushed a commit that referenced this pull request Feb 26, 2023
…tion (#15914)

* Truncate topic before deletion to avoid orphaned offloaded ledgers

* CR feedback

(cherry picked from commit 9026d19)
@codelipenghui codelipenghui added the release/important-notice The changes which are important should be mentioned in the release note label Feb 28, 2023
@tisonkun
Copy link
Member

Remove the release/* tags since it changes the default behavior and should not go into early releases.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/tieredstorage doc-not-needed Your PR changes do not impact docs release/important-notice The changes which are important should be mentioned in the release note type/bug The PR fixed a bug or issue reported a bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Tiered Storage] Eagerly Delete Offloaded Segments On Topic Deletion
10 participants