Java Code Examples for org.apache.hadoop.hbase.replication.ReplicationPeerConfig#isSyncReplication()

The following examples show how to use org.apache.hadoop.hbase.replication.ReplicationPeerConfig#isSyncReplication() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ReplicationPeerManager.java    From hbase with Apache License 2.0 6 votes vote down vote up
void preAddPeer(String peerId, ReplicationPeerConfig peerConfig)
    throws DoNotRetryIOException, ReplicationException {
  if (peerId.contains("-")) {
    throw new DoNotRetryIOException("Found invalid peer name: " + peerId);
  }
  checkPeerConfig(peerConfig);
  if (peerConfig.isSyncReplication()) {
    checkSyncReplicationPeerConfigConflict(peerConfig);
  }
  if (peers.containsKey(peerId)) {
    throw new DoNotRetryIOException("Replication peer " + peerId + " already exists");
  }
  // make sure that there is no queues with the same peer id. This may happen when we create a
  // peer with the same id with a old deleted peer. If the replication queues for the old peer
  // have not been cleaned up yet then we should not create the new peer, otherwise the old wal
  // file may also be replicated.
  checkQueuesDeleted(peerId);
}
 
Example 2
Source File: ReplicationSourceManager.java    From hbase with Apache License 2.0 5 votes vote down vote up
/**
 * Add a normal source for the given peer on this region server. Meanwhile, add new replication
 * queue to storage. For the newly added peer, we only need to enqueue the latest log of each wal
 * group and do replication
 * @param peerId the id of the replication peer
 * @return the source that was created
 */
@VisibleForTesting
ReplicationSourceInterface addSource(String peerId) throws IOException {
  ReplicationPeer peer = replicationPeers.getPeer(peerId);
  ReplicationSourceInterface src = createSource(peerId, peer);
  // synchronized on latestPaths to avoid missing the new log
  synchronized (this.latestPaths) {
    this.sources.put(peerId, src);
    Map<String, NavigableSet<String>> walsByGroup = new HashMap<>();
    this.walsById.put(peerId, walsByGroup);
    // Add the latest wal to that source's queue
    if (!latestPaths.isEmpty()) {
      for (Map.Entry<String, Path> walPrefixAndPath : latestPaths.entrySet()) {
        Path walPath = walPrefixAndPath.getValue();
        NavigableSet<String> wals = new TreeSet<>();
        wals.add(walPath.getName());
        walsByGroup.put(walPrefixAndPath.getKey(), wals);
        // Abort RS and throw exception to make add peer failed
        abortAndThrowIOExceptionWhenFail(
          () -> this.queueStorage.addWAL(server.getServerName(), peerId, walPath.getName()));
        src.enqueueLog(walPath);
        LOG.trace("Enqueued {} to source {} during source creation.", walPath, src.getQueueId());
      }
    }
  }
  ReplicationPeerConfig peerConfig = peer.getPeerConfig();
  if (peerConfig.isSyncReplication()) {
    syncReplicationPeerMappingManager.add(peer.getId(), peerConfig);
  }
  src.startup();
  return src;
}
 
Example 3
Source File: ReplicationPeerManager.java    From hbase with Apache License 2.0 5 votes vote down vote up
/**
 * Return the old peer description. Can never be null.
 */
ReplicationPeerDescription preUpdatePeerConfig(String peerId, ReplicationPeerConfig peerConfig)
    throws DoNotRetryIOException {
  checkPeerConfig(peerConfig);
  ReplicationPeerDescription desc = checkPeerExists(peerId);
  ReplicationPeerConfig oldPeerConfig = desc.getPeerConfig();
  if (!isStringEquals(peerConfig.getClusterKey(), oldPeerConfig.getClusterKey())) {
    throw new DoNotRetryIOException(
      "Changing the cluster key on an existing peer is not allowed. Existing key '" +
        oldPeerConfig.getClusterKey() + "' for peer " + peerId + " does not match new key '" +
        peerConfig.getClusterKey() + "'");
  }

  if (!isStringEquals(peerConfig.getReplicationEndpointImpl(),
    oldPeerConfig.getReplicationEndpointImpl())) {
    throw new DoNotRetryIOException("Changing the replication endpoint implementation class " +
      "on an existing peer is not allowed. Existing class '" +
      oldPeerConfig.getReplicationEndpointImpl() + "' for peer " + peerId +
      " does not match new class '" + peerConfig.getReplicationEndpointImpl() + "'");
  }

  if (!isStringEquals(peerConfig.getRemoteWALDir(), oldPeerConfig.getRemoteWALDir())) {
    throw new DoNotRetryIOException(
      "Changing the remote wal dir on an existing peer is not allowed. Existing remote wal " +
        "dir '" + oldPeerConfig.getRemoteWALDir() + "' for peer " + peerId +
        " does not match new remote wal dir '" + peerConfig.getRemoteWALDir() + "'");
  }

  if (oldPeerConfig.isSyncReplication()) {
    if (!ReplicationUtils.isNamespacesAndTableCFsEqual(oldPeerConfig, peerConfig)) {
      throw new DoNotRetryIOException(
        "Changing the replicated namespace/table config on a synchronous replication " +
          "peer(peerId: " + peerId + ") is not allowed.");
    }
  }
  return desc;
}
 
