public void flushVolatileNodes(boolean needLock) {
    if (needLock) {
      lockManager.globalReadLock();
    }
    long startTime = System.currentTimeMillis();
    AtomicLong flushNodeNum = new AtomicLong(0);
    AtomicLong flushMemSize = new AtomicLong(0);
    try {
      PBTreeFlushExecutor flushExecutor = new PBTreeFlushExecutor(memoryManager, file, lockManager);

      flushExecutor.flushVolatileNodes(flushNodeNum, flushMemSize);

    } catch (Throwable e) {
      LOGGER.error(
          "Error occurred during MTree flush, current SchemaRegionId is {}", schemaRegionId, e);
    } finally {
      long time = System.currentTimeMillis() - startTime;
      if (time > 10_000) {
        LOGGER.info("It takes {}ms to flush MTree in SchemaRegion {}", time, schemaRegionId);
      } else {
        LOGGER.debug("It takes {}ms to flush MTree in SchemaRegion {}", time, schemaRegionId);
      }
      recordFlushMetrics(time, flushNodeNum.get(), flushMemSize.get());
      if (needLock) {
        lockManager.globalReadUnlock();
      }
    }
  }
Sync all volatile nodes to PBTree and execute memory release after flush.
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/schemaengine/schemaregion/mtree/impl/pbtree/CachedMTreeStore.java