Search in sources :

Example 26 with ReplicationPeerConfig

use of org.apache.hadoop.hbase.replication.ReplicationPeerConfig in project hbase by apache.

the class TestRegionReplicaReplicationEndpoint method testRegionReplicaReplicationPeerIsCreatedForModifyTable.

@Test(timeout = 240000)
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";
    ReplicationPeerConfig peerConfig = null;
    try {
        peerConfig = admin.getPeerConfig(peerId);
    } catch (ReplicationPeerNotFoundException e) {
        LOG.warn("Region replica replication peer id=" + peerId + " not exist", e);
    }
    if (peerConfig != null) {
        admin.removePeer(peerId);
        peerConfig = null;
    }
    HTableDescriptor htd = HTU.createTableDescriptor("testRegionReplicaReplicationPeerIsCreatedForModifyTable");
    HTU.getAdmin().createTable(htd);
    // assert that replication peer is not created yet
    try {
        peerConfig = admin.getPeerConfig(peerId);
        fail("Should throw ReplicationException, because replication peer id=" + peerId + " not exist");
    } catch (ReplicationPeerNotFoundException e) {
    }
    assertNull(peerConfig);
    HTU.getAdmin().disableTable(htd.getTableName());
    htd.setRegionReplication(2);
    HTU.getAdmin().modifyTable(htd.getTableName(), htd);
    HTU.getAdmin().enableTable(htd.getTableName());
    // assert peer configuration is correct
    peerConfig = admin.getPeerConfig(peerId);
    assertNotNull(peerConfig);
    assertEquals(peerConfig.getClusterKey(), ZKConfig.getZooKeeperClusterKey(HTU.getConfiguration()));
    assertEquals(peerConfig.getReplicationEndpointImpl(), RegionReplicaReplicationEndpoint.class.getName());
    admin.close();
}
Also used : ReplicationPeerConfig(org.apache.hadoop.hbase.replication.ReplicationPeerConfig) ReplicationPeerNotFoundException(org.apache.hadoop.hbase.ReplicationPeerNotFoundException) ReplicationAdmin(org.apache.hadoop.hbase.client.replication.ReplicationAdmin) HTableDescriptor(org.apache.hadoop.hbase.HTableDescriptor) Test(org.junit.Test)

Example 27 with ReplicationPeerConfig

use of org.apache.hadoop.hbase.replication.ReplicationPeerConfig in project hbase by apache.

the class HBaseAdmin method needToReplicate.

/**
   * Decide whether the table need replicate to the peer cluster according to the peer config
   * @param table name of the table
   * @param peerConfig config for the peer
   * @return true if the table need replicate to the peer cluster
   */
private boolean needToReplicate(TableName table, ReplicationPeerDescription peer) {
    ReplicationPeerConfig peerConfig = peer.getPeerConfig();
    Set<String> namespaces = peerConfig.getNamespaces();
    Map<TableName, List<String>> tableCFsMap = peerConfig.getTableCFsMap();
    // so all the tables data are applicable for replication
    if (namespaces == null && tableCFsMap == null) {
        return true;
    }
    if (namespaces != null && namespaces.contains(table.getNamespaceAsString())) {
        return true;
    }
    if (tableCFsMap != null && tableCFsMap.containsKey(table)) {
        return true;
    }
    LOG.debug("Table " + table.getNameAsString() + " doesn't need replicate to peer cluster, peerId=" + peer.getPeerId() + ", clusterKey=" + peerConfig.getClusterKey());
    return false;
}
Also used : TableName(org.apache.hadoop.hbase.TableName) ReplicationPeerConfig(org.apache.hadoop.hbase.replication.ReplicationPeerConfig) ArrayList(java.util.ArrayList) List(java.util.List) LinkedList(java.util.LinkedList)

Example 28 with ReplicationPeerConfig

use of org.apache.hadoop.hbase.replication.ReplicationPeerConfig in project hbase by apache.

the class HBaseAdmin method removeReplicationPeerTableCFs.

