Source:
private void readFromFile(String mountPath) throws ReplicationException, IOException { logger.info("Reading replica tokens for mount path {}", mountPath); long readStartTime = SystemTime.getInstance().milliseconds(); File replicaTokenFile = new File(mountPath, replicaTokenFileName); if (replicaTokenFile.exists()) { CrcInputStream crcStream = new CrcInputStream(new FileInputStream(replicaTokenFile)); DataInputStream stream = new DataInputStream(crcStream); try { short version = stream.readShort(); switch (version) { case 0: while (stream.available() > Crc_Size) { PartitionId partitionId = clusterMap.getPartitionIdFromStream(stream); String hostname = Utils.readIntString(stream); int port = stream.readInt(); long totalBytesReadFromLocalStore = stream.readLong(); FindToken token = factory.getFindToken(stream); PartitionInfo partitionInfo = partitionsToReplicate.get(partitionId); boolean updatedToken = false; for (RemoteReplicaInfo info : partitionInfo.getRemoteReplicaInfo()) { if (info.getReplicaId().getDataNodeId().getHostname().equalsIgnoreCase(hostname) && info.getReplicaId().getDataNodeId().getPort() == port) { info.setToken(token); info.setTotalBytesReadFromLocalStore(totalBytesReadFromLocalStore); logger .trace("Read token for partition remote host port token {}", partitionId, hostname, port, token); updatedToken = true; } } if (!updatedToken) { logger.warn("Persisted remote replica host and port not present in new cluster ", hostname, port); } } long crc = crcStream.getValue(); if (crc != stream.readLong()) { throw new ReplicationException( "Crc check does not match for replica token file for mount path " + mountPath); } break; default: throw new ReplicationException("Invalid version in replica token file for mount path " + mountPath); } } catch (IOException e) { throw new ReplicationException("IO error while reading from replica token file " + e); } finally { stream.close(); replicationMetrics.remoteReplicaRecreatingTime.update(SystemTime.getInstance().milliseconds() - readStartTime); } } }

Target:
private void readFromFile(String mountPath) throws ReplicationException, IOException { logger.info("Reading replica tokens for mount path {}", mountPath); long readStartTimeMs = SystemTime.getInstance().milliseconds(); File replicaTokenFile = new File(mountPath, replicaTokenFileName); if (replicaTokenFile.exists()) { CrcInputStream crcStream = new CrcInputStream(new FileInputStream(replicaTokenFile)); DataInputStream stream = new DataInputStream(crcStream); try { short version = stream.readShort(); switch (version) { case 0: while (stream.available() > Crc_Size) { PartitionId partitionId = clusterMap.getPartitionIdFromStream(stream); String hostname = Utils.readIntString(stream); String replicaPath = Utils.readIntString(stream); int port = stream.readInt(); long totalBytesReadFromLocalStore = stream.readLong(); FindToken token = factory.getFindToken(stream); PartitionInfo partitionInfo = partitionsToReplicate.get(partitionId); boolean updatedToken = false; for (RemoteReplicaInfo info : partitionInfo.getRemoteReplicaInfos()) { if (info.getReplicaId().getDataNodeId().getHostname().equalsIgnoreCase(hostname) && info.getReplicaId().getDataNodeId().getPort() == port && info.getReplicaId().getReplicaPath() .equals(replicaPath)) { info.setToken(token); info.setTotalBytesReadFromLocalStore(totalBytesReadFromLocalStore); logger .trace("Read token for partition remote host port token {}", partitionId, hostname, port, token); updatedToken = true; } } if (!updatedToken) { logger.warn("Persisted remote replica host and port not present in new cluster ", hostname, port); } } long crc = crcStream.getValue(); if (crc != stream.readLong()) { throw new ReplicationException( "Crc check does not match for replica token file for mount path " + mountPath); } break; default: throw new ReplicationException("Invalid version in replica token file for mount path " + mountPath); } } catch (IOException e) { throw new ReplicationException("IO error while reading from replica token file " + e); } finally { stream.close(); replicationMetrics.remoteReplicaTokensRestoreTime .update(SystemTime.getInstance().milliseconds() - readStartTimeMs); } } }