diff --git ql/src/java/org/apache/hadoop/hive/ql/exec/tez/ObjectCache.java ql/src/java/org/apache/hadoop/hive/ql/exec/tez/ObjectCache.java index c2462d7..56428b1 100644 --- ql/src/java/org/apache/hadoop/hive/ql/exec/tez/ObjectCache.java +++ ql/src/java/org/apache/hadoop/hive/ql/exec/tez/ObjectCache.java @@ -21,18 +21,35 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.tez.runtime.api.ObjectRegistry; -import org.apache.tez.runtime.common.objectregistry.ObjectRegistryImpl; + +import com.google.common.base.Preconditions; /** * ObjectCache. Tez implementation based on the tez object registry. * */ public class ObjectCache implements org.apache.hadoop.hive.ql.exec.ObjectCache { - + private static final Log LOG = LogFactory.getLog(ObjectCache.class.getName()); - // TODO HIVE-7809. This is broken. A new instance of ObjectRegistry should not be created. - private final ObjectRegistry registry = new ObjectRegistryImpl(); + + // ObjectRegistry is available via the Input/Output/ProcessorContext. + // This is setup as part of the Tez Processor construction, so that it is available whenever an + // instance of the ObjectCache is created. The assumption is that Tez will initialize the Processor + // before anything else. + private volatile static ObjectRegistry staticRegistry; + + private final ObjectRegistry registry; + + public ObjectCache() { + Preconditions.checkNotNull(staticRegistry, + "Object registry not setup yet. This should have been setup by the TezProcessor"); + registry = staticRegistry; + } + public static void setupObjectRegistry(ObjectRegistry objectRegistry) { + staticRegistry = objectRegistry; + } + @Override public void cache(String key, Object value) { LOG.info("Adding " + key + " to cache with value " + value); diff --git ql/src/java/org/apache/hadoop/hive/ql/exec/tez/TezProcessor.java ql/src/java/org/apache/hadoop/hive/ql/exec/tez/TezProcessor.java index 610f985..a8dc960 100644 --- ql/src/java/org/apache/hadoop/hive/ql/exec/tez/TezProcessor.java +++ ql/src/java/org/apache/hadoop/hive/ql/exec/tez/TezProcessor.java @@ -69,6 +69,7 @@ public TezProcessor(ProcessorContext context) { super(context); + ObjectCache.setupObjectRegistry(context.getObjectRegistry()); } @Override