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

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

                Author: ASF GitHub Bot
            Created on: 07/Mar/23 13:56
            Start Date: 07/Mar/23 13:56
    Worklog Time Spent: 10m 
      Work Description: SourabhBadhya commented on code in PR #4098:
URL: https://github.com/apache/hive/pull/4098#discussion_r1127894227


##########
ql/src/java/org/apache/hadoop/hive/ql/txn/compactor/MetadataCache.java:
##########
@@ -17,32 +17,27 @@
  */
 package org.apache.hadoop.hive.ql.txn.compactor;
 
-import com.google.common.cache.Cache;
-import com.google.common.cache.CacheBuilder;
+import com.github.benmanes.caffeine.cache.Cache;
+import com.github.benmanes.caffeine.cache.Caffeine;
 import org.apache.thrift.TBase;
 
-import java.util.concurrent.Callable;
-import java.util.concurrent.ExecutionException;
+import java.util.function.Function;
 
 public class MetadataCache {
 
   private Cache<String, TBase> metaCache;
 
   public MetadataCache(boolean tableCacheOn) {
     if (tableCacheOn) {
-      metaCache = CacheBuilder.newBuilder().softValues().build();
+      metaCache = Caffeine.newBuilder().softValues().build();
     }
   }
 
-  public <T extends TBase<T,?>> T computeIfAbsent(String key, Callable<T> 
callable) throws Exception {
+  public <T extends TBase<T,?>> T computeIfAbsent(String key, Function<? super 
String, ? extends TBase> function) throws Exception {
     if (metaCache != null) {
-      try {
-        return (T) metaCache.get(key, callable);
-      } catch (ExecutionException e) {
-        throw (Exception) e.getCause();
-      }

Review Comment:
   This is required as an input parameter for caching in Caffeine - 
   `metaCache.get(key, an instance of Function).`
   
   Since the API itself is using functional interface, I modified all callables 
to functional instances. Yes there is a problem of exception handling when 
using functional interface which is why I wrote the `ThrowingFunction` 
interface.





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

    Worklog Id:     (was: 849556)
    Time Spent: 2.5h  (was: 2h 20m)

> Use Caffeine for caching metadata objects in Compactor threads
> --------------------------------------------------------------
>
>                 Key: HIVE-27122
>                 URL: https://issues.apache.org/jira/browse/HIVE-27122
>             Project: Hive
>          Issue Type: Improvement
>            Reporter: Sourabh Badhya
>            Assignee: Sourabh Badhya
>            Priority: Major
>              Labels: pull-request-available
>          Time Spent: 2.5h
>  Remaining Estimate: 0h
>
> Currently, compactor threads make use of Guava package to cache metadata 
> objects like database/table objects. We should consider using Caffeine 
> package since it provides more control on the cache. It is also observed that 
> cache created from Caffeine package is more performant than cache created 
> from Guava package.
> Some benchmarks comparing Caffeine package vs Guava package - 
> [https://github.com/ben-manes/caffeine/wiki/Benchmarks]



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to