private void chooseTsFileResourceToDegrade() {
    while (memoryBlock.getUsedMemoryInBytes() > memoryBlock.getTotalMemorySizeInBytes()) {
      TsFileResource tsFileResource = sealedTsFileResources.pollFirst();
      if (tsFileResource == null
          || TimeIndexLevel.valueOf(tsFileResource.getTimeIndexType())
              == TimeIndexLevel.FILE_TIME_INDEX) {
        logger.debug("Can't degrade time index any more because all time index are file level.");
        sealedTsFileResources.add(tsFileResource);
        return;
      }
      long memoryReduce = tsFileResource.degradeTimeIndex();
      logger.debug("Degrade tsfile resource {}", tsFileResource.getTsFilePath());
      degradedTimeIndexNum++;
      releaseTimeIndexMemCost(memoryReduce);
      // add the polled tsFileResource to the priority queue
      sealedTsFileResources.add(tsFileResource);
    }
  }
choose the top TsFileResource in priorityQueue to degrade until the memory is smaller than
threshold.
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/rescon/memory/TsFileResourceManager.java