@Override
  public void discardEventsOfPipe(final String pipeNameToDrop, final int regionId) {
    super.discardEventsOfPipe(pipeNameToDrop, regionId);
    tsfileInsertEventDeque.removeIf(
        event -> {
          if (event instanceof EnrichedEvent
              && pipeNameToDrop.equals(((EnrichedEvent) event).getPipeName())
              && regionId == ((EnrichedEvent) event).getRegionId()) {
            if (((EnrichedEvent) event)
                .clearReferenceCount(PipeRealtimePriorityBlockingQueue.class.getName())) {
              eventCounter.decreaseEventCount(event);
            }
            return true;
          }
          return false;
        });
  }
When the number of polls exceeds the pollHistoryThreshold, the {@link TsFileInsertionEvent} of
the earliest write to the queue is returned. if the pollHistoryThreshold is not reached then an
attempt is made to poll the queue for the latest insertion {@link Event}. First, it tries to
poll the first provided If there is no such {@link Event}, poll the last supplied {@link
TsFileInsertionEvent}. If no {@link Event} is available, it blocks until a {@link Event} is
available.

@return the freshest insertion {@link Event}. can be {@code null} if no {@link Event} is
    available.
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/pipe/agent/task/subtask/connector/PipeRealtimePriorityBlockingQueue.java