public void activateTemplate(PartialPath activatePath, Template template)
      throws MetadataException {
    String[] nodes = activatePath.getNodes();
    ICachedMNode cur = storageGroupMNode;
    ICachedMNode child;
    IDeviceMNode<ICachedMNode> entityMNode;

    try {
      for (int i = levelOfSG + 1; i < nodes.length; i++) {
        child = store.getChild(cur, nodes[i]);
        if (child == null) {
          throw new PathNotExistException(activatePath.getFullPath());
        }
        cur = child;
      }
      synchronized (this) {
        if (cur.isDevice()) {
          entityMNode = cur.getAsDeviceMNode();
        } else {
          entityMNode = store.setToEntity(cur);
        }

        if (entityMNode.isUseTemplate()) {
          if (template.getId() == entityMNode.getSchemaTemplateId()) {
            throw new TemplateIsInUseException(cur.getFullPath());
          } else {
            throw new DifferentTemplateException(activatePath.getFullPath(), template.getName());
          }
        }
      }

      store.updateMNode(
          entityMNode.getAsMNode(),
          o -> {
            if (!entityMNode.isAligned()) {
              entityMNode.setAligned(template.isDirectAligned());
            }
            entityMNode.setUseTemplate(true);
            entityMNode.setSchemaTemplateId(template.getId());
          });

      regionStatistics.activateTemplate(template.getId());
    } finally {
      unPinPath(cur);
    }
  }
Get node by the path

@return last node in given seriesPath
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/schemaengine/schemaregion/mtree/impl/pbtree/MTreeBelowSGCachedImpl.java