private void verifySchema(ISchemaTree schemaTree)
      throws LoadAnalyzeException, IllegalPathException {
    for (final Map.Entry<IDeviceID, Set<MeasurementSchema>> entry :
        schemaCache.getDevice2TimeSeries().entrySet()) {
      final IDeviceID device = entry.getKey();
      final List<IMeasurementSchema> tsfileTimeseriesSchemas = new ArrayList<>(entry.getValue());
      final DeviceSchemaInfo iotdbDeviceSchemaInfo =
          schemaTree.searchDeviceSchemaInfo(
              new PartialPath(device),
              tsfileTimeseriesSchemas.stream()
                  .map(IMeasurementSchema::getMeasurementName)
                  .collect(Collectors.toList()));

      if (iotdbDeviceSchemaInfo == null) {
        throw new LoadAnalyzeException(
            String.format(
                "Device %s does not exist in IoTDB and can not be created. "
                    + "Please check weather auto-create-schema is enabled.",
                device));
      }

      // check device schema: is aligned or not
      final boolean isAlignedInTsFile = schemaCache.getDeviceIsAligned(device);
      final boolean isAlignedInIoTDB = iotdbDeviceSchemaInfo.isAligned();
      if (isAlignedInTsFile != isAlignedInIoTDB) {
        throw new LoadAnalyzeException(
            String.format(
                "Device %s in TsFile is %s, but in IoTDB is %s.",
                device,
                isAlignedInTsFile ? "aligned" : "not aligned",
                isAlignedInIoTDB ? "aligned" : "not aligned"));
      }

      // check timeseries schema
      final List<IMeasurementSchema> iotdbTimeseriesSchemas =
          iotdbDeviceSchemaInfo.getMeasurementSchemaList();
      for (int i = 0, n = iotdbTimeseriesSchemas.size(); i < n; i++) {
        final IMeasurementSchema tsFileSchema = tsfileTimeseriesSchemas.get(i);
        final IMeasurementSchema iotdbSchema = iotdbTimeseriesSchemas.get(i);
        if (iotdbSchema == null) {
          throw new LoadAnalyzeException(
              String.format(
                  "Measurement %s does not exist in IoTDB and can not be created. "
                      + "Please check weather auto-create-schema is enabled.",
                  device + TsFileConstant.PATH_SEPARATOR + tsfileTimeseriesSchemas.get(i)));
        }

        // check datatype
        if (!tsFileSchema.getType().equals(iotdbSchema.getType())) {
          throw new LoadAnalyzeTypeMismatchException(
              String.format(
                  "Measurement %s%s%s datatype not match, TsFile: %s, IoTDB: %s",
                  device,
                  TsFileConstant.PATH_SEPARATOR,
                  iotdbSchema.getMeasurementName(),
                  tsFileSchema.getType(),
                  iotdbSchema.getType()));
        }

        // check encoding
        if (LOGGER.isDebugEnabled()
            && !tsFileSchema.getEncodingType().equals(iotdbSchema.getEncodingType())) {
          // we allow a measurement to have different encodings in different chunks
          LOGGER.debug(
              "Encoding type not match, measurement: {}{}{}, "
                  + "TsFile encoding: {}, IoTDB encoding: {}",
              device,
              TsFileConstant.PATH_SEPARATOR,
              iotdbSchema.getMeasurementName(),
              tsFileSchema.getEncodingType().name(),
              iotdbSchema.getEncodingType().name());
        }

        // check compressor
        if (LOGGER.isDebugEnabled()
            && !tsFileSchema.getCompressor().equals(iotdbSchema.getCompressor())) {
          // we allow a measurement to have different compressors in different chunks
          LOGGER.debug(
              "Compressor not match, measurement: {}{}{}, "
                  + "TsFile compressor: {}, IoTDB compressor: {}",
              device,
              TsFileConstant.PATH_SEPARATOR,
              iotdbSchema.getMeasurementName(),
              tsFileSchema.getCompressor().name(),
              iotdbSchema.getCompressor().name());
        }
      }
    }
  }
This can only be invoked after all timeseries in the current tsfile have been processed.
Otherwise, the isAligned status may be wrong.
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/analyze/load/TreeSchemaAutoCreatorAndVerifier.java