@Override
public void removeReplicationPeerTableCFs(String id, Map<TableName, ? extends Collection<String>> tableCfs) throws ReplicationException, IOException {
    if (tableCfs == null) {
        throw new ReplicationException("tableCfs is null");
    }
    ReplicationPeerConfig peerConfig = getReplicationPeerConfig(id);
    Map<TableName, List<String>> preTableCfs = peerConfig.getTableCFsMap();
    if (preTableCfs == null) {
        throw new ReplicationException("Table-Cfs for peer" + id + " is null");
    }
    for (Map.Entry<TableName, ? extends Collection<String>> entry : tableCfs.entrySet()) {
        TableName table = entry.getKey();
        Collection<String> removeCfs = entry.getValue();
        if (preTableCfs.containsKey(table)) {
            List<String> cfs = preTableCfs.get(table);
            if (cfs == null && (removeCfs == null || removeCfs.isEmpty())) {
                preTableCfs.remove(table);
            } else if (cfs != null && (removeCfs != null && !removeCfs.isEmpty())) {
                Set<String> cfSet = new HashSet<String>(cfs);
                cfSet.removeAll(removeCfs);
                if (cfSet.isEmpty()) {
                    preTableCfs.remove(table);
                } else {
                    preTableCfs.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 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 table-cfs config in peer: " + id);
            }
        } else {
            throw new ReplicationException("No table: " + table + " in table-cfs config of peer: " + id);
        }
    }
    updateReplicationPeerConfig(id, peerConfig);
}
Also used : TableName(org.apache.hadoop.hbase.TableName) ReplicationPeerConfig(org.apache.hadoop.hbase.replication.ReplicationPeerConfig) Set(java.util.Set) HashSet(java.util.HashSet) ReplicationException(org.apache.hadoop.hbase.replication.ReplicationException) ArrayList(java.util.ArrayList) List(java.util.List) LinkedList(java.util.LinkedList) Map(java.util.Map) TreeMap(java.util.TreeMap) HashMap(java.util.HashMap)

Example 29 with ReplicationPeerConfig

use of org.apache.hadoop.hbase.replication.ReplicationPeerConfig in project hbase by apache.

the class HBaseAdmin method appendReplicationPeerTableCFs.

@Override
public void appendReplicationPeerTableCFs(String id, Map<TableName, ? extends Collection<String>> tableCfs) throws ReplicationException, IOException {
    if (tableCfs == null) {
        throw new ReplicationException("tableCfs is null");
    }
    ReplicationPeerConfig peerConfig = getReplicationPeerConfig(id);
    Map<TableName, List<String>> preTableCfs = peerConfig.getTableCFsMap();
    if (preTableCfs == null) {
        peerConfig.setTableCFsMap(tableCfs);
    } else {
        for (Map.Entry<TableName, ? extends Collection<String>> entry : tableCfs.entrySet()) {
            TableName table = entry.getKey();
            Collection<String> appendCfs = entry.getValue();
            if (preTableCfs.containsKey(table)) {
                List<String> cfs = preTableCfs.get(table);
                if (cfs == null || appendCfs == null || appendCfs.isEmpty()) {
                    preTableCfs.put(table, null);
                } else {
                    Set<String> cfSet = new HashSet<String>(cfs);
                    cfSet.addAll(appendCfs);
                    preTableCfs.put(table, Lists.newArrayList(cfSet));
                }
            } else {
                if (appendCfs == null || appendCfs.isEmpty()) {
                    preTableCfs.put(table, null);
                } else {
                    preTableCfs.put(table, Lists.newArrayList(appendCfs));
                }
            }
        }
    }
    updateReplicationPeerConfig(id, peerConfig);
}
Also used : TableName(org.apache.hadoop.hbase.TableName) ReplicationPeerConfig(org.apache.hadoop.hbase.replication.ReplicationPeerConfig) ReplicationException(org.apache.hadoop.hbase.replication.ReplicationException) ArrayList(java.util.ArrayList) List(java.util.List) LinkedList(java.util.LinkedList) Map(java.util.Map) TreeMap(java.util.TreeMap) HashMap(java.util.HashMap) HashSet(java.util.HashSet)

Example 30 with ReplicationPeerConfig

use of org.apache.hadoop.hbase.replication.ReplicationPeerConfig in project hbase by apache.

the class ReplicationAdmin method listPeerConfigs.

/**
   * @deprecated use {@link org.apache.hadoop.hbase.client.Admin#listReplicationPeers()} instead
   */
@Deprecated
public Map<String, ReplicationPeerConfig> listPeerConfigs() throws IOException {
    List<ReplicationPeerDescription> peers = this.admin.listReplicationPeers();
    Map<String, ReplicationPeerConfig> result = new TreeMap<>();
    for (ReplicationPeerDescription peer : peers) {
        result.put(peer.getPeerId(), peer.getPeerConfig());
    }
    return result;
}
Also used : ReplicationPeerConfig(org.apache.hadoop.hbase.replication.ReplicationPeerConfig) ReplicationPeerDescription(org.apache.hadoop.hbase.replication.ReplicationPeerDescription) TreeMap(java.util.TreeMap)

Aggregations

ReplicationPeerConfig (org.apache.hadoop.hbase.replication.ReplicationPeerConfig)42 Test (org.junit.Test)18 ReplicationException (org.apache.hadoop.hbase.replication.ReplicationException)11 IOException (java.io.IOException)10 ArrayList (java.util.ArrayList)10 List (java.util.List)10 TableName (org.apache.hadoop.hbase.TableName)10 HashMap (java.util.HashMap)8 HashSet (java.util.HashSet)7 Configuration (org.apache.hadoop.conf.Configuration)7 ReplicationAdmin (org.apache.hadoop.hbase.client.replication.ReplicationAdmin)7 HTableDescriptor (org.apache.hadoop.hbase.HTableDescriptor)6 ReplicationPeerNotFoundException (org.apache.hadoop.hbase.ReplicationPeerNotFoundException)6 ZooKeeperWatcher (org.apache.hadoop.hbase.zookeeper.ZooKeeperWatcher)6 TreeMap (java.util.TreeMap)5 HBaseConfiguration (org.apache.hadoop.hbase.HBaseConfiguration)5 HBaseTestingUtility (org.apache.hadoop.hbase.HBaseTestingUtility)5 Map (java.util.Map)4 HColumnDescriptor (org.apache.hadoop.hbase.HColumnDescriptor)4 ReplicationPeerDescription (org.apache.hadoop.hbase.replication.ReplicationPeerDescription)4