Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 454D2200CC8 for ; Fri, 14 Jul 2017 23:24:42 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 43A7F16E825; Fri, 14 Jul 2017 21:24:42 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 88C5116E824 for ; Fri, 14 Jul 2017 23:24:41 +0200 (CEST) Received: (qmail 16353 invoked by uid 500); 14 Jul 2017 21:24:40 -0000 Mailing-List: contact commits-help@phoenix.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@phoenix.apache.org Delivered-To: mailing list commits@phoenix.apache.org Received: (qmail 16344 invoked by uid 99); 14 Jul 2017 21:24:40 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 14 Jul 2017 21:24:40 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 88DDFEE68C; Fri, 14 Jul 2017 21:24:40 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: samarth@apache.org To: commits@phoenix.apache.org Message-Id: <95be6b854fb14df5a03cdb545396bccc@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: phoenix git commit: PHOENIX-4024 Renew lease thread names should be unique across various ConnectionQueryServices instances Date: Fri, 14 Jul 2017 21:24:40 +0000 (UTC) archived-at: Fri, 14 Jul 2017 21:24:42 -0000 Repository: phoenix Updated Branches: refs/heads/master ce52c37f0 -> 3477977f3 PHOENIX-4024 Renew lease thread names should be unique across various ConnectionQueryServices instances Project: http://git-wip-us.apache.org/repos/asf/phoenix/repo Commit: http://git-wip-us.apache.org/repos/asf/phoenix/commit/3477977f Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/3477977f Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/3477977f Branch: refs/heads/master Commit: 3477977f3589e5458013715652953a6aa1697814 Parents: ce52c37 Author: Samarth Jain Authored: Fri Jul 14 14:24:35 2017 -0700 Committer: Samarth Jain Committed: Fri Jul 14 14:24:35 2017 -0700 ---------------------------------------------------------------------- .../query/ConnectionQueryServicesImpl.java | 25 ++++++++++++++++---- 1 file changed, 20 insertions(+), 5 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/phoenix/blob/3477977f/phoenix-core/src/main/java/org/apache/phoenix/query/ConnectionQueryServicesImpl.java ---------------------------------------------------------------------- diff --git a/phoenix-core/src/main/java/org/apache/phoenix/query/ConnectionQueryServicesImpl.java b/phoenix-core/src/main/java/org/apache/phoenix/query/ConnectionQueryServicesImpl.java index 3e8eb07..1789318 100644 --- a/phoenix-core/src/main/java/org/apache/phoenix/query/ConnectionQueryServicesImpl.java +++ b/phoenix-core/src/main/java/org/apache/phoenix/query/ConnectionQueryServicesImpl.java @@ -93,6 +93,7 @@ import java.util.concurrent.ThreadLocalRandom; import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; import java.util.concurrent.atomic.AtomicBoolean; +import java.util.concurrent.atomic.AtomicInteger; import javax.annotation.concurrent.GuardedBy; @@ -305,6 +306,11 @@ public class ConnectionQueryServicesImpl extends DelegateQueryServices implement // List of queues instead of a single queue to provide reduced contention via lock striping private final List>> connectionQueues; private ScheduledExecutorService renewLeaseExecutor; + /* + * We can have multiple instances of ConnectionQueryServices. By making the thread factory + * static, renew lease thread names will be unique across them. + */ + private static final ThreadFactory renewLeaseThreadFactory = new RenewLeaseThreadFactory(); private final boolean renewLeaseEnabled; private final boolean isAutoUpgradeEnabled; private final AtomicBoolean upgradeRequired = new AtomicBoolean(false); @@ -3326,18 +3332,27 @@ public class ConnectionQueryServicesImpl extends DelegateQueryServices implement private void scheduleRenewLeaseTasks() { if (isRenewingLeasesEnabled()) { - ThreadFactory threadFactory = - new ThreadFactoryBuilder().setDaemon(true) - .setNameFormat("PHOENIX-SCANNER-RENEW-LEASE" + "-thread-%s").build(); renewLeaseExecutor = - Executors.newScheduledThreadPool(renewLeasePoolSize, threadFactory); + Executors.newScheduledThreadPool(renewLeasePoolSize, renewLeaseThreadFactory); for (LinkedBlockingQueue> q : connectionQueues) { renewLeaseExecutor.scheduleAtFixedRate(new RenewLeaseTask(q), 0, - renewLeaseTaskFrequency, TimeUnit.MILLISECONDS); + renewLeaseTaskFrequency, TimeUnit.MILLISECONDS); } } } + private static class RenewLeaseThreadFactory implements ThreadFactory { + private static final AtomicInteger threadNumber = new AtomicInteger(1); + private static final String NAME_PREFIX = "PHOENIX-SCANNER-RENEW-LEASE-thread-"; + + @Override + public Thread newThread(Runnable r) { + Thread t = new Thread(r, NAME_PREFIX + threadNumber.getAndIncrement()); + t.setDaemon(true); + return t; + } + } + private static int getSaltBuckets(TableAlreadyExistsException e) { PTable table = e.getTable(); Integer sequenceSaltBuckets = table == null ? null : table.getBucketNum();