This is an automated email from the ASF dual-hosted git repository.
chenyz 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 a5445177d5d Fix template device aligned properties recover unexpectly
with SimpleConsensus (#11968)
a5445177d5d is described below
commit a5445177d5d53cda7ad6a5104c2e41e2b4de5c3c
Author: Chen YZ <[email protected]>
AuthorDate: Sat Jan 27 14:09:21 2024 +0800
Fix template device aligned properties recover unexpectly with
SimpleConsensus (#11968)
Fix template device aligned properties recover unexpectly with
SimpleConsensus
---
.../schemaregion/SchemaExecutionVisitor.java | 1 -
.../schemaregion/impl/SchemaRegionMemoryImpl.java | 1 +
.../schemaregion/impl/SchemaRegionPBTreeImpl.java | 1 +
.../mtree/impl/pbtree/CachedMTreeStore.java | 2 +-
.../pbtree/schemafile/pagemgr/PageIOChannel.java | 2 +-
.../SchemaRegionSimpleRecoverTest.java | 98 ++++++++++++++++++++++
6 files changed, 102 insertions(+), 3 deletions(-)
diff --git
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/consensus/statemachine/schemaregion/SchemaExecutionVisitor.java
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/consensus/statemachine/schemaregion/SchemaExecutionVisitor.java
index a1496e7b6d7..28048073a99 100644
---
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/consensus/statemachine/schemaregion/SchemaExecutionVisitor.java
+++
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/consensus/statemachine/schemaregion/SchemaExecutionVisitor.java
@@ -326,7 +326,6 @@ public class SchemaExecutionVisitor extends
PlanVisitor<TSStatus, ISchemaRegion>
public TSStatus visitActivateTemplate(ActivateTemplateNode node,
ISchemaRegion schemaRegion) {
try {
Template template =
ClusterTemplateManager.getInstance().getTemplate(node.getTemplateId());
- node.setAligned(template.isDirectAligned());
schemaRegion.activateSchemaTemplate(node, template);
return RpcUtils.getStatus(TSStatusCode.SUCCESS_STATUS);
} catch (MetadataException e) {
diff --git
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/schemaengine/schemaregion/impl/SchemaRegionMemoryImpl.java
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/schemaengine/schemaregion/impl/SchemaRegionMemoryImpl.java
index 496beba9db2..c8f336eeb83 100644
---
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/schemaengine/schemaregion/impl/SchemaRegionMemoryImpl.java
+++
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/schemaengine/schemaregion/impl/SchemaRegionMemoryImpl.java
@@ -1138,6 +1138,7 @@ public class SchemaRegionMemoryImpl implements
ISchemaRegion {
}
try {
+ plan.setAligned(template.isDirectAligned());
getDeviceNodeWithAutoCreate(plan.getActivatePath());
mtree.activateTemplate(plan.getActivatePath(), template);
diff --git
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/schemaengine/schemaregion/impl/SchemaRegionPBTreeImpl.java
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/schemaengine/schemaregion/impl/SchemaRegionPBTreeImpl.java
index ec2d93f2b8f..8c5e52fbd36 100644
---
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/schemaengine/schemaregion/impl/SchemaRegionPBTreeImpl.java
+++
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/schemaengine/schemaregion/impl/SchemaRegionPBTreeImpl.java
@@ -1243,6 +1243,7 @@ public class SchemaRegionPBTreeImpl implements
ISchemaRegion {
try {
ICachedMNode deviceNode =
getDeviceNodeWithAutoCreate(plan.getActivatePath());
try {
+ plan.setAligned(template.isDirectAligned());
mtree.activateTemplate(plan.getActivatePath(), template);
writeToMLog(plan);
} finally {
diff --git
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/schemaengine/schemaregion/mtree/impl/pbtree/CachedMTreeStore.java
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/schemaengine/schemaregion/mtree/impl/pbtree/CachedMTreeStore.java
index d4d2e73e46c..2addd6e908d 100644
---
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/schemaengine/schemaregion/mtree/impl/pbtree/CachedMTreeStore.java
+++
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/schemaengine/schemaregion/mtree/impl/pbtree/CachedMTreeStore.java
@@ -553,7 +553,7 @@ public class CachedMTreeStore implements
IMTreeStore<ICachedMNode> {
file.clear();
file.close();
} catch (MetadataException | IOException e) {
- LOGGER.error("Error occurred during PBTree clear, {}",
e.getMessage());
+ LOGGER.error("Error occurred during PBTree clear, {}",
e.getMessage(), e);
}
}
file = null;
diff --git
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/schemaengine/schemaregion/mtree/impl/pbtree/schemafile/pagemgr/PageIOChannel.java
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/schemaengine/schemaregion/mtree/impl/pbtree/schemafile/pagemgr/PageIOChannel.java
index 87a05cdca42..044b7339a82 100644
---
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/schemaengine/schemaregion/mtree/impl/pbtree/schemafile/pagemgr/PageIOChannel.java
+++
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/schemaengine/schemaregion/mtree/impl/pbtree/schemafile/pagemgr/PageIOChannel.java
@@ -70,7 +70,7 @@ public class PageIOChannel {
public void renewLogWriter() throws IOException {
if (logWriter != null) {
- logWriter.renew();
+ logWriter = logWriter.renew();
}
}
diff --git
a/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/metadata/schemaRegion/SchemaRegionSimpleRecoverTest.java
b/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/metadata/schemaRegion/SchemaRegionSimpleRecoverTest.java
new file mode 100644
index 00000000000..fc8fa680f6e
--- /dev/null
+++
b/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/metadata/schemaRegion/SchemaRegionSimpleRecoverTest.java
@@ -0,0 +1,98 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.iotdb.db.metadata.schemaRegion;
+
+import org.apache.iotdb.commons.path.PartialPath;
+import org.apache.iotdb.consensus.ConsensusFactory;
+import org.apache.iotdb.db.conf.IoTDBDescriptor;
+import org.apache.iotdb.db.queryengine.common.schematree.ClusterSchemaTree;
+import org.apache.iotdb.db.schemaengine.schemaregion.ISchemaRegion;
+import
org.apache.iotdb.db.schemaengine.schemaregion.write.req.SchemaRegionWritePlanFactory;
+import org.apache.iotdb.db.schemaengine.template.Template;
+import org.apache.iotdb.tsfile.file.metadata.enums.CompressionType;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSEncoding;
+
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+import java.util.Arrays;
+import java.util.Collections;
+
+import static org.apache.iotdb.commons.schema.SchemaConstant.ALL_MATCH_SCOPE;
+
+public class SchemaRegionSimpleRecoverTest extends AbstractSchemaRegionTest {
+
+ private String schemaRegionConsensusProtocolClass;
+
+ public SchemaRegionSimpleRecoverTest(SchemaRegionTestParams testParams) {
+ super(testParams);
+ }
+
+ @Before
+ public void setUp() throws Exception {
+ super.setUp();
+ schemaRegionConsensusProtocolClass =
+
IoTDBDescriptor.getInstance().getConfig().getSchemaRegionConsensusProtocolClass();
+ IoTDBDescriptor.getInstance()
+ .getConfig()
+
.setSchemaRegionConsensusProtocolClass(ConsensusFactory.SIMPLE_CONSENSUS);
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ super.tearDown();
+ IoTDBDescriptor.getInstance()
+ .getConfig()
+
.setSchemaRegionConsensusProtocolClass(schemaRegionConsensusProtocolClass);
+ }
+
+ @Test
+ public void testRecoverWithAlignedTemplate() throws Exception {
+ ISchemaRegion schemaRegion = getSchemaRegion("root.sg", 0);
+ int templateId = 1;
+ Template template =
+ new Template(
+ "t1",
+ Arrays.asList("s1", "s2"),
+ Arrays.asList(TSDataType.DOUBLE, TSDataType.INT32),
+ Arrays.asList(TSEncoding.RLE, TSEncoding.RLE),
+ Arrays.asList(CompressionType.SNAPPY, CompressionType.SNAPPY),
+ true);
+ template.setId(templateId);
+ schemaRegion.activateSchemaTemplate(
+ SchemaRegionWritePlanFactory.getActivateTemplateInClusterPlan(
+ new PartialPath("root.sg.d1"), 2, templateId),
+ template);
+ ClusterSchemaTree schemaTree =
+ schemaRegion.fetchSchema(
+ ALL_MATCH_SCOPE, Collections.singletonMap(templateId, template),
true, true);
+ Assert.assertTrue(schemaTree.getAllDevices().get(0).isAligned());
+
+ simulateRestart();
+ schemaRegion = getSchemaRegion("root.sg", 0);
+ schemaTree =
+ schemaRegion.fetchSchema(
+ ALL_MATCH_SCOPE, Collections.singletonMap(templateId, template),
true, true);
+ Assert.assertTrue(schemaTree.getAllDevices().get(0).isAligned());
+ }
+}