This is an automated email from the ASF dual-hosted git repository.
jackietien pushed a commit to branch ty/TableModelGrammar
in repository https://gitbox.apache.org/repos/asf/iotdb.git
The following commit(s) were added to refs/heads/ty/TableModelGrammar by this
push:
new 3673568a4ed Fixed the bug that the configMTree can not be recovered
when there are tables
3673568a4ed is described below
commit 3673568a4ed02d4c534ff638cdab5ca31baa4aaa
Author: Caideyipi <[email protected]>
AuthorDate: Mon Jul 15 20:17:56 2024 +0800
Fixed the bug that the configMTree can not be recovered when there are
tables
---
.../confignode/persistence/schema/ConfigMTree.java | 17 +++--
.../persistence/schema/ConfigMTreeTest.java | 81 ++++++++++++++++++++++
2 files changed, 92 insertions(+), 6 deletions(-)
diff --git
a/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/persistence/schema/ConfigMTree.java
b/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/persistence/schema/ConfigMTree.java
index e35df0b5c86..00190fde455 100644
---
a/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/persistence/schema/ConfigMTree.java
+++
b/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/persistence/schema/ConfigMTree.java
@@ -806,8 +806,8 @@ public class ConfigMTree {
public void deserialize(InputStream inputStream) throws IOException {
byte type = ReadWriteIOUtils.readByte(inputStream);
- String name = null;
- int childNum = 0;
+ String name;
+ int childNum;
Stack<Pair<IConfigMNode, Boolean>> stack = new Stack<>();
IConfigMNode databaseMNode;
IConfigMNode internalMNode;
@@ -817,9 +817,15 @@ public class ConfigMTree {
databaseMNode = deserializeDatabaseMNode(inputStream);
name = databaseMNode.getName();
stack.push(new Pair<>(databaseMNode, true));
+ } else if (type == TABLE_MNODE_TYPE) {
+ tableNode = deserializeTableMNode(inputStream);
+ name = tableNode.getName();
+ stack.push(new Pair<>(tableNode, false));
} else {
+ // Currently internal mNode will not be the leaf node and thus will not
be deserialized here
+ // This is just in case
internalMNode = deserializeInternalMNode(inputStream);
- childNum = ReadWriteIOUtils.readInt(inputStream);
+ ReadWriteIOUtils.readInt(inputStream);
name = internalMNode.getName();
stack.push(new Pair<>(internalMNode, false));
}
@@ -841,8 +847,7 @@ public class ConfigMTree {
break;
case STORAGE_GROUP_MNODE_TYPE:
databaseMNode = deserializeDatabaseMNode(inputStream).getAsMNode();
- childNum = 0;
- while (!stack.isEmpty() && !stack.peek().right) {
+ while (!stack.isEmpty() && Boolean.FALSE.equals(stack.peek().right))
{
databaseMNode.addChild(stack.pop().left);
}
stack.push(new Pair<>(databaseMNode, true));
@@ -854,7 +859,7 @@ public class ConfigMTree {
name = tableNode.getName();
break;
default:
- logger.error("Unrecognized node type. Cannot deserialize
MTreeAboveSG from given buffer");
+ logger.error("Unrecognized node type {} when recovering the mTree.",
type);
return;
}
}
diff --git
a/iotdb-core/confignode/src/test/java/org/apache/iotdb/confignode/persistence/schema/ConfigMTreeTest.java
b/iotdb-core/confignode/src/test/java/org/apache/iotdb/confignode/persistence/schema/ConfigMTreeTest.java
index a56e8757255..5b8dc0b89c9 100644
---
a/iotdb-core/confignode/src/test/java/org/apache/iotdb/confignode/persistence/schema/ConfigMTreeTest.java
+++
b/iotdb-core/confignode/src/test/java/org/apache/iotdb/confignode/persistence/schema/ConfigMTreeTest.java
@@ -22,9 +22,16 @@ import
org.apache.iotdb.commons.exception.IllegalPathException;
import org.apache.iotdb.commons.exception.MetadataException;
import org.apache.iotdb.commons.path.PartialPath;
import org.apache.iotdb.commons.schema.node.role.IDatabaseMNode;
+import org.apache.iotdb.commons.schema.table.TsTable;
+import org.apache.iotdb.commons.schema.table.column.AttributeColumnSchema;
+import org.apache.iotdb.commons.schema.table.column.IdColumnSchema;
+import org.apache.iotdb.commons.schema.table.column.MeasurementColumnSchema;
import org.apache.iotdb.confignode.persistence.schema.mnode.IConfigMNode;
import org.apache.iotdb.confignode.rpc.thrift.TDatabaseSchema;
+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.After;
import org.junit.Assert;
@@ -298,6 +305,80 @@ public class ConfigMTreeTest {
newTree.getMatchedDatabases(new PartialPath("root.a.b.sg"),
ALL_MATCH_SCOPE, true).size());
}
+ @Test
+ public void testTableSerialization() throws Exception {
+ final PartialPath[] pathList =
+ new PartialPath[] {
+ new PartialPath("root.sg"),
+ new PartialPath("root.a.sg"),
+ new PartialPath("root.a.b.sg"),
+ new PartialPath("root.a.a.b.sg")
+ };
+
+ for (int i = 0; i < pathList.length; i++) {
+ root.setStorageGroup(pathList[i]);
+ final IDatabaseMNode<IConfigMNode> storageGroupMNode =
+ root.getDatabaseNodeByDatabasePath(pathList[i]);
+
storageGroupMNode.getAsMNode().getDatabaseSchema().setDataReplicationFactor(i);
+
storageGroupMNode.getAsMNode().getDatabaseSchema().setSchemaReplicationFactor(i);
+
storageGroupMNode.getAsMNode().getDatabaseSchema().setTimePartitionInterval(i);
+
+ final String tableName = "table" + i;
+ final TsTable table = new TsTable(tableName);
+ table.addColumnSchema(new IdColumnSchema("Id", TSDataType.STRING));
+ table.addColumnSchema(new AttributeColumnSchema("Attr",
TSDataType.STRING));
+ table.addColumnSchema(
+ new MeasurementColumnSchema(
+ "Measurement", TSDataType.DOUBLE, TSEncoding.GORILLA,
CompressionType.SNAPPY));
+
+ root.preCreateTable(pathList[i], table);
+ root.commitCreateTable(pathList[i], tableName);
+ }
+
+ final ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
+ root.serialize(outputStream);
+
+ final ConfigMTree newTree = new ConfigMTree();
+ final ByteArrayInputStream inputStream = new
ByteArrayInputStream(outputStream.toByteArray());
+ newTree.deserialize(inputStream);
+
+ for (int i = 0; i < pathList.length; i++) {
+ final TDatabaseSchema storageGroupSchema =
+
newTree.getDatabaseNodeByDatabasePath(pathList[i]).getAsMNode().getDatabaseSchema();
+ Assert.assertEquals(i, storageGroupSchema.getSchemaReplicationFactor());
+ Assert.assertEquals(i, storageGroupSchema.getDataReplicationFactor());
+ Assert.assertEquals(i, storageGroupSchema.getTimePartitionInterval());
+ }
+
+ assertEquals(
+ 3,
+ newTree.getMatchedDatabases(new PartialPath("root.**.sg"),
ALL_MATCH_SCOPE, false).size());
+ assertEquals(
+ 2,
+ newTree
+ .getMatchedDatabases(new PartialPath("root.**.b.sg"),
ALL_MATCH_SCOPE, false)
+ .size());
+ assertEquals(
+ 1,
+ newTree.getMatchedDatabases(new PartialPath("root.*.*.sg"),
ALL_MATCH_SCOPE, false).size());
+ assertEquals(
+ 3, newTree.getMatchedDatabases(new PartialPath("root.a"),
ALL_MATCH_SCOPE, true).size());
+ assertEquals(
+ 1, newTree.getMatchedDatabases(new PartialPath("root.a.b"),
ALL_MATCH_SCOPE, true).size());
+ assertEquals(
+ 1,
+ newTree.getMatchedDatabases(new PartialPath("root.a.b.sg"),
ALL_MATCH_SCOPE, true).size());
+
+ for (int i = 0; i < pathList.length; i++) {
+ final List<TsTable> tables =
newTree.getAllUsingTablesUnderSpecificDatabase(pathList[i]);
+ assertEquals(1, tables.size());
+ final TsTable table = tables.get(0);
+ assertEquals("table" + i, table.getTableName());
+ assertEquals(1, table.getIdNums());
+ assertEquals(4, table.getColumnNum());
+ }
+ }
+
@Test
public void testSetTemplate() throws MetadataException {
root.setStorageGroup(new PartialPath("root.a"));