public List<String> getPathsSetOnTemplate(
      final int templateId, final PathPatternTree scope, final boolean filterPreUnset)
      throws MetadataException {
    final List<String> resSet = new ArrayList<>();
    try (final MNodeCollector<Void, IConfigMNode> collector =
        new MNodeCollector<Void, IConfigMNode>(
            root, new PartialPath(ALL_RESULT_NODES), store, false, scope) {
          @Override
          protected boolean acceptFullMatchedNode(final IConfigMNode node) {
            if (super.acceptFullMatchedNode(node)) {
              // if node not set template, go on traversing
              if (node.getSchemaTemplateId() != NON_TEMPLATE) {
                if (filterPreUnset && node.isSchemaTemplatePreUnset()) {
                  // filter the pre unset template
                  return false;
                }
                // if set template, and equals to target or target for all, add to result
                return templateId == ALL_TEMPLATE || templateId == node.getSchemaTemplateId();
              }
            }
            return false;
          }

          @Override
          protected Void collectMNode(final IConfigMNode node) {
            resSet.add(node.getFullPath());
            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 resSet;
  }
check whether there is template on given path and the subTree has template return true,
otherwise false
iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/persistence/schema/ConfigMTree.java