diff --git a/standalone-metastore/src/main/java/org/apache/hadoop/hive/metastore/HiveMetaStore.java b/standalone-metastore/src/main/java/org/apache/hadoop/hive/metastore/HiveMetaStore.java index c6e34a8a22..ac71d0882f 100644 --- a/standalone-metastore/src/main/java/org/apache/hadoop/hive/metastore/HiveMetaStore.java +++ b/standalone-metastore/src/main/java/org/apache/hadoop/hive/metastore/HiveMetaStore.java @@ -7856,7 +7856,7 @@ public static void startMetaStore(int port, HadoopThriftAuthBridge bridge, IHMSHandler handler = newRetryingHMSHandler(baseHandler, conf); // Initialize materializations invalidation cache - MaterializationsInvalidationCache.get().init(handler.getMS(), handler.getTxnHandler()); + MaterializationsInvalidationCache.get().init(conf, handler); TServerSocket serverSocket; diff --git a/standalone-metastore/src/main/java/org/apache/hadoop/hive/metastore/HiveMetaStoreClient.java b/standalone-metastore/src/main/java/org/apache/hadoop/hive/metastore/HiveMetaStoreClient.java index 14ba4ea0a2..59c0cff1c2 100644 --- a/standalone-metastore/src/main/java/org/apache/hadoop/hive/metastore/HiveMetaStoreClient.java +++ b/standalone-metastore/src/main/java/org/apache/hadoop/hive/metastore/HiveMetaStoreClient.java @@ -165,7 +165,7 @@ public HiveMetaStoreClient(Configuration conf, HiveMetaHookLoader hookLoader, Bo // through the network client = HiveMetaStore.newRetryingHMSHandler("hive client", this.conf, true); // Initialize materializations invalidation cache (only for local metastore) - MaterializationsInvalidationCache.get().init(((IHMSHandler) client).getMS(), ((IHMSHandler) client).getTxnHandler()); + MaterializationsInvalidationCache.get().init(conf, (IHMSHandler) client); isConnected = true; snapshotActiveConf(); return; diff --git a/standalone-metastore/src/main/java/org/apache/hadoop/hive/metastore/MaterializationsInvalidationCache.java b/standalone-metastore/src/main/java/org/apache/hadoop/hive/metastore/MaterializationsInvalidationCache.java index 6e54eb9f38..1636d48d2c 100644 --- a/standalone-metastore/src/main/java/org/apache/hadoop/hive/metastore/MaterializationsInvalidationCache.java +++ b/standalone-metastore/src/main/java/org/apache/hadoop/hive/metastore/MaterializationsInvalidationCache.java @@ -29,6 +29,7 @@ import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; +import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.hive.common.ValidReadTxnList; import org.apache.hadoop.hive.common.ValidTxnList; import com.google.common.collect.HashMultimap; @@ -38,7 +39,6 @@ import org.apache.hadoop.hive.metastore.api.MetaException; import org.apache.hadoop.hive.metastore.api.Table; import org.apache.hadoop.hive.metastore.conf.MetastoreConf; -import org.apache.hadoop.hive.metastore.txn.TxnStore; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -81,10 +81,10 @@ /* Whether the cache has been initialized or not. */ private boolean initialized; - /* Store to answer calls not related to transactions. */ - private RawStore store; - /* Store to answer calls related to transactions. */ - private TxnStore txnStore; + /* Configuration for cache. */ + private Configuration conf; + /* Handler to connect to metastore. */ + private IHMSHandler handler; private MaterializationsInvalidationCache() { } @@ -105,12 +105,12 @@ public static MaterializationsInvalidationCache get() { * multiple times in embedded mode. This will not happen when we run the metastore remotely * as the method is called only once. */ - public synchronized void init(final RawStore store, final TxnStore txnStore) { - this.store = store; - this.txnStore = txnStore; + public synchronized void init(Configuration conf, IHMSHandler handler) { + this.conf = conf; + this.handler = handler; // This will only be true for debugging purposes - this.disable = MetastoreConf.getVar(store.getConf(), + this.disable = MetastoreConf.getVar(conf, MetastoreConf.ConfVars.MATERIALIZATIONS_INVALIDATION_CACHE_IMPL).equals("DISABLE"); if (disable) { // Nothing to do @@ -129,6 +129,7 @@ public synchronized void init(final RawStore store, final TxnStore txnStore) { @Override public void run() { try { + RawStore store = handler.getMS(); for (String dbName : store.getAllDatabases()) { for (Table mv : store.getTableObjectsByName(dbName, store.getTables(dbName, null, TableType.MATERIALIZED_VIEW))) { addMaterializedView(mv.getDbName(), mv.getTableName(), ImmutableSet.copyOf(mv.getCreationMetadata().getTablesUsed()), @@ -217,7 +218,7 @@ private void addMaterializedView(String dbName, String tableName, Set ta // check if the MV is still valid. try { String[] names = qNameTableUsed.split("\\."); - BasicTxnInfo e = txnStore.getFirstCompletedTransactionForTableAfterCommit( + BasicTxnInfo e = handler.getTxnHandler().getFirstCompletedTransactionForTableAfterCommit( names[0], names[1], txnList); if (!e.isIsnull()) { modificationsTree.put(e.getTxnid(), e.getTime()); diff --git a/standalone-metastore/src/test/java/org/apache/hadoop/hive/metastore/TestMetaStoreMaterializationsCacheCleaner.java b/standalone-metastore/src/test/java/org/apache/hadoop/hive/metastore/TestMetaStoreMaterializationsCacheCleaner.java index 8f8bff6d93..6d3f68c0f0 100644 --- a/standalone-metastore/src/test/java/org/apache/hadoop/hive/metastore/TestMetaStoreMaterializationsCacheCleaner.java +++ b/standalone-metastore/src/test/java/org/apache/hadoop/hive/metastore/TestMetaStoreMaterializationsCacheCleaner.java @@ -24,7 +24,6 @@ import org.apache.hadoop.hive.metastore.api.CreationMetadata; import org.apache.hadoop.hive.metastore.api.Materialization; import org.apache.hadoop.hive.metastore.api.Table; -import org.apache.hadoop.hive.metastore.txn.TxnStore; import org.junit.Assert; import org.junit.FixMethodOrder; import org.junit.Test; @@ -55,15 +54,12 @@ @Test public void testCleanerScenario1() throws Exception { // create mock raw store - final RawStore rawStore = mock(RawStore.class); - when(rawStore.getAllDatabases()).thenReturn(ImmutableList.of()); Configuration conf = new Configuration(); conf.set("metastore.materializations.invalidation.impl", "DISABLE"); - when(rawStore.getConf()).thenReturn(conf); - // create mock txn store - final TxnStore txnStore = mock(TxnStore.class); + // create mock handler + final IHMSHandler handler = mock(IHMSHandler.class); // initialize invalidation cache (set conf to disable) - MaterializationsInvalidationCache.get().init(rawStore, txnStore); + MaterializationsInvalidationCache.get().init(conf, handler); // This is a dummy test, invalidation cache is not supposed to // record any information. @@ -176,15 +172,12 @@ public void testCleanerScenario1() throws Exception { @Test public void testCleanerScenario2() throws Exception { // create mock raw store - final RawStore rawStore = mock(RawStore.class); - when(rawStore.getAllDatabases()).thenReturn(ImmutableList.of()); Configuration conf = new Configuration(); conf.set("metastore.materializations.invalidation.impl", "DEFAULT"); - when(rawStore.getConf()).thenReturn(conf); - // create mock txn store - final TxnStore txnStore = mock(TxnStore.class); + // create mock handler + final IHMSHandler handler = mock(IHMSHandler.class); // initialize invalidation cache (set conf to default) - MaterializationsInvalidationCache.get().init(rawStore, txnStore); + MaterializationsInvalidationCache.get().init(conf, handler); // Scenario consists of the following steps: // Create tbl1