Search in sources :

Example 31 with ReplicationPeerConfig

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

the class ReplicationAdmin method removePeerTableCFs.

/**
   * Remove some table-cfs from config of the specified peer
   * @param id a short name that identifies the cluster
   * @param tableCfs A map from tableName to column family names
   * @throws ReplicationException
   * @throws IOException
   */
@Deprecated
public void removePeerTableCFs(String id, Map<TableName, ? extends Collection<String>> tableCfs) throws ReplicationException, IOException {
    if (tableCfs == null) {
        throw new ReplicationException("tableCfs is null");
    }
    ReplicationPeerConfig peerConfig = admin.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<>(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);
        }
    }
    updatePeerConfig(id, peerConfig);
}
Also used : TableName(org.apache.hadoop.hbase.TableName) ReplicationPeerConfig(org.apache.hadoop.hbase.replication.ReplicationPeerConfig) HashSet(java.util.HashSet) Set(java.util.Set) ReplicationException(org.apache.hadoop.hbase.replication.ReplicationException) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) TreeMap(java.util.TreeMap)

Example 32 with ReplicationPeerConfig

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

the class ReplicationAdmin method listReplicationPeers.

/**
   * @deprecated use {@link org.apache.hadoop.hbase.client.Admin#listReplicationPeers()} instead
   */
@VisibleForTesting
@Deprecated
List<ReplicationPeer> listReplicationPeers() throws IOException {
    Map<String, ReplicationPeerConfig> peers = listPeerConfigs();
    if (peers == null || peers.size() <= 0) {
        return null;
    }
    List<ReplicationPeer> listOfPeers = new ArrayList<>(peers.size());
    for (Entry<String, ReplicationPeerConfig> peerEntry : peers.entrySet()) {
        String peerId = peerEntry.getKey();
        try {
            Pair<ReplicationPeerConfig, Configuration> pair = this.replicationPeers.getPeerConf(peerId);
            Configuration peerConf = pair.getSecond();
            ReplicationPeer peer = new ReplicationPeerZKImpl(zkw, pair.getSecond(), peerId, pair.getFirst(), this.connection);
            listOfPeers.add(peer);
        } catch (ReplicationException e) {
            LOG.warn("Failed to get valid replication peers. " + "Error connecting to peer cluster with peerId=" + peerId + ". Error message=" + e.getMessage());
            LOG.debug("Failure details to get valid replication peers.", e);
            continue;
        }
    }
    return listOfPeers;
}
Also used : ReplicationPeerConfig(org.apache.hadoop.hbase.replication.ReplicationPeerConfig) Configuration(org.apache.hadoop.conf.Configuration) ArrayList(java.util.ArrayList) ReplicationPeerZKImpl(org.apache.hadoop.hbase.replication.ReplicationPeerZKImpl) ReplicationException(org.apache.hadoop.hbase.replication.ReplicationException) ReplicationPeer(org.apache.hadoop.hbase.replication.ReplicationPeer) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 33 with ReplicationPeerConfig

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

the class ReplicationSerDeHelper method parsePeerFrom.

/**
   * @param bytes Content of a peer znode.
   * @return ClusterKey parsed from the passed bytes.
   * @throws DeserializationException
   */
public static ReplicationPeerConfig parsePeerFrom(final byte[] bytes) throws DeserializationException {
    if (ProtobufUtil.isPBMagicPrefix(bytes)) {
        int pblen = ProtobufUtil.lengthOfPBMagic();
        ReplicationProtos.ReplicationPeer.Builder builder = ReplicationProtos.ReplicationPeer.newBuilder();
        ReplicationProtos.ReplicationPeer peer;
        try {
            ProtobufUtil.mergeFrom(builder, bytes, pblen, bytes.length - pblen);
            peer = builder.build();
        } catch (IOException e) {
            throw new DeserializationException(e);
        }
        return convert(peer);
    } else {
        if (bytes.length > 0) {
            return new ReplicationPeerConfig().setClusterKey(Bytes.toString(bytes));
        }
        return new ReplicationPeerConfig().setClusterKey("");
    }
}
Also used : ReplicationProtos(org.apache.hadoop.hbase.shaded.protobuf.generated.ReplicationProtos) ReplicationPeerConfig(org.apache.hadoop.hbase.replication.ReplicationPeerConfig) IOException(java.io.IOException) DeserializationException(org.apache.hadoop.hbase.exceptions.DeserializationException)

