You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iotdb.apache.org by zy...@apache.org on 2022/12/19 15:46:47 UTC
[iotdb] branch rel/1.0 updated: [To rel/1.0][IOTDB-5240] Add template id to schema region snapshot (#8517)
This is an automated email from the ASF dual-hosted git repository.
zyk pushed a commit to branch rel/1.0
in repository https://gitbox.apache.org/repos/asf/iotdb.git
The following commit(s) were added to refs/heads/rel/1.0 by this push:
new 062d163397 [To rel/1.0][IOTDB-5240] Add template id to schema region snapshot (#8517)
062d163397 is described below
commit 062d163397cd7f8e4253796e437efede77111d7a
Author: Marcos_Zyk <38...@users.noreply.github.com>
AuthorDate: Mon Dec 19 23:46:40 2022 +0800
[To rel/1.0][IOTDB-5240] Add template id to schema region snapshot (#8517)
---
.../mtree/snapshot/MemMTreeSnapshotUtil.java | 4 +--
.../schemaregion/impl/SchemaRegionPlanFactory.java | 6 ++++
.../schemaRegion/SchemaRegionBasicTest.java | 35 ++++++++++++++++++++++
3 files changed, 43 insertions(+), 2 deletions(-)
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 71509b2724..3681a975d0 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
@@ -301,7 +301,7 @@ public class MemMTreeSnapshotUtil {
throws IOException {
ReadWriteIOUtils.write(node.getChildren().size(), outputStream);
ReadWriteIOUtils.write(node.getName(), outputStream);
- ReadWriteIOUtils.write(-1, outputStream); // todo template id
+ ReadWriteIOUtils.write(node.getSchemaTemplateId(), outputStream);
ReadWriteIOUtils.write(node.isUseTemplate(), outputStream);
}
}
@@ -354,7 +354,7 @@ public class MemMTreeSnapshotUtil {
private void deserializeInternalBasicInfo(InternalMNode node, InputStream inputStream)
throws IOException {
- int templateId = ReadWriteIOUtils.readInt(inputStream);
+ node.setSchemaTemplateId(ReadWriteIOUtils.readInt(inputStream));
node.setUseTemplate(ReadWriteIOUtils.readBool(inputStream));
}
}
diff --git a/server/src/main/java/org/apache/iotdb/db/metadata/plan/schemaregion/impl/SchemaRegionPlanFactory.java b/server/src/main/java/org/apache/iotdb/db/metadata/plan/schemaregion/impl/SchemaRegionPlanFactory.java
index 53bad3c928..792ed3ffb8 100644
--- a/server/src/main/java/org/apache/iotdb/db/metadata/plan/schemaregion/impl/SchemaRegionPlanFactory.java
+++ b/server/src/main/java/org/apache/iotdb/db/metadata/plan/schemaregion/impl/SchemaRegionPlanFactory.java
@@ -22,6 +22,7 @@ package org.apache.iotdb.db.metadata.plan.schemaregion.impl;
import org.apache.iotdb.commons.path.PartialPath;
import org.apache.iotdb.db.metadata.plan.schemaregion.ISchemaRegionPlan;
import org.apache.iotdb.db.metadata.plan.schemaregion.SchemaRegionPlanType;
+import org.apache.iotdb.db.metadata.plan.schemaregion.write.IActivateTemplateInClusterPlan;
import org.apache.iotdb.db.metadata.plan.schemaregion.write.IAutoCreateDeviceMNodePlan;
import org.apache.iotdb.db.metadata.plan.schemaregion.write.IChangeAliasPlan;
import org.apache.iotdb.db.metadata.plan.schemaregion.write.IChangeTagOffsetPlan;
@@ -136,6 +137,11 @@ public class SchemaRegionPlanFactory {
return new RollbackPreDeleteTimeSeriesPlanImpl(path);
}
+ public static IActivateTemplateInClusterPlan getActivateTemplateInClusterPlan(
+ PartialPath activatePath, int templateSetLevel, int templateId) {
+ return new ActivateTemplateInClusterPlanImpl(activatePath, templateSetLevel, templateId);
+ }
+
public static IPreDeactivateTemplatePlan getPreDeactivateTemplatePlan(
Map<PartialPath, List<Integer>> templateSetInfo) {
return new PreDeactivateTemplatePlanImpl(templateSetInfo);
diff --git a/server/src/test/java/org/apache/iotdb/db/metadata/schemaRegion/SchemaRegionBasicTest.java b/server/src/test/java/org/apache/iotdb/db/metadata/schemaRegion/SchemaRegionBasicTest.java
index 9135a5fdb9..c981009481 100644
--- a/server/src/test/java/org/apache/iotdb/db/metadata/schemaRegion/SchemaRegionBasicTest.java
+++ b/server/src/test/java/org/apache/iotdb/db/metadata/schemaRegion/SchemaRegionBasicTest.java
@@ -19,6 +19,7 @@
package org.apache.iotdb.db.metadata.schemaRegion;
import org.apache.iotdb.commons.consensus.SchemaRegionId;
+import org.apache.iotdb.commons.exception.IllegalPathException;
import org.apache.iotdb.commons.exception.MetadataException;
import org.apache.iotdb.commons.file.SystemFileFactory;
import org.apache.iotdb.commons.path.MeasurementPath;
@@ -36,8 +37,10 @@ import org.apache.iotdb.db.metadata.plan.schemaregion.impl.CreateTimeSeriesPlanI
import org.apache.iotdb.db.metadata.plan.schemaregion.impl.DeactivateTemplatePlanImpl;
import org.apache.iotdb.db.metadata.plan.schemaregion.impl.PreDeactivateTemplatePlanImpl;
import org.apache.iotdb.db.metadata.plan.schemaregion.impl.RollbackPreDeactivateTemplatePlanImpl;
+import org.apache.iotdb.db.metadata.plan.schemaregion.impl.SchemaRegionPlanFactory;
import org.apache.iotdb.db.metadata.schemaregion.ISchemaRegion;
import org.apache.iotdb.db.metadata.schemaregion.SchemaEngine;
+import org.apache.iotdb.db.metadata.schemaregion.SchemaEngineMode;
import org.apache.iotdb.db.metadata.template.Template;
import org.apache.iotdb.db.mpp.plan.statement.metadata.template.CreateSchemaTemplateStatement;
import org.apache.iotdb.db.qp.physical.sys.CreateTimeSeriesPlan;
@@ -93,6 +96,9 @@ public abstract class SchemaRegionBasicTest {
@Test
public void testRatisModeSnapshot() throws Exception {
+ if (config.getSchemaEngineMode().equals(SchemaEngineMode.Schema_File.name())) {
+ return;
+ }
String schemaRegionConsensusProtocolClass = config.getSchemaRegionConsensusProtocolClass();
config.setSchemaRegionConsensusProtocolClass(ConsensusFactory.RATIS_CONSENSUS);
try {
@@ -123,6 +129,12 @@ public abstract class SchemaRegionBasicTest {
null),
-1);
+ Template template = generateTemplate();
+ schemaRegion.activateSchemaTemplate(
+ SchemaRegionPlanFactory.getActivateTemplateInClusterPlan(
+ new PartialPath("root.sg.d2"), 1, template.getId()),
+ template);
+
File snapshotDir = new File(config.getSchemaDir() + File.separator + "snapshot");
snapshotDir.mkdir();
schemaRegion.createSnapshot(snapshotDir);
@@ -158,11 +170,34 @@ public abstract class SchemaRegionBasicTest {
Assert.assertEquals(1, resultTagMap.size());
Assert.assertEquals("tag-value", resultTagMap.get("tag-key"));
+ ShowTimeSeriesPlan showTimeSeriesPlan =
+ new ShowTimeSeriesPlan(new PartialPath("root.sg.*.s1"), false, null, null, 0, 0, false);
+ showTimeSeriesPlan.setRelatedTemplate(Collections.singletonMap(template.getId(), template));
+ result = newSchemaRegion.showTimeseries(showTimeSeriesPlan, null);
+ result.left.sort(ShowTimeSeriesResult::compareTo);
+ Assert.assertEquals(
+ new PartialPath("root.sg.d1.s1").getFullPath(), result.left.get(0).getName());
+ Assert.assertEquals(
+ new PartialPath("root.sg.d2.s1").getFullPath(), result.left.get(1).getName());
+
} finally {
config.setSchemaRegionConsensusProtocolClass(schemaRegionConsensusProtocolClass);
}
}
+ private Template generateTemplate() throws IllegalPathException {
+ Template template =
+ new Template(
+ new CreateSchemaTemplateStatement(
+ "t1",
+ Collections.singletonList(Collections.singletonList("s1")),
+ Collections.singletonList(Collections.singletonList(TSDataType.INT32)),
+ Collections.singletonList(Collections.singletonList(TSEncoding.PLAIN)),
+ Collections.singletonList(Collections.singletonList(CompressionType.GZIP))));
+ template.setId(1);
+ return template;
+ }
+
@Test
@Ignore
public void testSnapshotPerformance() throws Exception {