[jira] [Commented] (HIVE-19241) HMSHandler initialization isn't thread-safe

2018-05-15 Thread Alexander Kolbasov (JIRA)

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

Alexander Kolbasov commented on HIVE-19241:
---

Marta - you re changing the code around it - may be you can fix this as well.

> HMSHandler initialization isn't thread-safe
> ---
>
> Key: HIVE-19241
> URL: https://issues.apache.org/jira/browse/HIVE-19241
> Project: Hive
>  Issue Type: Bug
>Affects Versions: 2.0.2, 3.0.0, 3.1.0
>Reporter: Alexander Kolbasov
>Assignee: Marta Kuczora
>Priority: Major
>
> The code in HMSHandler uses the double-check anti-pattern:
> {code:java}
> public HMSHandler(String name, Configuration conf, boolean init) throws 
> MetaException {
>   super(name);
>   this.conf = conf;
>   isInTest = MetastoreConf.getBoolVar(this.conf, ConfVars.HIVE_IN_TEST);
>   if (threadPool == null) { // No lock held!!
> synchronized (HMSHandler.class) {
>   int numThreads = MetastoreConf.getIntVar(conf, 
> ConfVars.FS_HANDLER_THREADS_COUNT);
>   threadPool = Executors.newFixedThreadPool(numThreads,
>   new ThreadFactoryBuilder().setDaemon(true)
>   .setNameFormat("HMSHandler #%d").build());
> }
>   }
> {code}
> Notice that the check for threadPool == null isn't protected.
> This means that users of threadPool may see thread pool that isn't completely 
> initialized.
> See https://www.cs.umd.edu/~pugh/java/memoryModel/DoubleCheckedLocking.html 
> for a detailed explanation.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)


[jira] [Commented] (HIVE-19241) HMSHandler initialization isn't thread-safe

2018-05-15 Thread Alexander Kolbasov (JIRA)

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

Alexander Kolbasov commented on HIVE-19241:
---

There is a second problem here - since there is no synchronization, we may 
incidentally create two thread pools and one of these would never be destroyed 
and will never be used.

> HMSHandler initialization isn't thread-safe
> ---
>
> Key: HIVE-19241
> URL: https://issues.apache.org/jira/browse/HIVE-19241
> Project: Hive
>  Issue Type: Bug
>Affects Versions: 2.0.2, 3.0.0, 3.1.0
>Reporter: Alexander Kolbasov
>Assignee: Marta Kuczora
>Priority: Major
>
> The code in HMSHandler uses the double-check anti-pattern:
> {code:java}
> public HMSHandler(String name, Configuration conf, boolean init) throws 
> MetaException {
>   super(name);
>   this.conf = conf;
>   isInTest = MetastoreConf.getBoolVar(this.conf, ConfVars.HIVE_IN_TEST);
>   if (threadPool == null) { // No lock held!!
> synchronized (HMSHandler.class) {
>   int numThreads = MetastoreConf.getIntVar(conf, 
> ConfVars.FS_HANDLER_THREADS_COUNT);
>   threadPool = Executors.newFixedThreadPool(numThreads,
>   new ThreadFactoryBuilder().setDaemon(true)
>   .setNameFormat("HMSHandler #%d").build());
> }
>   }
> {code}
> Notice that the check for threadPool == null isn't protected.
> This means that users of threadPool may see thread pool that isn't completely 
> initialized.
> See https://www.cs.umd.edu/~pugh/java/memoryModel/DoubleCheckedLocking.html 
> for a detailed explanation.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)