HBASE-19934 HBaseSnapshotException when read replicas is enabled and online snapshot is taken after region splitting

Signed-off-by: tedyu <yuzhihong@gmail.com>
This commit is contained in:
Toshihiro Suzuki 2018-02-06 14:51:14 +09:00 committed by tedyu
parent 673e809250
commit 92f733db4b
3 changed files with 45 additions and 11 deletions

View File

@ -27,6 +27,7 @@ import org.apache.commons.logging.LogFactory;
import org.apache.hadoop.hbase.classification.InterfaceAudience;
import org.apache.hadoop.hbase.HRegionInfo;
import org.apache.hadoop.hbase.ServerName;
import org.apache.hadoop.hbase.client.RegionReplicaUtil;
import org.apache.hadoop.hbase.errorhandling.ForeignException;
import org.apache.hadoop.hbase.master.MasterServices;
import org.apache.hadoop.hbase.procedure.Procedure;
@ -98,7 +99,8 @@ public class EnabledTableSnapshotHandler extends TakeSnapshotHandler {
// Take the offline regions as disabled
for (Pair<HRegionInfo, ServerName> region : regions) {
HRegionInfo regionInfo = region.getFirst();
if (regionInfo.isOffline() && (regionInfo.isSplit() || regionInfo.isSplitParent())) {
if (regionInfo.isOffline() && (regionInfo.isSplit() || regionInfo.isSplitParent()) &&
RegionReplicaUtil.isDefaultReplica(regionInfo)) {
LOG.info("Take disabled snapshot of offline region=" + regionInfo);
snapshotDisabledRegion(regionInfo);
}

View File

@ -30,6 +30,7 @@ import org.apache.hadoop.hbase.CategoryBasedTimeout;
import org.apache.hadoop.hbase.HBaseTestingUtility;
import org.apache.hadoop.hbase.HColumnDescriptor;
import org.apache.hadoop.hbase.HConstants;
import org.apache.hadoop.hbase.HRegionInfo;
import org.apache.hadoop.hbase.HTableDescriptor;
import org.apache.hadoop.hbase.testclassification.LargeTests;
import org.apache.hadoop.hbase.TableName;
@ -59,18 +60,18 @@ public class TestRestoreSnapshotFromClient {
.withLookingForStuckThread(true)
.build();
private final static HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility();
protected final static HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility();
private final byte[] FAMILY = Bytes.toBytes("cf");
protected final byte[] FAMILY = Bytes.toBytes("cf");
private byte[] emptySnapshot;
private byte[] snapshotName0;
private byte[] snapshotName1;
private byte[] snapshotName2;
private int snapshot0Rows;
private int snapshot1Rows;
private TableName tableName;
private Admin admin;
protected byte[] emptySnapshot;
protected byte[] snapshotName0;
protected byte[] snapshotName1;
protected byte[] snapshotName2;
protected int snapshot0Rows;
protected int snapshot1Rows;
protected TableName tableName;
protected Admin admin;
@BeforeClass
public static void setUpBeforeClass() throws Exception {
@ -299,4 +300,9 @@ public class TestRestoreSnapshotFromClient {
}
return families;
}
protected void splitRegion(final HRegionInfo regionInfo) throws IOException {
byte[][] splitPoints = Bytes.split(regionInfo.getStartKey(), regionInfo.getEndKey(), 1);
admin.split(regionInfo.getTable(), splitPoints[1]);
}
}

View File

@ -17,7 +17,14 @@
*/
package org.apache.hadoop.hbase.client;
import java.io.IOException;
import java.util.List;
import org.apache.hadoop.hbase.HRegionInfo;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.snapshot.SnapshotTestingUtils;
import org.apache.hadoop.hbase.testclassification.LargeTests;
import org.junit.Test;
import org.junit.experimental.categories.Category;
@Category(LargeTests.class)
@ -27,4 +34,23 @@ public class TestRestoreSnapshotFromClientWithRegionReplicas extends
protected int getNumReplicas() {
return 3;
}
@Test
public void testOnlineSnapshotAfterSplittingRegions() throws IOException, InterruptedException {
List<HRegionInfo> regionInfos = admin.getTableRegions(tableName);
RegionReplicaUtil.removeNonDefaultRegions(regionInfos);
// Split a region
splitRegion(regionInfos.get(0));
// Take a online snapshot
admin.snapshot(snapshotName1, tableName);
// Clone the snapshot to another table
TableName clonedTableName = TableName.valueOf("testOnlineSnapshotAfterSplittingRegions-" +
System.currentTimeMillis());
admin.cloneSnapshot(snapshotName1, clonedTableName);
SnapshotTestingUtils.verifyRowCount(TEST_UTIL, clonedTableName, snapshot1Rows);
}
}