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


##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/schemaengine/schemaregion/mtree/impl/mem/MTreeBelowSGMemoryImpl.java:
##########
@@ -1041,6 +1041,9 @@ protected Void collectEntity(final 
IDeviceMNode<IMemMNode> node) {
   public IMemMNode getNodeByPath(final PartialPath path) throws 
PathNotExistException {
     final String[] nodes = path.getNodes();
     IMemMNode cur = databaseMNode;
+    if (cur == null) {

Review Comment:
   SchemaRegion.clear() nulls the MTree database root. Converting that cleared 
state to the existing PathNotExistException lets checkDeviceNodeExists handle 
shutdown without an NPE in quota validation; live-tree path lookup behavior is 
unchanged.



##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/schemaengine/schemaregion/mtree/impl/mem/MTreeBelowSGMemoryImpl.java:
##########
@@ -1924,6 +1927,9 @@ protected Void collectMeasurement(final 
IMeasurementMNode<IMemMNode> node) {
   // region table device management
 
   public int getTableDeviceNotExistNum(final String tableName, final 
List<Object[]> deviceIdList) {
+    if (databaseMNode == null) {

Review Comment:
   Table-device quota validation calls this count after the schema MTree may 
have been cleared. Treating every requested device as absent avoids 
dereferencing the missing root and keeps the count consistent with an empty 
tree.



##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/schemaengine/schemaregion/mtree/impl/pbtree/MTreeBelowSGCachedImpl.java:
##########
@@ -1074,6 +1074,9 @@ public ICachedMNode getNodeByPath(PartialPath path) 
throws MetadataException {
     ICachedMNode cur = databaseMNode;
     ICachedMNode next;
     try {
+      if (cur == null) {

Review Comment:
   After PBTree clear, the database root is null. This maps that state to 
PathNotExistException, and the guarded finally block avoids trying to unpin a 
null node. checkDeviceNodeExists can then handle the shutdown state without an 
NPE.



##########
iotdb-core/datanode/src/test/java/org/apache/iotdb/db/schemaengine/schemaregion/mtree/impl/mem/MTreeBelowSGMemoryImplTest.java:
##########
@@ -43,13 +43,27 @@
 import org.junit.Test;
 
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.Collections;
 import java.util.List;
 import java.util.Map;
 import java.util.concurrent.atomic.AtomicInteger;
 
 public class MTreeBelowSGMemoryImplTest {
 
+  @Test
+  public void testPathAndTableDeviceChecksAfterClear() throws Exception {

Review Comment:
   This regression test clears the memory MTree and verifies path lookup, 
device existence checks, and table-device counting handle the absent root 
without throwing an NPE.



##########
iotdb-core/datanode/src/test/java/org/apache/iotdb/db/schemaengine/schemaregion/mtree/impl/pbtree/MTreeBelowSGCachedImplTest.java:
##########
@@ -178,6 +178,17 @@ private MTreeBelowSGCachedImpl newMTree() throws Exception 
{
         new SchemaRegionCachedMetric(regionStatistics, "root.sg"));
   }
 
+  @Test
+  public void testPathLookupAfterClear() throws Exception {

Review Comment:
   This regression test exercises path lookup and device existence checks after 
PBTree clear, covering both the missing-root exception and safe null-node 
unpinning.



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