@Override
  @SuppressWarnings("squid:S3776") // Suppress high Cognitive Complexity warning
  public void createTimeSeries(final ICreateTimeSeriesPlan plan, long offset)
      throws MetadataException {
    if (!regionStatistics.isAllowToCreateNewSeries()) {
      throw new SeriesOverflowException(
          regionStatistics.getGlobalMemoryUsage(), regionStatistics.getGlobalSeriesNumber());
    }

    final IMeasurementMNode<IMemMNode> leafMNode;

    try {
      final PartialPath path = plan.getPath();
      SchemaUtils.checkDataTypeWithEncoding(plan.getDataType(), plan.getEncoding());

      final TSDataType type = plan.getDataType();
      // Create time series in MTree
      leafMNode =
          mTree.createTimeSeries(
              path,
              type,
              plan.getEncoding(),
              plan.getCompressor(),
              plan.getProps(),
              plan.getAlias(),
              plan instanceof CreateTimeSeriesPlanImpl
                      && ((CreateTimeSeriesPlanImpl) plan).isWithMerge()
                  || plan instanceof CreateTimeSeriesNode
                      && ((CreateTimeSeriesNode) plan).isGeneratedByPipe());

      // Should merge
      if (Objects.isNull(leafMNode)) {
        // Write an upsert plan directly
        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);
      } else if (plan.getTags() != null) {
        // Tag key, tag value
        tagManager.addIndex(plan.getTags(), leafMNode);
      }

      // 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) {
        leafMNode.setOffset(offset);
      }

    } 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/SchemaRegionMemoryImpl.java