Backport PR #15233 to 8.9: Fix DeadLetterQueueWriter unable to finalize segment error #15241
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Backport PR #15233 to 8.9 branch, original message:
Release notes
Fixed
DeadLetterQueueWriter
unable to finalize segment -java.nio.file.NoSuchFileException
What does this PR do?
For more details about the error, please check the #15227.
This PR moves the
Files.size(...)
call into the try catch block, that way, when the oldest segment is deleted by theDeadLetterQueueReader
, noNoSuchFileException
will be thrown up, and the writter will gracefully update the oldest segment on the nextupdateOldestSegmentReference
invocation (scheduled flush, entry write, delete expired, etc).It also adds the
volatile
keyword to the shared mutable variables, making sure that all the changes will be instantly visible among all the running threads (scheduler & writer).Why is it important/What is the impact to the user?
Checklist
How to test this PR locally
DeadLetterQueueWriter#createFlushScheduler
to run more oftetn, it's not mandatory but will make the problem happen much faster:main
branch code, it should eventually throw a fewjava.nio.file.NoSuchFileException
.Related issues