This is an automated email from the ASF dual-hosted git repository.
xingtanzjr 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 85d27c3e20 [IOTDB-3259] fix sg already exists check. (#6162)
85d27c3e20 is described below
commit 85d27c3e20ecf7c58f30e80a06d43cdf4ce1d28e
Author: ZhangHongYin <[email protected]>
AuthorDate: Tue Jun 7 09:28:20 2022 +0800
[IOTDB-3259] fix sg already exists check. (#6162)
---
.../confignode/manager/ClusterSchemaManager.java | 21 +++++++++++--------
.../confignode/persistence/ClusterSchemaInfo.java | 11 ++--------
.../iotdb/db/metadata/mtree/MTreeAboveSG.java | 24 ++++++++++++++++++++++
3 files changed, 39 insertions(+), 17 deletions(-)
diff --git
a/confignode/src/main/java/org/apache/iotdb/confignode/manager/ClusterSchemaManager.java
b/confignode/src/main/java/org/apache/iotdb/confignode/manager/ClusterSchemaManager.java
index e888075a84..f10051c4ea 100644
---
a/confignode/src/main/java/org/apache/iotdb/confignode/manager/ClusterSchemaManager.java
+++
b/confignode/src/main/java/org/apache/iotdb/confignode/manager/ClusterSchemaManager.java
@@ -21,6 +21,7 @@ package org.apache.iotdb.confignode.manager;
import org.apache.iotdb.common.rpc.thrift.TConsensusGroupId;
import org.apache.iotdb.common.rpc.thrift.TConsensusGroupType;
import org.apache.iotdb.common.rpc.thrift.TSStatus;
+import org.apache.iotdb.commons.exception.IllegalPathException;
import org.apache.iotdb.commons.exception.MetadataException;
import org.apache.iotdb.confignode.consensus.request.read.CountStorageGroupReq;
import org.apache.iotdb.confignode.consensus.request.read.GetStorageGroupReq;
@@ -65,16 +66,20 @@ public class ClusterSchemaManager {
*/
public TSStatus setStorageGroup(SetStorageGroupReq setStorageGroupReq) {
TSStatus result;
- if
(clusterSchemaInfo.containsStorageGroup(setStorageGroupReq.getSchema().getName()))
{
+ try {
+
clusterSchemaInfo.checkContainsStorageGroup(setStorageGroupReq.getSchema().getName());
+ } catch (MetadataException metadataException) {
// Reject if StorageGroup already set
- result = new
TSStatus(TSStatusCode.STORAGE_GROUP_ALREADY_EXISTS.getStatusCode());
- result.setMessage(
- String.format(
- "StorageGroup %s is already set.",
setStorageGroupReq.getSchema().getName()));
- } else {
- // Persist StorageGroupSchema
- result = getConsensusManager().write(setStorageGroupReq).getStatus();
+ if (metadataException instanceof IllegalPathException) {
+ result = new TSStatus(TSStatusCode.PATH_ILLEGAL.getStatusCode());
+ } else {
+ result = new
TSStatus(TSStatusCode.STORAGE_GROUP_ALREADY_EXISTS.getStatusCode());
+ }
+ result.setMessage(metadataException.getMessage());
+ return result;
}
+ // Persist StorageGroupSchema
+ result = getConsensusManager().write(setStorageGroupReq).getStatus();
return result;
}
diff --git
a/confignode/src/main/java/org/apache/iotdb/confignode/persistence/ClusterSchemaInfo.java
b/confignode/src/main/java/org/apache/iotdb/confignode/persistence/ClusterSchemaInfo.java
index 26b25e05ab..0236d6e240 100644
---
a/confignode/src/main/java/org/apache/iotdb/confignode/persistence/ClusterSchemaInfo.java
+++
b/confignode/src/main/java/org/apache/iotdb/confignode/persistence/ClusterSchemaInfo.java
@@ -22,7 +22,6 @@ import org.apache.iotdb.common.rpc.thrift.TConsensusGroupId;
import org.apache.iotdb.common.rpc.thrift.TConsensusGroupType;
import org.apache.iotdb.common.rpc.thrift.TRegionReplicaSet;
import org.apache.iotdb.common.rpc.thrift.TSStatus;
-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.snapshot.SnapshotProcessor;
@@ -371,19 +370,13 @@ public class ClusterSchemaInfo implements
SnapshotProcessor {
return result;
}
- /** @return True if StorageGroupInfo contains the specific StorageGroup */
- public boolean containsStorageGroup(String storageName) {
- boolean result;
+ public void checkContainsStorageGroup(String storageName) throws
MetadataException {
storageGroupReadWriteLock.readLock().lock();
try {
- result = mTree.isStorageGroupAlreadySet(new PartialPath(storageName));
- } catch (IllegalPathException e) {
- LOGGER.error("Error StorageGroup name", e);
- return false;
+ mTree.checkStorageGroupAlreadySet(new PartialPath(storageName));
} finally {
storageGroupReadWriteLock.readLock().unlock();
}
- return result;
}
/**
diff --git
a/server/src/main/java/org/apache/iotdb/db/metadata/mtree/MTreeAboveSG.java
b/server/src/main/java/org/apache/iotdb/db/metadata/mtree/MTreeAboveSG.java
index 2d04d6130c..7b31e8fd4a 100644
--- a/server/src/main/java/org/apache/iotdb/db/metadata/mtree/MTreeAboveSG.java
+++ b/server/src/main/java/org/apache/iotdb/db/metadata/mtree/MTreeAboveSG.java
@@ -439,6 +439,30 @@ public class MTreeAboveSG {
return true;
}
+ /**
+ * Check whether the storage group of given path exists. The given path may
be a prefix path of
+ * existing storage group. if exists will throw MetaException.
+ *
+ * @param path a full path or a prefix path
+ */
+ public void checkStorageGroupAlreadySet(PartialPath path) throws
StorageGroupAlreadySetException {
+ String[] nodeNames = path.getNodes();
+ IMNode cur = root;
+ if (!nodeNames[0].equals(root.getName())) {
+ return;
+ }
+ for (int i = 1; i < nodeNames.length; i++) {
+ if (!cur.hasChild(nodeNames[i])) {
+ return;
+ }
+ cur = cur.getChild(nodeNames[i]);
+ if (cur.isStorageGroup()) {
+ throw new StorageGroupAlreadySetException(cur.getFullPath());
+ }
+ }
+ throw new StorageGroupAlreadySetException(path.getFullPath(), true);
+ }
+
/**
* Get all paths of nodes in the given level matching the given path. If
using prefix match, the
* path pattern is used to match prefix path.