-
Notifications
You must be signed in to change notification settings - Fork 3.4k
HBASE-24795 : RegionMover to deal with unknown region while (un)loading #2172
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
c83e789
HBASE-24795 : RegionMover to deal with unknown region while (un)loading
virajjasani 51a74d6
update based on review
virajjasani bdec03c
update based on review
virajjasani 433cb91
addressing review
virajjasani feced89
moved table creation in Before and deletion in After
virajjasani File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
158 changes: 158 additions & 0 deletions
158
hbase-server/src/main/java/org/apache/hadoop/hbase/util/MoveWithAck.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,158 @@ | ||
| /* | ||
| * | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package org.apache.hadoop.hbase.util; | ||
|
|
||
| import org.apache.hadoop.hbase.HRegionLocation; | ||
| import org.apache.hadoop.hbase.ServerName; | ||
| import org.apache.hadoop.hbase.client.Admin; | ||
| import org.apache.hadoop.hbase.client.Connection; | ||
| import org.apache.hadoop.hbase.client.RegionInfo; | ||
| import org.apache.hadoop.hbase.client.ResultScanner; | ||
| import org.apache.hadoop.hbase.client.Scan; | ||
| import org.apache.hadoop.hbase.client.Table; | ||
| import org.apache.hadoop.hbase.filter.FirstKeyOnlyFilter; | ||
| import org.apache.yetus.audience.InterfaceAudience; | ||
| import org.slf4j.Logger; | ||
| import org.slf4j.LoggerFactory; | ||
|
|
||
| import java.io.IOException; | ||
| import java.util.List; | ||
| import java.util.concurrent.Callable; | ||
|
|
||
| /** | ||
| * Move Regions and make sure that they are up on the target server.If a region movement fails we | ||
| * exit as failure | ||
| */ | ||
| @InterfaceAudience.Private | ||
| class MoveWithAck implements Callable<Boolean> { | ||
|
|
||
| private static final Logger LOG = LoggerFactory.getLogger(MoveWithAck.class); | ||
|
|
||
| private final RegionInfo region; | ||
| private final ServerName targetServer; | ||
| private final List<RegionInfo> movedRegions; | ||
| private final ServerName sourceServer; | ||
| private final Connection conn; | ||
| private final Admin admin; | ||
|
|
||
| MoveWithAck(Connection conn, RegionInfo regionInfo, ServerName sourceServer, | ||
| ServerName targetServer, List<RegionInfo> movedRegions) throws IOException { | ||
| this.conn = conn; | ||
| this.region = regionInfo; | ||
| this.targetServer = targetServer; | ||
| this.movedRegions = movedRegions; | ||
| this.sourceServer = sourceServer; | ||
| this.admin = conn.getAdmin(); | ||
| } | ||
|
|
||
| @Override | ||
| public Boolean call() throws IOException, InterruptedException { | ||
| boolean moved = false; | ||
| int count = 0; | ||
| int retries = admin.getConfiguration() | ||
| .getInt(RegionMover.MOVE_RETRIES_MAX_KEY, RegionMover.DEFAULT_MOVE_RETRIES_MAX); | ||
| int maxWaitInSeconds = admin.getConfiguration() | ||
| .getInt(RegionMover.MOVE_WAIT_MAX_KEY, RegionMover.DEFAULT_MOVE_WAIT_MAX); | ||
| long startTime = EnvironmentEdgeManager.currentTime(); | ||
| boolean sameServer = true; | ||
| // Assert we can scan the region in its current location | ||
| isSuccessfulScan(region); | ||
| LOG.info("Moving region: {} from {} to {}", region.getRegionNameAsString(), sourceServer, | ||
| targetServer); | ||
| while (count < retries && sameServer) { | ||
| if (count > 0) { | ||
| LOG.debug("Retry {} of maximum {} for region: {}", count, retries, | ||
| region.getRegionNameAsString()); | ||
| } | ||
| count = count + 1; | ||
| admin.move(region.getEncodedNameAsBytes(), targetServer); | ||
| long maxWait = startTime + (maxWaitInSeconds * 1000); | ||
| while (EnvironmentEdgeManager.currentTime() < maxWait) { | ||
| sameServer = isSameServer(region, sourceServer); | ||
| if (!sameServer) { | ||
| break; | ||
| } | ||
| Thread.sleep(1000); | ||
| } | ||
| } | ||
| if (sameServer) { | ||
| LOG.error("Region: {} stuck on {} for {} sec , newServer={}", region.getRegionNameAsString(), | ||
| this.sourceServer, getTimeDiffInSec(startTime), this.targetServer); | ||
| } else { | ||
| isSuccessfulScan(region); | ||
| LOG.info("Moved Region {} , cost (sec): {}", region.getRegionNameAsString(), | ||
| getTimeDiffInSec(startTime)); | ||
| moved = true; | ||
| movedRegions.add(region); | ||
| } | ||
| return moved; | ||
| } | ||
|
|
||
| private static String getTimeDiffInSec(long startTime) { | ||
| return String.format("%.3f", (float) (EnvironmentEdgeManager.currentTime() - startTime) / 1000); | ||
| } | ||
|
|
||
| /** | ||
| * Tries to scan a row from passed region | ||
| */ | ||
| private void isSuccessfulScan(RegionInfo region) throws IOException { | ||
| Scan scan = new Scan().withStartRow(region.getStartKey()).setRaw(true).setOneRowLimit() | ||
| .setMaxResultSize(1L).setCaching(1).setFilter(new FirstKeyOnlyFilter()) | ||
| .setCacheBlocks(false); | ||
| try (Table table = conn.getTable(region.getTable()); | ||
| ResultScanner scanner = table.getScanner(scan)) { | ||
| scanner.next(); | ||
| } catch (IOException e) { | ||
| LOG.error("Could not scan region: {}", region.getEncodedName(), e); | ||
| throw e; | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Returns true if passed region is still on serverName when we look at hbase:meta. | ||
| * @return true if region is hosted on serverName otherwise false | ||
| */ | ||
| private boolean isSameServer(RegionInfo region, ServerName serverName) | ||
| throws IOException { | ||
| ServerName serverForRegion = getServerNameForRegion(region, admin, conn); | ||
| return serverForRegion != null && serverForRegion.equals(serverName); | ||
| } | ||
|
|
||
| /** | ||
| * Get servername that is up in hbase:meta hosting the given region. this is hostname + port + | ||
| * startcode comma-delimited. Can return null | ||
| * @return regionServer hosting the given region | ||
| */ | ||
| static ServerName getServerNameForRegion(RegionInfo region, Admin admin, Connection conn) | ||
| throws IOException { | ||
| if (!admin.isTableEnabled(region.getTable())) { | ||
| return null; | ||
| } | ||
| HRegionLocation loc = | ||
| conn.getRegionLocator(region.getTable()).getRegionLocation(region.getStartKey(), | ||
| region.getReplicaId(),true); | ||
| if (loc != null) { | ||
| return loc.getServerName(); | ||
| } else { | ||
| return null; | ||
| } | ||
| } | ||
|
|
||
| } | ||
71 changes: 71 additions & 0 deletions
71
hbase-server/src/main/java/org/apache/hadoop/hbase/util/MoveWithoutAck.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| /* | ||
| * | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package org.apache.hadoop.hbase.util; | ||
|
|
||
| import org.apache.hadoop.hbase.ServerName; | ||
| import org.apache.hadoop.hbase.client.Admin; | ||
| import org.apache.hadoop.hbase.client.RegionInfo; | ||
| import org.apache.yetus.audience.InterfaceAudience; | ||
| import org.slf4j.Logger; | ||
| import org.slf4j.LoggerFactory; | ||
|
|
||
| import java.util.List; | ||
| import java.util.concurrent.Callable; | ||
|
|
||
| /** | ||
| * Move Regions without Acknowledging.Usefule in case of RS shutdown as we might want to shut the | ||
| * RS down anyways and not abort on a stuck region. Improves movement performance | ||
| */ | ||
| @InterfaceAudience.Private | ||
| class MoveWithoutAck implements Callable<Boolean> { | ||
|
|
||
| private static final Logger LOG = LoggerFactory.getLogger(MoveWithoutAck.class); | ||
|
|
||
| private final RegionInfo region; | ||
| private final ServerName targetServer; | ||
| private final List<RegionInfo> movedRegions; | ||
| private final ServerName sourceServer; | ||
| private final Admin admin; | ||
|
|
||
| MoveWithoutAck(Admin admin, RegionInfo regionInfo, ServerName sourceServer, | ||
| ServerName targetServer, List<RegionInfo> movedRegions) { | ||
| this.admin = admin; | ||
| this.region = regionInfo; | ||
| this.targetServer = targetServer; | ||
| this.movedRegions = movedRegions; | ||
| this.sourceServer = sourceServer; | ||
| } | ||
|
|
||
| @Override | ||
| public Boolean call() { | ||
| try { | ||
| LOG.info("Moving region: {} from {} to {}", region.getEncodedName(), sourceServer, | ||
| targetServer); | ||
| admin.move(region.getEncodedNameAsBytes(), targetServer); | ||
| LOG.info("Requested move {} from {} to {}", region.getEncodedName(), sourceServer, | ||
| targetServer); | ||
| } catch (Exception e) { | ||
| LOG.error("Error Moving Region: {}", region.getEncodedName(), e); | ||
| } finally { | ||
| movedRegions.add(region); | ||
| } | ||
| return true; | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.