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

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

                Author: ASF GitHub Bot
            Created on: 12/Nov/20 10:23
            Start Date: 12/Nov/20 10:23
    Worklog Time Spent: 10m 
      Work Description: pvary commented on a change in pull request #1665:
URL: https://github.com/apache/hive/pull/1665#discussion_r521996167



##########
File path: 
llap-server/src/java/org/apache/hadoop/hive/llap/cache/ProactiveEvictingCachePolicy.java
##########
@@ -0,0 +1,100 @@
+/*
+ * 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.llap.cache;
+
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicLong;
+
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.hive.conf.HiveConf;
+import org.apache.hive.common.util.ShutdownHookManager;
+
+import com.google.common.util.concurrent.ThreadFactoryBuilder;
+
+/**
+ * Interface for classes required to be able to receive 
notifyProactiveEvictionMark event. Had to be this way due to
+ * how CacheContentsTracker is designed to wrap around actual cache policies.
+ *
+ * Implementing this interface is required but not sufficient for a cache 
policy to be proactive eviction supporting.
+ * Such policies also need to extend the implementation below, so that the 
asynchronous sweeping is taken care of,
+ * and they need to implement evictProactively() method.
+ */
+public interface ProactiveEvictingCachePolicy {
+
+  /**
+   * Invoking this signals that new buffers have been marked for proactive 
eviction. Cache policies implementing this
+   * need this information to correctly time sweep runs.
+   */
+  void notifyProactiveEvictionMark();
+
+  abstract class Impl implements ProactiveEvictingCachePolicy {
+    protected final boolean proactiveEvictionEnabled;
+    private final long proactiveEvictionSweepIntervalInMs;
+    private static final ScheduledExecutorService 
PROACTIVE_EVICTION_SWEEPER_EXECUTOR =
+        Executors.newSingleThreadScheduledExecutor(new ThreadFactoryBuilder()
+            
.setNameFormat("Proactive-Eviction-Sweeper").setDaemon(true).build());
+
+    // Last sweep starts higher, so we don't trigger sweeps before the first 
mark
+    AtomicLong lastMarkTime = new AtomicLong(0L);
+    AtomicLong lastSweepTime = new AtomicLong(1L);
+
+    static {
+      ShutdownHookManager.addShutdownHook(new Runnable() {
+        @Override
+        public void run() {
+          if (PROACTIVE_EVICTION_SWEEPER_EXECUTOR != null) {
+            PROACTIVE_EVICTION_SWEEPER_EXECUTOR.shutdownNow();
+          }
+        }
+      });
+    }
+
+    protected Impl(Configuration conf) {
+      proactiveEvictionEnabled = HiveConf.getBoolVar(conf, 
HiveConf.ConfVars.LLAP_IO_PROACTIVE_EVICTION_ENABLED);
+      proactiveEvictionSweepIntervalInMs = HiveConf.getTimeVar(conf,
+          HiveConf.ConfVars.LLAP_IO_PROACTIVE_EVICTION_SWEEP_INTERVAL, 
TimeUnit.MILLISECONDS);
+
+      if (proactiveEvictionEnabled) {
+        PROACTIVE_EVICTION_SWEEPER_EXECUTOR.scheduleWithFixedDelay(new 
Runnable() {

Review comment:
       Do not we want to create the executor here?




----------------------------------------------------------------
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.

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


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

    Worklog Id:     (was: 510714)
    Time Spent: 0.5h  (was: 20m)

> Sweep phase for proactive cache eviction
> ----------------------------------------
>
>                 Key: HIVE-24341
>                 URL: https://issues.apache.org/jira/browse/HIVE-24341
>             Project: Hive
>          Issue Type: Sub-task
>            Reporter: Ádám Szita
>            Assignee: Ádám Szita
>            Priority: Major
>              Labels: pull-request-available
>          Time Spent: 0.5h
>  Remaining Estimate: 0h
>




--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to