[ 
https://issues.apache.org/jira/browse/PHOENIX-1143?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Samarth Jain updated PHOENIX-1143:
----------------------------------

    Attachment: PHOENIX-1143_v3.patch

Changes in this patch:
1) Made reads and writes to latestMetadata thread safe. Existing implementation 
wasn't correctly doing that.
2) With access to latestMetadata correctly guarded by lock, we now throw a 
connection closed exception whenever latest metadata is seen as null. This also 
helps prevent all the NPEs that can happen because of metadata being set to 
null in close(). 
3) When a new connection is requested, ConnectionQueryServicesImpl.connect() 
method now checks whether it is closed or metadata is null. This helps prevent 
the NPE originally reported in this bug.
4) PhoenixDriver now checks before doing any operation whether or not it is 
closed. This is done in a thread safe way by employing a read write lock that 
guards the "closed" member variable. Alternatively, all the phoenix driver 
methods could have been made synchronized. But then that would have been 
excessive as the only mutable state we need to guard is "closed" and hence 
locking the entire PhoenixDriver instance (which happens to be a singleton too) 
for every such operation would have been excessive.
5) PhoenixTestDriver - all methods are now synchronized for simplicity 
purposes. Besides we don't really run multi-threaded tests and hence 
performance isn't a consideration.
6) PhoenixEmbeddedDriver - has an immutable tag now to be more explicit. 

[~jamestaylor] - please review. Thanks!

> Prevent race condition between creating phoenix connection and closing 
> phoenix driver/connection query services.
> ----------------------------------------------------------------------------------------------------------------
>
>                 Key: PHOENIX-1143
>                 URL: https://issues.apache.org/jira/browse/PHOENIX-1143
>             Project: Phoenix
>          Issue Type: Bug
>            Reporter: Samarth Jain
>            Assignee: Samarth Jain
>             Fix For: 5.0.0, 3.1, 4.1
>
>         Attachments: PHOENIX-1143-3.0.patch, PHOENIX-1143_v3.patch
>
>
> The race condition manifests when the following NPE is thrown: 
> {code}
> java.lang.NullPointerException
> Thrown-StackTrace: at 
> org.apache.phoenix.jdbc.PhoenixConnection.<init>(PhoenixConnection.java:178)
> at 
> org.apache.phoenix.query.ConnectionQueryServicesImpl.connect(ConnectionQueryServicesImpl.java:513)
> at 
> org.apache.phoenix.jdbc.PhoenixEmbeddedDriver.connect(PhoenixEmbeddedDriver.java:116)
> {code}



--
This message was sent by Atlassian JIRA
(v6.2#6252)

Reply via email to