[ 
https://issues.apache.org/jira/browse/RATIS-1923?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17783693#comment-17783693
 ] 

Tsz-wo Sze commented on RATIS-1923:
-----------------------------------

However, not sure if it may drop the value computed from the mappingFunction 
when two threads are updating it at the same time.  Probably not?  But the code 
is not easy to understand.

> Netty: atomic operations require side-effect-free functions
> -----------------------------------------------------------
>
>                 Key: RATIS-1923
>                 URL: https://issues.apache.org/jira/browse/RATIS-1923
>             Project: Ratis
>          Issue Type: Bug
>          Components: Netty
>            Reporter: Tsz-wo Sze
>            Assignee: Tsz-wo Sze
>            Priority: Major
>             Fix For: 3.0.0
>
>         Attachments: for-loop.jpg, screenshot-1.png
>
>          Time Spent: 40m
>  Remaining Estimate: 0h
>
> - The update methods in AtomicReference run in a loop and may call the update 
> function multiple time. The old values created by the update function may be 
> discarded without cleaning up. In NettyClientStreamRpc.Connection the connect 
> method is not side-effect-free. Although it passes a [MemoizedSupplier to 
> getAndUpdate|https://github.com/apache/ratis/blob/47e5b6aa148cfe777fb3b7742154fe6b417ea42a/ratis-netty/src/main/java/org/apache/ratis/netty/client/NettyClientStreamRpc.java#L187-L188],
>  it still is possible that a value is supplied but then discarded in the 
> AtomicReference loop.
>  - Similarly, the computeIfAbsent in ConcurrentHashMap also runs in a loop 
> and may call the mapping function multiple times. DataStreamMap is 
> implemented using a ConcurrentHashMap. However, [the mapping function is not 
> side-effect-free|https://github.com/apache/ratis/blob/47e5b6aa148cfe777fb3b7742154fe6b417ea42a/ratis-netty/src/main/java/org/apache/ratis/netty/server/DataStreamManagement.java#L281-L289]
>  although it uses a MemoizedSupplier.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to