You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iotdb.apache.org by ha...@apache.org on 2023/07/24 10:43:31 UTC
[iotdb] 02/05: Revert "[To rel/1.1][IOTDB-6076] Add duplicate checking when upsert alias"
This is an automated email from the ASF dual-hosted git repository.
haonan pushed a commit to branch rc/1.1.2
in repository https://gitbox.apache.org/repos/asf/iotdb.git
commit d0432e57775778fbf4db6d9919b8447fc5756072
Author: HTHou <hh...@outlook.com>
AuthorDate: Mon Jul 24 18:23:19 2023 +0800
Revert "[To rel/1.1][IOTDB-6076] Add duplicate checking when upsert alias"
This reverts commit 2a5bac3e379792873682c4e63e0d577a59015b95.
---
.../apache/iotdb/db/it/schema/IoTDBTagAlterIT.java | 29 ---------------
.../db/metadata/mtree/MTreeBelowSGCachedImpl.java | 27 --------------
.../db/metadata/mtree/MTreeBelowSGMemoryImpl.java | 23 ------------
.../schemaregion/SchemaRegionMemoryImpl.java | 39 +++++++++++++++++---
.../schemaregion/SchemaRegionSchemaFileImpl.java | 43 +++++++++++++++++++---
.../schemaRegion/SchemaRegionAliasAndTagTest.java | 19 ----------
6 files changed, 70 insertions(+), 110 deletions(-)
diff --git a/integration-test/src/test/java/org/apache/iotdb/db/it/schema/IoTDBTagAlterIT.java b/integration-test/src/test/java/org/apache/iotdb/db/it/schema/IoTDBTagAlterIT.java
index deae20bbee2..d37c241df35 100644
--- a/integration-test/src/test/java/org/apache/iotdb/db/it/schema/IoTDBTagAlterIT.java
+++ b/integration-test/src/test/java/org/apache/iotdb/db/it/schema/IoTDBTagAlterIT.java
@@ -601,33 +601,4 @@ public class IoTDBTagAlterIT extends AbstractSchemaIT {
fail();
}
}
-
- @Test
- public void alterDuplicateAliasTest() {
- try (Connection connection = EnvFactory.getEnv().getConnection();
- Statement statement = connection.createStatement()) {
- statement.execute(
- "create timeseries root.turbine.d1.s1(a1) with datatype=FLOAT, encoding=RLE, compression=SNAPPY;");
- statement.execute("create timeseries root.turbine.d1.s2 with datatype=INT32, encoding=RLE;");
- try {
- statement.execute("alter timeseries root.turbine.d1.s2 upsert alias=s1;");
- fail();
- } catch (Exception e) {
- assertTrue(
- e.getMessage()
- .contains("The alias is duplicated with the name or alias of other measurement."));
- }
- try {
- statement.execute("alter timeseries root.turbine.d1.s2 upsert alias=a1;");
- fail();
- } catch (Exception e) {
- assertTrue(
- e.getMessage()
- .contains("The alias is duplicated with the name or alias of other measurement."));
- }
- } catch (Exception e) {
- e.printStackTrace();
- fail();
- }
- }
}
diff --git a/server/src/main/java/org/apache/iotdb/db/metadata/mtree/MTreeBelowSGCachedImpl.java b/server/src/main/java/org/apache/iotdb/db/metadata/mtree/MTreeBelowSGCachedImpl.java
index 738f2ce2bb3..ae670621dc4 100644
--- a/server/src/main/java/org/apache/iotdb/db/metadata/mtree/MTreeBelowSGCachedImpl.java
+++ b/server/src/main/java/org/apache/iotdb/db/metadata/mtree/MTreeBelowSGCachedImpl.java
@@ -416,33 +416,6 @@ public class MTreeBelowSGCachedImpl implements IMTreeBelowSG {
}
}
- public boolean changeAlias(String alias, PartialPath fullPath) throws MetadataException {
- IMeasurementMNode measurementMNode = getMeasurementMNode(fullPath);
- try {
- // upsert alias
- if (alias != null && !alias.equals(measurementMNode.getAlias())) {
- synchronized (this) {
- IEntityMNode device = measurementMNode.getParent().getAsEntityMNode();
- IMNode cachedMNode = store.getChild(device, alias);
- if (cachedMNode != null) {
- unPinMNode(cachedMNode);
- throw new MetadataException(
- "The alias is duplicated with the name or alias of other measurement.");
- }
- if (measurementMNode.getAlias() != null) {
- device.deleteAliasChild(measurementMNode.getAlias());
- }
- device.addAlias(alias, measurementMNode);
- setAlias(measurementMNode, alias);
- }
- return true;
- }
- return false;
- } finally {
- unPinMNode(measurementMNode);
- }
- }
-
@Override
public Map<Integer, MetadataException> checkMeasurementExistence(
PartialPath devicePath, List<String> measurementList, List<String> aliasList) {
diff --git a/server/src/main/java/org/apache/iotdb/db/metadata/mtree/MTreeBelowSGMemoryImpl.java b/server/src/main/java/org/apache/iotdb/db/metadata/mtree/MTreeBelowSGMemoryImpl.java
index d33965bd4af..26376b38f01 100644
--- a/server/src/main/java/org/apache/iotdb/db/metadata/mtree/MTreeBelowSGMemoryImpl.java
+++ b/server/src/main/java/org/apache/iotdb/db/metadata/mtree/MTreeBelowSGMemoryImpl.java
@@ -432,29 +432,6 @@ public class MTreeBelowSGMemoryImpl implements IMTreeBelowSG {
}
return failingMeasurementMap;
}
-
- public boolean changeAlias(String alias, PartialPath fullPath) throws MetadataException {
- IMeasurementMNode measurementMNode = getMeasurementMNode(fullPath);
- // upsert alias
- if (alias != null && !alias.equals(measurementMNode.getAlias())) {
- synchronized (this) {
- IEntityMNode device = measurementMNode.getParent().getAsEntityMNode();
- IMNode memMNode = store.getChild(device, alias);
- if (memMNode != null) {
- throw new MetadataException(
- "The alias is duplicated with the name or alias of other measurement.");
- }
- if (measurementMNode.getAlias() != null) {
- device.deleteAliasChild(measurementMNode.getAlias());
- }
- device.addAlias(alias, measurementMNode);
- setAlias(measurementMNode, alias);
- }
- return true;
- }
- return false;
- }
-
/**
* Delete path. The path should be a full path from root to leaf node
*
diff --git a/server/src/main/java/org/apache/iotdb/db/metadata/schemaregion/SchemaRegionMemoryImpl.java b/server/src/main/java/org/apache/iotdb/db/metadata/schemaregion/SchemaRegionMemoryImpl.java
index ddf731a5672..6c18a976a2d 100644
--- a/server/src/main/java/org/apache/iotdb/db/metadata/schemaregion/SchemaRegionMemoryImpl.java
+++ b/server/src/main/java/org/apache/iotdb/db/metadata/schemaregion/SchemaRegionMemoryImpl.java
@@ -841,6 +841,21 @@ public class SchemaRegionMemoryImpl implements ISchemaRegion {
}
}
+ private void changeAlias(PartialPath path, String alias) throws MetadataException {
+ IMeasurementMNode leafMNode = mtree.getMeasurementMNode(path);
+ if (leafMNode.getAlias() != null) {
+ leafMNode.getParent().deleteAliasChild(leafMNode.getAlias());
+ }
+ leafMNode.getParent().addAlias(alias, leafMNode);
+ mtree.setAlias(leafMNode, alias);
+
+ try {
+ writeToMLog(SchemaRegionWritePlanFactory.getChangeAliasPlan(path, alias));
+ } catch (IOException e) {
+ throw new MetadataException(e);
+ }
+ }
+
/**
* Upsert tags and attributes key-value for the timeseries if the key has existed, just use the
* new value to update it.
@@ -858,9 +873,11 @@ public class SchemaRegionMemoryImpl implements ISchemaRegion {
Map<String, String> attributesMap,
PartialPath fullPath)
throws MetadataException, IOException {
- // upsert alias
- upsertAlias(alias, fullPath);
IMeasurementMNode leafMNode = mtree.getMeasurementMNode(fullPath);
+
+ // upsert alias
+ upsertAlias(alias, fullPath, leafMNode);
+
if (tagsMap == null && attributesMap == null) {
return;
}
@@ -880,9 +897,19 @@ public class SchemaRegionMemoryImpl implements ISchemaRegion {
tagManager.updateTagsAndAttributes(tagsMap, attributesMap, leafMNode);
}
- private void upsertAlias(String alias, PartialPath fullPath)
+ private void upsertAlias(String alias, PartialPath fullPath, IMeasurementMNode leafMNode)
throws MetadataException, IOException {
- if (mtree.changeAlias(alias, fullPath)) {
+ // upsert alias
+ if (alias != null && !alias.equals(leafMNode.getAlias())) {
+ if (!leafMNode.getParent().addAlias(alias, leafMNode)) {
+ throw new MetadataException("The alias already exists.");
+ }
+
+ if (leafMNode.getAlias() != null) {
+ leafMNode.getParent().deleteAliasChild(leafMNode.getAlias());
+ }
+
+ mtree.setAlias(leafMNode, alias);
// persist to WAL
writeToMLog(SchemaRegionWritePlanFactory.getChangeAliasPlan(fullPath, alias));
}
@@ -1176,9 +1203,9 @@ public class SchemaRegionMemoryImpl implements ISchemaRegion {
public RecoverOperationResult visitChangeAlias(
IChangeAliasPlan changeAliasPlan, SchemaRegionMemoryImpl context) {
try {
- upsertAlias(changeAliasPlan.getAlias(), changeAliasPlan.getPath());
+ changeAlias(changeAliasPlan.getPath(), changeAliasPlan.getAlias());
return RecoverOperationResult.SUCCESS;
- } catch (MetadataException | IOException e) {
+ } catch (MetadataException e) {
return new RecoverOperationResult(e);
}
}
diff --git a/server/src/main/java/org/apache/iotdb/db/metadata/schemaregion/SchemaRegionSchemaFileImpl.java b/server/src/main/java/org/apache/iotdb/db/metadata/schemaregion/SchemaRegionSchemaFileImpl.java
index 22883da896c..95fdbac528f 100644
--- a/server/src/main/java/org/apache/iotdb/db/metadata/schemaregion/SchemaRegionSchemaFileImpl.java
+++ b/server/src/main/java/org/apache/iotdb/db/metadata/schemaregion/SchemaRegionSchemaFileImpl.java
@@ -958,6 +958,25 @@ public class SchemaRegionSchemaFileImpl implements ISchemaRegion {
}
}
+ private void changeAlias(PartialPath path, String alias) throws MetadataException {
+ IMeasurementMNode leafMNode = mtree.getMeasurementMNode(path);
+ try {
+ if (leafMNode.getAlias() != null) {
+ leafMNode.getParent().deleteAliasChild(leafMNode.getAlias());
+ }
+ leafMNode.getParent().addAlias(alias, leafMNode);
+ mtree.setAlias(leafMNode, alias);
+ } finally {
+ mtree.unPinMNode(leafMNode);
+ }
+
+ try {
+ writeToMLog(SchemaRegionWritePlanFactory.getChangeAliasPlan(path, alias));
+ } catch (IOException e) {
+ throw new MetadataException(e);
+ }
+ }
+
/**
* Upsert tags and attributes key-value for the timeseries if the key has existed, just use the
* new value to update it.
@@ -975,13 +994,15 @@ public class SchemaRegionSchemaFileImpl implements ISchemaRegion {
Map<String, String> attributesMap,
PartialPath fullPath)
throws MetadataException, IOException {
- // upsert alias
- upsertAlias(alias, fullPath);
IMeasurementMNode leafMNode = mtree.getMeasurementMNode(fullPath);
try {
+ // upsert alias
+ upsertAlias(alias, fullPath, leafMNode);
+
if (tagsMap == null && attributesMap == null) {
return;
}
+
// no tag or attribute, we need to add a new record in log
if (leafMNode.getOffset() < 0) {
long offset = tagManager.writeTagFile(tagsMap, attributesMap);
@@ -1002,9 +1023,19 @@ public class SchemaRegionSchemaFileImpl implements ISchemaRegion {
}
}
- private void upsertAlias(String alias, PartialPath fullPath)
+ private void upsertAlias(String alias, PartialPath fullPath, IMeasurementMNode leafMNode)
throws MetadataException, IOException {
- if (mtree.changeAlias(alias, fullPath)) {
+ // upsert alias
+ if (alias != null && !alias.equals(leafMNode.getAlias())) {
+ if (!leafMNode.getParent().addAlias(alias, leafMNode)) {
+ throw new MetadataException("The alias already exists.");
+ }
+
+ if (leafMNode.getAlias() != null) {
+ leafMNode.getParent().deleteAliasChild(leafMNode.getAlias());
+ }
+
+ mtree.setAlias(leafMNode, alias);
// persist to WAL
writeToMLog(SchemaRegionWritePlanFactory.getChangeAliasPlan(fullPath, alias));
}
@@ -1326,9 +1357,9 @@ public class SchemaRegionSchemaFileImpl implements ISchemaRegion {
public RecoverOperationResult visitChangeAlias(
IChangeAliasPlan changeAliasPlan, SchemaRegionSchemaFileImpl context) {
try {
- upsertAlias(changeAliasPlan.getAlias(), changeAliasPlan.getPath());
+ changeAlias(changeAliasPlan.getPath(), changeAliasPlan.getAlias());
return RecoverOperationResult.SUCCESS;
- } catch (MetadataException | IOException e) {
+ } catch (MetadataException e) {
return new RecoverOperationResult(e);
}
}
diff --git a/server/src/test/java/org/apache/iotdb/db/metadata/schemaRegion/SchemaRegionAliasAndTagTest.java b/server/src/test/java/org/apache/iotdb/db/metadata/schemaRegion/SchemaRegionAliasAndTagTest.java
index cb994441693..d2f237408a3 100644
--- a/server/src/test/java/org/apache/iotdb/db/metadata/schemaRegion/SchemaRegionAliasAndTagTest.java
+++ b/server/src/test/java/org/apache/iotdb/db/metadata/schemaRegion/SchemaRegionAliasAndTagTest.java
@@ -245,25 +245,6 @@ public class SchemaRegionAliasAndTagTest extends AbstractSchemaRegionTest {
public void testUpsertAliasAndTagsAndAttributes() {
try {
prepareTimeseries();
- try {
- schemaRegion.upsertAliasAndTagsAndAttributes(
- "s2", null, null, new PartialPath("root.sg.wf01.wt01.v1.s1"));
- Assert.fail();
- } catch (Exception e) {
- Assert.assertTrue(
- e.getMessage()
- .contains("The alias is duplicated with the name or alias of other measurement."));
- }
- try {
- schemaRegion.upsertAliasAndTagsAndAttributes(
- "temp", null, null, new PartialPath("root.sg.wf01.wt01.v1.s1"));
- Assert.fail();
- } catch (Exception e) {
- Assert.assertTrue(
- e.getMessage()
- .contains("The alias is duplicated with the name or alias of other measurement."));
- }
-
Map<String, String> newTags =
new HashMap<String, String>() {
{