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

huaxiang sun commented on HBASE-20229:
--------------------------------------

Look at the implementation, it actually can be optimized.
{code:java}
@Override
public List<HRegionLocation> locateRegions(TableName tableName, boolean 
useCache,
    boolean offlined) throws IOException {
  List<RegionInfo> regions;
  if (TableName.isMetaTableName(tableName)) {
    regions = 
Collections.singletonList(RegionInfoBuilder.FIRST_META_REGIONINFO);
  } else {
    regions = MetaTableAccessor.getTableRegions(this, tableName, !offlined);
  }
  List<HRegionLocation> locations = new ArrayList<>();
  for (RegionInfo regionInfo : regions) {
    RegionLocations list = locateRegion(tableName, regionInfo.getStartKey(), 
useCache, true);
    if (list != null) {
      for (HRegionLocation loc : list.getRegionLocations()) {
        if (loc != null) {
          locations.add(loc);
        }
      }
    }
  }
  return locations;
}
{code}
 
{code:java}
regions = MetaTableAccessor.getTableRegions(this, tableName, !offlined);{code}
Actually got all the regions from meta table scan, it does not really need to 
call locateRegions() again to get region locations (a possible scan of meta 
region again). My suggestion is to remove the following block totally and build 
region location by 

getTableRegionsAndLocations().
{code:java}
  for (RegionInfo regionInfo : regions) {
    RegionLocations list = locateRegion(tableName, regionInfo.getStartKey(), 
useCache, true);
    if (list != null) {
      for (HRegionLocation loc : list.getRegionLocations()) {
        if (loc != null) {
          locations.add(loc);
        }
      }
    }
  }{code}
 

[~brfrn169], do you want to change the title and post a new patch? Thanks.

> ConnectionImplementation.locateRegions() returns duplicated entries when 
> region replication is on
> -------------------------------------------------------------------------------------------------
>
>                 Key: HBASE-20229
>                 URL: https://issues.apache.org/jira/browse/HBASE-20229
>             Project: HBase
>          Issue Type: Bug
>            Reporter: Toshihiro Suzuki
>            Assignee: Toshihiro Suzuki
>            Priority: Major
>             Fix For: 2.0.0
>
>         Attachments: HBASE-20229.master.001.patch, 
> HBASE-20229.master.002.patch, HBASE-20229.master.003.patch, 
> HBASE-20229.master.004.patch
>
>
> The issue is when region replication is on, 
> ConnectionImplementation.locateRegions() returns duplicated entries.
> In the test in my patch, the table should have 1 primary region + 2 
> secondaries, but ConnectionImplementation.locateRegions() returns 9 regions. 
> Every region repeats 3 times (3 = replicas count).
> I think this is because the following code calls locateRegion() even for 
> replica regions and then the result triples.
> {code:java}
>     for (RegionInfo regionInfo : regions) {
>       RegionLocations list = locateRegion(tableName, 
> regionInfo.getStartKey(), useCache, true);
>       if (list != null) {
>         for (HRegionLocation loc : list.getRegionLocations()) {
>           if (loc != null) {
>             locations.add(loc);
>           }
>         }
>       }
> {code}
> The fix in my patch is to make it call locateRegion() only for a primary 
> region.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to