use of org.apache.hadoop.hbase.replication.ReplicationPeerConfigBuilder in project hbase by apache.
the class TestReplicationAdminForSyncReplication method buildSyncReplicationPeerConfig.
private ReplicationPeerConfig buildSyncReplicationPeerConfig(String clusterKey, TableName tableName) throws IOException {
Path rootDir = TEST_UTIL.getDataTestDirOnTestFS("remoteWAL");
ReplicationPeerConfigBuilder builder = ReplicationPeerConfig.newBuilder();
builder.setClusterKey(clusterKey);
builder.setRemoteWALDir(rootDir.makeQualified(TEST_UTIL.getTestFileSystem().getUri(), TEST_UTIL.getTestFileSystem().getWorkingDirectory()).toString());
builder.setReplicateAllUserTables(false);
Map<TableName, List<String>> tableCfs = new HashMap<>();
tableCfs.put(tableName, new ArrayList<>());
builder.setTableCFsMap(tableCfs);
return builder.build();
}
use of org.apache.hadoop.hbase.replication.ReplicationPeerConfigBuilder in project hbase by apache.
the class TestAsyncReplicationAdminApi method testNamespacesAndTableCfsConfigConflict.
@Test
public void testNamespacesAndTableCfsConfigConflict() throws Exception {
String ns1 = "ns1";
String ns2 = "ns2";
final TableName tableName1 = TableName.valueOf(ns1 + ":" + tableName.getNameAsString() + "1");
final TableName tableName2 = TableName.valueOf(ns2 + ":" + tableName.getNameAsString() + "2");
ReplicationPeerConfigBuilder rpcBuilder = ReplicationPeerConfig.newBuilder().setClusterKey(KEY_ONE);
admin.addReplicationPeer(ID_ONE, rpcBuilder.build()).join();
rpcBuilder.setReplicateAllUserTables(false);
admin.updateReplicationPeerConfig(ID_ONE, rpcBuilder.build()).join();
Set<String> namespaces = new HashSet<String>();
namespaces.add(ns1);
rpcBuilder.setNamespaces(namespaces);
admin.updateReplicationPeerConfig(ID_ONE, rpcBuilder.build()).get();
Map<TableName, List<String>> tableCfs = new HashMap<>();
tableCfs.put(tableName1, new ArrayList<>());
rpcBuilder.setTableCFsMap(tableCfs);
try {
admin.updateReplicationPeerConfig(ID_ONE, rpcBuilder.build()).join();
fail("Test case should fail, because table " + tableName1 + " conflict with namespace " + ns1);
} catch (CompletionException e) {
// OK
}
tableCfs.clear();
tableCfs.put(tableName2, new ArrayList<>());
rpcBuilder.setTableCFsMap(tableCfs);
admin.updateReplicationPeerConfig(ID_ONE, rpcBuilder.build()).get();
namespaces.clear();
namespaces.add(ns2);
rpcBuilder.setNamespaces(namespaces);
try {
admin.updateReplicationPeerConfig(ID_ONE, rpcBuilder.build()).join();
fail("Test case should fail, because namespace " + ns2 + " conflict with table " + tableName2);
} catch (CompletionException e) {
// OK
}
admin.removeReplicationPeer(ID_ONE).join();
}
use of org.apache.hadoop.hbase.replication.ReplicationPeerConfigBuilder in project hbase by apache.
the class TestAsyncReplicationAdminApi method testSetPeerNamespaces.
@Test
public void testSetPeerNamespaces() throws Exception {
String ns1 = "ns1";
String ns2 = "ns2";
ReplicationPeerConfigBuilder rpcBuilder = ReplicationPeerConfig.newBuilder().setClusterKey(KEY_ONE);
admin.addReplicationPeer(ID_ONE, rpcBuilder.build()).join();
rpcBuilder.setReplicateAllUserTables(false);
admin.updateReplicationPeerConfig(ID_ONE, rpcBuilder.build()).join();
// add ns1 and ns2 to peer config
Set<String> namespaces = new HashSet<>();
namespaces.add(ns1);
namespaces.add(ns2);
rpcBuilder.setNamespaces(namespaces);
admin.updateReplicationPeerConfig(ID_ONE, rpcBuilder.build()).join();
namespaces = admin.getReplicationPeerConfig(ID_ONE).get().getNamespaces();
assertEquals(2, namespaces.size());
assertTrue(namespaces.contains(ns1));
assertTrue(namespaces.contains(ns2));
// update peer config only contains ns1
namespaces = new HashSet<>();
namespaces.add(ns1);
rpcBuilder.setNamespaces(namespaces);
admin.updateReplicationPeerConfig(ID_ONE, rpcBuilder.build()).join();
namespaces = admin.getReplicationPeerConfig(ID_ONE).get().getNamespaces();
assertEquals(1, namespaces.size());
assertTrue(namespaces.contains(ns1));
admin.removeReplicationPeer(ID_ONE).join();
}
use of org.apache.hadoop.hbase.replication.ReplicationPeerConfigBuilder in project hbase by apache.
the class TestAsyncReplicationAdminApi method testPeerBandwidth.
@Test
public void testPeerBandwidth() throws Exception {
ReplicationPeerConfigBuilder rpcBuilder = ReplicationPeerConfig.newBuilder().setClusterKey(KEY_ONE);
admin.addReplicationPeer(ID_ONE, rpcBuilder.build()).join();
;
assertEquals(0, admin.getReplicationPeerConfig(ID_ONE).get().getBandwidth());
rpcBuilder.setBandwidth(2097152);
admin.updateReplicationPeerConfig(ID_ONE, rpcBuilder.build()).join();
assertEquals(2097152, admin.getReplicationPeerConfig(ID_ONE).join().getBandwidth());
admin.removeReplicationPeer(ID_ONE).join();
}
use of org.apache.hadoop.hbase.replication.ReplicationPeerConfigBuilder in project hbase by apache.
the class TestAsyncReplicationAdminApiWithClusters method testEnableReplicationForExplicitSetTableCfs.
/*
* Test enable table replication should create table only in user explicit specified table-cfs.
* HBASE-14717
*/
@Test
public void testEnableReplicationForExplicitSetTableCfs() throws Exception {
TableName tableName2 = TableName.valueOf(tableName.getNameAsString() + "2");
// Only create table in source cluster
createTableWithDefaultConf(tableName);
createTableWithDefaultConf(tableName2);
assertFalse("Table should not exists in the peer cluster", admin2.tableExists(tableName).get());
assertFalse("Table should not exists in the peer cluster", admin2.tableExists(tableName2).get());
Map<TableName, List<String>> tableCfs = new HashMap<>();
tableCfs.put(tableName, null);
ReplicationPeerConfigBuilder rpcBuilder = ReplicationPeerConfig.newBuilder(admin.getReplicationPeerConfig(ID_SECOND).get()).setReplicateAllUserTables(false).setTableCFsMap(tableCfs);
try {
// Only add tableName to replication peer config
admin.updateReplicationPeerConfig(ID_SECOND, rpcBuilder.build()).join();
admin.enableTableReplication(tableName2).join();
assertFalse("Table should not be created if user has set table cfs explicitly for the " + "peer and this is not part of that collection", admin2.tableExists(tableName2).get());
// Add tableName2 to replication peer config, too
tableCfs.put(tableName2, null);
rpcBuilder.setTableCFsMap(tableCfs);
admin.updateReplicationPeerConfig(ID_SECOND, rpcBuilder.build()).join();
admin.enableTableReplication(tableName2).join();
assertTrue("Table should be created if user has explicitly added table into table cfs collection", admin2.tableExists(tableName2).get());
} finally {
rpcBuilder.setTableCFsMap(null).setReplicateAllUserTables(true).build();
admin.updateReplicationPeerConfig(ID_SECOND, rpcBuilder.build()).join();
}
}
Aggregations