public synchronized boolean deregister(final String pipeNameToDeregister, int regionId) {
    if (registeredTaskCount <= 0) {
      throw new IllegalStateException("registeredTaskCount <= 0");
    }

    subtask.discardEventsOfPipe(pipeNameToDeregister, regionId);

    try {
      if (registeredTaskCount > 1) {
        return false;
      }

      close();
      // This subtask is out of life cycle, should never be used again
      return true;
    } finally {
      registeredTaskCount--;
      LOGGER.info(
          "Deregister subtask {}. runningTaskCount: {}, registeredTaskCount: {}",
          subtask,
          runningTaskCount,
          registeredTaskCount);
    }
  }
Deregister the {@link PipeConnectorSubtask}. If the {@link PipeConnectorSubtask} is the last
one, close the {@link PipeConnectorSubtask}.

<p>Note that this method should be called after the {@link PipeConnectorSubtask} is stopped.
Otherwise, the {@link PipeConnectorSubtaskLifeCycle#runningTaskCount} might be inconsistent
with the {@link PipeConnectorSubtaskLifeCycle#registeredTaskCount} because of parallel
connector scheduling.

@param pipeNameToDeregister pipe name
@param regionId region id
@return {@code true} if the {@link PipeConnectorSubtask} is out of life cycle, indicating that
    the {@link PipeConnectorSubtask} should never be used again
@throws IllegalStateException if {@link PipeConnectorSubtaskLifeCycle#registeredTaskCount} <= 0
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/pipe/agent/task/subtask/connector/PipeConnectorSubtaskLifeCycle.java