Caideyipi commented on code in PR #15160:
URL: https://github.com/apache/iotdb/pull/15160#discussion_r4374058901


##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/schemaengine/SchemaEngine.java:
##########
@@ -336,20 +337,34 @@ private ISchemaRegion 
createSchemaRegionWithoutExistenceCheck(
     return schemaRegion;
   }
 
-  public synchronized boolean deleteSchemaRegion(SchemaRegionId schemaRegionId)
+  public synchronized boolean deleteSchemaRegion(final SchemaRegionId 
schemaRegionId)
       throws MetadataException {
-    ISchemaRegion schemaRegion = schemaRegionMap.get(schemaRegionId);
+    final ISchemaRegion schemaRegion = schemaRegionMap.get(schemaRegionId);
     if (schemaRegion == null) {
       logger.warn(DataNodeSchemaMessages.SCHEMA_REGION_ALREADY_DELETED, 
schemaRegionId);
       return false;
     }
-    schemaRegion.deleteSchemaRegion();
+    final AtomicReference<MetadataException> lastException = new 
AtomicReference<>();
+    // Synchronize it for region deletion detection when error occurs
+    schemaRegionMap.compute(

Review Comment:
   ConcurrentHashMap.compute keeps the existing mapping visible to lock-free 
getSchemaRegion() calls while the remapping function is running. Therefore, 
while schemaRegion.deleteSchemaRegion() is clearing the region, 
DataNodeRegionManager still retains the validation lock and isRegionExists() 
still returns true. An in-flight schema write can fail in that window and be 
reported as INTERNAL_SERVER_ERROR instead of the retryable 
NO_AVAILABLE_REGION_GROUP, which is the concurrent-deletion race this PR is 
intended to fix. Please publish a deletion-in-progress state (or remove the map 
entry before teardown and restore it on failure) so isRegionExists() observes 
the region as unavailable during teardown.



-- 
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