jt2594838 commented on code in PR #18821:
URL: https://github.com/apache/iotdb/pull/18821#discussion_r4237556576


##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/execution/executor/RegionWriteExecutor.java:
##########
@@ -842,16 +842,21 @@ private RegionExecutionResult 
executeInternalCreateMultiTimeSeries(
     }
 
     /**
-     * Check the quota before creating time series.
+     * Check region availability, data types and quota before creating time 
series.
      *
-     * @return null if the quota is not exceeded, otherwise return the 
execution result.
+     * @return null if all checks pass, otherwise return the execution result.
      */
     private RegionExecutionResult checkQuotaAndTypeBeforeCreatingTimeSeries(
         final ISchemaRegion schemaRegion,
         final PartialPath path,
         final int size,
         final List<String> measurements,
         final List<TSDataType> dataTypes) {
+      // Shutdown may clear SchemaEngine while the region's validation lock 
still exists.
+      // Reject the request as retryable before dereferencing the missing 
region.
+      if (schemaRegion == null) {
+        return createSchemaRegionUnavailableResult();

Review Comment:
   This reuses the centralized retryable result for internal timeseries 
creation after the original guard. Keeping one result builder ensures shutdown 
races consistently return NO_AVAILABLE_REGION_GROUP (906) with the localized 
message across all schema-write prechecks; live-region quota and type 
validation remain unchanged.



##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/execution/executor/RegionWriteExecutor.java:
##########
@@ -933,6 +938,9 @@ private RegionExecutionResult executeAlterTimeSeries(
         AlterTimeSeriesNode node, WritePlanNodeExecutionContext context, 
boolean receivedFromPipe) {
       ISchemaRegion schemaRegion =
           schemaEngine.getSchemaRegion((SchemaRegionId) context.getRegionId());
+      if (schemaRegion == null) {

Review Comment:
   AlterTimeSeries fetches its measurement before consensus, so a cleared 
SchemaEngine entry could otherwise be dereferenced while the validation lock 
still exists. Returning the same retryable 906 result here preserves the 
shutdown behavior established for timeseries creation; the available-region 
path remains unchanged.



##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/execution/executor/RegionWriteExecutor.java:
##########
@@ -1123,6 +1131,9 @@ private RegionExecutionResult executeCreateLogicalView(
       final ISchemaRegion schemaRegion =
           schemaEngine.getSchemaRegion((SchemaRegionId) context.getRegionId());
       if 
(CONFIG.getSchemaRegionConsensusProtocolClass().equals(ConsensusFactory.RATIS_CONSENSUS))
 {
+        if (schemaRegion == null) {

Review Comment:
   Ratis validates logical-view targets locally before writing consensus state. 
Guarding the missing region prevents a shutdown-time null dereference and makes 
the request retryable; SimpleConsensus continues to use its existing direct 
write path.



##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/execution/executor/RegionWriteExecutor.java:
##########
@@ -1180,6 +1191,9 @@ private RegionExecutionResult 
executeCreateOrUpdateTableDevice(
         final boolean receivedFromPipe) {
       final ISchemaRegion schemaRegion =
           schemaEngine.getSchemaRegion((SchemaRegionId) context.getRegionId());
+      if (schemaRegion == null) {

Review Comment:
   Table-device quota validation also reads the schema region before consensus. 
This guard covers the same shutdown window as the timeseries path and returns 
906 before checkSchemaQuota is called, while preserving normal validation for 
an available region.



##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/execution/executor/RegionWriteExecutor.java:
##########
@@ -1192,6 +1206,15 @@ private RegionExecutionResult 
executeCreateOrUpdateTableDevice(
           : PlanVisitor.super.visitCreateOrUpdateTableDevice(node, context);
     }
 
+    private RegionExecutionResult createSchemaRegionUnavailableResult() {

Review Comment:
   Centralizing the unavailable-region result keeps all guarded schema-write 
paths aligned on the retryable status and localized message. The helper also 
documents why a still-registered validation lock must not be treated as proof 
that the region is usable.



##########
iotdb-core/datanode/src/test/java/org/apache/iotdb/db/queryengine/execution/executor/RegionWriteExecutorTest.java:
##########
@@ -22,32 +22,248 @@
 import org.apache.iotdb.common.rpc.thrift.TSStatus;
 import org.apache.iotdb.commons.consensus.ConsensusGroupId;
 import org.apache.iotdb.commons.consensus.DataRegionId;
+import org.apache.iotdb.commons.consensus.SchemaRegionId;
 import org.apache.iotdb.commons.exception.IllegalPathException;
+import org.apache.iotdb.commons.path.MeasurementPath;
 import org.apache.iotdb.commons.path.PartialPath;
 import org.apache.iotdb.commons.queryengine.plan.planner.plan.node.PlanNodeId;
+import 
org.apache.iotdb.commons.schema.view.viewExpression.leaf.TimeSeriesViewOperand;
+import org.apache.iotdb.consensus.ConsensusFactory;
 import org.apache.iotdb.consensus.IConsensus;
 import org.apache.iotdb.consensus.exception.ConsensusException;
+import org.apache.iotdb.db.conf.IoTDBDescriptor;
 import org.apache.iotdb.db.protocol.thrift.impl.DataNodeRegionManager;
+import org.apache.iotdb.db.queryengine.plan.planner.plan.node.WritePlanNode;
+import 
org.apache.iotdb.db.queryengine.plan.planner.plan.node.metadata.write.AlterTimeSeriesNode;
+import 
org.apache.iotdb.db.queryengine.plan.planner.plan.node.metadata.write.InternalCreateMultiTimeSeriesNode;
+import 
org.apache.iotdb.db.queryengine.plan.planner.plan.node.metadata.write.InternalCreateTimeSeriesNode;
+import 
org.apache.iotdb.db.queryengine.plan.planner.plan.node.metadata.write.MeasurementGroup;
+import 
org.apache.iotdb.db.queryengine.plan.planner.plan.node.metadata.write.view.CreateLogicalViewNode;
+import 
org.apache.iotdb.db.queryengine.plan.planner.plan.node.pipe.PipeEnrichedWritePlanNode;
 import 
org.apache.iotdb.db.queryengine.plan.planner.plan.node.write.InsertRowNode;
+import 
org.apache.iotdb.db.queryengine.plan.relational.planner.node.schema.CreateOrUpdateTableDeviceNode;
+import 
org.apache.iotdb.db.queryengine.plan.statement.metadata.AlterTimeSeriesStatement.AlterType;
 import org.apache.iotdb.db.schemaengine.SchemaEngine;
+import org.apache.iotdb.db.schemaengine.schemaregion.ISchemaRegion;
 import org.apache.iotdb.db.schemaengine.template.ClusterTemplateManager;
 import org.apache.iotdb.db.trigger.executor.TriggerFireResult;
 import org.apache.iotdb.db.trigger.executor.TriggerFireVisitor;
 import org.apache.iotdb.rpc.TSStatusCode;
 import org.apache.iotdb.trigger.api.enums.TriggerEvent;
 
 import org.apache.tsfile.enums.TSDataType;
+import org.apache.tsfile.file.metadata.enums.CompressionType;
+import org.apache.tsfile.file.metadata.enums.TSEncoding;
+import org.apache.tsfile.utils.Pair;
 import org.junit.Test;
 import org.mockito.Mockito;
 
+import java.util.Collections;
 import java.util.concurrent.locks.ReentrantReadWriteLock;
 
+import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 
 public class RegionWriteExecutorTest {
 
+  @Test
+  public void testAlterTimeSeriesRegionAvailability() throws Exception {

Review Comment:
   This regression test exercises AlterTimeSeries with the validation lock 
retained while the schema region is absent. It verifies the new retryable 906 
result and the unchanged successful path for ordinary and Pipe requests under 
both consensus protocols.



##########
iotdb-core/datanode/src/test/java/org/apache/iotdb/db/queryengine/execution/executor/RegionWriteExecutorTest.java:
##########
@@ -22,32 +22,248 @@
 import org.apache.iotdb.common.rpc.thrift.TSStatus;
 import org.apache.iotdb.commons.consensus.ConsensusGroupId;
 import org.apache.iotdb.commons.consensus.DataRegionId;
+import org.apache.iotdb.commons.consensus.SchemaRegionId;
 import org.apache.iotdb.commons.exception.IllegalPathException;
+import org.apache.iotdb.commons.path.MeasurementPath;
 import org.apache.iotdb.commons.path.PartialPath;
 import org.apache.iotdb.commons.queryengine.plan.planner.plan.node.PlanNodeId;
+import 
org.apache.iotdb.commons.schema.view.viewExpression.leaf.TimeSeriesViewOperand;
+import org.apache.iotdb.consensus.ConsensusFactory;
 import org.apache.iotdb.consensus.IConsensus;
 import org.apache.iotdb.consensus.exception.ConsensusException;
+import org.apache.iotdb.db.conf.IoTDBDescriptor;
 import org.apache.iotdb.db.protocol.thrift.impl.DataNodeRegionManager;
+import org.apache.iotdb.db.queryengine.plan.planner.plan.node.WritePlanNode;
+import 
org.apache.iotdb.db.queryengine.plan.planner.plan.node.metadata.write.AlterTimeSeriesNode;
+import 
org.apache.iotdb.db.queryengine.plan.planner.plan.node.metadata.write.InternalCreateMultiTimeSeriesNode;
+import 
org.apache.iotdb.db.queryengine.plan.planner.plan.node.metadata.write.InternalCreateTimeSeriesNode;
+import 
org.apache.iotdb.db.queryengine.plan.planner.plan.node.metadata.write.MeasurementGroup;
+import 
org.apache.iotdb.db.queryengine.plan.planner.plan.node.metadata.write.view.CreateLogicalViewNode;
+import 
org.apache.iotdb.db.queryengine.plan.planner.plan.node.pipe.PipeEnrichedWritePlanNode;
 import 
org.apache.iotdb.db.queryengine.plan.planner.plan.node.write.InsertRowNode;
+import 
org.apache.iotdb.db.queryengine.plan.relational.planner.node.schema.CreateOrUpdateTableDeviceNode;
+import 
org.apache.iotdb.db.queryengine.plan.statement.metadata.AlterTimeSeriesStatement.AlterType;
 import org.apache.iotdb.db.schemaengine.SchemaEngine;
+import org.apache.iotdb.db.schemaengine.schemaregion.ISchemaRegion;
 import org.apache.iotdb.db.schemaengine.template.ClusterTemplateManager;
 import org.apache.iotdb.db.trigger.executor.TriggerFireResult;
 import org.apache.iotdb.db.trigger.executor.TriggerFireVisitor;
 import org.apache.iotdb.rpc.TSStatusCode;
 import org.apache.iotdb.trigger.api.enums.TriggerEvent;
 
 import org.apache.tsfile.enums.TSDataType;
+import org.apache.tsfile.file.metadata.enums.CompressionType;
+import org.apache.tsfile.file.metadata.enums.TSEncoding;
+import org.apache.tsfile.utils.Pair;
 import org.junit.Test;
 import org.mockito.Mockito;
 
+import java.util.Collections;
 import java.util.concurrent.locks.ReentrantReadWriteLock;
 
+import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 
 public class RegionWriteExecutorTest {
 
+  @Test
+  public void testAlterTimeSeriesRegionAvailability() throws Exception {
+    // Alter validation fetches the measurement before consensus; a missing 
region must be
+    // retryable.
+    checkSchemaWriteWithRegionAvailability(
+        new AlterTimeSeriesNode(
+            new PlanNodeId("alter"),
+            new MeasurementPath("root.sg.d.s"),
+            AlterType.ADD_TAGS,
+            Collections.singletonMap("tag", "value"),
+            null,
+            null,
+            null,
+            false));
+  }
+
+  @Test
+  public void testCreateLogicalViewRegionAvailability() throws Exception {

Review Comment:
   This test covers both logical-view consensus modes: Ratis performs local 
target validation and must reject a missing region with 906, while 
SimpleConsensus keeps its direct write behavior. The matrix also checks 
available regions, Pipe wrapping, and lock cleanup.



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