[FLINK-32049][checkpoint] Fix thread-safe bug of channel state executor when some subtasks are closed while other subtasks are starting #22983
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.
What is the purpose of the change
Fix thread-safe bug of channel state executor when some subtasks are closed while other subtasks are starting.
When one subtask is closing, it will call the
ChannelStateWriteRequestExecutorImpl#releaseSubtask. ThereleaseSubtaskmethod will hold 2 locks at the different time.ChannelStateWriteRequestExecutorImpl#lock, and update theisRegisteringfrom true to false.onRegistered.accept(this)will holdChannelStateWriteRequestExecutorFactory#lockand update theChannelStateWriteRequestExecutorFactory#executorHowever, these 2 locks are held at the different time. The following calls will meet a bug:
releaseSubtask, and doesn't hold the second lock.executor#registerSubtaskSubtask2 will throw
This executor has been registered.Brief change log
Ensure that update the
isRegisteringand call theonRegisteredwithin one registerLock. They should guarantee idempotence.Verifying this change
Created 2 threads, one thread creates the executor and register subtask, one thread releases these subtask. This bug can reproduce by the following test .
This change added tests and can be verified as follows:
Does this pull request potentially affect one of the following parts:
@Public(Evolving): noDocumentation