private List<ResponseInfo> filterTimedOutRequests(Map<Integer, RequestInfo> correlationIdToRequest,
      Map<Integer, RemoteReplicaGroup> correlationIdToRemoteReplicaGroup) {
    logger.trace("Thread Name: {} Trying to filter out timed out requests", threadName);
    List<ResponseInfo> responseInfosForTimedOutRequests = new ArrayList<>();
    Iterator<Map.Entry<Integer, RequestInfo>> inFlightRequestIterator = correlationIdToRequest.entrySet().iterator();
    while (inFlightRequestIterator.hasNext()) {
      Map.Entry<Integer, RequestInfo> entry = inFlightRequestIterator.next();
      RequestInfo requestInfo = entry.getValue();
      long currentTimeInMs = time.milliseconds();
      if (currentTimeInMs > requestInfo.getRequestCreateTime() + replicationConfig.replicationRequestNetworkTimeoutMs) {
        inFlightRequestIterator.remove();
        responseInfosForTimedOutRequests.add(new ResponseInfo(requestInfo, NetworkClientErrorCode.TimeoutError, null));
        RemoteReplicaGroup group = correlationIdToRemoteReplicaGroup.get(entry.getKey());
        if (group != null) {
          logger.error(
              "Remote node: {} Thread name: {} RemoteReplicaGroup {} Request {} timed out, it was issued at {}",
              group.getRemoteDataNode(), threadName, group.getId(), entry.getKey(), requestInfo.getRequestCreateTime());
        } else {
          // This shouldn't happen
          logger.error("Thread name: {} Request {} timed out", threadName, entry.getKey());
        }
      } else {
        // The correlationIdToRequest should be a LinkedHashMap that has a predictable iteration order based on insertion.
        // The correlation id increases as we insert it to the map. So if current request is not timed out, then all the
        // requests after are not timed out.
        break;
      }
    }
    if (!responseInfosForTimedOutRequests.isEmpty()) {
      logger.error("Thread Name: {} There are {} requests timed out", threadName,
          responseInfosForTimedOutRequests.size());
    }
    return responseInfosForTimedOutRequests;
  }
Filter requests that are timed out and return corresponding response info for them. This method would also remove
the timed out request form the map.
@param correlationIdToRequest The map from correlation id to request.
@param correlationIdToRemoteReplicaGroup The map from correlation id to RemoteReplicaGroup
@return A list of {@link ResponseInfo} for timed out requests.
ambry-replication/src/main/java/com/github/ambry/replication/ReplicaThread.java