ygerzhedovich commented on a change in pull request #652:
URL: https://github.com/apache/ignite-3/pull/652#discussion_r803862941
##########
File path:
modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/prepare/QueryPlanCacheImpl.java
##########
@@ -18,50 +18,99 @@
package org.apache.ignite.internal.sql.engine.prepare;
import com.github.benmanes.caffeine.cache.Caffeine;
-import java.util.Map;
+import java.util.concurrent.BlockingQueue;
+import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ConcurrentMap;
+import java.util.concurrent.LinkedBlockingQueue;
+import java.util.concurrent.ThreadPoolExecutor;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.locks.ReadWriteLock;
+import java.util.concurrent.locks.ReentrantReadWriteLock;
import java.util.function.Supplier;
+import org.apache.ignite.internal.thread.NamedThreadFactory;
/**
* Implementation of {@link QueryPlanCache} that simply wraps a {@link
Caffeine} cache.
*/
public class QueryPlanCacheImpl implements QueryPlanCache {
- private final ConcurrentMap<CacheKey, QueryPlan> cache;
+ private static final long THREAD_TIMEOUT_MS = 60_000;
+
+ private final ConcurrentMap<CacheKey, CompletableFuture<QueryPlan>> cache;
+
+ private final ThreadPoolExecutor planningPool;
+
+ private final BlockingQueue<Runnable> planningTasks = new
LinkedBlockingQueue<>();
+
+ private final ReadWriteLock lock = new ReentrantReadWriteLock();
/**
* Creates a plan cache of provided size.
*
* @param cacheSize Desired cache size.
*/
- public QueryPlanCacheImpl(int cacheSize) {
+ public QueryPlanCacheImpl(String nodeName, int cacheSize) {
+ planningPool = new ThreadPoolExecutor(
+ 4,
+ 4,
+ THREAD_TIMEOUT_MS,
+ TimeUnit.MILLISECONDS,
+ planningTasks,
+ new
NamedThreadFactory(NamedThreadFactory.threadPrefix(nodeName, "sqlPlan"))
+ );
+
+ planningPool.allowCoreThreadTimeOut(true);
+
cache = Caffeine.newBuilder()
.maximumSize(cacheSize)
- .<CacheKey, QueryPlan>build()
+ .<CacheKey, CompletableFuture<QueryPlan>>build()
.asMap();
}
/** {@inheritDoc} */
@Override
public QueryPlan queryPlan(CacheKey key, Supplier<QueryPlan> planSupplier)
{
- Map<CacheKey, QueryPlan> cache = this.cache;
- QueryPlan plan = cache.computeIfAbsent(key, k -> planSupplier.get());
+ lock.readLock().lock();
Review comment:
why not write lock?
--
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]