protected ISegmentedPage getMinApplSegmentedPageInMem(short size, SchemaPageContext cxt)
      throws SegmentNotFoundException {
    // pages retrieved from context is unnecessary and inefficient to lock
    ISchemaPage targetPage = cxt.indexBuckets.getNearestFitPage(size, false);
    if (targetPage != null) {
      cxt.indexBuckets.sortIntoBucket(targetPage, size);
      return targetPage.getAsSegmentedPage();
    }

    pagePool.lock();
    try {
      // pageIndexBuckets sorts pages within pageInstCache into buckets to expedite access
      targetPage = pagePool.getNearestFitPage(size);
      if (targetPage != null) {
        cxt.markDirty(targetPage);
        cxt.traceLock(targetPage);

        // transfer the page from pageIndexBuckets to cxt.buckets thus not be accessed by other
        //  WRITE thread
        cxt.indexBuckets.sortIntoBucket(targetPage, size);
        return targetPage.getAsSegmentedPage();
      }

      // due to be dirty thus its index only sorted into local buckets
      targetPage = allocNewSegmentedPage(cxt);
      cxt.indexBuckets.sortIntoBucket(targetPage, size);
      return targetPage.getAsSegmentedPage();
    } finally {
      pagePool.unlock();
    }
  }
Only accessed during write operation and every page returned is due to be modified thus they
are all marked dirty.

@param size size of the expected segment
@return always write locked
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/schemaengine/schemaregion/mtree/impl/pbtree/schemafile/pagemgr/PageManager.java