private boolean constructBatchFromWAL(long currentIndex, long maxIndex, Batch logBatches) {
      logger.debug(
          "DataRegion[{}]->{}: currentIndex: {}, maxIndex: {}",
          peer.getGroupId().getId(),
          peer.getEndpoint().getIp(),
          currentIndex,
          maxIndex);
      boolean hasCorruptedData = false;
      // targetIndex is the index of request that we need to find
      long targetIndex = currentIndex;
      // Even if there is no WAL files, these code won't produce error.
      walEntryIterator.skipTo(targetIndex);
      while (targetIndex < maxIndex && logBatches.canAccumulate()) {
        logger.debug("construct from WAL for one Entry, index : {}", targetIndex);
        try {
          walEntryIterator.waitForNextReady();
        } catch (InterruptedException e) {
          Thread.currentThread().interrupt();
          logger.warn("wait for next WAL entry is interrupted");
        }
        IndexedConsensusRequest data = walEntryIterator.next();
        if (data.getSearchIndex() < targetIndex) {
          // if the index of request is smaller than currentIndex, then continue
          logger.warn(
              "search for one Entry which index is {}, but find a smaller one, index : {}",
              targetIndex,
              data.getSearchIndex());
          continue;
        } else if (data.getSearchIndex() > targetIndex) {
          logger.warn(
              "search for one Entry which index is {}, but find a larger one, index : {}."
                  + "Perhaps the wal file is corrupted, in which case we skip it and choose a larger index to replicate",
              targetIndex,
              data.getSearchIndex());
          hasCorruptedData = true;
        }
        targetIndex = data.getSearchIndex() + 1;
        data.buildSerializedRequests();
        // construct request from wal
        logBatches.addTLogEntry(
            new TLogEntry(data.getSerializedRequests(), data.getSearchIndex(), true));
      }
      // In the case of corrupt Data, we return true so that we can send a batch as soon as
      // possible, avoiding potential duplication
      return hasCorruptedData;
    }
try to remove a request from queue with memory control.
iotdb-core/consensus/src/main/java/org/apache/iotdb/consensus/iot/logdispatcher/LogDispatcher.java