@Override
  @SuppressWarnings("squid:S3776") // Suppress high Cognitive Complexity warning
  public void createTimeSeries(final ICreateTimeSeriesPlan plan, long offset)
      throws MetadataException {
    while (!regionStatistics.isAllowToCreateNewSeries()) {
      ReleaseFlushMonitor.getInstance().waitIfReleasing();
    }

    final PartialPath path = plan.getPath();
    final IMeasurementMNode<ICachedMNode> leafMNode;
    try {
      SchemaUtils.checkDataTypeWithEncoding(plan.getDataType(), plan.getEncoding());

      final TSDataType type = plan.getDataType();
      // Create time series in MTree
      leafMNode =
          mtree.createTimeSeriesWithPinnedReturn(
              path,
              type,
              plan.getEncoding(),
              plan.getCompressor(),
              plan.getProps(),
              plan.getAlias(),
              (plan instanceof CreateTimeSeriesPlanImpl
                  && ((CreateTimeSeriesPlanImpl) plan).isWithMerge()));

      try {
        // Should merge
        if (Objects.isNull(leafMNode)) {
          // Write an upsert plan directly
          // Note that the "pin" and "unpin" is reentrant
          upsertAliasAndTagsAndAttributes(
              plan.getAlias(), plan.getTags(), plan.getAttributes(), path);
          return;
        }

        // Update statistics and schemaDataTypeNumMap
        regionStatistics.addMeasurement(1L);

        // Update tag index
        if (offset != -1 && isRecovering) {
          // The time series has already been created and now system is recovering, using the tag
          // info in tagFile to recover index directly
          tagManager.recoverIndex(offset, leafMNode);
          mtree.pinMNode(leafMNode.getAsMNode());
        } else if (plan.getTags() != null) {
          // Tag key, tag value
          tagManager.addIndex(plan.getTags(), leafMNode);
          mtree.pinMNode(leafMNode.getAsMNode());
        }

        // write log
        if (!isRecovering) {
          // either tags or attributes is not empty
          if ((plan.getTags() != null && !plan.getTags().isEmpty())
              || (plan.getAttributes() != null && !plan.getAttributes().isEmpty())) {
            offset = tagManager.writeTagFile(plan.getTags(), plan.getAttributes());
          }
          plan.setTagOffset(offset);
          writeToMLog(plan);
        }
        if (offset != -1) {
          long finalOffset = offset;
          mtree.updateMNode(
              leafMNode.getAsMNode(), o -> o.getAsMeasurementMNode().setOffset(finalOffset));
        }

      } finally {
        if (Objects.nonNull(leafMNode)) {
          mtree.unPinMNode(leafMNode.getAsMNode());
        }
      }

    } catch (IOException e) {
      throw new MetadataException(e);
    }
  }
Function for clearing metadata components of one schema region
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/schemaengine/schemaregion/impl/SchemaRegionPBTreeImpl.java