Skip to content

Commit

Permalink
Fix template device aligned properties recover unexpectly with Simple…
Browse files Browse the repository at this point in the history
…Consensus (apache#11968)

Fix template device aligned properties recover unexpectly with SimpleConsensus
  • Loading branch information
Cpaulyz authored Jan 27, 2024
1 parent 7d0a735 commit a544517
Show file tree
Hide file tree
Showing 6 changed files with 102 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,6 @@ public TSStatus visitAlterTimeSeries(AlterTimeSeriesNode node, ISchemaRegion sch
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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1138,6 +1138,7 @@ public void activateSchemaTemplate(IActivateTemplateInClusterPlan plan, Template
}

try {
plan.setAligned(template.isDirectAligned());
getDeviceNodeWithAutoCreate(plan.getActivatePath());

mtree.activateTemplate(plan.getActivatePath(), template);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1243,6 +1243,7 @@ public void activateSchemaTemplate(IActivateTemplateInClusterPlan plan, Template
try {
ICachedMNode deviceNode = getDeviceNodeWithAutoCreate(plan.getActivatePath());
try {
plan.setAligned(template.isDirectAligned());
mtree.activateTemplate(plan.getActivatePath(), template);
writeToMLog(plan);
} finally {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -553,7 +553,7 @@ public void clear() {
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public class PageIOChannel {

public void renewLogWriter() throws IOException {
if (logWriter != null) {
logWriter.renew();
logWriter = logWriter.renew();
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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());
}
}

0 comments on commit a544517

Please sign in to comment.