This is an automated email from the ASF dual-hosted git repository.
dmollitor pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/hive.git
The following commit(s) were added to refs/heads/master by this push:
new b846bbe HIVE-19261: Avro SerDe's InstanceCache should not be
synchronized on retrieve (Alexey Diomin via David Mollitor)
b846bbe is described below
commit b846bbe229b2225ff1122ec14b91ae910b73772c
Author: Alexey <[email protected]>
AuthorDate: Fri Jun 19 20:36:24 2020 +0700
HIVE-19261: Avro SerDe's InstanceCache should not be synchronized on
retrieve (Alexey Diomin via David Mollitor)
---
.../apache/hadoop/hive/serde2/avro/InstanceCache.java | 19 +++++++++----------
1 file changed, 9 insertions(+), 10 deletions(-)
diff --git
a/serde/src/java/org/apache/hadoop/hive/serde2/avro/InstanceCache.java
b/serde/src/java/org/apache/hadoop/hive/serde2/avro/InstanceCache.java
index 2d52020..3e80576 100644
--- a/serde/src/java/org/apache/hadoop/hive/serde2/avro/InstanceCache.java
+++ b/serde/src/java/org/apache/hadoop/hive/serde2/avro/InstanceCache.java
@@ -17,9 +17,9 @@
*/
package org.apache.hadoop.hive.serde2.avro;
-import java.util.HashMap;
import java.util.Map;
import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -35,7 +35,7 @@ import org.slf4j.LoggerFactory;
*/
public abstract class InstanceCache<SeedObject, Instance> {
private static final Logger LOG =
LoggerFactory.getLogger(InstanceCache.class);
- Map<SeedObject, Instance> cache = new HashMap<SeedObject, Instance>();
+ Map<SeedObject, Instance> cache = new ConcurrentHashMap<>();
public InstanceCache() {}
@@ -51,20 +51,19 @@ public abstract class InstanceCache<SeedObject, Instance> {
* Retrieve (or create if it doesn't exist) the correct Instance for this
* SeedObject using 'seenSchemas' to resolve circular references
*/
- public synchronized Instance retrieve(SeedObject hv,
- Set<SeedObject> seenSchemas) throws AvroSerdeException {
+ public Instance retrieve(SeedObject hv, Set<SeedObject> seenSchemas)
+ throws AvroSerdeException {
if(LOG.isDebugEnabled()) LOG.debug("Checking for hv: " + hv.toString());
if(cache.containsKey(hv)) {
if(LOG.isDebugEnabled()) LOG.debug("Returning cache result.");
return cache.get(hv);
+ } else {
+ if(LOG.isDebugEnabled()) LOG.debug("Creating new instance and storing in
cache");
+ Instance newInstance = makeInstance(hv, seenSchemas);
+ Instance cachedInstance = cache.putIfAbsent(hv, newInstance);
+ return cachedInstance == null ? newInstance : cachedInstance;
}
-
- if(LOG.isDebugEnabled()) LOG.debug("Creating new instance and storing in
cache");
-
- Instance instance = makeInstance(hv, seenSchemas);
- cache.put(hv, instance);
- return instance;
}
protected abstract Instance makeInstance(SeedObject hv,