public Map<Integer, Set<PartialPath>> getTemplateSetInfo(final PartialPath pathPattern)
      throws MetadataException {
    final Map<Integer, Set<PartialPath>> result = new HashMap<>();
    try (final MNodeCollector<Void, IConfigMNode> collector =
        new MNodeCollector<Void, IConfigMNode>(root, pathPattern, store, false, ALL_MATCH_SCOPE) {
          @Override
          protected boolean acceptFullMatchedNode(final IConfigMNode node) {
            return node.getSchemaTemplateId() != NON_TEMPLATE || super.acceptFullMatchedNode(node);
          }

          @Override
          protected boolean acceptInternalMatchedNode(final IConfigMNode node) {
            return node.getSchemaTemplateId() != NON_TEMPLATE
                || super.acceptInternalMatchedNode(node);
          }

          @Override
          protected Void collectMNode(final IConfigMNode node) {
            if (node.getSchemaTemplateId() != NON_TEMPLATE && !node.isSchemaTemplatePreUnset()) {
              result
                  .computeIfAbsent(node.getSchemaTemplateId(), k -> new HashSet<>())
                  .add(getPartialPathFromRootToNode(node));
            }
            return null;
          }

          @Override
          protected boolean shouldVisitSubtreeOfFullMatchedNode(final IConfigMNode node) {
            // descendants of the node cannot set another template, exit from this branch
            return node.getSchemaTemplateId() == NON_TEMPLATE
                && super.shouldVisitSubtreeOfFullMatchedNode(node);
          }

          @Override
          protected boolean shouldVisitSubtreeOfInternalMatchedNode(final IConfigMNode node) {
            // descendants of the node cannot set another template, exit from this branch
            return node.getSchemaTemplateId() == NON_TEMPLATE
                && super.shouldVisitSubtreeOfInternalMatchedNode(node);
          }
        }) {
      collector.traverse();
    }
    return result;
  }
This method returns the templateId set on paths if the path set matches or is a prefix of input
path pattern.
iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/persistence/schema/ConfigMTree.java