001/**
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements.  See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership.  The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License.  You may obtain a copy of the License at
009 *
010 *     http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing, software
013 * distributed under the License is distributed on an "AS IS" BASIS,
014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015 * See the License for the specific language governing permissions and
016 * limitations under the License.
017 */
018package org.apache.hadoop.hbase.client;
019
020import java.util.concurrent.CompletableFuture;
021import org.apache.hadoop.hbase.HRegionLocation;
022import org.apache.hadoop.hbase.TableName;
023import org.apache.yetus.audience.InterfaceAudience;
024
025/**
026 * The asynchronous version of RegionLocator.
027 * <p>
028 * Usually the implementations will not throw any exception directly, you need to get the exception
029 * from the returned {@link CompletableFuture}.
030 * @since 2.0.0
031 */
032@InterfaceAudience.Public
033public interface AsyncTableRegionLocator {
034
035  /**
036   * Gets the fully qualified table name instance of the table whose region we want to locate.
037   */
038  TableName getName();
039
040  /**
041   * Finds the region on which the given row is being served. Does not reload the cache.
042   * <p>
043   * Returns the location of the region to which the row belongs.
044   * @param row Row to find.
045   */
046  default CompletableFuture<HRegionLocation> getRegionLocation(byte[] row) {
047    return getRegionLocation(row, false);
048  }
049
050  /**
051   * Finds the region on which the given row is being served.
052   * <p>
053   * Returns the location of the region to which the row belongs.
054   * @param row Row to find.
055   * @param reload true to reload information or false to use cached information
056   */
057  default CompletableFuture<HRegionLocation> getRegionLocation(byte[] row, boolean reload) {
058    return getRegionLocation(row, RegionReplicaUtil.DEFAULT_REPLICA_ID, reload);
059  }
060
061  /**
062   * Finds the region with the given <code>replicaId</code> on which the given row is being served.
063   * <p>
064   * Returns the location of the region with the given <code>replicaId</code> to which the row
065   * belongs.
066   * @param row Row to find.
067   * @param replicaId the replica id of the region
068   */
069  default CompletableFuture<HRegionLocation> getRegionLocation(byte[] row, int replicaId) {
070    return getRegionLocation(row, replicaId, false);
071  }
072
073  /**
074   * Finds the region with the given <code>replicaId</code> on which the given row is being served.
075   * <p>
076   * Returns the location of the region with the given <code>replicaId</code> to which the row
077   * belongs.
078   * @param row Row to find.
079   * @param replicaId the replica id of the region
080   * @param reload true to reload information or false to use cached information
081   */
082  CompletableFuture<HRegionLocation> getRegionLocation(byte[] row, int replicaId, boolean reload);
083}