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


##########
iotdb-core/datanode/src/main/i18n/en/org/apache/iotdb/db/i18n/DataNodeQueryMessages.java:
##########
@@ -20,6 +20,8 @@
 package org.apache.iotdb.db.i18n;
 
 public final class DataNodeQueryMessages {
+  public static final String 
MESSAGE_SCHEMA_REGION_IS_UNAVAILABLE_PLEASE_RETRY_LATER_D642510A =
+      "Schema region is unavailable. Please retry later.";

Review Comment:
   Adds the retryable missing-region message to the English message catalog so 
the new validation result participates in the existing compile-time 
localization mechanism.



##########
iotdb-core/datanode/src/test/java/org/apache/iotdb/db/queryengine/execution/executor/RegionWriteExecutorTest.java:
##########
@@ -22,32 +22,130 @@
 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.PartialPath;
 import org.apache.iotdb.commons.queryengine.plan.planner.plan.node.PlanNodeId;
+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.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.pipe.PipeEnrichedWritePlanNode;
 import 
org.apache.iotdb.db.queryengine.plan.planner.plan.node.write.InsertRowNode;
 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 testInternalCreateTimeSeriesAfterSchemaRegionCleared() throws 
Exception {
+    // A shutdown can clear the region while its validation lock remains 
registered.
+    checkInternalCreateWithRegionAvailability(false, false);
+  }
+
+  @Test
+  public void testInternalCreateMultiTimeSeriesAfterSchemaRegionCleared() 
throws Exception {
+    // Batch and Pipe auto-creation must return a retryable status for the 
same shutdown window.
+    checkInternalCreateWithRegionAvailability(true, false);

Review Comment:
   Covers batch internal creation against the same missing-region state so both 
auto-creation entry points have regression coverage. The helper also exercises 
Pipe-wrapped requests.



##########
iotdb-core/datanode/src/test/java/org/apache/iotdb/db/queryengine/execution/executor/RegionWriteExecutorTest.java:
##########
@@ -22,32 +22,130 @@
 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.PartialPath;
 import org.apache.iotdb.commons.queryengine.plan.planner.plan.node.PlanNodeId;
+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.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.pipe.PipeEnrichedWritePlanNode;
 import 
org.apache.iotdb.db.queryengine.plan.planner.plan.node.write.InsertRowNode;
 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 testInternalCreateTimeSeriesAfterSchemaRegionCleared() throws 
Exception {
+    // A shutdown can clear the region while its validation lock remains 
registered.
+    checkInternalCreateWithRegionAvailability(false, false);

Review Comment:
   Reproduces the single-device internal creation failure by retaining the 
validation lock while returning a missing region. Before the fix this test 
received status 305 instead of the retryable 906; it now passes.



##########
iotdb-core/datanode/src/test/java/org/apache/iotdb/db/queryengine/execution/executor/RegionWriteExecutorTest.java:
##########
@@ -22,32 +22,130 @@
 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.PartialPath;
 import org.apache.iotdb.commons.queryengine.plan.planner.plan.node.PlanNodeId;
+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.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.pipe.PipeEnrichedWritePlanNode;
 import 
org.apache.iotdb.db.queryengine.plan.planner.plan.node.write.InsertRowNode;
 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 testInternalCreateTimeSeriesAfterSchemaRegionCleared() throws 
Exception {
+    // A shutdown can clear the region while its validation lock remains 
registered.
+    checkInternalCreateWithRegionAvailability(false, false);
+  }
+
+  @Test
+  public void testInternalCreateMultiTimeSeriesAfterSchemaRegionCleared() 
throws Exception {
+    // Batch and Pipe auto-creation must return a retryable status for the 
same shutdown window.
+    checkInternalCreateWithRegionAvailability(true, false);
+  }
+
+  @Test
+  public void testInternalCreateWithAvailableSchemaRegion() throws Exception {
+    // The guard must preserve quota checks and consensus writes for both 
live-region requests.
+    checkInternalCreateWithRegionAvailability(false, true);
+    checkInternalCreateWithRegionAvailability(true, true);
+  }
+
+  private void checkInternalCreateWithRegionAvailability(boolean batch, 
boolean available)
+      throws Exception {
+    final String originalProtocol =
+        
IoTDBDescriptor.getInstance().getConfig().getSchemaRegionConsensusProtocolClass();
+    try {
+      for (String protocol :
+          new String[] {ConsensusFactory.SIMPLE_CONSENSUS, 
ConsensusFactory.RATIS_CONSENSUS}) {
+        
IoTDBDescriptor.getInstance().getConfig().setSchemaRegionConsensusProtocolClass(protocol);
+        for (boolean fromPipe : new boolean[] {false, true}) {
+          final IConsensus consensus = Mockito.mock(IConsensus.class);
+          final DataNodeRegionManager regionManager = 
Mockito.mock(DataNodeRegionManager.class);
+          final SchemaEngine schemaEngine = Mockito.mock(SchemaEngine.class);
+          final SchemaRegionId regionId = new SchemaRegionId(1);
+          final ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
+          Mockito.when(regionManager.getRegionLock(regionId)).thenReturn(lock);
+          final ISchemaRegion region = Mockito.mock(ISchemaRegion.class);
+          Mockito.when(schemaEngine.getSchemaRegion(regionId))
+              .thenReturn(available ? region : null);
+          final RegionWriteExecutor executor =
+              new RegionWriteExecutor(
+                  Mockito.mock(IConsensus.class),
+                  consensus,
+                  regionManager,
+                  schemaEngine,
+                  Mockito.mock(ClusterTemplateManager.class),
+                  Mockito.mock(TriggerFireVisitor.class));
+          final PartialPath device = new PartialPath("root.sg.d");
+          final MeasurementGroup measurements = new MeasurementGroup();
+          measurements.addMeasurement(
+              "s", TSDataType.INT64, TSEncoding.PLAIN, CompressionType.SNAPPY);
+          final WritePlanNode node =
+              batch
+                  ? new InternalCreateMultiTimeSeriesNode(
+                      new PlanNodeId("test"),
+                      Collections.singletonMap(device, new Pair<>(false, 
measurements)))
+                  : new InternalCreateTimeSeriesNode(
+                      new PlanNodeId("test"), device, measurements, false);
+          final WritePlanNode request = fromPipe ? new 
PipeEnrichedWritePlanNode(node) : node;
+          Mockito.when(consensus.write(regionId, request))
+              .thenReturn(new 
TSStatus(TSStatusCode.SUCCESS_STATUS.getStatusCode()));
+
+          final RegionExecutionResult result = executor.execute(regionId, 
request);
+          assertEquals(available, result.isAccepted());
+          assertEquals(
+              (available ? TSStatusCode.SUCCESS_STATUS : 
TSStatusCode.NO_AVAILABLE_REGION_GROUP)
+                  .getStatusCode(),
+              result.getStatus().getCode());
+          assertFalse(lock.isWriteLocked());
+          assertEquals(0, lock.getReadLockCount());
+          if (available) {
+            Mockito.verify(region).checkSchemaQuota(device, 1);
+            Mockito.verify(consensus).write(regionId, request);
+          } else {
+            Mockito.verifyZeroInteractions(consensus);
+            assertEquals(1, measurements.size());
+          }
+        }
+      }
+    } finally {
+      IoTDBDescriptor.getInstance()
+          .getConfig()
+          .setSchemaRegionConsensusProtocolClass(originalProtocol);

Review Comment:
   The shared fixture runs SimpleConsensus and Ratis with ordinary and Pipe 
requests, using a real validation lock and mocked region/consensus services. 
Assertions check the returned status, lock release, and either the expected 
write or the absence of consensus interaction; configuration is restored in 
finally. All four tests in this class passed. This is deterministic 
executor-level coverage, not a full cluster shutdown stress test. The added 
imports support this fixture and its request variants.



##########
iotdb-core/datanode/src/main/i18n/zh/org/apache/iotdb/db/i18n/DataNodeQueryMessages.java:
##########
@@ -20,6 +20,8 @@
 package org.apache.iotdb.db.i18n;
 
 public final class DataNodeQueryMessages {
+  public static final String 
MESSAGE_SCHEMA_REGION_IS_UNAVAILABLE_PLEASE_RETRY_LATER_D642510A =
+      "SchemaRegion 不可用,请稍后重试。";

Review Comment:
   Adds the same message key in Chinese to preserve locale parity. DataNode and 
ConfigNode compiled successfully with the Chinese profile; the full reactor 
stopped later at distribution because SNAPSHOT ZIP dependencies were 
unavailable.



##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/execution/executor/RegionWriteExecutor.java:
##########
@@ -842,16 +842,24 @@ 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) {
+        final String message =
+            
DataNodeQueryMessages.MESSAGE_SCHEMA_REGION_IS_UNAVAILABLE_PLEASE_RETRY_LATER_D642510A;
+        return RegionExecutionResult.create(
+            false, message, 
RpcUtils.getStatus(TSStatusCode.NO_AVAILABLE_REGION_GROUP, message));

Review Comment:
   Shutdown can clear the schema region while its validation lock is still 
registered. The previous quota check dereferenced null, and the outer catch 
returned INTERNAL_SERVER_ERROR because the lock still existed. Checking 
availability here returns NO_AVAILABLE_REGION_GROUP before dereferencing the 
region and covers the shared timeseries prevalidation callers. The method 
documentation now describes all three checks. Existing live-region validation 
and consensus writes are preserved.



##########
iotdb-core/datanode/src/test/java/org/apache/iotdb/db/queryengine/execution/executor/RegionWriteExecutorTest.java:
##########
@@ -22,32 +22,130 @@
 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.PartialPath;
 import org.apache.iotdb.commons.queryengine.plan.planner.plan.node.PlanNodeId;
+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.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.pipe.PipeEnrichedWritePlanNode;
 import 
org.apache.iotdb.db.queryengine.plan.planner.plan.node.write.InsertRowNode;
 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 testInternalCreateTimeSeriesAfterSchemaRegionCleared() throws 
Exception {
+    // A shutdown can clear the region while its validation lock remains 
registered.
+    checkInternalCreateWithRegionAvailability(false, false);
+  }
+
+  @Test
+  public void testInternalCreateMultiTimeSeriesAfterSchemaRegionCleared() 
throws Exception {
+    // Batch and Pipe auto-creation must return a retryable status for the 
same shutdown window.
+    checkInternalCreateWithRegionAvailability(true, false);
+  }
+
+  @Test
+  public void testInternalCreateWithAvailableSchemaRegion() throws Exception {
+    // The guard must preserve quota checks and consensus writes for both 
live-region requests.
+    checkInternalCreateWithRegionAvailability(false, true);
+    checkInternalCreateWithRegionAvailability(true, true);

Review Comment:
   Checks both single-device and batch requests with an available region to 
ensure that the early rejection does not suppress valid quota checks or 
consensus writes.



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