use of org.apache.hadoop.hbase.replication.ReplicationPeerConfigBuilder in project hbase by apache.
the class ReplicationPeerConfigUtil method removeExcludeTableCFsFromReplicationPeerConfig.
public static ReplicationPeerConfig removeExcludeTableCFsFromReplicationPeerConfig(Map<TableName, List<String>> excludeTableCfs, ReplicationPeerConfig peerConfig, String id) throws ReplicationException {
if (excludeTableCfs == null) {
throw new ReplicationException("exclude tableCfs is null");
}
Map<TableName, List<String>> preExcludeTableCfs = peerConfig.getExcludeTableCFsMap();
if (preExcludeTableCfs == null) {
throw new ReplicationException("exclude-Table-Cfs for peer: " + id + " is null");
}
Map<TableName, List<String>> newExcludeTableCfs = copyTableCFsMap(preExcludeTableCfs);
for (Map.Entry<TableName, ? extends Collection<String>> entry : excludeTableCfs.entrySet()) {
TableName table = entry.getKey();
Collection<String> removeCfs = entry.getValue();
if (newExcludeTableCfs.containsKey(table)) {
List<String> cfs = newExcludeTableCfs.get(table);
if (cfs == null && (removeCfs == null || removeCfs.isEmpty())) {
newExcludeTableCfs.remove(table);
} else if (cfs != null && (removeCfs != null && !removeCfs.isEmpty())) {
Set<String> cfSet = new HashSet<String>(cfs);
cfSet.removeAll(removeCfs);
if (cfSet.isEmpty()) {
newExcludeTableCfs.remove(table);
} else {
newExcludeTableCfs.put(table, Lists.newArrayList(cfSet));
}
} else if (cfs == null && (removeCfs != null && !removeCfs.isEmpty())) {
throw new ReplicationException("Cannot remove cf of table: " + table + " which doesn't specify cfs from exclude-table-cfs config in peer: " + id);
} else if (cfs != null && (removeCfs == null || removeCfs.isEmpty())) {
throw new ReplicationException("Cannot remove table: " + table + " which has specified cfs from exclude-table-cfs config in peer: " + id);
}
} else {
throw new ReplicationException("No table: " + table + " in exclude-table-cfs config of peer: " + id);
}
}
ReplicationPeerConfigBuilder builder = ReplicationPeerConfig.newBuilder(peerConfig);
builder.setExcludeTableCFsMap(newExcludeTableCfs);
return builder.build();
}
use of org.apache.hadoop.hbase.replication.ReplicationPeerConfigBuilder in project hbase by apache.
the class ReplicationPeerManager method updatePeerConfig.
public void updatePeerConfig(String peerId, ReplicationPeerConfig peerConfig) throws ReplicationException {
// the checking rules are too complicated here so we give up checking whether this is a retry.
ReplicationPeerDescription desc = peers.get(peerId);
ReplicationPeerConfig oldPeerConfig = desc.getPeerConfig();
ReplicationPeerConfigBuilder newPeerConfigBuilder = ReplicationPeerConfig.newBuilder(peerConfig);
// we need to use the new conf to overwrite the old one.
newPeerConfigBuilder.putAllConfiguration(oldPeerConfig.getConfiguration());
newPeerConfigBuilder.putAllConfiguration(peerConfig.getConfiguration());
ReplicationPeerConfig newPeerConfig = newPeerConfigBuilder.build();
peerStorage.updatePeerConfig(peerId, newPeerConfig);
peers.put(peerId, new ReplicationPeerDescription(peerId, desc.isEnabled(), newPeerConfig, desc.getSyncReplicationState()));
}
use of org.apache.hadoop.hbase.replication.ReplicationPeerConfigBuilder in project hbase by apache.
the class TestAsyncReplicationAdminApi method testRemovePeerTableCFs.
@Test
public void testRemovePeerTableCFs() throws Exception {
ReplicationPeerConfigBuilder rpcBuilder = ReplicationPeerConfig.newBuilder().setClusterKey(KEY_ONE);
final TableName tableName1 = TableName.valueOf(tableName.getNameAsString() + "t1");
final TableName tableName2 = TableName.valueOf(tableName.getNameAsString() + "t2");
final TableName tableName3 = TableName.valueOf(tableName.getNameAsString() + "t3");
final TableName tableName4 = TableName.valueOf(tableName.getNameAsString() + "t4");
// Add a valid peer
admin.addReplicationPeer(ID_ONE, rpcBuilder.build()).join();
rpcBuilder.setReplicateAllUserTables(false);
admin.updateReplicationPeerConfig(ID_ONE, rpcBuilder.build()).join();
Map<TableName, List<String>> tableCFs = new HashMap<>();
try {
tableCFs.put(tableName3, null);
admin.removeReplicationPeerTableCFs(ID_ONE, tableCFs).join();
fail("Test case should fail as removing table-cfs from a peer whose table-cfs is null");
} catch (CompletionException e) {
assertTrue(e.getCause() instanceof ReplicationException);
}
assertNull(admin.getReplicationPeerConfig(ID_ONE).get().getTableCFsMap());
tableCFs.clear();
tableCFs.put(tableName1, null);
tableCFs.put(tableName2, new ArrayList<>());
tableCFs.get(tableName2).add("cf1");
admin.appendReplicationPeerTableCFs(ID_ONE, tableCFs).join();
try {
tableCFs.clear();
tableCFs.put(tableName3, null);
admin.removeReplicationPeerTableCFs(ID_ONE, tableCFs).join();
fail("Test case should fail as removing table-cfs from a peer whose" + " table-cfs didn't contain t3");
} catch (CompletionException e) {
assertTrue(e.getCause() instanceof ReplicationException);
}
Map<TableName, List<String>> result = admin.getReplicationPeerConfig(ID_ONE).get().getTableCFsMap();
assertEquals(2, result.size());
assertTrue("Should contain t1", result.containsKey(tableName1));
assertTrue("Should contain t2", result.containsKey(tableName2));
assertNull(result.get(tableName1));
assertEquals(1, result.get(tableName2).size());
assertEquals("cf1", result.get(tableName2).get(0));
try {
tableCFs.clear();
tableCFs.put(tableName1, new ArrayList<>());
tableCFs.get(tableName1).add("cf1");
admin.removeReplicationPeerTableCFs(ID_ONE, tableCFs).join();
fail("Test case should fail, because table t1 didn't specify cfs in peer config");
} catch (CompletionException e) {
assertTrue(e.getCause() instanceof ReplicationException);
}
tableCFs.clear();
tableCFs.put(tableName1, null);
admin.removeReplicationPeerTableCFs(ID_ONE, tableCFs).join();
result = admin.getReplicationPeerConfig(ID_ONE).get().getTableCFsMap();
assertEquals(1, result.size());
assertEquals(1, result.get(tableName2).size());
assertEquals("cf1", result.get(tableName2).get(0));
try {
tableCFs.clear();
tableCFs.put(tableName2, null);
admin.removeReplicationPeerTableCFs(ID_ONE, tableCFs).join();
fail("Test case should fail, because table t2 hase specified cfs in peer config");
} catch (CompletionException e) {
assertTrue(e.getCause() instanceof ReplicationException);
}
tableCFs.clear();
tableCFs.put(tableName2, new ArrayList<>());
tableCFs.get(tableName2).add("cf1");
admin.removeReplicationPeerTableCFs(ID_ONE, tableCFs).join();
assertNull(admin.getReplicationPeerConfig(ID_ONE).get().getTableCFsMap());
tableCFs.clear();
tableCFs.put(tableName4, new ArrayList<>());
admin.appendReplicationPeerTableCFs(ID_ONE, tableCFs).join();
admin.removeReplicationPeerTableCFs(ID_ONE, tableCFs).join();
assertNull(admin.getReplicationPeerConfig(ID_ONE).get().getTableCFsMap());
admin.removeReplicationPeer(ID_ONE);
}
use of org.apache.hadoop.hbase.replication.ReplicationPeerConfigBuilder in project hbase by apache.
the class TestAsyncReplicationAdminApi method testAppendPeerTableCFs.
@Test
public void testAppendPeerTableCFs() throws Exception {
ReplicationPeerConfigBuilder rpcBuilder = ReplicationPeerConfig.newBuilder().setClusterKey(KEY_ONE);
final TableName tableName1 = TableName.valueOf(tableName.getNameAsString() + "t1");
final TableName tableName2 = TableName.valueOf(tableName.getNameAsString() + "t2");
final TableName tableName3 = TableName.valueOf(tableName.getNameAsString() + "t3");
final TableName tableName4 = TableName.valueOf(tableName.getNameAsString() + "t4");
final TableName tableName5 = TableName.valueOf(tableName.getNameAsString() + "t5");
final TableName tableName6 = TableName.valueOf(tableName.getNameAsString() + "t6");
// Add a valid peer
admin.addReplicationPeer(ID_ONE, rpcBuilder.build()).join();
rpcBuilder.setReplicateAllUserTables(false);
admin.updateReplicationPeerConfig(ID_ONE, rpcBuilder.build()).join();
Map<TableName, List<String>> tableCFs = new HashMap<>();
// append table t1 to replication
tableCFs.put(tableName1, null);
admin.appendReplicationPeerTableCFs(ID_ONE, tableCFs).join();
Map<TableName, List<String>> result = admin.getReplicationPeerConfig(ID_ONE).get().getTableCFsMap();
assertEquals(1, result.size());
assertEquals(true, result.containsKey(tableName1));
assertNull(result.get(tableName1));
// append table t2 to replication
tableCFs.clear();
tableCFs.put(tableName2, null);
admin.appendReplicationPeerTableCFs(ID_ONE, tableCFs).join();
result = admin.getReplicationPeerConfig(ID_ONE).get().getTableCFsMap();
assertEquals(2, result.size());
assertTrue("Should contain t1", result.containsKey(tableName1));
assertTrue("Should contain t2", result.containsKey(tableName2));
assertNull(result.get(tableName1));
assertNull(result.get(tableName2));
// append table column family: f1 of t3 to replication
tableCFs.clear();
tableCFs.put(tableName3, new ArrayList<>());
tableCFs.get(tableName3).add("f1");
admin.appendReplicationPeerTableCFs(ID_ONE, tableCFs).join();
result = admin.getReplicationPeerConfig(ID_ONE).get().getTableCFsMap();
assertEquals(3, result.size());
assertTrue("Should contain t1", result.containsKey(tableName1));
assertTrue("Should contain t2", result.containsKey(tableName2));
assertTrue("Should contain t3", result.containsKey(tableName3));
assertNull(result.get(tableName1));
assertNull(result.get(tableName2));
assertEquals(1, result.get(tableName3).size());
assertEquals("f1", result.get(tableName3).get(0));
// append table column family: f1,f2 of t4 to replication
tableCFs.clear();
tableCFs.put(tableName4, new ArrayList<>());
tableCFs.get(tableName4).add("f1");
tableCFs.get(tableName4).add("f2");
admin.appendReplicationPeerTableCFs(ID_ONE, tableCFs).join();
result = admin.getReplicationPeerConfig(ID_ONE).get().getTableCFsMap();
assertEquals(4, result.size());
assertTrue("Should contain t1", result.containsKey(tableName1));
assertTrue("Should contain t2", result.containsKey(tableName2));
assertTrue("Should contain t3", result.containsKey(tableName3));
assertTrue("Should contain t4", result.containsKey(tableName4));
assertNull(result.get(tableName1));
assertNull(result.get(tableName2));
assertEquals(1, result.get(tableName3).size());
assertEquals("f1", result.get(tableName3).get(0));
assertEquals(2, result.get(tableName4).size());
assertEquals("f1", result.get(tableName4).get(0));
assertEquals("f2", result.get(tableName4).get(1));
// append "table5" => [], then append "table5" => ["f1"]
tableCFs.clear();
tableCFs.put(tableName5, new ArrayList<>());
admin.appendReplicationPeerTableCFs(ID_ONE, tableCFs).join();
tableCFs.clear();
tableCFs.put(tableName5, new ArrayList<>());
tableCFs.get(tableName5).add("f1");
admin.appendReplicationPeerTableCFs(ID_ONE, tableCFs).join();
result = admin.getReplicationPeerConfig(ID_ONE).get().getTableCFsMap();
assertEquals(5, result.size());
assertTrue("Should contain t5", result.containsKey(tableName5));
// null means replication all cfs of tab5
assertNull(result.get(tableName5));
// append "table6" => ["f1"], then append "table6" => []
tableCFs.clear();
tableCFs.put(tableName6, new ArrayList<>());
tableCFs.get(tableName6).add("f1");
admin.appendReplicationPeerTableCFs(ID_ONE, tableCFs).join();
tableCFs.clear();
tableCFs.put(tableName6, new ArrayList<>());
admin.appendReplicationPeerTableCFs(ID_ONE, tableCFs).join();
result = admin.getReplicationPeerConfig(ID_ONE).get().getTableCFsMap();
assertEquals(6, result.size());
assertTrue("Should contain t6", result.containsKey(tableName6));
// null means replication all cfs of tab6
assertNull(result.get(tableName6));
admin.removeReplicationPeer(ID_ONE).join();
}
use of org.apache.hadoop.hbase.replication.ReplicationPeerConfigBuilder in project hbase by apache.
the class ReplicationPeerConfigUtil method appendExcludeTableCFsToReplicationPeerConfig.
public static ReplicationPeerConfig appendExcludeTableCFsToReplicationPeerConfig(Map<TableName, List<String>> excludeTableCfs, ReplicationPeerConfig peerConfig) throws ReplicationException {
if (excludeTableCfs == null) {
throw new ReplicationException("exclude tableCfs is null");
}
ReplicationPeerConfigBuilder builder = ReplicationPeerConfig.newBuilder(peerConfig);
Map<TableName, List<String>> preExcludeTableCfs = peerConfig.getExcludeTableCFsMap();
if (preExcludeTableCfs == null) {
builder.setExcludeTableCFsMap(excludeTableCfs);
} else {
builder.setExcludeTableCFsMap(mergeTableCFs(preExcludeTableCfs, excludeTableCfs));
}
return builder.build();
}
Aggregations