private void getNext() {
    nextMatchedNode = null;
    VisitorStackEntry stackEntry;
    AbstractChildrenIterator iterator;
    while (!visitorStack.isEmpty()) {
      stackEntry = visitorStack.peek();
      iterator = stackEntry.iterator;

      if (!iterator.hasNext()) {
        popStack();
        continue;
      }

      N nextTempNode = iterator.next();

      shouldVisitSubtree = false;
      if (currentStateMatchInfo.hasFinalState()) {
        if (acceptFullMatchedNode(nextTempNode)) {
          nextMatchedNode = nextTempNode;
        }
        shouldVisitSubtree = shouldVisitSubtreeOfFullMatchedNode(nextTempNode);
      } else {
        if (acceptInternalMatchedNode(nextTempNode)) {
          nextMatchedNode = nextTempNode;
        }
        shouldVisitSubtree = shouldVisitSubtreeOfInternalMatchedNode(nextTempNode);
      }

      if (shouldVisitSubtree) {
        pushChildren(nextTempNode);
        // After adding nextTempNode into ancestorStack, nextTempNode will be released finally.
      } else if (nextMatchedNode != nextTempNode) {
        // Else if nextTempNode is not accepted, it needs to be released.
        releaseNode(nextTempNode);
      }
      // Otherwise, it will be released when invoking next()

      if (nextMatchedNode != null) {
        return;
      }
    }
  }
This method must be invoked before iteration
iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/schema/tree/AbstractTreeVisitor.java