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 47de215a23..612442858e 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 @@ -7845,7 +7845,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 5b62114bda..7b5f06dc7e 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 @@ -164,7 +164,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..c7c3f31ac2 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; @@ -81,10 +82,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 +106,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 +130,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 +219,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..f3ed9f0908 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 @@ -55,15 +55,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 +173,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