Source:
<code>public void refreshSources(String peerId) throws IOException { String terminateMessage = "Peer " + peerId + " state or config changed. Will close the previous replication source and open a new one"; ReplicationPeer peer = replicationPeers.getPeer(peerId); ReplicationSourceInterface src = createSource(peerId, peer); synchronized (this.latestPaths) { ReplicationSourceInterface toRemove = this.sources.put(peerId, src); if (toRemove != null) { LOG.info("Terminate replication source for " + toRemove.getPeerId()); toRemove.terminate(terminateMessage, null, false); } for (NavigableSet<String> walsByGroup : walsById.get(peerId).values()) { walsByGroup.forEach(wal -> src.enqueueLog(new Path(this.logDir, wal))); } } LOG.info("Startup replication source for " + src.getPeerId()); src.startup(); List<ReplicationSourceInterface> toStartup = new ArrayList<>(); synchronized (this.oldsources) { List<String> previousQueueIds = new ArrayList<>(); for (Iterator<ReplicationSourceInterface> iter = this.oldsources.iterator(); iter .hasNext();) { ReplicationSourceInterface oldSource = iter.next(); if (oldSource.getPeerId().equals(peerId)) { previousQueueIds.add(oldSource.getQueueId()); oldSource.terminate(terminateMessage); iter.remove(); } } for (String queueId : previousQueueIds) { ReplicationSourceInterface replicationSource = createSource(queueId, peer); this.oldsources.add(replicationSource); for (SortedSet<String> walsByGroup : walsByIdRecoveredQueues.get(queueId).values()) { <START> walsByGroup.forEach(wal -> replicationSource.enqueueLog(new Path(wal))); <END> } toStartup.add(replicationSource); } } for (ReplicationSourceInterface replicationSource : toStartup) { replicationSource.startup(); } }</code><technical_language>problem is logs recovered queues added new "normal" queue? logs read, then? Nit: worth rename variable line #516 replicationSource recoveredReplicationSource, for clarity? I endorse call for additional UT, here</technical_language>

Target:
public void refreshSources(String peerId) throws IOException { String terminateMessage = "Peer " + peerId + " state or config changed. Will close the previous replication source and open a new one"; ReplicationPeer peer = replicationPeers.getPeer(peerId); ReplicationSourceInterface src = createSource(peerId, peer); synchronized (this.latestPaths) { ReplicationSourceInterface toRemove = this.sources.put(peerId, src); if (toRemove != null) { LOG.info("Terminate replication source for " + toRemove.getPeerId()); toRemove.terminate(terminateMessage, null, false); } for (NavigableSet<String> walsByGroup : walsById.get(peerId).values()) { walsByGroup.forEach(wal -> src.enqueueLog(new Path(this.logDir, wal))); } } LOG.info("Startup replication source for " + src.getPeerId()); src.startup(); List<ReplicationSourceInterface> toStartup = new ArrayList<>(); synchronized (this.oldsources) { List<String> previousQueueIds = new ArrayList<>(); for (Iterator<ReplicationSourceInterface> iter = this.oldsources.iterator(); iter .hasNext();) { ReplicationSourceInterface oldSource = iter.next(); if (oldSource.getPeerId().equals(peerId)) { previousQueueIds.add(oldSource.getQueueId()); oldSource.terminate(terminateMessage); iter.remove(); } } for (String queueId : previousQueueIds) { ReplicationSourceInterface recoveredReplicationSource = createSource(queueId, peer); this.oldsources.add(recoveredReplicationSource); for (SortedSet<String> walsByGroup : walsByIdRecoveredQueues.get(queueId).values()) { walsByGroup.forEach(wal -> recoveredReplicationSource.enqueueLog(new Path(wal))); } toStartup.add(recoveredReplicationSource); } } for (ReplicationSourceInterface replicationSource : toStartup) { replicationSource.startup(); } }