You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@avro.apache.org by "Ryan Blue (JIRA)" <ji...@apache.org> on 2016/01/20 04:13:39 UTC

[jira] [Reopened] (AVRO-1781) Schema.parse is not thread safe

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

Ryan Blue reopened AVRO-1781:
-----------------------------

I'm reopening this because after looking into it more, I don't think we need the cache at all. It was originally used to avoid parsing the logical type from a Schema's properties several times, but is now only used by the Schema parse method to do this once. The LogicalType instance is then set on the Schema and is available through Schema#getLogicalType. That's a much better way to keep track of them.

> Schema.parse is not thread safe
> -------------------------------
>
>                 Key: AVRO-1781
>                 URL: https://issues.apache.org/jira/browse/AVRO-1781
>             Project: Avro
>          Issue Type: Bug
>          Components: java
>    Affects Versions: 1.8.0
>            Reporter: Sean Busbey
>            Assignee: Ryan Blue
>            Priority: Blocker
>             Fix For: 1.8.0
>
>         Attachments: AVRO-1781.1.patch, AVRO-1781.2.patch
>
>
> Post AVRO-1497, Schema.parse calls {{LogicalTypes.fromSchemaIgnoreInvalid}} on any schema that is expressed as a JSON object (anything except bare primitives).
> That static method relies on a static cache based on WeakIdentityHashMap (WIHM).
> WIHM clearly states that it isn't threadsafe [ref|https://github.com/apache/avro/blob/branch-1.8/lang/java/avro/src/main/java/org/apache/avro/util/WeakIdentityHashMap.java#L42]
> {code}
>  * 
>  * Note that this implementation is not synchronized.
>  * </b>
>  */
> public class WeakIdentityHashMap<K, V> implements Map<K, V> {
> {code}
> All of the Schema.Parser instances use that same static Schema.parse method.
> The end result is that as-is it's only safe to have a single thread parsing schemas in a given JVM.



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