public TSStatus createSchemaRegion(
      final TRegionReplicaSet regionReplicaSet, final String storageGroup) {
    TSStatus tsStatus;
    final SchemaRegionId schemaRegionId =
        new SchemaRegionId(regionReplicaSet.getRegionId().getId());
    try {
      schemaEngine.createSchemaRegion(storageGroup, schemaRegionId);
      schemaRegionLockMap.put(schemaRegionId, new ReentrantReadWriteLock(false));
      final List<Peer> peers = new ArrayList<>();
      for (final TDataNodeLocation dataNodeLocation : regionReplicaSet.getDataNodeLocations()) {
        final TEndPoint endpoint =
            new TEndPoint(
                dataNodeLocation.getSchemaRegionConsensusEndPoint().getIp(),
                dataNodeLocation.getSchemaRegionConsensusEndPoint().getPort());
        peers.add(new Peer(schemaRegionId, dataNodeLocation.getDataNodeId(), endpoint));
      }
      SchemaRegionConsensusImpl.getInstance().createLocalPeer(schemaRegionId, peers);
      tsStatus = new TSStatus(TSStatusCode.SUCCESS_STATUS.getStatusCode());
    } catch (final IllegalPathException e1) {
      LOGGER.error("Create Schema Region {} failed because path is illegal.", storageGroup);
      tsStatus = new TSStatus(TSStatusCode.ILLEGAL_PATH.getStatusCode());
      tsStatus.setMessage("Create Schema Region failed because storageGroup path is illegal.");
    } catch (final MetadataException e2) {
      LOGGER.error("Create Schema Region {} failed because {}", storageGroup, e2.getMessage());
      tsStatus = new TSStatus(TSStatusCode.CREATE_REGION_ERROR.getStatusCode());
      tsStatus.setMessage(
          String.format("Create Schema Region failed because of %s", e2.getMessage()));
    } catch (final ConsensusGroupAlreadyExistException e) {
      tsStatus = new TSStatus(TSStatusCode.SUCCESS_STATUS.getStatusCode());
      tsStatus.setMessage(String.format("SchemaRegion %d already exists.", schemaRegionId.getId()));
    } catch (final ConsensusException e) {
      tsStatus = new TSStatus(TSStatusCode.CREATE_REGION_ERROR.getStatusCode());
      tsStatus.setMessage(e.getMessage());
    }
    return tsStatus;
  }
This class takes the responsibility of managing regions, executing PlanNode of write type on
according regions and controlling the execution concurrency.
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/protocol/thrift/impl/DataNodeRegionManager.java