[ 
https://issues.apache.org/jira/browse/HIVE-24805?focusedWorklogId=703264&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-703264
 ]

ASF GitHub Bot logged work on HIVE-24805:
-----------------------------------------

                Author: ASF GitHub Bot
            Created on: 04/Jan/22 12:03
            Start Date: 04/Jan/22 12:03
    Worklog Time Spent: 10m 
      Work Description: deniskuzZ commented on a change in pull request #2906:
URL: https://github.com/apache/hive/pull/2906#discussion_r778029906



##########
File path: 
standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/txn/CacheAwareCompactor.java
##########
@@ -0,0 +1,137 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.hadoop.hive.metastore.txn;
+
+import com.google.common.annotations.VisibleForTesting;
+import com.google.common.cache.Cache;
+import com.google.common.cache.CacheBuilder;
+import com.google.common.util.concurrent.UncheckedExecutionException;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.hive.metastore.api.Partition;
+import org.apache.hadoop.hive.metastore.api.Table;
+import org.apache.hadoop.hive.metastore.conf.MetastoreConf;
+
+import java.util.Objects;
+import java.util.concurrent.Callable;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.TimeUnit;
+
+public interface CacheAwareCompactor {
+
+  static void trySetCache(Object obj, CompactorMetadataCache cache) {
+    if (CacheAwareCompactor.class.isAssignableFrom(obj.getClass())) {
+      ((CacheAwareCompactor) obj).setCache(cache);
+    }
+  }
+
+  void setCache(CompactorMetadataCache cache);
+
+  class CompactorMetadataCache {
+
+    private final Cache<TableCacheKey, Table> tableCache;
+    private final Cache<PartitionCacheKey, Partition> partitionCache;
+
+    @VisibleForTesting
+    public CompactorMetadataCache(long timeout, TimeUnit unit) {
+      this.tableCache = CacheBuilder.newBuilder().expireAfterAccess(timeout, 
unit).softValues().build();
+      this.partitionCache = 
CacheBuilder.newBuilder().expireAfterAccess(timeout, unit).softValues().build();
+    }
+
+    public static CompactorMetadataCache createIfEnabled(Configuration conf) {
+      long timeout = MetastoreConf.getTimeVar(conf,
+        MetastoreConf.ConfVars.COMPACTOR_METADATA_CACHE_TIMEOUT, 
TimeUnit.SECONDS);
+      if (timeout == 0) {
+        return null;
+      }
+      return new CompactorMetadataCache(timeout, TimeUnit.SECONDS);
+    }
+
+    public Table resolveTable(CompactionInfo ci, Callable<Table> loader) {
+      try {
+        TableCacheKey key = new TableCacheKey(ci);
+        return tableCache.get(key, loader);
+      } catch (ExecutionException e) {
+        throw new UncheckedExecutionException(e);
+      }
+    }
+
+    public Partition resolvePartition(CompactionInfo ci, Callable<Partition> 
loader) {
+      try {
+        if (ci.partName == null) {
+          return null;
+        }
+        PartitionCacheKey key = new PartitionCacheKey(ci);

Review comment:
       same as above:
   ````
   ci.getFullPartitionName
   ````




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: gitbox-unsubscr...@hive.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Issue Time Tracking
-------------------

    Worklog Id:     (was: 703264)
    Time Spent: 50m  (was: 40m)

> Compactor: Initiator shouldn't fetch table details again and again for 
> partitioned tables
> -----------------------------------------------------------------------------------------
>
>                 Key: HIVE-24805
>                 URL: https://issues.apache.org/jira/browse/HIVE-24805
>             Project: Hive
>          Issue Type: Improvement
>          Components: Transactions
>            Reporter: Rajesh Balamohan
>            Assignee: Antal Sinkovits
>            Priority: Major
>              Labels: pull-request-available
>          Time Spent: 50m
>  Remaining Estimate: 0h
>
> Initiator shouldn't be fetch table details for all its partitions. When there 
> are large number of databases/tables, it takes lot of time for Initiator to 
> complete its initial iteration and load on DB also goes higher.
> https://github.com/apache/hive/blob/master/ql/src/java/org/apache/hadoop/hive/ql/txn/compactor/Initiator.java#L129
> https://github.com/apache/hive/blob/64bb52316f19426ebea0087ee15e282cbde1d852/ql/src/java/org/apache/hadoop/hive/ql/txn/compactor/Initiator.java#L456
> For all the following partitions, table details would be the same. However, 
> it ends up fetching table details from HMS again and again.
> {noformat}
> 2021-02-22 08:13:16,106 INFO  
> org.apache.hadoop.hive.ql.txn.compactor.Initiator: [Thread-11]: Checking to 
> see if we should compact 
> tpcds_bin_partitioned_orc_1000.store_returns_tmp2.sr_returned_date_sk=2451899
> 2021-02-22 08:13:16,124 INFO  
> org.apache.hadoop.hive.ql.txn.compactor.Initiator: [Thread-11]: Checking to 
> see if we should compact 
> tpcds_bin_partitioned_orc_1000.store_returns_tmp2.sr_returned_date_sk=2451830
> 2021-02-22 08:13:16,140 INFO  
> org.apache.hadoop.hive.ql.txn.compactor.Initiator: [Thread-11]: Checking to 
> see if we should compact 
> tpcds_bin_partitioned_orc_1000.store_returns_tmp2.sr_returned_date_sk=2452586
> 2021-02-22 08:13:16,149 INFO  
> org.apache.hadoop.hive.ql.txn.compactor.Initiator: [Thread-11]: Checking to 
> see if we should compact 
> tpcds_bin_partitioned_orc_1000.store_returns_tmp2.sr_returned_date_sk=2452698
> 2021-02-22 08:13:16,158 INFO  
> org.apache.hadoop.hive.ql.txn.compactor.Initiator: [Thread-11]: Checking to 
> see if we should compact 
> tpcds_bin_partitioned_orc_1000.store_returns_tmp2.sr_returned_date_sk=2452063
> {noformat}



--
This message was sent by Atlassian Jira
(v8.20.1#820001)

Reply via email to