[ 
https://issues.apache.org/jira/browse/HBASE-8218?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13617271#comment-13617271
 ] 

Jean-Marc Spaggiari commented on HBASE-8218:
--------------------------------------------

[[email protected]] I'm not sure this is a clean solution.

This is the signature of AggregationClient.max():
public <R, S> R max(final byte[] tableName, final ColumnInterpreter<R, S> ci, 
final Scan scan)

If we add setHTable(HTable) to ignore the tableName parameter, many will miss 
that might wonder why tableName is not used. Is it nos better "duplicte" the 
methods and make one calling the other one?

Something like that where we keep the current signature and introduce the new 
option too?

{code}
  /**
   * It gives the maximum value of a column for a given column family for the
   * given range. In case qualifier is null, a max of all values for the given
   * family is returned.
   * @param tableName
   * @param ci
   * @param scan
   * @return max val <R>
   * @throws Throwable
   *           The caller is supposed to handle the exception as they are thrown
   *           & propagated to it.
   */
  public <R, S> R max(final byte[] tableName, final ColumnInterpreter<R, S> ci,
      final Scan scan) throws Throwable {
    HTable table = null;
    try {
      table = new HTable(conf, tableName);
      return max(table, ci, scan);
    } finally {
      if (table != null) {
        table.close();
      }
    }
  }

  /**
   * It gives the maximum value of a column for a given column family for the
   * given range. In case qualifier is null, a max of all values for the given
   * family is returned.
   * @param table
   * @param ci
   * @param scan
   * @return max val <R>
   * @throws Throwable
   *           The caller is supposed to handle the exception as they are thrown
   *           & propagated to it.
   */
  public <R, S> R max(final HTable table, final ColumnInterpreter<R, S> ci,
      final Scan scan) throws Throwable {
    validateParameters(scan);
    class MaxCallBack implements Batch.Callback<R> {
      R max = null;

      R getMax() {
        return max;
      }

      @Override
      public synchronized void update(byte[] region, byte[] row, R result) {
        max = (max == null || (result != null && ci.compare(max, result) < 0)) 
? result : max;
      }
    }
    MaxCallBack aMaxCallBack = new MaxCallBack();
    table.coprocessorExec(AggregateProtocol.class, scan.getStartRow(),
        scan.getStopRow(), new Batch.Call<AggregateProtocol, R>() {
          @Override
          public R call(AggregateProtocol instance) throws IOException {
            return instance.getMax(ci, scan);
          }
        }, aMaxCallBack);
    return aMaxCallBack.getMax();
  }
{code}

                
> pass HTable as a parameter to method of AggregationClient
> ---------------------------------------------------------
>
>                 Key: HBASE-8218
>                 URL: https://issues.apache.org/jira/browse/HBASE-8218
>             Project: HBase
>          Issue Type: Improvement
>          Components: Client, Coprocessors
>    Affects Versions: 0.94.3
>            Reporter: cuijianwei
>
> In AggregationClient, methods such as max(...), min(...) pass 'tableName' as 
> a parameter, then a HTable will be created in the method, before the method 
> return, the created HTable will be closed.
> The process above may be heavy because each call must create and close a 
> HTable. The situation becomes worse when there is only one thread access 
> HBase using AggregationClient. The underly HConnection of created HTable will 
> also be created and then closed each time when we invoke these method because 
> no other HTables using the HConnection. This operation is heavy. Therefore, 
> can we add another group of methods which pass HTable or HTablePool as a 
> parameter to methods defined in AggregationClient? 

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

Reply via email to