HBASE-13169 ModifyTable increasing the region replica count should also auto-setup RRRE
This commit is contained in:
parent
9aa8f0672e
commit
be25b0d595
|
@ -44,6 +44,7 @@ import org.apache.hadoop.hbase.master.MasterCoprocessorHost;
|
|||
import org.apache.hadoop.hbase.master.MasterFileSystem;
|
||||
import org.apache.hadoop.hbase.master.MasterServices;
|
||||
import org.apache.hadoop.hbase.util.Bytes;
|
||||
import org.apache.hadoop.hbase.util.ServerRegionReplicaUtil;
|
||||
|
||||
@InterfaceAudience.Private
|
||||
public class ModifyTableHandler extends TableEventHandler {
|
||||
|
@ -88,6 +89,11 @@ public class ModifyTableHandler extends TableEventHandler {
|
|||
this.htd.getRegionReplication(),
|
||||
oldDescriptor.getRegionReplication(),
|
||||
this.htd.getTableName());
|
||||
|
||||
// Setup replication for region replicas if needed
|
||||
if (htd.getRegionReplication() > 1 && oldDescriptor.getRegionReplication() <= 1) {
|
||||
ServerRegionReplicaUtil.setupRegionReplicaReplication(server.getConfiguration());
|
||||
}
|
||||
if (cpHost != null) {
|
||||
cpHost.postModifyTableHandler(this.tableName, this.htd);
|
||||
}
|
||||
|
|
|
@ -135,6 +135,45 @@ public class TestRegionReplicaReplicationEndpoint {
|
|||
admin.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRegionReplicaReplicationPeerIsCreatedForModifyTable() throws Exception {
|
||||
// modify a table by adding region replicas. Check whether the replication peer is created
|
||||
// and replication started.
|
||||
ReplicationAdmin admin = new ReplicationAdmin(HTU.getConfiguration());
|
||||
String peerId = "region_replica_replication";
|
||||
|
||||
if (admin.getPeerConfig(peerId) != null) {
|
||||
admin.removePeer(peerId);
|
||||
}
|
||||
|
||||
HTableDescriptor htd
|
||||
= HTU.createTableDescriptor("testRegionReplicaReplicationPeerIsCreatedForModifyTable");
|
||||
HTU.getHBaseAdmin().createTable(htd);
|
||||
|
||||
// assert that replication peer is not created yet
|
||||
ReplicationPeerConfig peerConfig = admin.getPeerConfig(peerId);
|
||||
assertNull(peerConfig);
|
||||
|
||||
HTU.getHBaseAdmin().disableTable(htd.getTableName());
|
||||
htd.setRegionReplication(2);
|
||||
HTU.getHBaseAdmin().modifyTable(htd.getTableName(), htd);
|
||||
HTU.getHBaseAdmin().enableTable(htd.getTableName());
|
||||
|
||||
// assert peer configuration is correct
|
||||
peerConfig = admin.getPeerConfig(peerId);
|
||||
assertNotNull(peerConfig);
|
||||
assertEquals(peerConfig.getClusterKey(), ZKUtil.getZooKeeperClusterKey(HTU.getConfiguration()));
|
||||
assertEquals(peerConfig.getReplicationEndpointImpl(),
|
||||
RegionReplicaReplicationEndpoint.class.getName());
|
||||
admin.close();
|
||||
|
||||
// verify it is working
|
||||
try(Connection connection = ConnectionFactory.createConnection(HTU.getConfiguration());
|
||||
Table table = connection.getTable(htd.getTableName());){
|
||||
HTU.loadNumericRows(table, HBaseTestingUtility.fam1, 0, 1000);
|
||||
verifyReplication(htd.getTableName(), 2, 0, 1000);
|
||||
}
|
||||
}
|
||||
|
||||
public void testRegionReplicaReplication(int regionReplication) throws Exception {
|
||||
// test region replica replication. Create a table with single region, write some data
|
||||
|
|
Loading…
Reference in New Issue