Search in sources :

Example 11 with ReplicationException

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

the class ReplicationSourceManager method addSource.

/**
   * Add sources for the given peer cluster on this region server. For the newly added peer, we only
   * need to enqueue the latest log of each wal group and do replication
   * @param id the id of the peer cluster
   * @return the source that was created
   * @throws IOException
   */
protected ReplicationSourceInterface addSource(String id) throws IOException, ReplicationException {
    ReplicationPeerConfig peerConfig = replicationPeers.getReplicationPeerConfig(id);
    ReplicationPeer peer = replicationPeers.getConnectedPeer(id);
    ReplicationSourceInterface src = getReplicationSource(this.conf, this.fs, this, this.replicationQueues, this.replicationPeers, server, id, this.clusterId, peerConfig, peer);
    synchronized (this.walsById) {
        this.sources.add(src);
        Map<String, SortedSet<String>> walsByGroup = new HashMap<>();
        this.walsById.put(id, walsByGroup);
        // Add the latest wal to that source's queue
        synchronized (latestPaths) {
            if (this.latestPaths.size() > 0) {
                for (Path logPath : latestPaths) {
                    String name = logPath.getName();
                    String walPrefix = AbstractFSWALProvider.getWALPrefixFromWALName(name);
                    SortedSet<String> logs = new TreeSet<>();
                    logs.add(name);
                    walsByGroup.put(walPrefix, logs);
                    try {
                        this.replicationQueues.addLog(id, name);
                    } catch (ReplicationException e) {
                        String message = "Cannot add log to queue when creating a new source, queueId=" + id + ", filename=" + name;
                        server.stop(message);
                        throw e;
                    }
                    src.enqueueLog(logPath);
                }
            }
        }
    }
    src.startup();
    return src;
}
Also used : Path(org.apache.hadoop.fs.Path) ReplicationPeerConfig(org.apache.hadoop.hbase.replication.ReplicationPeerConfig) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) TreeSet(java.util.TreeSet) ReplicationException(org.apache.hadoop.hbase.replication.ReplicationException) ReplicationPeer(org.apache.hadoop.hbase.replication.ReplicationPeer) SortedSet(java.util.SortedSet)

Aggregations

ReplicationException (org.apache.hadoop.hbase.replication.ReplicationException)11 ReplicationPeerConfig (org.apache.hadoop.hbase.replication.ReplicationPeerConfig)9 HashMap (java.util.HashMap)7 ArrayList (java.util.ArrayList)6 List (java.util.List)5 Map (java.util.Map)5 TableName (org.apache.hadoop.hbase.TableName)5 IOException (java.io.IOException)4 HashSet (java.util.HashSet)4 TreeMap (java.util.TreeMap)4 LinkedList (java.util.LinkedList)2 Set (java.util.Set)2 SortedSet (java.util.SortedSet)2 TreeSet (java.util.TreeSet)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 Configuration (org.apache.hadoop.conf.Configuration)2 ReplicationPeer (org.apache.hadoop.hbase.replication.ReplicationPeer)2 ReplicationPeerZKImpl (org.apache.hadoop.hbase.replication.ReplicationPeerZKImpl)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 Path (org.apache.hadoop.fs.Path)1