Source:
<code>abstract protected MutationState mutate(StatementContext parentContext, ResultIterator iterator, PhoenixConnection connection) throws SQLException; @Override public PeekingResultIterator newIterator(final StatementContext parentContext, ResultIterator iterator, Scan scan, String tableName, QueryPlan plan) throws SQLException { final PhoenixConnection clonedConnection = new PhoenixConnection(this.connection); connection.addChildConnection(clonedConnection); <START> System.out.println("MutatingParallelIteratorFactor making cloned connections."); <END> try { MutationState state = mutate(parentContext, iterator, clonedConnection); final long totalRowCount = state.getUpdateCount(); final boolean autoFlush = connection.getAutoCommit() || plan.getTableRef().getTable().isTransactional(); if (autoFlush) { clonedConnection.getMutationState().join(state); state = clonedConnection.getMutationState(); } final MutationState finalState = state; byte[] value = PLong.INSTANCE.toBytes(totalRowCount); KeyValue keyValue = KeyValueUtil.newKeyValue(UNGROUPED_AGG_ROW_KEY, SINGLE_COLUMN_FAMILY, SINGLE_COLUMN, AGG_TIMESTAMP, value, 0, value.length); final Tuple tuple = new SingleKeyValueTuple(keyValue); return new PeekingResultIterator() { private boolean done = false; @Override public Tuple next() { if (done) { return null; } done = true; return tuple; } @Override public void explain(List<String> planSteps) { } @Override public void close() throws SQLException { try { MutatingParallelIteratorFactory.this.connection.getMutationState() .join(finalState); } finally { clonedConnection.close(); } } @Override public Tuple peek() { return done ? null : tuple; } }; } catch (Throwable ex) { try { clonedConnection.close(); } catch (SQLException sqlEx) { LOGGER.error("Closing cloned Phoenix connection inside iterator, failed with: ", sqlEx); } throw ex; } }</code><technical_language>@dbwong Left this print here</technical_language>

Target:
abstract protected MutationState mutate(StatementContext parentContext, ResultIterator iterator, PhoenixConnection connection) throws SQLException; @Override public PeekingResultIterator newIterator(final StatementContext parentContext, ResultIterator iterator, Scan scan, String tableName, QueryPlan plan) throws SQLException { final PhoenixConnection clonedConnection = new PhoenixConnection(this.connection); connection.addChildConnection(clonedConnection); try { MutationState state = mutate(parentContext, iterator, clonedConnection); final long totalRowCount = state.getUpdateCount(); final boolean autoFlush = connection.getAutoCommit() || plan.getTableRef().getTable().isTransactional(); if (autoFlush) { clonedConnection.getMutationState().join(state); state = clonedConnection.getMutationState(); } final MutationState finalState = state; byte[] value = PLong.INSTANCE.toBytes(totalRowCount); KeyValue keyValue = KeyValueUtil.newKeyValue(UNGROUPED_AGG_ROW_KEY, SINGLE_COLUMN_FAMILY, SINGLE_COLUMN, AGG_TIMESTAMP, value, 0, value.length); final Tuple tuple = new SingleKeyValueTuple(keyValue); return new PeekingResultIterator() { private boolean done = false; @Override public Tuple next() { if (done) { return null; } done = true; return tuple; } @Override public void explain(List<String> planSteps) { } @Override public void close() throws SQLException { try { MutatingParallelIteratorFactory.this.connection.getMutationState() .join(finalState); } finally { clonedConnection.close(); } } @Override public Tuple peek() { return done ? null : tuple; } }; } catch (Throwable ex) { try { clonedConnection.close(); } catch (SQLException sqlEx) { LOGGER.error("Closing cloned Phoenix connection inside iterator, failed with: ", sqlEx); } throw ex; } }