Example 34 with ReplicationPeerConfig

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

the class ReplicationSerDeHelper method convert.

public static ReplicationPeerConfig convert(ReplicationProtos.ReplicationPeer peer) {
    ReplicationPeerConfig peerConfig = new ReplicationPeerConfig();
    if (peer.hasClusterkey()) {
        peerConfig.setClusterKey(peer.getClusterkey());
    }
    if (peer.hasReplicationEndpointImpl()) {
        peerConfig.setReplicationEndpointImpl(peer.getReplicationEndpointImpl());
    }
    for (HBaseProtos.BytesBytesPair pair : peer.getDataList()) {
        peerConfig.getPeerData().put(pair.getFirst().toByteArray(), pair.getSecond().toByteArray());
    }
    for (HBaseProtos.NameStringPair pair : peer.getConfigurationList()) {
        peerConfig.getConfiguration().put(pair.getName(), pair.getValue());
    }
    Map<TableName, ? extends Collection<String>> tableCFsMap = convert2Map(peer.getTableCfsList().toArray(new ReplicationProtos.TableCF[peer.getTableCfsCount()]));
    if (tableCFsMap != null) {
        peerConfig.setTableCFsMap(tableCFsMap);
    }
    List<ByteString> namespacesList = peer.getNamespacesList();
    if (namespacesList != null && namespacesList.size() != 0) {
        Set<String> namespaces = new HashSet<>();
        for (ByteString namespace : namespacesList) {
            namespaces.add(namespace.toStringUtf8());
        }
        peerConfig.setNamespaces(namespaces);
    }
    if (peer.hasBandwidth()) {
        peerConfig.setBandwidth(peer.getBandwidth());
    }
    return peerConfig;
}
Also used : TableName(org.apache.hadoop.hbase.TableName) ReplicationPeerConfig(org.apache.hadoop.hbase.replication.ReplicationPeerConfig) ByteString(org.apache.hadoop.hbase.shaded.com.google.protobuf.ByteString) ByteString(org.apache.hadoop.hbase.shaded.com.google.protobuf.ByteString) HBaseProtos(org.apache.hadoop.hbase.shaded.protobuf.generated.HBaseProtos) HashSet(java.util.HashSet)

Example 35 with ReplicationPeerConfig

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

the class ServerRegionReplicaUtil method setupRegionReplicaReplication.

/**
   * Create replication peer for replicating to region replicas if needed.
   * @param conf configuration to use
   * @throws IOException
   */
public static void setupRegionReplicaReplication(Configuration conf) throws IOException {
    if (!isRegionReplicaReplicationEnabled(conf)) {
        return;
    }
    Admin admin = ConnectionFactory.createConnection(conf).getAdmin();
    ReplicationPeerConfig peerConfig = null;
    try {
        peerConfig = admin.getReplicationPeerConfig(REGION_REPLICA_REPLICATION_PEER);
    } catch (ReplicationPeerNotFoundException e) {
        LOG.warn("Region replica replication peer id=" + REGION_REPLICA_REPLICATION_PEER + " not exist", e);
    }
    try {
        if (peerConfig == null) {
            LOG.info("Region replica replication peer id=" + REGION_REPLICA_REPLICATION_PEER + " not exist. Creating...");
            peerConfig = new ReplicationPeerConfig();
            peerConfig.setClusterKey(ZKConfig.getZooKeeperClusterKey(conf));
            peerConfig.setReplicationEndpointImpl(RegionReplicaReplicationEndpoint.class.getName());
            admin.addReplicationPeer(REGION_REPLICA_REPLICATION_PEER, peerConfig);
        }
    } finally {
        admin.close();
    }
}
Also used : RegionReplicaReplicationEndpoint(org.apache.hadoop.hbase.replication.regionserver.RegionReplicaReplicationEndpoint) ReplicationPeerConfig(org.apache.hadoop.hbase.replication.ReplicationPeerConfig) ReplicationPeerNotFoundException(org.apache.hadoop.hbase.ReplicationPeerNotFoundException) Admin(org.apache.hadoop.hbase.client.Admin) ReplicationAdmin(org.apache.hadoop.hbase.client.replication.ReplicationAdmin)

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