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

This commit is contained in:
tedyu 2018-02-05 21:03:56 -08:00
parent 3bb8daa605
commit 11e3a83870
3 changed files with 41 additions and 8 deletions

View File

@ -24,6 +24,7 @@ import java.util.Set;
import org.apache.hadoop.hbase.ServerName;
import org.apache.hadoop.hbase.client.RegionInfo;
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.mob.MobUtils;
@ -98,7 +99,8 @@ public class EnabledTableSnapshotHandler extends TakeSnapshotHandler {
// Take the offline regions as disabled
for (Pair<RegionInfo, ServerName> region : regions) {
RegionInfo 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

@ -24,6 +24,7 @@ import static org.junit.Assert.fail;
import java.io.IOException;
import java.util.HashSet;
import java.util.Set;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.hbase.HBaseClassTestRule;
@ -67,13 +68,13 @@ public class TestRestoreSnapshotFromClient {
protected final byte[] TEST_FAMILY2 = Bytes.toBytes("cf2");
protected TableName tableName;
private byte[] emptySnapshot;
private byte[] snapshotName0;
private byte[] snapshotName1;
private byte[] snapshotName2;
private int snapshot0Rows;
private int snapshot1Rows;
private Admin admin;
protected byte[] emptySnapshot;
protected byte[] snapshotName0;
protected byte[] snapshotName1;
protected byte[] snapshotName2;
protected int snapshot0Rows;
protected int snapshot1Rows;
protected Admin admin;
@Rule
public TestName name = new TestName();
@ -321,4 +322,9 @@ public class TestRestoreSnapshotFromClient {
protected int countRows(final Table table, final byte[]... families) throws IOException {
return TEST_UTIL.countRows(table, families);
}
protected void splitRegion(final RegionInfo regionInfo) throws IOException {
byte[][] splitPoints = Bytes.split(regionInfo.getStartKey(), regionInfo.getEndKey(), 1);
admin.split(regionInfo.getTable(), splitPoints[1]);
}
}

View File

@ -17,12 +17,18 @@
*/
package org.apache.hadoop.hbase.client;
import java.io.IOException;
import java.util.List;
import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.testclassification.ClientTests;
import org.apache.hadoop.hbase.testclassification.LargeTests;
import org.junit.ClassRule;
import org.junit.Test;
import org.junit.experimental.categories.Category;
@Category({LargeTests.class, ClientTests.class})
public class TestRestoreSnapshotFromClientWithRegionReplicas extends
TestRestoreSnapshotFromClient {
@ -35,4 +41,23 @@ public class TestRestoreSnapshotFromClientWithRegionReplicas extends
protected int getNumReplicas() {
return 3;
}
@Test
public void testOnlineSnapshotAfterSplittingRegions() throws IOException, InterruptedException {
List<RegionInfo> regionInfos = admin.getRegions(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(name.getMethodName() + "-" +
System.currentTimeMillis());
admin.cloneSnapshot(snapshotName1, clonedTableName);
verifyRowCount(TEST_UTIL, clonedTableName, snapshot1Rows);
}
}