001/**
002 *
003 * Licensed to the Apache Software Foundation (ASF) under one
004 * or more contributor license agreements.  See the NOTICE file
005 * distributed with this work for additional information
006 * regarding copyright ownership.  The ASF licenses this file
007 * to you under the Apache License, Version 2.0 (the
008 * "License"); you may not use this file except in compliance
009 * with the License.  You may obtain a copy of the License at
010 *
011 *     http://www.apache.org/licenses/LICENSE-2.0
012 *
013 * Unless required by applicable law or agreed to in writing, software
014 * distributed under the License is distributed on an "AS IS" BASIS,
015 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
016 * See the License for the specific language governing permissions and
017 * limitations under the License.
018 */
019package org.apache.hadoop.hbase.client;
020
021import java.io.Closeable;
022import java.io.IOException;
023import java.util.List;
024import java.util.Map;
025import java.util.concurrent.TimeUnit;
026
027import org.apache.hadoop.conf.Configuration;
028import org.apache.hadoop.hbase.CompareOperator;
029import org.apache.hadoop.hbase.HTableDescriptor;
030import org.apache.hadoop.hbase.TableName;
031import org.apache.yetus.audience.InterfaceAudience;
032import org.apache.hadoop.hbase.client.coprocessor.Batch;
033import org.apache.hadoop.hbase.filter.CompareFilter;
034import org.apache.hadoop.hbase.ipc.CoprocessorRpcChannel;
035
036import com.google.protobuf.Descriptors;
037import com.google.protobuf.Message;
038import com.google.protobuf.Service;
039import com.google.protobuf.ServiceException;
040
041/**
042 * Used to communicate with a single HBase table.
043 * Obtain an instance from a {@link Connection} and call {@link #close()} afterwards.
044 *
045 * <p>Table can be used to get, put, delete or scan data from a table.
046 * @see ConnectionFactory
047 * @see Connection
048 * @see Admin
049 * @see RegionLocator
050 * @since 0.99.0
051 */
052@InterfaceAudience.Public
053public interface Table extends Closeable {
054  /**
055   * Gets the fully qualified table name instance of this table.
056   */
057  TableName getName();
058
059  /**
060   * Returns the {@link org.apache.hadoop.conf.Configuration} object used by this instance.
061   * <p>
062   * The reference returned is not a copy, so any change made to it will
063   * affect this instance.
064   */
065  Configuration getConfiguration();
066
067  /**
068   * Gets the {@link org.apache.hadoop.hbase.HTableDescriptor table descriptor} for this table.
069   * @throws java.io.IOException if a remote or network exception occurs.
070   * @deprecated since 2.0 version and will be removed in 3.0 version.
071   *             use {@link #getDescriptor()}
072   */
073  @Deprecated
074  HTableDescriptor getTableDescriptor() throws IOException;
075
076  /**
077   * Gets the {@link org.apache.hadoop.hbase.client.TableDescriptor table descriptor} for this table.
078   * @throws java.io.IOException if a remote or network exception occurs.
079   */
080  TableDescriptor getDescriptor() throws IOException;
081
082  /**
083   * Test for the existence of columns in the table, as specified by the Get.
084   * <p>
085   *
086   * This will return true if the Get matches one or more keys, false if not.
087   * <p>
088   *
089   * This is a server-side call so it prevents any data from being transfered to
090   * the client.
091   *
092   * @param get the Get
093   * @return true if the specified Get matches one or more keys, false if not
094   * @throws IOException e
095   */
096  boolean exists(Get get) throws IOException;
097
098  /**
099   * Test for the existence of columns in the table, as specified by the Gets.
100   * <p>
101   *
102   * This will return an array of booleans. Each value will be true if the related Get matches
103   * one or more keys, false if not.
104   * <p>
105   *
106   * This is a server-side call so it prevents any data from being transferred to
107   * the client.
108   *
109   * @param gets the Gets
110   * @return Array of boolean.  True if the specified Get matches one or more keys, false if not.
111   * @throws IOException e
112   */
113  boolean[] exists(List<Get> gets) throws IOException;
114
115  /**
116   * Test for the existence of columns in the table, as specified by the Gets.
117   * This will return an array of booleans. Each value will be true if the related Get matches
118   * one or more keys, false if not.
119   * This is a server-side call so it prevents any data from being transferred to
120   * the client.
121   *
122   * @param gets the Gets
123   * @return Array of boolean.  True if the specified Get matches one or more keys, false if not.
124   * @throws IOException e
125   * @deprecated since 2.0 version and will be removed in 3.0 version.
126   *             use {@link #exists(List)}
127   */
128  @Deprecated
129  default boolean[] existsAll(List<Get> gets) throws IOException {
130    return exists(gets);
131  }
132
133  /**
134   * Method that does a batch call on Deletes, Gets, Puts, Increments, Appends, RowMutations.
135   * The ordering of execution of the actions is not defined. Meaning if you do a Put and a
136   * Get in the same {@link #batch} call, you will not necessarily be
137   * guaranteed that the Get returns what the Put had put.
138   *
139   * @param actions list of Get, Put, Delete, Increment, Append, RowMutations.
140   * @param results Empty Object[], same size as actions. Provides access to partial
141   *                results, in case an exception is thrown. A null in the result array means that
142   *                the call for that action failed, even after retries. The order of the objects
143   *                in the results array corresponds to the order of actions in the request list.
144   * @throws IOException
145   * @since 0.90.0
146   */
147  void batch(final List<? extends Row> actions, final Object[] results) throws IOException,
148    InterruptedException;
149
150  /**
151   * Same as {@link #batch(List, Object[])}, but with a callback.
152   * @since 0.96.0
153   */
154  <R> void batchCallback(
155    final List<? extends Row> actions, final Object[] results, final Batch.Callback<R> callback
156  ) throws IOException, InterruptedException;
157
158  /**
159   * Extracts certain cells from a given row.
160   * @param get The object that specifies what data to fetch and from which row.
161   * @return The data coming from the specified row, if it exists.  If the row
162   * specified doesn't exist, the {@link Result} instance returned won't
163   * contain any {@link org.apache.hadoop.hbase.KeyValue}, as indicated by {@link Result#isEmpty()}.
164   * @throws IOException if a remote or network exception occurs.
165   * @since 0.20.0
166   */
167  Result get(Get get) throws IOException;
168
169  /**
170   * Extracts specified cells from the given rows, as a batch.
171   *
172   * @param gets The objects that specify what data to fetch and from which rows.
173   * @return The data coming from the specified rows, if it exists.  If the row specified doesn't
174   * exist, the {@link Result} instance returned won't contain any {@link
175   * org.apache.hadoop.hbase.Cell}s, as indicated by {@link Result#isEmpty()}. If there are any
176   * failures even after retries, there will be a <code>null</code> in the results' array for those
177   * Gets, AND an exception will be thrown. The ordering of the Result array corresponds to the order
178   * of the list of passed in Gets.
179   * @throws IOException if a remote or network exception occurs.
180   * @since 0.90.0
181   * @apiNote {@link #put(List)} runs pre-flight validations on the input list on client.
182   * Currently {@link #get(List)} doesn't run any validations on the client-side, currently there
183   * is no need, but this may change in the future. An
184   * {@link IllegalArgumentException} will be thrown in this case.
185   */
186  Result[] get(List<Get> gets) throws IOException;
187
188  /**
189   * Returns a scanner on the current table as specified by the {@link Scan}
190   * object.
191   * Note that the passed {@link Scan}'s start row and caching properties
192   * maybe changed.
193   *
194   * @param scan A configured {@link Scan} object.
195   * @return A scanner.
196   * @throws IOException if a remote or network exception occurs.
197   * @since 0.20.0
198   */
199  ResultScanner getScanner(Scan scan) throws IOException;
200
201  /**
202   * Gets a scanner on the current table for the given family.
203   *
204   * @param family The column family to scan.
205   * @return A scanner.
206   * @throws IOException if a remote or network exception occurs.
207   * @since 0.20.0
208   */
209  ResultScanner getScanner(byte[] family) throws IOException;
210
211  /**
212   * Gets a scanner on the current table for the given family and qualifier.
213   *
214   * @param family The column family to scan.
215   * @param qualifier The column qualifier to scan.
216   * @return A scanner.
217   * @throws IOException if a remote or network exception occurs.
218   * @since 0.20.0
219   */
220  ResultScanner getScanner(byte[] family, byte[] qualifier) throws IOException;
221
222
223  /**
224   * Puts some data in the table.
225   *
226   * @param put The data to put.
227   * @throws IOException if a remote or network exception occurs.
228   * @since 0.20.0
229   */
230  void put(Put put) throws IOException;
231
232  /**
233   * Batch puts the specified data into the table.
234   * <p>
235   * This can be used for group commit, or for submitting user defined batches. Before sending
236   * a batch of mutations to the server, the client runs a few validations on the input list. If an
237   * error is found, for example, a mutation was supplied but was missing it's column an
238   * {@link IllegalArgumentException} will be thrown and no mutations will be applied. If there
239   * are any failures even after retries, a {@link RetriesExhaustedWithDetailsException} will be
240   * thrown. RetriesExhaustedWithDetailsException contains lists of failed mutations and
241   * corresponding remote exceptions. The ordering of mutations and exceptions in the
242   * encapsulating exception corresponds to the order of the input list of Put requests.
243   *
244   * @param puts The list of mutations to apply.
245   * @throws IOException if a remote or network exception occurs.
246   * @since 0.20.0
247   */
248  void put(List<Put> puts) throws IOException;
249
250  /**
251   * Atomically checks if a row/family/qualifier value matches the expected
252   * value. If it does, it adds the put.  If the passed value is null, the check
253   * is for the lack of column (ie: non-existance)
254   *
255   * @param row to check
256   * @param family column family to check
257   * @param qualifier column qualifier to check
258   * @param value the expected value
259   * @param put data to put if check succeeds
260   * @throws IOException e
261   * @return true if the new put was executed, false otherwise
262   * @deprecated Since 2.0.0. Will be removed in 3.0.0. Use {@link #checkAndMutate(byte[], byte[])}
263   */
264  @Deprecated
265  boolean checkAndPut(byte[] row, byte[] family, byte[] qualifier,
266      byte[] value, Put put) throws IOException;
267
268  /**
269   * Atomically checks if a row/family/qualifier value matches the expected
270   * value. If it does, it adds the put.  If the passed value is null, the check
271   * is for the lack of column (ie: non-existence)
272   *
273   * The expected value argument of this call is on the left and the current
274   * value of the cell is on the right side of the comparison operator.
275   *
276   * Ie. eg. GREATER operator means expected value > existing <=> add the put.
277   *
278   * @param row to check
279   * @param family column family to check
280   * @param qualifier column qualifier to check
281   * @param compareOp comparison operator to use
282   * @param value the expected value
283   * @param put data to put if check succeeds
284   * @throws IOException e
285   * @return true if the new put was executed, false otherwise
286   * @deprecated Since 2.0.0. Will be removed in 3.0.0. Use {@link #checkAndMutate(byte[], byte[])}
287   */
288  @Deprecated
289  boolean checkAndPut(byte[] row, byte[] family, byte[] qualifier,
290      CompareFilter.CompareOp compareOp, byte[] value, Put put) throws IOException;
291
292  /**
293   * Atomically checks if a row/family/qualifier value matches the expected
294   * value. If it does, it adds the put.  If the passed value is null, the check
295   * is for the lack of column (ie: non-existence)
296   *
297   * The expected value argument of this call is on the left and the current
298   * value of the cell is on the right side of the comparison operator.
299   *
300   * Ie. eg. GREATER operator means expected value > existing <=> add the put.
301   *
302   * @param row to check
303   * @param family column family to check
304   * @param qualifier column qualifier to check
305   * @param op comparison operator to use
306   * @param value the expected value
307   * @param put data to put if check succeeds
308   * @throws IOException e
309   * @return true if the new put was executed, false otherwise
310   * @deprecated Since 2.0.0. Will be removed in 3.0.0. Use {@link #checkAndMutate(byte[], byte[])}
311   */
312  @Deprecated
313  boolean checkAndPut(byte[] row, byte[] family, byte[] qualifier, CompareOperator op,
314      byte[] value, Put put) throws IOException;
315
316  /**
317   * Deletes the specified cells/row.
318   *
319   * @param delete The object that specifies what to delete.
320   * @throws IOException if a remote or network exception occurs.
321   * @since 0.20.0
322   */
323  void delete(Delete delete) throws IOException;
324
325  /**
326   * Batch Deletes the specified cells/rows from the table.
327   * <p>
328   * If a specified row does not exist, {@link Delete} will report as though sucessful
329   * delete; no exception will be thrown. If there are any failures even after retries,
330   * a * {@link RetriesExhaustedWithDetailsException} will be thrown.
331   * RetriesExhaustedWithDetailsException contains lists of failed {@link Delete}s and
332   * corresponding remote exceptions.
333   *
334   * @param deletes List of things to delete. The input list gets modified by this
335   * method. All successfully applied {@link Delete}s in the list are removed (in particular it
336   * gets re-ordered, so the order in which the elements are inserted in the list gives no
337   * guarantee as to the order in which the {@link Delete}s are executed).
338   * @throws IOException if a remote or network exception occurs. In that case
339   * the {@code deletes} argument will contain the {@link Delete} instances
340   * that have not be successfully applied.
341   * @since 0.20.1
342   * @apiNote In 3.0.0 version, the input list {@code deletes} will no longer be modified. Also,
343   * {@link #put(List)} runs pre-flight validations on the input list on client. Currently
344   * {@link #delete(List)} doesn't run validations on the client, there is no need currently,
345   * but this may change in the future. An * {@link IllegalArgumentException} will be thrown
346   * in this case.
347   */
348  void delete(List<Delete> deletes) throws IOException;
349
350  /**
351   * Atomically checks if a row/family/qualifier value matches the expected
352   * value. If it does, it adds the delete.  If the passed value is null, the
353   * check is for the lack of column (ie: non-existance)
354   *
355   * @param row to check
356   * @param family column family to check
357   * @param qualifier column qualifier to check
358   * @param value the expected value
359   * @param delete data to delete if check succeeds
360   * @throws IOException e
361   * @return true if the new delete was executed, false otherwise
362   * @deprecated Since 2.0.0. Will be removed in 3.0.0. Use {@link #checkAndMutate(byte[], byte[])}
363   */
364  @Deprecated
365  boolean checkAndDelete(byte[] row, byte[] family, byte[] qualifier,
366    byte[] value, Delete delete) throws IOException;
367
368  /**
369   * Atomically checks if a row/family/qualifier value matches the expected
370   * value. If it does, it adds the delete.  If the passed value is null, the
371   * check is for the lack of column (ie: non-existence)
372   *
373   * The expected value argument of this call is on the left and the current
374   * value of the cell is on the right side of the comparison operator.
375   *
376   * Ie. eg. GREATER operator means expected value > existing <=> add the delete.
377   *
378   * @param row to check
379   * @param family column family to check
380   * @param qualifier column qualifier to check
381   * @param compareOp comparison operator to use
382   * @param value the expected value
383   * @param delete data to delete if check succeeds
384   * @throws IOException e
385   * @return true if the new delete was executed, false otherwise
386   * @deprecated Since 2.0.0. Will be removed in 3.0.0. Use {@link #checkAndMutate(byte[], byte[])}
387   */
388  @Deprecated
389  boolean checkAndDelete(byte[] row, byte[] family, byte[] qualifier,
390    CompareFilter.CompareOp compareOp, byte[] value, Delete delete) throws IOException;
391
392  /**
393   * Atomically checks if a row/family/qualifier value matches the expected
394   * value. If it does, it adds the delete.  If the passed value is null, the
395   * check is for the lack of column (ie: non-existence)
396   *
397   * The expected value argument of this call is on the left and the current
398   * value of the cell is on the right side of the comparison operator.
399   *
400   * Ie. eg. GREATER operator means expected value > existing <=> add the delete.
401   *
402   * @param row to check
403   * @param family column family to check
404   * @param qualifier column qualifier to check
405   * @param op comparison operator to use
406   * @param value the expected value
407   * @param delete data to delete if check succeeds
408   * @throws IOException e
409   * @return true if the new delete was executed, false otherwise
410   * @deprecated Since 2.0.0. Will be removed in 3.0.0. Use {@link #checkAndMutate(byte[], byte[])}
411   */
412  @Deprecated
413  boolean checkAndDelete(byte[] row, byte[] family, byte[] qualifier,
414                         CompareOperator op, byte[] value, Delete delete) throws IOException;
415
416  /**
417   * Atomically checks if a row/family/qualifier value matches the expected value. If it does, it
418   * adds the Put/Delete/RowMutations.
419   * <p>
420   * Use the returned {@link CheckAndMutateBuilder} to construct your request and then execute it.
421   * This is a fluent style API, the code is like:
422   *
423   * <pre>
424   * <code>
425   * table.checkAndMutate(row, family).qualifier(qualifier).ifNotExists().thenPut(put);
426   * </code>
427   * </pre>
428   */
429  CheckAndMutateBuilder checkAndMutate(byte[] row, byte[] family);
430  /**
431   * A helper class for sending checkAndMutate request.
432   */
433  interface CheckAndMutateBuilder {
434
435    /**
436     * @param qualifier column qualifier to check.
437     */
438    CheckAndMutateBuilder qualifier(byte[] qualifier);
439
440    /**
441     * Check for lack of column.
442     */
443    CheckAndMutateBuilder ifNotExists();
444
445    /**
446     * Check for equality.
447     * @param value the expected value
448     */
449    default CheckAndMutateBuilder ifEquals(byte[] value) {
450      return ifMatches(CompareOperator.EQUAL, value);
451    }
452
453    /**
454     * @param compareOp comparison operator to use
455     * @param value the expected value
456     */
457    CheckAndMutateBuilder ifMatches(CompareOperator compareOp, byte[] value);
458
459    /**
460     * @param put data to put if check succeeds
461     * @return {@code true} if the new put was executed, {@code false} otherwise.
462     */
463    boolean thenPut(Put put) throws IOException;
464
465    /**
466     * @param delete data to delete if check succeeds
467     * @return {@code true} if the new delete was executed, {@code false} otherwise.
468     */
469    boolean thenDelete(Delete delete) throws IOException;
470    /**
471     * @param mutation mutations to perform if check succeeds
472     * @return true if the new mutation was executed, false otherwise.
473     */
474    boolean thenMutate(RowMutations mutation) throws IOException;
475
476  }
477
478  /**
479   * Performs multiple mutations atomically on a single row. Currently
480   * {@link Put} and {@link Delete} are supported.
481   *
482   * @param rm object that specifies the set of mutations to perform atomically
483   * @throws IOException
484   */
485  void mutateRow(final RowMutations rm) throws IOException;
486
487  /**
488   * Appends values to one or more columns within a single row.
489   * <p>
490   * This operation guaranteed atomicity to readers. Appends are done
491   * under a single row lock, so write operations to a row are synchronized, and
492   * readers are guaranteed to see this operation fully completed.
493   *
494   * @param append object that specifies the columns and amounts to be used
495   *                  for the increment operations
496   * @throws IOException e
497   * @return values of columns after the append operation (maybe null)
498   */
499  Result append(final Append append) throws IOException;
500
501  /**
502   * Increments one or more columns within a single row.
503   * <p>
504   * This operation ensures atomicity to readers. Increments are done
505   * under a single row lock, so write operations to a row are synchronized, and
506   * readers are guaranteed to see this operation fully completed.
507   *
508   * @param increment object that specifies the columns and amounts to be used
509   *                  for the increment operations
510   * @throws IOException e
511   * @return values of columns after the increment
512   */
513  Result increment(final Increment increment) throws IOException;
514
515  /**
516   * See {@link #incrementColumnValue(byte[], byte[], byte[], long, Durability)}
517   * <p>
518   * The {@link Durability} is defaulted to {@link Durability#SYNC_WAL}.
519   * @param row The row that contains the cell to increment.
520   * @param family The column family of the cell to increment.
521   * @param qualifier The column qualifier of the cell to increment.
522   * @param amount The amount to increment the cell with (or decrement, if the
523   * amount is negative).
524   * @return The new value, post increment.
525   * @throws IOException if a remote or network exception occurs.
526   */
527  long incrementColumnValue(byte[] row, byte[] family, byte[] qualifier,
528    long amount) throws IOException;
529
530  /**
531   * Atomically increments a column value. If the column value already exists
532   * and is not a big-endian long, this could throw an exception. If the column
533   * value does not yet exist it is initialized to <code>amount</code> and
534   * written to the specified column.
535   *
536   * <p>Setting durability to {@link Durability#SKIP_WAL} means that in a fail
537   * scenario you will lose any increments that have not been flushed.
538   * @param row The row that contains the cell to increment.
539   * @param family The column family of the cell to increment.
540   * @param qualifier The column qualifier of the cell to increment.
541   * @param amount The amount to increment the cell with (or decrement, if the
542   * amount is negative).
543   * @param durability The persistence guarantee for this increment.
544   * @return The new value, post increment.
545   * @throws IOException if a remote or network exception occurs.
546   */
547  long incrementColumnValue(byte[] row, byte[] family, byte[] qualifier,
548    long amount, Durability durability) throws IOException;
549
550  /**
551   * Releases any resources held or pending changes in internal buffers.
552   *
553   * @throws IOException if a remote or network exception occurs.
554   */
555  @Override
556  void close() throws IOException;
557
558  /**
559   * Creates and returns a {@link com.google.protobuf.RpcChannel} instance connected to the
560   * table region containing the specified row.  The row given does not actually have
561   * to exist.  Whichever region would contain the row based on start and end keys will
562   * be used.  Note that the {@code row} parameter is also not passed to the
563   * coprocessor handler registered for this protocol, unless the {@code row}
564   * is separately passed as an argument in the service request.  The parameter
565   * here is only used to locate the region used to handle the call.
566   *
567   * <p>
568   * The obtained {@link com.google.protobuf.RpcChannel} instance can be used to access a published
569   * coprocessor {@link com.google.protobuf.Service} using standard protobuf service invocations:
570   * </p>
571   *
572   * <div style="background-color: #cccccc; padding: 2px">
573   * <blockquote><pre>
574   * CoprocessorRpcChannel channel = myTable.coprocessorService(rowkey);
575   * MyService.BlockingInterface service = MyService.newBlockingStub(channel);
576   * MyCallRequest request = MyCallRequest.newBuilder()
577   *     ...
578   *     .build();
579   * MyCallResponse response = service.myCall(null, request);
580   * </pre></blockquote></div>
581   *
582   * @param row The row key used to identify the remote region location
583   * @return A CoprocessorRpcChannel instance
584   */
585  CoprocessorRpcChannel coprocessorService(byte[] row);
586
587  /**
588   * Creates an instance of the given {@link com.google.protobuf.Service} subclass for each table
589   * region spanning the range from the {@code startKey} row to {@code endKey} row (inclusive), and
590   * invokes the passed {@link org.apache.hadoop.hbase.client.coprocessor.Batch.Call#call} method
591   * with each {@link com.google.protobuf.Service} instance.
592   *
593   * @param service the protocol buffer {@code Service} implementation to call
594   * @param startKey start region selection with region containing this row.  If {@code null}, the
595   * selection will start with the first table region.
596   * @param endKey select regions up to and including the region containing this row. If {@code
597   * null}, selection will continue through the last table region.
598   * @param callable this instance's {@link org.apache.hadoop.hbase.client.coprocessor.Batch
599   * .Call#call}
600   * method will be invoked once per table region, using the {@link com.google.protobuf.Service}
601   * instance connected to that region.
602   * @param <T> the {@link com.google.protobuf.Service} subclass to connect to
603   * @param <R> Return type for the {@code callable} parameter's {@link
604   * org.apache.hadoop.hbase.client.coprocessor.Batch.Call#call} method
605   * @return a map of result values keyed by region name
606   */
607  <T extends Service, R> Map<byte[],R> coprocessorService(final Class<T> service,
608    byte[] startKey, byte[] endKey, final Batch.Call<T,R> callable)
609    throws ServiceException, Throwable;
610
611  /**
612   * Creates an instance of the given {@link com.google.protobuf.Service} subclass for each table
613   * region spanning the range from the {@code startKey} row to {@code endKey} row (inclusive), and
614   * invokes the passed {@link org.apache.hadoop.hbase.client.coprocessor.Batch.Call#call} method
615   * with each {@link Service} instance.
616   *
617   * <p> The given {@link org.apache.hadoop.hbase.client.coprocessor.Batch.Callback#update(byte[],
618   * byte[], Object)} method will be called with the return value from each region's {@link
619   * org.apache.hadoop.hbase.client.coprocessor.Batch.Call#call} invocation. </p>
620   *
621   * @param service the protocol buffer {@code Service} implementation to call
622   * @param startKey start region selection with region containing this row.  If {@code null}, the
623   * selection will start with the first table region.
624   * @param endKey select regions up to and including the region containing this row. If {@code
625   * null}, selection will continue through the last table region.
626   * @param callable this instance's {@link org.apache.hadoop.hbase.client.coprocessor.Batch
627   * .Call#call}
628   * method will be invoked once per table region, using the {@link Service} instance connected to
629   * that region.
630   * @param callback
631   * @param <T> the {@link Service} subclass to connect to
632   * @param <R> Return type for the {@code callable} parameter's {@link
633   * org.apache.hadoop.hbase.client.coprocessor.Batch.Call#call} method
634   */
635  <T extends Service, R> void coprocessorService(final Class<T> service,
636    byte[] startKey, byte[] endKey, final Batch.Call<T,R> callable,
637    final Batch.Callback<R> callback) throws ServiceException, Throwable;
638
639  /**
640   * Creates an instance of the given {@link com.google.protobuf.Service} subclass for each table
641   * region spanning the range from the {@code startKey} row to {@code endKey} row (inclusive), all
642   * the invocations to the same region server will be batched into one call. The coprocessor
643   * service is invoked according to the service instance, method name and parameters.
644   *
645   * @param methodDescriptor
646   *          the descriptor for the protobuf service method to call.
647   * @param request
648   *          the method call parameters
649   * @param startKey
650   *          start region selection with region containing this row. If {@code null}, the
651   *          selection will start with the first table region.
652   * @param endKey
653   *          select regions up to and including the region containing this row. If {@code null},
654   *          selection will continue through the last table region.
655   * @param responsePrototype
656   *          the proto type of the response of the method in Service.
657   * @param <R>
658   *          the response type for the coprocessor Service method
659   * @throws ServiceException
660   * @throws Throwable
661   * @return a map of result values keyed by region name
662   */
663  <R extends Message> Map<byte[], R> batchCoprocessorService(
664    Descriptors.MethodDescriptor methodDescriptor, Message request,
665    byte[] startKey, byte[] endKey, R responsePrototype) throws ServiceException, Throwable;
666
667  /**
668   * Creates an instance of the given {@link com.google.protobuf.Service} subclass for each table
669   * region spanning the range from the {@code startKey} row to {@code endKey} row (inclusive), all
670   * the invocations to the same region server will be batched into one call. The coprocessor
671   * service is invoked according to the service instance, method name and parameters.
672   *
673   * <p>
674   * The given
675   * {@link org.apache.hadoop.hbase.client.coprocessor.Batch.Callback#update(byte[],byte[],Object)}
676   * method will be called with the return value from each region's invocation.
677   * </p>
678   *
679   * @param methodDescriptor
680   *          the descriptor for the protobuf service method to call.
681   * @param request
682   *          the method call parameters
683   * @param startKey
684   *          start region selection with region containing this row. If {@code null}, the
685   *          selection will start with the first table region.
686   * @param endKey
687   *          select regions up to and including the region containing this row. If {@code null},
688   *          selection will continue through the last table region.
689   * @param responsePrototype
690   *          the proto type of the response of the method in Service.
691   * @param callback
692   *          callback to invoke with the response for each region
693   * @param <R>
694   *          the response type for the coprocessor Service method
695   * @throws ServiceException
696   * @throws Throwable
697   */
698  <R extends Message> void batchCoprocessorService(Descriptors.MethodDescriptor methodDescriptor,
699    Message request, byte[] startKey, byte[] endKey, R responsePrototype,
700    Batch.Callback<R> callback) throws ServiceException, Throwable;
701
702  /**
703   * Atomically checks if a row/family/qualifier value matches the expected value.
704   * If it does, it performs the row mutations.  If the passed value is null, the check
705   * is for the lack of column (ie: non-existence)
706   *
707   * The expected value argument of this call is on the left and the current
708   * value of the cell is on the right side of the comparison operator.
709   *
710   * Ie. eg. GREATER operator means expected value > existing <=> perform row mutations.
711   *
712   * @param row to check
713   * @param family column family to check
714   * @param qualifier column qualifier to check
715   * @param compareOp the comparison operator
716   * @param value the expected value
717   * @param mutation  mutations to perform if check succeeds
718   * @throws IOException e
719   * @return true if the new put was executed, false otherwise
720   * @deprecated Since 2.0.0. Will be removed in 3.0.0. Use {@link #checkAndMutate(byte[], byte[])}
721   */
722  @Deprecated
723  boolean checkAndMutate(byte[] row, byte[] family, byte[] qualifier,
724      CompareFilter.CompareOp compareOp, byte[] value, RowMutations mutation) throws IOException;
725
726  /**
727   * Atomically checks if a row/family/qualifier value matches the expected value.
728   * If it does, it performs the row mutations.  If the passed value is null, the check
729   * is for the lack of column (ie: non-existence)
730   *
731   * The expected value argument of this call is on the left and the current
732   * value of the cell is on the right side of the comparison operator.
733   *
734   * Ie. eg. GREATER operator means expected value > existing <=> perform row mutations.
735   *
736   * @param row to check
737   * @param family column family to check
738   * @param qualifier column qualifier to check
739   * @param op the comparison operator
740   * @param value the expected value
741   * @param mutation  mutations to perform if check succeeds
742   * @throws IOException e
743   * @return true if the new put was executed, false otherwise
744   * @deprecated Since 2.0.0. Will be removed in 3.0.0. Use {@link #checkAndMutate(byte[], byte[])}
745   */
746  @Deprecated
747  boolean checkAndMutate(byte[] row, byte[] family, byte[] qualifier, CompareOperator op,
748                         byte[] value, RowMutations mutation) throws IOException;
749
750  /**
751   * Get timeout of each rpc request in this Table instance. It will be overridden by a more
752   * specific rpc timeout config such as readRpcTimeout or writeRpcTimeout.
753   * @see #getReadRpcTimeout(TimeUnit)
754   * @see #getWriteRpcTimeout(TimeUnit)
755   * @param unit the unit of time the timeout to be represented in
756   * @return rpc timeout in the specified time unit
757   */
758  long getRpcTimeout(TimeUnit unit);
759
760  /**
761   * Get timeout (millisecond) of each rpc request in this Table instance.
762   *
763   * @return Currently configured read timeout
764   * @deprecated use {@link #getReadRpcTimeout(TimeUnit)} or
765   *             {@link #getWriteRpcTimeout(TimeUnit)} instead
766   */
767  @Deprecated
768  int getRpcTimeout();
769
770  /**
771   * Set timeout (millisecond) of each rpc request in operations of this Table instance, will
772   * override the value of hbase.rpc.timeout in configuration.
773   * If a rpc request waiting too long, it will stop waiting and send a new request to retry until
774   * retries exhausted or operation timeout reached.
775   * <p>
776   * NOTE: This will set both the read and write timeout settings to the provided value.
777   *
778   * @param rpcTimeout the timeout of each rpc request in millisecond.
779   *
780   * @deprecated Use setReadRpcTimeout or setWriteRpcTimeout instead
781   */
782  @Deprecated
783  void setRpcTimeout(int rpcTimeout);
784
785  /**
786   * Get timeout of each rpc read request in this Table instance.
787   * @param unit the unit of time the timeout to be represented in
788   * @return read rpc timeout in the specified time unit
789   */
790  long getReadRpcTimeout(TimeUnit unit);
791
792  /**
793   * Get timeout (millisecond) of each rpc read request in this Table instance.
794   * @deprecated since 2.0 and will be removed in 3.0 version
795   *             use {@link #getReadRpcTimeout(TimeUnit)} instead
796   */
797  @Deprecated
798  int getReadRpcTimeout();
799
800  /**
801   * Set timeout (millisecond) of each rpc read request in operations of this Table instance, will
802   * override the value of hbase.rpc.read.timeout in configuration.
803   * If a rpc read request waiting too long, it will stop waiting and send a new request to retry
804   * until retries exhausted or operation timeout reached.
805   *
806   * @param readRpcTimeout the timeout for read rpc request in milliseconds
807   * @deprecated since 2.0.0, use {@link TableBuilder#setReadRpcTimeout} instead
808   */
809  @Deprecated
810  void setReadRpcTimeout(int readRpcTimeout);
811
812  /**
813   * Get timeout of each rpc write request in this Table instance.
814   * @param unit the unit of time the timeout to be represented in
815   * @return write rpc timeout in the specified time unit
816   */
817  long getWriteRpcTimeout(TimeUnit unit);
818
819  /**
820   * Get timeout (millisecond) of each rpc write request in this Table instance.
821   * @deprecated since 2.0 and will be removed in 3.0 version
822   *             use {@link #getWriteRpcTimeout(TimeUnit)} instead
823   */
824  @Deprecated
825  int getWriteRpcTimeout();
826
827  /**
828   * Set timeout (millisecond) of each rpc write request in operations of this Table instance, will
829   * override the value of hbase.rpc.write.timeout in configuration.
830   * If a rpc write request waiting too long, it will stop waiting and send a new request to retry
831   * until retries exhausted or operation timeout reached.
832   *
833   * @param writeRpcTimeout the timeout for write rpc request in milliseconds
834   * @deprecated since 2.0.0, use {@link TableBuilder#setWriteRpcTimeout} instead
835   */
836  @Deprecated
837  void setWriteRpcTimeout(int writeRpcTimeout);
838
839  /**
840   * Get timeout of each operation in Table instance.
841   * @param unit the unit of time the timeout to be represented in
842   * @return operation rpc timeout in the specified time unit
843   */
844  long getOperationTimeout(TimeUnit unit);
845
846  /**
847   * Get timeout (millisecond) of each operation for in Table instance.
848   * @deprecated since 2.0 and will be removed in 3.0 version
849   *             use {@link #getOperationTimeout(TimeUnit)} instead
850   */
851  @Deprecated
852  int getOperationTimeout();
853
854  /**
855   * Set timeout (millisecond) of each operation in this Table instance, will override the value
856   * of hbase.client.operation.timeout in configuration.
857   * Operation timeout is a top-level restriction that makes sure a blocking method will not be
858   * blocked more than this. In each operation, if rpc request fails because of timeout or
859   * other reason, it will retry until success or throw a RetriesExhaustedException. But if the
860   * total time being blocking reach the operation timeout before retries exhausted, it will break
861   * early and throw SocketTimeoutException.
862   * @param operationTimeout the total timeout of each operation in millisecond.
863   * @deprecated since 2.0.0, use {@link TableBuilder#setOperationTimeout} instead
864   */
865  @Deprecated
866  void setOperationTimeout(int operationTimeout);
867}