private void setupWALAndReplication() throws IOException {
    WALFactory factory = new WALFactory(conf, serverName, this);
    // TODO Replication make assumptions here based on the default filesystem impl
    Path oldLogDir = new Path(walRootDir, HConstants.HREGION_OLDLOGDIR_NAME);
    String logName = AbstractFSWALProvider.getWALDirectoryName(this.serverName.toString());

    Path logDir = new Path(walRootDir, logName);
    LOG.debug("logDir={}", logDir);
    if (this.walFs.exists(logDir)) {
      throw new RegionServerRunningException(
        "Region server has already created directory at " + this.serverName.toString());
    }
    // Always create wal directory as now we need this when master restarts to find out the live
    // region servers.
    if (!this.walFs.mkdirs(logDir)) {
      throw new IOException("Can not create wal directory " + logDir);
    }
    // Instantiate replication if replication enabled. Pass it the log directories.
    createNewReplicationInstance(conf, this, this.walFs, logDir, oldLogDir, factory);

    WALActionsListener walEventListener = getWALEventTrackerListener(conf);
    if (walEventListener != null && factory.getWALProvider() != null) {
      factory.getWALProvider().addWALActionsListener(walEventListener);
    }
    this.walFactory = factory;
  }
Setup WAL log and replication if enabled. Replication setup is done in here because it wants to
be hooked up to WAL.
hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java