Example 4
Source File: ReplicationPeerManager.java    From hbase with Apache License 2.0 5 votes vote down vote up
public void addPeer(String peerId, ReplicationPeerConfig peerConfig, boolean enabled)
    throws ReplicationException {
  if (peers.containsKey(peerId)) {
    // this should be a retry, just return
    return;
  }
  ReplicationPeerConfig copiedPeerConfig = ReplicationPeerConfig.newBuilder(peerConfig).build();
  SyncReplicationState syncReplicationState =
    copiedPeerConfig.isSyncReplication() ? SyncReplicationState.DOWNGRADE_ACTIVE
      : SyncReplicationState.NONE;
  peerStorage.addPeer(peerId, copiedPeerConfig, enabled, syncReplicationState);
  peers.put(peerId,
    new ReplicationPeerDescription(peerId, enabled, copiedPeerConfig, syncReplicationState));
}
 
Example 5
Source File: ReplicationPeerManager.java    From hbase with Apache License 2.0 5 votes vote down vote up
private void checkSyncReplicationPeerConfigConflict(ReplicationPeerConfig peerConfig)
    throws DoNotRetryIOException {
  for (TableName tableName : peerConfig.getTableCFsMap().keySet()) {
    for (Map.Entry<String, ReplicationPeerDescription> entry : peers.entrySet()) {
      ReplicationPeerConfig rpc = entry.getValue().getPeerConfig();
      if (rpc.isSyncReplication() && rpc.getTableCFsMap().containsKey(tableName)) {
        throw new DoNotRetryIOException(
            "Table " + tableName + " has been replicated by peer " + entry.getKey());
      }
    }
  }
}
 
Example 6
Source File: ReplicationPeerManager.java    From hbase with Apache License 2.0 4 votes vote down vote up
private void checkPeerConfig(ReplicationPeerConfig peerConfig) throws DoNotRetryIOException {
  String replicationEndpointImpl = peerConfig.getReplicationEndpointImpl();
  boolean checkClusterKey = true;
  if (!StringUtils.isBlank(replicationEndpointImpl)) {
    // try creating a instance
    ReplicationEndpoint endpoint;
    try {
      endpoint = Class.forName(replicationEndpointImpl)
        .asSubclass(ReplicationEndpoint.class).getDeclaredConstructor().newInstance();
    } catch (Throwable e) {
      throw new DoNotRetryIOException(
        "Can not instantiate configured replication endpoint class=" + replicationEndpointImpl,
        e);
    }
    // do not check cluster key if we are not HBaseInterClusterReplicationEndpoint
    if (!(endpoint instanceof HBaseInterClusterReplicationEndpoint)) {
      checkClusterKey = false;
    }
  }
  if (checkClusterKey) {
    checkClusterKey(peerConfig.getClusterKey());
  }

  if (peerConfig.replicateAllUserTables()) {
    // If replicate_all flag is true, it means all user tables will be replicated to peer cluster.
    // Then allow config exclude namespaces or exclude table-cfs which can't be replicated to peer
    // cluster.
    if ((peerConfig.getNamespaces() != null && !peerConfig.getNamespaces().isEmpty()) ||
      (peerConfig.getTableCFsMap() != null && !peerConfig.getTableCFsMap().isEmpty())) {
      throw new DoNotRetryIOException("Need clean namespaces or table-cfs config firstly " +
        "when you want replicate all cluster");
    }
    checkNamespacesAndTableCfsConfigConflict(peerConfig.getExcludeNamespaces(),
      peerConfig.getExcludeTableCFsMap());
  } else {
    // If replicate_all flag is false, it means all user tables can't be replicated to peer
    // cluster. Then allow to config namespaces or table-cfs which will be replicated to peer
    // cluster.
    if ((peerConfig.getExcludeNamespaces() != null &&
      !peerConfig.getExcludeNamespaces().isEmpty()) ||
      (peerConfig.getExcludeTableCFsMap() != null &&
        !peerConfig.getExcludeTableCFsMap().isEmpty())) {
      throw new DoNotRetryIOException(
        "Need clean exclude-namespaces or exclude-table-cfs config firstly" +
          " when replicate_all flag is false");
    }
    checkNamespacesAndTableCfsConfigConflict(peerConfig.getNamespaces(),
      peerConfig.getTableCFsMap());
  }

  if (peerConfig.isSyncReplication()) {
    checkPeerConfigForSyncReplication(peerConfig);
  }

  checkConfiguredWALEntryFilters(peerConfig);
}