protected void entrantLock(ICachedMNode node, SchemaPageContext cxt)
      throws IOException, MetadataException {
    int initPageIndex = getPageIndex(getNodeAddress(node));
    ISchemaPage page;

    if (node.isDatabase()) {
      if (initPageIndex < 0) {
        // node is using template
        return;
      }

      page = getPageInstance(initPageIndex, cxt);
      page.getLock().writeLock().lock();
      cxt.traceLock(page);
      cxt.indexBuckets.sortIntoBucket(page, (short) -1);
    } else {
      int parIndex = getPageIndex(getNodeAddress(node.getParent()));

      int minPageIndex = Math.min(initPageIndex, parIndex);
      int maxPageIndex = Math.max(initPageIndex, parIndex);

      // as InternalPage will not transplant, its parent pointer needs no lock
      page = getPageInstance(initPageIndex, cxt);
      if (page.getAsInternalPage() != null) {
        page.getLock().writeLock().lock();
        cxt.traceLock(page);
        cxt.indexBuckets.sortIntoBucket(page, (short) -1);
        return;
      }

      if (minPageIndex >= 0) {
        page = getPageInstance(minPageIndex, cxt);
        page.getLock().writeLock().lock();
        cxt.traceLock(page);
        cxt.indexBuckets.sortIntoBucket(page, (short) -1);
      }

      if (minPageIndex != maxPageIndex && maxPageIndex >= 0) {
        page = getPageInstance(maxPageIndex, cxt);
        page.getLock().writeLock().lock();
        cxt.traceLock(page);
        cxt.indexBuckets.sortIntoBucket(page, (short) -1);
      }
    }
  }
locking in the order of page index to avoid deadlock.
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/schemaengine/schemaregion/mtree/impl/pbtree/schemafile/pagemgr/PageManager.java