This is an automated email from the ASF dual-hosted git repository.
zyk pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/iotdb.git
The following commit(s) were added to refs/heads/master by this push:
new e8104a499e [IOTDB-5277] SchemaRegion throws NPE when loading snapshot
(#8605)
e8104a499e is described below
commit e8104a499ea15e81cabb4ed09c6deea9b143c75b
Author: Chen YZ <[email protected]>
AuthorDate: Mon Dec 26 06:32:14 2022 +0800
[IOTDB-5277] SchemaRegion throws NPE when loading snapshot (#8605)
---
.../apache/iotdb/db/metadata/MetadataConstant.java | 4 ++
.../mtree/snapshot/MemMTreeSnapshotUtil.java | 4 +-
.../schemaRegion/SchemaRegionManagementTest.java | 43 ++++++++++++++++++++++
3 files changed, 50 insertions(+), 1 deletion(-)
diff --git
a/server/src/main/java/org/apache/iotdb/db/metadata/MetadataConstant.java
b/server/src/main/java/org/apache/iotdb/db/metadata/MetadataConstant.java
index 4981c9c088..a1f167e24a 100644
--- a/server/src/main/java/org/apache/iotdb/db/metadata/MetadataConstant.java
+++ b/server/src/main/java/org/apache/iotdb/db/metadata/MetadataConstant.java
@@ -85,4 +85,8 @@ public class MetadataConstant {
throw new RuntimeException("Undefined MNode type " + type);
}
}
+
+ public static boolean isStorageGroupType(byte type) {
+ return type == STORAGE_GROUP_MNODE_TYPE || type ==
STORAGE_GROUP_ENTITY_MNODE_TYPE;
+ }
}
diff --git
a/server/src/main/java/org/apache/iotdb/db/metadata/mtree/snapshot/MemMTreeSnapshotUtil.java
b/server/src/main/java/org/apache/iotdb/db/metadata/mtree/snapshot/MemMTreeSnapshotUtil.java
index ab1de6b1aa..6306d8eaeb 100644
---
a/server/src/main/java/org/apache/iotdb/db/metadata/mtree/snapshot/MemMTreeSnapshotUtil.java
+++
b/server/src/main/java/org/apache/iotdb/db/metadata/mtree/snapshot/MemMTreeSnapshotUtil.java
@@ -57,6 +57,7 @@ import static
org.apache.iotdb.db.metadata.MetadataConstant.INTERNAL_MNODE_TYPE;
import static
org.apache.iotdb.db.metadata.MetadataConstant.MEASUREMENT_MNODE_TYPE;
import static
org.apache.iotdb.db.metadata.MetadataConstant.STORAGE_GROUP_ENTITY_MNODE_TYPE;
import static
org.apache.iotdb.db.metadata.MetadataConstant.STORAGE_GROUP_MNODE_TYPE;
+import static org.apache.iotdb.db.metadata.MetadataConstant.isStorageGroupType;
public class MemMTreeSnapshotUtil {
@@ -220,7 +221,8 @@ public class MemMTreeSnapshotUtil {
ancestors.peek().addChild(node);
}
- if (childrenNum > 0) {
+ // Storage type means current node is root node, so it must be returned.
+ if (childrenNum > 0 || isStorageGroupType(type)) {
ancestors.push(node);
restChildrenNum.push(childrenNum);
}
diff --git
a/server/src/test/java/org/apache/iotdb/db/metadata/schemaRegion/SchemaRegionManagementTest.java
b/server/src/test/java/org/apache/iotdb/db/metadata/schemaRegion/SchemaRegionManagementTest.java
index 0f50780a8a..f7c13c883c 100644
---
a/server/src/test/java/org/apache/iotdb/db/metadata/schemaRegion/SchemaRegionManagementTest.java
+++
b/server/src/test/java/org/apache/iotdb/db/metadata/schemaRegion/SchemaRegionManagementTest.java
@@ -149,6 +149,49 @@ public class SchemaRegionManagementTest extends
AbstractSchemaRegionTest {
return template;
}
+ @Test
+ public void testEmptySnapshot() throws Exception {
+ String schemaRegionConsensusProtocolClass =
config.getSchemaRegionConsensusProtocolClass();
+
config.setSchemaRegionConsensusProtocolClass(ConsensusFactory.RATIS_CONSENSUS);
+ try {
+ ISchemaRegion schemaRegion = getSchemaRegion("root.sg", 0);
+
+ File mLogFile =
+ SystemFileFactory.INSTANCE.getFile(
+ schemaRegion.getStorageGroupFullPath()
+ + File.separator
+ + schemaRegion.getSchemaRegionId().getId(),
+ MetadataConstant.METADATA_LOG);
+ Assert.assertFalse(mLogFile.exists());
+
+ File snapshotDir = new File(config.getSchemaDir() + File.separator +
"snapshot");
+ snapshotDir.mkdir();
+ schemaRegion.createSnapshot(snapshotDir);
+
+ schemaRegion.loadSnapshot(snapshotDir);
+
+ Pair<List<ShowTimeSeriesResult>, Integer> result =
+ schemaRegion.showTimeseries(
+ SchemaRegionReadPlanFactory.getShowTimeSeriesPlan(
+ new PartialPath("root.sg.**"), false, "tag-key",
"tag-value"));
+
+ Assert.assertEquals(0, result.left.size());
+
+ simulateRestart();
+
+ ISchemaRegion newSchemaRegion = getSchemaRegion("root.sg", 0);
+ newSchemaRegion.loadSnapshot(snapshotDir);
+ result =
+ newSchemaRegion.showTimeseries(
+ SchemaRegionReadPlanFactory.getShowTimeSeriesPlan(
+ new PartialPath("root.sg.**"), false, "tag-key",
"tag-value"));
+
+ Assert.assertEquals(0, result.left.size());
+ } finally {
+
config.setSchemaRegionConsensusProtocolClass(schemaRegionConsensusProtocolClass);
+ }
+ }
+
@Test
@Ignore
public void testSnapshotPerformance() throws Exception {