Do not throw recursive update exception when producer state recovery failed
Motivation
When transaction is enabled, PartitionLog#initialise will recover the state from the local snapshot. It's an asynchronous operation that could fail. In this case, an "recursive update" IllegalStateException will be thrown, which is unexpected.
Suppressed: java.lang.IllegalStateException: Recursive update
at java.util.concurrent.ConcurrentHashMap.replaceNode(ConcurrentHashMap.java:1167) ~[?:?]
at java.util.concurrent.ConcurrentHashMap.remove(ConcurrentHashMap.java:1552) ~[?:?]
at io.streamnative.pulsar.handlers.kop.storage.PartitionLogManager.lambda$getLog$0(PartitionLogManager.java:88) ~[?:?]
The reason is that in PartitionLogManager#getLog, logMap.remove is called in the callback of whenComplete, which could be called in the same thread. Then the remove method is just called in the 2nd argument of computeIfAbsent.
https://github.com/streamnative/kop/blob/3602c9e826d903d97091af1cc608b9d88c1b8cf3/kafka-impl/src/main/java/io/streamnative/pulsar/handlers/kop/storage/PartitionLogManager.java#L88
Modifications
Store the future of PartitionLog in PartitionLogManager, move the remove call out of the computeIfAbsent in the exceptionally callback of ReplicaManager#getPartitionLog.
@BewareMyPower:Thanks for your contribution. For this PR, do we need to update docs? (The PR template contains info about doc, which helps others know more about the changes. Can you provide doc-related info in this and future PR descriptions? Thanks)
@BewareMyPower:Thanks for your contribution. For this PR, do we need to update docs? (The PR template contains info about doc, which helps others know more about the changes. Can you provide doc-related info in this and future PR descriptions? Thanks)
Codecov Report
Merging #1982 (e648861) into master (e931b6d) will increase coverage by
0.03%. Report is 2 commits behind head on master. The diff coverage is0.00%.
@@ Coverage Diff @@
## master #1982 +/- ##
============================================
+ Coverage 17.72% 17.75% +0.03%
- Complexity 751 752 +1
============================================
Files 195 195
Lines 14156 14146 -10
Branches 1322 1319 -3
============================================
+ Hits 2509 2512 +3
+ Misses 11464 11452 -12
+ Partials 183 182 -1
| Files Changed | Coverage Δ | |
|---|---|---|
| ...ative/pulsar/handlers/kop/KafkaRequestHandler.java | 1.06% <ø> (+<0.01%) |
:arrow_up: |
| ...sar/handlers/kop/storage/AppendRecordsContext.java | 0.00% <0.00%> (ø) |
|
| ...tive/pulsar/handlers/kop/storage/PartitionLog.java | 7.93% <ø> (+0.03%) |
:arrow_up: |
| ...lsar/handlers/kop/storage/PartitionLogManager.java | 0.00% <0.00%> (ø) |
|
| ...ve/pulsar/handlers/kop/storage/ReplicaManager.java | 0.00% <0.00%> (ø) |