You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@hive.apache.org by "Liyin Tang (JIRA)" <ji...@apache.org> on 2010/11/09 22:20:36 UTC

[jira] Resolved: (HIVE-1647) Incorrect initialization of thread local variable inside IOContext ( implementation is not threadsafe )

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

Liyin Tang resolved HIVE-1647.
------------------------------

      Resolution: Fixed
    Release Note: This problem is fixed in Hive-1754

> Incorrect initialization of thread local variable inside IOContext ( implementation is not threadsafe ) 
> --------------------------------------------------------------------------------------------------------
>
>                 Key: HIVE-1647
>                 URL: https://issues.apache.org/jira/browse/HIVE-1647
>             Project: Hive
>          Issue Type: Bug
>          Components: Server Infrastructure
>    Affects Versions: 0.6.0, 0.7.0
>            Reporter: Raman Grover
>            Assignee: Liyin Tang
>             Fix For: 0.7.0
>
>         Attachments: HIVE-1647.patch
>
>   Original Estimate: 0.17h
>  Remaining Estimate: 0.17h
>
> Bug in org.apache.hadoop.hive.ql.io.IOContext
> in relation to initialization of thread local variable.
>  
> public class IOContext {
>  
>   private static ThreadLocal<IOContext> threadLocal = new ThreadLocal<IOContext>(){ };
>  
>   static {
>     if (threadLocal.get() == null) {
>       threadLocal.set(new IOContext());
>     }
>   }
>  
> In a multi-threaded environment, the thread that gets to load the class first for the JVM (assuming threads share the classloader),
> gets to initialize itself correctly by executing the code in the static block. Once the class is loaded, 
> any subsequent threads would  have their respective threadlocal variable as null.  Since IOContext
> is set during initialization of HiveRecordReader, In a scenario where multiple threads get to acquire
>  an instance of HiveRecordReader, it would result in a NPE for all but the first thread that gets to load the class in the VM.
>  
> Is the above scenario of multiple threads initializing HiveRecordReader a typical one ?  or we could just provide the following fix...
>  
>   private static ThreadLocal<IOContext> threadLocal = new ThreadLocal<IOContext>(){
>     protected synchronized IOContext initialValue() {
>       return new IOContext();
>     }  
>   };

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.