@Override
  public void addPeer(String peerId, ReplicationPeerConfig peerConfig, boolean enabled,
    SyncReplicationState syncReplicationState) throws ReplicationException {
    Path peerDir = getPeerDir(peerId);
    try {
      if (fs.exists(peerDir)) {
        // check whether this is a valid peer, if so we should fail the add peer operation
        if (read(fs, peerDir, PEER_CONFIG_FILE) != null) {
          throw new ReplicationException("Could not add peer with id=" + peerId + ", peerConfig=>"
            + peerConfig + ", state=" + (enabled ? "ENABLED" : "DISABLED")
            + ", syncReplicationState=" + syncReplicationState + ", peer already exists");
        }
      }
      if (!enabled) {
        fs.createNewFile(new Path(peerDir, DISABLED_FILE));
      }
      write(fs, peerDir, SYNC_REPLICATION_STATE_FILE,
        SyncReplicationState.toByteArray(syncReplicationState, SyncReplicationState.NONE));
      // write the peer config data at last, so when loading, if we can not load the peer_config, we
      // know that this is not a valid peer
      write(fs, peerDir, PEER_CONFIG_FILE, ReplicationPeerConfigUtil.toByteArray(peerConfig));
    } catch (IOException e) {
      throw new ReplicationException(
        "Could not add peer with id=" + peerId + ", peerConfig=>" + peerConfig + ", state="
          + (enabled ? "ENABLED" : "DISABLED") + ", syncReplicationState=" + syncReplicationState,
        e);
    }
  }
A filesystem based replication peer storage. The implementation does not require atomic rename so
you can use it on cloud OSS.
<p/>
FileSystem layout:

<pre>
hbase
  |
  --peers
      |
      --&lt;peer_id&gt;
          |
          --peer_config
          |
          --disabled
          |
          --sync-rep-state
</pre>

Notice that, if the peer is enabled, we will not have a disabled file.
<p/>
And for other files, to avoid depending on atomic rename, we will use two files for storing the
content. When loading, we will try to read both the files and load the newer one. And when
writing, we will write to the older file.
hbase-replication/src/main/java/org/apache/hadoop/hbase/replication/FSReplicationPeerStorage.java