HBASE-19343 Restore snapshot makes split parent region online
This commit is contained in:
parent
e84f5dff7b
commit
eacbe002e5
|
@ -203,7 +203,9 @@ public class RestoreSnapshotHelper {
|
|||
if (regionNames.contains(regionName)) {
|
||||
LOG.info("region to restore: " + regionName);
|
||||
regionNames.remove(regionName);
|
||||
metaChanges.addRegionToRestore(regionInfo);
|
||||
// Add the regionInfo from snapshot manifest, so that will not miss parent region details
|
||||
metaChanges.addRegionToRestore(
|
||||
HRegionInfo.convert(regionManifests.get(regionName).getRegionInfo()));
|
||||
} else {
|
||||
LOG.info("region to remove: " + regionName);
|
||||
metaChanges.addRegionToRemove(regionInfo);
|
||||
|
|
|
@ -35,6 +35,7 @@ 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.MetaTableAccessor;
|
||||
import org.apache.hadoop.hbase.coprocessor.BaseRegionObserver;
|
||||
import org.apache.hadoop.hbase.coprocessor.ObserverContext;
|
||||
import org.apache.hadoop.hbase.coprocessor.RegionCoprocessorEnvironment;
|
||||
|
@ -43,10 +44,14 @@ import org.apache.hadoop.hbase.regionserver.ScanType;
|
|||
import org.apache.hadoop.hbase.regionserver.Store;
|
||||
import org.apache.hadoop.hbase.testclassification.LargeTests;
|
||||
import org.apache.hadoop.hbase.TableName;
|
||||
import org.apache.hadoop.hbase.Waiter;
|
||||
import org.apache.hadoop.hbase.master.AssignmentManager;
|
||||
import org.apache.hadoop.hbase.master.MasterFileSystem;
|
||||
import org.apache.hadoop.hbase.master.RegionState;
|
||||
import org.apache.hadoop.hbase.master.snapshot.SnapshotManager;
|
||||
import org.apache.hadoop.hbase.regionserver.NoSuchColumnFamilyException;
|
||||
import org.apache.hadoop.hbase.snapshot.CorruptedSnapshotException;
|
||||
import org.apache.hadoop.hbase.snapshot.SnapshotDoesNotExistException;
|
||||
import org.apache.hadoop.hbase.snapshot.SnapshotTestingUtils;
|
||||
import org.apache.hadoop.hbase.util.Bytes;
|
||||
import org.apache.hadoop.hbase.util.FSUtils;
|
||||
|
@ -90,8 +95,9 @@ public class TestRestoreSnapshotFromClient {
|
|||
TEST_UTIL.getConfiguration().setInt("hbase.regionserver.msginterval", 100);
|
||||
TEST_UTIL.getConfiguration().setInt("hbase.client.pause", 250);
|
||||
TEST_UTIL.getConfiguration().setInt(HConstants.HBASE_CLIENT_RETRIES_NUMBER, 6);
|
||||
TEST_UTIL.getConfiguration().setBoolean(
|
||||
"hbase.master.enabletable.roundrobin", true);
|
||||
TEST_UTIL.getConfiguration().setBoolean("hbase.master.enabletable.roundrobin", true);
|
||||
// Setting bigger value to avoid catalog janitor execution (parent region cleanup)
|
||||
TEST_UTIL.getConfiguration().setLong("hbase.catalogjanitor.interval", 1800000);
|
||||
TEST_UTIL.startMiniCluster(3);
|
||||
}
|
||||
|
||||
|
@ -182,6 +188,64 @@ public class TestRestoreSnapshotFromClient {
|
|||
SnapshotTestingUtils.verifyReplicasCameOnline(tableName, admin, getNumReplicas());
|
||||
}
|
||||
|
||||
@Test(timeout = 300000)
|
||||
public void testRestoreSnapshotAfterSplit() throws Exception {
|
||||
Admin admin = null;
|
||||
try {
|
||||
admin = TEST_UTIL.getHBaseAdmin();
|
||||
final int regionReplication = admin.getTableDescriptor(tableName).getRegionReplication();
|
||||
// Region count before split
|
||||
final int primaryRegionCountBeforeSplit = MetaTableAccessor
|
||||
.getTableRegions(TEST_UTIL.getZooKeeperWatcher(), TEST_UTIL.getConnection(), tableName)
|
||||
.size() / regionReplication;
|
||||
|
||||
admin.split(tableName, "m".getBytes());
|
||||
final AssignmentManager am = TEST_UTIL.getHBaseCluster().getMaster().getAssignmentManager();
|
||||
// Wait for replica region to become online
|
||||
TEST_UTIL.waitFor(60000, 500, new Waiter.Predicate<IOException>() {
|
||||
@Override
|
||||
public boolean evaluate() throws IOException {
|
||||
return am.getRegionStates().getRegionByStateOfTable(tableName).get(RegionState.State.OPEN)
|
||||
.size() == ((primaryRegionCountBeforeSplit + 1) * regionReplication);
|
||||
}
|
||||
});
|
||||
|
||||
int regionCountAfterSplit = MetaTableAccessor
|
||||
.getTableRegions(TEST_UTIL.getZooKeeperWatcher(), TEST_UTIL.getConnection(), tableName)
|
||||
.size() / regionReplication;
|
||||
// regionCountAfterSplit will contain parent region, so primaryregionCountBeforeSplit + 2
|
||||
assertEquals(primaryRegionCountBeforeSplit + 2, regionCountAfterSplit);
|
||||
|
||||
String snapshotName = "testRestoreSnapshotAfterSplit-snap";
|
||||
// Create snapshot after table split
|
||||
admin.snapshot(snapshotName, tableName);
|
||||
assertEquals(1,
|
||||
admin.listTableSnapshots("testtb-.*", "testRestoreSnapshotAfterSplit-snap*").size());
|
||||
// Restore snapshot
|
||||
admin.disableTable(tableName);
|
||||
admin.restoreSnapshot(snapshotName);
|
||||
|
||||
int regionCountAfterRestoreSnapshot = MetaTableAccessor
|
||||
.getTableRegions(TEST_UTIL.getZooKeeperWatcher(), TEST_UTIL.getConnection(), tableName)
|
||||
.size();
|
||||
assertEquals(primaryRegionCountBeforeSplit + 2, regionCountAfterRestoreSnapshot);
|
||||
|
||||
// Enable the table
|
||||
admin.enableTable(tableName);
|
||||
assertEquals((primaryRegionCountBeforeSplit + 1) * regionReplication,
|
||||
am.getRegionStates().getRegionByStateOfTable(tableName).get(RegionState.State.OPEN).size());
|
||||
|
||||
} finally {
|
||||
if (admin != null) {
|
||||
try {
|
||||
admin.deleteTableSnapshots("testtb-.*", "testRestoreSnapshotAfterSplit-snap*");
|
||||
} catch (SnapshotDoesNotExistException ignore) {
|
||||
}
|
||||
admin.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected int getNumReplicas() {
|
||||
return 1;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue