Repository: phoenix Updated Branches: refs/heads/4.x-HBase-0.98 211f1ebc7 -> 683aef7a8
PHOENIX-3980 Wrap iterator returned by BaseQueryPlan so that it always closes dependencies Project: http://git-wip-us.apache.org/repos/asf/phoenix/repo Commit: http://git-wip-us.apache.org/repos/asf/phoenix/commit/683aef7a Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/683aef7a Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/683aef7a Branch: refs/heads/4.x-HBase-0.98 Commit: 683aef7a8c51bfb530c1abe3c9f3d1a6c9de6756 Parents: 211f1eb Author: Thomas <[email protected]> Authored: Tue Jun 27 20:02:22 2017 -0700 Committer: Thomas <[email protected]> Committed: Wed Jun 28 11:42:58 2017 -0700 ---------------------------------------------------------------------- .../ConnectionQueryServicesTestImpl.java | 4 +-- .../apache/phoenix/execute/BaseQueryPlan.java | 33 +++++++++++--------- 2 files changed, 20 insertions(+), 17 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/phoenix/blob/683aef7a/phoenix-core/src/it/java/org/apache/phoenix/end2end/ConnectionQueryServicesTestImpl.java ---------------------------------------------------------------------- diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/ConnectionQueryServicesTestImpl.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/ConnectionQueryServicesTestImpl.java index 5b64c98..a1ad1ad 100644 --- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/ConnectionQueryServicesTestImpl.java +++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/ConnectionQueryServicesTestImpl.java @@ -70,8 +70,8 @@ public class ConnectionQueryServicesTestImpl extends ConnectionQueryServicesImpl this.connections = Sets.newHashSet(); } SQLCloseables.closeAll(connections); - // long unfreedBytes = clearCache(); - // assertEquals("Found unfreed bytes in server-side cache", 0, unfreedBytes); + long unfreedBytes = clearCache(); + assertEquals("Found unfreed bytes in server-side cache", 0, unfreedBytes); } finally { super.close(); } http://git-wip-us.apache.org/repos/asf/phoenix/blob/683aef7a/phoenix-core/src/main/java/org/apache/phoenix/execute/BaseQueryPlan.java ---------------------------------------------------------------------- diff --git a/phoenix-core/src/main/java/org/apache/phoenix/execute/BaseQueryPlan.java b/phoenix-core/src/main/java/org/apache/phoenix/execute/BaseQueryPlan.java index 15af929..dae00fd 100644 --- a/phoenix-core/src/main/java/org/apache/phoenix/execute/BaseQueryPlan.java +++ b/phoenix-core/src/main/java/org/apache/phoenix/execute/BaseQueryPlan.java @@ -208,6 +208,21 @@ public abstract class BaseQueryPlan implements QueryPlan { public final ResultIterator iterator(ParallelScanGrouper scanGrouper, Scan scan) throws SQLException { return iterator(Collections.<SQLCloseable>emptyList(), scanGrouper, scan); } + + private ResultIterator getWrappedIterator(final List<? extends SQLCloseable> dependencies, + ResultIterator iterator) { + ResultIterator wrappedIterator = dependencies.isEmpty() ? iterator : new DelegateResultIterator(iterator) { + @Override + public void close() throws SQLException { + try { + super.close(); + } finally { + SQLCloseables.closeAll(dependencies); + } + } + }; + return wrappedIterator; + } public final ResultIterator iterator(final List<? extends SQLCloseable> dependencies, ParallelScanGrouper scanGrouper, Scan scan) throws SQLException { if (scan == null) { @@ -220,11 +235,11 @@ public abstract class BaseQueryPlan implements QueryPlan { * row to be scanned. */ if (context.getScanRanges() == ScanRanges.NOTHING && !getStatement().isAggregate()) { - return ResultIterator.EMPTY_ITERATOR; + return getWrappedIterator(dependencies, ResultIterator.EMPTY_ITERATOR); } if (tableRef == TableRef.EMPTY_TABLE_REF) { - return newIterator(scanGrouper, scan); + return getWrappedIterator(dependencies, newIterator(scanGrouper, scan)); } // Set miscellaneous scan attributes. This is the last chance to set them before we @@ -327,19 +342,7 @@ public abstract class BaseQueryPlan implements QueryPlan { LOG.debug(LogUtil.addCustomAnnotations("Scan ready for iteration: " + scan, connection)); } - ResultIterator iterator = newIterator(scanGrouper, scan); - iterator = dependencies.isEmpty() ? - iterator : new DelegateResultIterator(iterator) { - @Override - public void close() throws SQLException { - try { - super.close(); - } finally { - SQLCloseables.closeAll(dependencies); - } - } - }; - + ResultIterator iterator = getWrappedIterator(dependencies, newIterator(scanGrouper, scan)); if (LOG.isDebugEnabled()) { LOG.debug(LogUtil.addCustomAnnotations("Iterator ready: " + iterator, connection)); }
