alpass163 commented on code in PR #18874:
URL: https://github.com/apache/iotdb/pull/18874#discussion_r4311518560


##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/protocol/thrift/impl/DataNodeInternalRPCServiceImpl.java:
##########
@@ -2898,6 +2928,62 @@ public TSStatus updateTemplate(final TUpdateTemplateReq 
req) {
     return RpcUtils.getStatus(TSStatusCode.SUCCESS_STATUS);
   }
 
+  /**
+   * The devices which activated the template, each with the measurements the 
extension added to it:
+   * the tree-to-table views covering these devices need them as columns.
+   *
+   * <p>The measurements come from comparing the new template with the old 
one. The devices come
+   * from the schema regions, where every device which uses a template records 
its id, see {@code
+   * EntityTraverser}; the template manager only knows where a template is 
mounted, so it cannot
+   * tell which devices use it.
+   */
+  private Map<PartialPath, List<Pair<String, TSDataType>>> 
collectDevicesUsingExtendedTemplate(
+      final Template oldTemplate, final Template newTemplate) throws Exception 
{
+    final List<Pair<String, TSDataType>> extendedMeasurements =
+        newTemplate.getSchemaMap().values().stream()
+            .filter(
+                schema ->
+                    Objects.isNull(oldTemplate)
+                        || 
!oldTemplate.getSchemaMap().containsKey(schema.getMeasurementName()))
+            .map(schema -> new Pair<>(schema.getMeasurementName(), 
schema.getType()))
+            .toList();
+    final Pair<Template, List<PartialPath>> templateSetInfo =
+        
ClusterTemplateManager.getInstance().getAllPathsSetTemplate(newTemplate.getName());
+    final List<PartialPath> setPaths =
+        Objects.isNull(templateSetInfo) ? null : templateSetInfo.getRight();
+    if (extendedMeasurements.isEmpty() || Objects.isNull(setPaths)) {
+      return Collections.emptyMap();
+    }
+
+    final Map<PartialPath, List<Pair<String, TSDataType>>> device2Measurements 
= new HashMap<>();
+    Collection<ISchemaRegion> allSchemaRegions = 
SchemaEngine.getInstance().getAllSchemaRegions();
+    for (final PartialPath setPath : setPaths) {
+      final String setPathString = setPath.getFullPath();
+      for (final ISchemaRegion schemaRegion : allSchemaRegions) {
+        // A device under this path can only live in the region of the 
database the path belongs to.
+        if (!setPathString.startsWith(schemaRegion.getDatabaseFullPath())) {
+          continue;
+        }
+        try (final ISchemaReader<IDeviceSchemaInfo> deviceReader =
+            schemaRegion.getDeviceReader(
+                SchemaRegionReadPlanFactory.getShowDevicesPlan(
+                    
setPath.concatNode(IoTDBConstant.MULTI_LEVEL_PATH_WILDCARD),

Review Comment:
   fixed it



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to