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

ASF GitHub Bot commented on METRON-601:
---------------------------------------

Github user justinleet commented on a diff in the pull request:

    https://github.com/apache/incubator-metron/pull/381#discussion_r90462687
  
    --- Diff: 
metron-platform/metron-test-utilities/src/main/java/org/apache/metron/test/mock/MockHTable.java
 ---
    @@ -437,15 +463,14 @@ public ResultScanner getScanner(byte[] family, byte[] 
qualifier)
         return getScanner(scan);
       }
     
    -  List<Put> putLog = new ArrayList<>();
    --- End diff --
    
    Couldn't you just change this to
    ```List<Put> putLog = Collections. synchronizedList(new ArrayList<>());```?
    
    I'd still keep the `ImmutableList.copyOf()` in `getPutLog()`, because a 
synchronized list still requires a synchronized block during iteration and 
callers could do whatever.  Notably, `ImmutableList.copyOf()` specifically 
states "This method is safe to use even when elements is a synchronized or 
concurrent collection that is currently being modified by another thread."
    
    At that point, it should be thread-safe.  It doesn't expose the underlying 
list, the putLog doesn't get iterated over in this class, and it only exposes 
thread safe copies of the putLog.
    
    I'm also not convinced that the Supplier solution is actually thread-safe, 
which may be my own ignorance. The `get()` itself is thread-safe (per 
`memoize()`), but just returns a regular ArrayList (```this.putLog = 
Suppliers.memoize(() -> new ArrayList<Put>());```).  The `add()` won't 
necessarily be thread-safe, because two threads could each call `get()` and 
still attempt to put onto the same list at the same time. Assuming that's 
correct (which I'd like a second opinion on), it's probably just more that 
shuffling things happens to ease the race condition.
    
    Somebody feel free to hop in and correct any misconceptions I have here.  
I'm not as familiar with Java's concurrency as I probably (definitely?) should 
be.


> MockHTable Put Log is Not Thread Safe
> -------------------------------------
>
>                 Key: METRON-601
>                 URL: https://issues.apache.org/jira/browse/METRON-601
>             Project: Metron
>          Issue Type: Sub-task
>            Reporter: Nick Allen
>            Assignee: Nick Allen
>
> The MockHTable uses an ArrayList to store a log of Puts that have been 
> submitted against the MockHTable.  The MockHTable, along with the put log, is 
> accessed from multiple threads during the integration tests.  Access to the 
> Put log is not thread safe, which is likely at least one cause of METRON-597.
> The Put log is used by multiple tests, but more so by the 
> ProfilerIntegrationTest.  This tests polls the list to block the thread until 
> the expected number of Puts have been submitted.  This is likely why this 
> test is more impacted by this issue than others.
> The Put Log needs to made thread safe.  See 
> `org.apache.metron.test.mock.MockHTable.putLog`



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to