Kikyou1997 commented on code in PR #18502:
URL: https://github.com/apache/doris/pull/18502#discussion_r1161531688


##########
fe/fe-core/src/main/java/org/apache/doris/statistics/StatisticsCache.java:
##########
@@ -44,85 +47,155 @@ public class StatisticsCache {
             = ThreadPoolManager.newDaemonFixedThreadPool(
             10, Integer.MAX_VALUE, "STATS_FETCH", true);
 
-    private final StatisticsCacheLoader cacheLoader = new 
StatisticsCacheLoader();
-
-    private final AsyncLoadingCache<StatisticsCacheKey, 
ColumnLevelStatisticCache> cache = Caffeine.newBuilder()
-            .maximumSize(StatisticConstants.STATISTICS_RECORDS_CACHE_SIZE)
-            
.expireAfterAccess(Duration.ofHours(StatisticConstants.STATISTICS_CACHE_VALID_DURATION_IN_HOURS))
-            
.refreshAfterWrite(Duration.ofHours(StatisticConstants.STATISTICS_CACHE_REFRESH_INTERVAL))
-            .executor(threadPool)
-            .buildAsync(cacheLoader);
+    private final ColumnStatisticsCacheLoader columnStatisticsCacheLoader = 
new ColumnStatisticsCacheLoader();
+    private final HistogramCacheLoader histogramCacheLoader = new 
HistogramCacheLoader();
+
+    private final AsyncLoadingCache<StatisticsCacheKey, 
Optional<ColumnStatistic>> columnStatisticsCache =
+            Caffeine.newBuilder()
+                    
.maximumSize(StatisticConstants.STATISTICS_RECORDS_CACHE_SIZE)
+                    
.expireAfterAccess(Duration.ofHours(StatisticConstants.STATISTICS_CACHE_VALID_DURATION_IN_HOURS))
+                    
.refreshAfterWrite(Duration.ofHours(StatisticConstants.STATISTICS_CACHE_REFRESH_INTERVAL))
+                    .executor(threadPool)
+                    .buildAsync(columnStatisticsCacheLoader);
+
+    private final AsyncLoadingCache<StatisticsCacheKey, Optional<Histogram>> 
histogramCache =
+            Caffeine.newBuilder()
+                    
.maximumSize(StatisticConstants.STATISTICS_RECORDS_CACHE_SIZE)
+                    
.expireAfterAccess(Duration.ofHours(StatisticConstants.STATISTICS_CACHE_VALID_DURATION_IN_HOURS))
+                    
.refreshAfterWrite(Duration.ofHours(StatisticConstants.STATISTICS_CACHE_REFRESH_INTERVAL))
+                    .executor(threadPool)
+                    .buildAsync(histogramCacheLoader);
 
     {
         threadPool.submit(() -> {
             while (true) {
                 try {
-                    cacheLoader.removeExpiredInProgressing();
-                    Thread.sleep(TimeUnit.MINUTES.toMillis(15));
+                    columnStatisticsCacheLoader.removeExpiredInProgressing();
+                    histogramCacheLoader.removeExpiredInProgressing();
                 } catch (Throwable t) {
                     // IGNORE
                 }
+                Thread.sleep(TimeUnit.MINUTES.toMillis(15));
             }
 
         });
     }
 
     public ColumnStatistic getColumnStatistics(long tblId, String colName) {
-        ColumnLevelStatisticCache columnLevelStatisticCache = 
getColumnStatistics(tblId, -1, colName);
-        if (columnLevelStatisticCache == null) {
-            return ColumnStatistic.UNKNOWN;
-        }
-        return columnLevelStatisticCache.columnStatistic;
+        return getColumnStatistics(tblId, -1, 
colName).orElse(ColumnStatistic.UNKNOWN);
     }
 
-    public ColumnLevelStatisticCache getColumnStatistics(long tblId, long 
idxId, String colName) {
+    public Optional<ColumnStatistic> getColumnStatistics(long tblId, long 
idxId, String colName) {
         ConnectContext ctx = ConnectContext.get();
         if (ctx != null && ctx.getSessionVariable().internalSession) {
             return null;
         }
         StatisticsCacheKey k = new StatisticsCacheKey(tblId, idxId, colName);
         try {
-            CompletableFuture<ColumnLevelStatisticCache> f = cache.get(k);
+            CompletableFuture<Optional<ColumnStatistic>> f = 
columnStatisticsCache.get(k);
             if (f.isDone() && f.get() != null) {
                 return f.get();
             }
         } catch (Exception e) {
             LOG.warn("Unexpected exception while returning ColumnStatistic", 
e);
         }
-        return null;
+        return Optional.empty();
     }
 
     public Histogram getHistogram(long tblId, String colName) {
-        return getHistogram(tblId, -1, colName);
+        return getHistogram(tblId, -1, colName).orElse(null);
     }
 
-    public Histogram getHistogram(long tblId, long idxId, String colName) {
+    public Optional<Histogram> getHistogram(long tblId, long idxId, String 
colName) {
         ConnectContext ctx = ConnectContext.get();
         if (ctx != null && ctx.getSessionVariable().internalSession) {
-            return null;
+            return Optional.empty();
         }
         StatisticsCacheKey k = new StatisticsCacheKey(tblId, idxId, colName);
         try {
-            CompletableFuture<ColumnLevelStatisticCache> f = cache.get(k);
+            CompletableFuture<Optional<Histogram>> f = histogramCache.get(k);
             if (f.isDone() && f.get() != null) {
-                return f.get().getHistogram();
+                return f.get();
             }
         } catch (Exception e) {
             LOG.warn("Unexpected exception while returning Histogram", e);
         }
-        return null;
+        return Optional.empty();
     }
 
     // TODO: finish this method.
     public void eraseExpiredCache(long tblId, long idxId, String colName) {
-        cache.synchronous().invalidate(new StatisticsCacheKey(tblId, idxId, 
colName));
+        columnStatisticsCache.synchronous().invalidate(new 
StatisticsCacheKey(tblId, idxId, colName));
     }
 
-    public void updateCache(long tblId, long idxId, String colName, 
ColumnLevelStatisticCache statistic) {
-        cache.synchronous().put(new StatisticsCacheKey(tblId, idxId, colName), 
statistic);
+    public void updateCache(long tblId, long idxId, String colName, 
ColumnStatistic statistic) {
+        columnStatisticsCache.synchronous().put(new StatisticsCacheKey(tblId, 
idxId, colName), Optional.of(statistic));
     }
 
     public void refreshSync(long tblId, long idxId, String colName) {
-        cache.synchronous().refresh(new StatisticsCacheKey(tblId, idxId, 
colName));
+        columnStatisticsCache.synchronous().refresh(new 
StatisticsCacheKey(tblId, idxId, colName));
     }
+
+    public void preHeat() {
+        threadPool.submit(this::doPreHeat);
+    }
+
+    private void doPreHeat() {

Review Comment:
   no



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to