public synchronized void removeBatch(Batch batch) {
    batch.setSynced(true);
    if (!pendingBatches.isEmpty() && pendingBatches.get(0).equals(batch)) {
      Iterator<Batch> iterator = pendingBatches.iterator();
      Batch current = iterator.next();
      while (current.isSynced()) {
        controller.update(current.getEndIndex(), false);
        iterator.remove();
        iotConsensusMemoryManager.free(current.getSerializedSize(), false);
        if (iterator.hasNext()) {
          current = iterator.next();
        } else {
          break;
        }
      }
      // wake up logDispatcherThread that might be blocked
      notifyAll();
    }
  }
We only set a flag if this batch is not the first one. Notice, We need to confirm that the
batch in the parameter is actually in pendingBatches, rather than a reference to a different
object with equal data, so we do not inherit method equals for Batch
iotdb-core/consensus/src/main/java/org/apache/iotdb/consensus/iot/logdispatcher/SyncStatus.java