Search in sources :

Example 1 with ReplicationPeerConfigBuilder

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();
}
Also used : Path(org.apache.hadoop.fs.Path) TableName(org.apache.hadoop.hbase.TableName) ReplicationPeerConfigBuilder(org.apache.hadoop.hbase.replication.ReplicationPeerConfigBuilder) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) List(java.util.List)

Example 2 with ReplicationPeerConfigBuilder

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();
}
Also used : TableName(org.apache.hadoop.hbase.TableName) ReplicationPeerConfigBuilder(org.apache.hadoop.hbase.replication.ReplicationPeerConfigBuilder) HashMap(java.util.HashMap) CompletionException(java.util.concurrent.CompletionException) ArrayList(java.util.ArrayList) List(java.util.List) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 3 with ReplicationPeerConfigBuilder

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();
}
Also used : ReplicationPeerConfigBuilder(org.apache.hadoop.hbase.replication.ReplicationPeerConfigBuilder) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 4 with ReplicationPeerConfigBuilder

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();
}
Also used : ReplicationPeerConfigBuilder(org.apache.hadoop.hbase.replication.ReplicationPeerConfigBuilder) Test(org.junit.Test)

Example 5 with ReplicationPeerConfigBuilder

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();
    }
}
Also used : TableName(org.apache.hadoop.hbase.TableName) ReplicationPeerConfigBuilder(org.apache.hadoop.hbase.replication.ReplicationPeerConfigBuilder) HashMap(java.util.HashMap) List(java.util.List) Test(org.junit.Test)

Aggregations

ReplicationPeerConfigBuilder (org.apache.hadoop.hbase.replication.ReplicationPeerConfigBuilder)14 List (java.util.List)10 TableName (org.apache.hadoop.hbase.TableName)10 ArrayList (java.util.ArrayList)9 HashMap (java.util.HashMap)8 Test (org.junit.Test)6 HashSet (java.util.HashSet)4 ReplicationException (org.apache.hadoop.hbase.replication.ReplicationException)4 ByteString (org.apache.hbase.thirdparty.com.google.protobuf.ByteString)4 Map (java.util.Map)3 Set (java.util.Set)2 CompletionException (java.util.concurrent.CompletionException)2 Path (org.apache.hadoop.fs.Path)1 ReplicationPeerConfig (org.apache.hadoop.hbase.replication.ReplicationPeerConfig)1 ReplicationPeerDescription (org.apache.hadoop.hbase.replication.ReplicationPeerDescription)1 HBaseProtos (org.apache.hadoop.hbase.shaded.protobuf.generated.HBaseProtos)1