[fix][ML] Fix offload read handle NPE. - #17056
Conversation
| } | ||
| }); | ||
| if (slowestNonDurableReadPosition.get() != null) { | ||
| ManagedLedger managedLedger = getManagedLedger(); |
There was a problem hiding this comment.
You can directly use ledger.updateTheSlowestNonDurableReadPosition
There was a problem hiding this comment.
Agrre, and there will reset ManagedLedgerImpl.slowestNonDurableReadPosition when there is no non-duranble cursor, fixed it in next commit.
| } | ||
| } else if (exception.getCause() instanceof TransactionBufferException.TransactionNotSealedException) { | ||
| } else if (exception.getCause() instanceof TransactionBufferException.TransactionNotSealedException | ||
| || exception.getCause() instanceof ManagedLedgerException.OffloadReadHandleClosedException) { |
There was a problem hiding this comment.
Looks like we don't want to handle the race condition of trimming ledgers and reading data, instead, to re-trigger the read operation?
There was a problem hiding this comment.
Yes, it's difficult to handle the race condition, the offload read handle execute read operation in offload-executor, before the read real execute, the read handle maybe invalidated.
|
And can we add a test to make sure the reader handle will not invalidate if we the slowest read position haven't go through it yet. |
|
Please review this pr again, use the new way to get the slowest non-durable read position. |
|
Heads up, cherry picking this commit to older branches broke them because of a missing import. I fixed 2.11 here: 74390d4 |
(cherry picked from commit 6fc48d1)
|
@horizonzy Can you help open a new PR to branch-2.10? There are a lot conflict when cherry-pick directly. |
|
alright. |
This pr cherry-pick from apache#17056.
|
|
move |
Motivation
This issue was introduced by #11389
Now, when we get offload ReadHandle(
BlobStoreBackedReadHandleImpl) and then use it to read data (Non-durable cursor read). Maybe the offload ReadHandle we get already is invalidated.There is a race condition, maybe after we get the ReadHandle, before use it to read.
The method
ManagedLedgerImpl#internalTrimLedgersinvalidate this ReadHandle (Cause in this method, it just calculate by durable-cursor, but there maybe a non-durable cursor read data) so we use the invalidated offload read handle to read data, invalidated will close the read handle.pulsar/managed-ledger/src/main/java/org/apache/bookkeeper/mledger/impl/ManagedLedgerImpl.java
Line 2542 in 96930fd
In the close method, it will set
index.segmentMetadata=null, so when getLastAddConfirmed, case NPE.pulsar/tiered-storage/jcloud/src/main/java/org/apache/bookkeeper/mledger/offload/jcloud/impl/BlobStoreBackedReadHandleImpl.java
Line 100 in bc68f02
The NPE stack info
Modifications
1.Fix the NPE.
2.Check the invalidate ledgerId is less than the slowest non-durable, reduce the npe probability.
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)