kop icon indicating copy to clipboard operation
kop copied to clipboard

Do not throw recursive update exception when producer state recovery failed

Open BewareMyPower opened this issue 3 years ago • 3 comments

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 avatar Jul 27 '23 13:07 BewareMyPower

@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)

github-actions[bot] avatar Jul 27 '23 13:07 github-actions[bot]

@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)

github-actions[bot] avatar Jul 27 '23 13:07 github-actions[bot]

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 is 0.00%.

Impacted file tree graph

@@             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%> (ø)

... and 8 files with indirect coverage changes

codecov[bot] avatar Jul 27 '23 13:07 codecov[bot]