public ISchemaPage getPageInstance(int pageIdx, SchemaPageContext cxt)
      throws IOException, MetadataException {
    if (pageIdx > lastPageIndex.get()) {
      throw new MetadataException(String.format("Page index %d out of range.", pageIdx));
    }

    // just return from (thread local) context
    if (cxt != null && cxt.referredPages.containsKey(pageIdx)) {
      return cxt.referredPages.get(pageIdx);
    }

    // lock for no duplicate page with same index from disk, and guarantees page will not be evicted
    //  by other thread before referred by current thread
    pagePool.lock();
    try {
      ISchemaPage page = pagePool.get(pageIdx);
      if (page != null) {
        cxt.refer(page);
        return page;
      }

      ByteBuffer newBuf = ByteBuffer.allocate(SchemaFileConfig.PAGE_LENGTH);
      if (metric != null) {
        metric.recordLoadPageNum(1);
      }
      pageIOChannel.loadFromFileToBuffer(newBuf, pageIdx);
      page = ISchemaPage.loadSchemaPage(newBuf);
      cxt.refer(page);
      pagePool.put(page);
      return page;
    } finally {
      pagePool.unlock();
    }
  }
Any page returned will be pinned/referred by the cxt. *
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/schemaengine/schemaregion/mtree/impl/pbtree/schemafile/pagemgr/PageManager.java