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 28C48200BEA for ; Mon, 12 Dec 2016 21:03:05 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id 253EE160B2D; Mon, 12 Dec 2016 20:03:05 +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 75F7C160B1A for ; Mon, 12 Dec 2016 21:03:04 +0100 (CET) Received: (qmail 43836 invoked by uid 500); 12 Dec 2016 20:03:03 -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 43820 invoked by uid 99); 12 Dec 2016 20:03:03 -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; Mon, 12 Dec 2016 20:03:03 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 9099CE9411; Mon, 12 Dec 2016 20:03:03 +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 Date: Mon, 12 Dec 2016 20:03:03 -0000 Message-Id: X-Mailer: ASF-Git Admin Mailer Subject: [1/2] phoenix git commit: Memory Leak in RenewLeaseTask archived-at: Mon, 12 Dec 2016 20:03:05 -0000 Repository: phoenix Updated Branches: refs/heads/4.x-HBase-1.1 8e0abfbbf -> 7c52cd702 Memory Leak in RenewLeaseTask Project: http://git-wip-us.apache.org/repos/asf/phoenix/repo Commit: http://git-wip-us.apache.org/repos/asf/phoenix/commit/7fba1285 Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/7fba1285 Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/7fba1285 Branch: refs/heads/4.x-HBase-1.1 Commit: 7fba1285bff20db546deb948489c6307b6e1e40f Parents: 8e0abfb Author: Samarth Authored: Mon Dec 12 12:02:22 2016 -0800 Committer: Samarth Committed: Mon Dec 12 12:02:22 2016 -0800 ---------------------------------------------------------------------- .../query/ConnectionQueryServicesImpl.java | 33 +++++++++++++++----- 1 file changed, 25 insertions(+), 8 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/phoenix/blob/7fba1285/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 d94a20e..edf12a8 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 @@ -3867,6 +3867,12 @@ public class ConnectionQueryServicesImpl extends DelegateQueryServices implement private void waitForRandomDuration() throws InterruptedException { new CountDownLatch(1).await(random.nextInt(MAX_WAIT_TIME), MILLISECONDS); } + + private static class InternalRenewLeaseTaskException extends Exception { + public InternalRenewLeaseTaskException(String msg) { + super(msg); + } + } @Override public void run() { @@ -3888,7 +3894,7 @@ public class ConnectionQueryServicesImpl extends DelegateQueryServices implement WeakReference connRef = connectionsQueue.poll(1, TimeUnit.MILLISECONDS); if (connRef == null) { - throw new IllegalStateException( + throw new InternalRenewLeaseTaskException( "Connection ref found to be null. This is a bug. Some other thread removed items from the connection queue."); } PhoenixConnection conn = connRef.get(); @@ -3907,7 +3913,7 @@ public class ConnectionQueryServicesImpl extends DelegateQueryServices implement WeakReference ref = scannerQueue.poll(1, TimeUnit.MILLISECONDS); if (ref == null) { - throw new IllegalStateException( + throw new InternalRenewLeaseTaskException( "TableResulIterator ref found to be null. This is a bug. Some other thread removed items from the scanner queue."); } TableResultIterator scanningItr = ref.get(); @@ -3944,13 +3950,24 @@ public class ConnectionQueryServicesImpl extends DelegateQueryServices implement } numConnections--; } - } catch (InterruptedException e1) { + } catch (InternalRenewLeaseTaskException e) { + logger.error("Exception thrown when renewing lease. Draining the queue of scanners ", e); + // clear up the queue since the task is about to be unscheduled. + connectionsQueue.clear(); + // throw an exception since we want the task execution to be suppressed because we just encountered an + // exception that happened because of a bug. + throw new RuntimeException(e); + } catch (InterruptedException e) { Thread.currentThread().interrupt(); // restore the interrupt status - logger.warn("Thread interrupted when renewing lease ", e1); - throw new RuntimeException(e1); - } catch (Exception e2) { - logger.warn("Exception thrown when renewing lease ", e2); - throw new RuntimeException(e2); + logger.error("Thread interrupted when renewing lease.", e); + } catch (Exception e) { + logger.error("Exception thrown when renewing lease ", e); + // don't drain the queue and swallow the exception in this case since we don't want the task + // execution to be suppressed because renewing lease of a scanner failed. + } catch (Throwable e) { + logger.error("Exception thrown when renewing lease. Draining the queue of scanners ", e); + connectionsQueue.clear(); // clear up the queue since the task is about to be unscheduled. + throw new RuntimeException(e); } } }