This is an automated email from the ASF dual-hosted git repository.

jackietien 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 d171a53053e Make TsTable always store uppercase "INF" && Fixed the NPE 
bug when TTL is set to "INF" && Distinguish database model in alter database
d171a53053e is described below

commit d171a53053e9b0a7a919785eb74c3fd082414017
Author: Caideyipi <[email protected]>
AuthorDate: Fri Nov 22 17:11:03 2024 +0800

    Make TsTable always store uppercase "INF" && Fixed the NPE bug when TTL is 
set to "INF" && Distinguish database model in alter database
---
 .../request/write/database/DatabaseSchemaPlan.java          | 12 ++++++------
 .../confignode/manager/schema/ClusterSchemaManager.java     |  7 ++++---
 .../confignode/persistence/schema/ClusterSchemaInfo.java    | 13 +++++++++++++
 .../service/thrift/ConfigNodeRPCServiceProcessor.java       |  6 +++---
 .../plan/execution/config/TableConfigTaskVisitor.java       |  2 +-
 .../config/executor/ClusterConfigTaskExecutor.java          | 13 +++++++------
 6 files changed, 34 insertions(+), 19 deletions(-)

diff --git 
a/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/consensus/request/write/database/DatabaseSchemaPlan.java
 
b/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/consensus/request/write/database/DatabaseSchemaPlan.java
index 96910a8e925..b8015762150 100644
--- 
a/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/consensus/request/write/database/DatabaseSchemaPlan.java
+++ 
b/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/consensus/request/write/database/DatabaseSchemaPlan.java
@@ -33,12 +33,12 @@ public class DatabaseSchemaPlan extends ConfigPhysicalPlan {
 
   private TDatabaseSchema schema;
 
-  public DatabaseSchemaPlan(ConfigPhysicalPlanType planType) {
+  public DatabaseSchemaPlan(final ConfigPhysicalPlanType planType) {
     super(planType);
     this.schema = new TDatabaseSchema();
   }
 
-  public DatabaseSchemaPlan(ConfigPhysicalPlanType planType, TDatabaseSchema 
schema) {
+  public DatabaseSchemaPlan(final ConfigPhysicalPlanType planType, final 
TDatabaseSchema schema) {
     this(planType);
     this.schema = schema;
   }
@@ -48,25 +48,25 @@ public class DatabaseSchemaPlan extends ConfigPhysicalPlan {
   }
 
   @Override
-  protected void serializeImpl(DataOutputStream stream) throws IOException {
+  protected void serializeImpl(final DataOutputStream stream) throws 
IOException {
     stream.writeShort(getType().getPlanType());
     ThriftConfigNodeSerDeUtils.serializeTDatabaseSchema(schema, stream);
   }
 
   @Override
-  protected void deserializeImpl(ByteBuffer buffer) throws IOException {
+  protected void deserializeImpl(final ByteBuffer buffer) throws IOException {
     schema = ThriftConfigNodeSerDeUtils.deserializeTDatabaseSchema(buffer);
   }
 
   @Override
-  public boolean equals(Object o) {
+  public boolean equals(final Object o) {
     if (this == o) {
       return true;
     }
     if (o == null || getClass() != o.getClass()) {
       return false;
     }
-    DatabaseSchemaPlan that = (DatabaseSchemaPlan) o;
+    final DatabaseSchemaPlan that = (DatabaseSchemaPlan) o;
     return schema.equals(that.schema);
   }
 
diff --git 
a/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/manager/schema/ClusterSchemaManager.java
 
b/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/manager/schema/ClusterSchemaManager.java
index d282bbcfd5a..afa3135df65 100644
--- 
a/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/manager/schema/ClusterSchemaManager.java
+++ 
b/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/manager/schema/ClusterSchemaManager.java
@@ -204,7 +204,8 @@ public class ClusterSchemaManager {
   }
 
   /** Alter Database */
-  public TSStatus alterDatabase(DatabaseSchemaPlan databaseSchemaPlan, boolean 
isGeneratedByPipe) {
+  public TSStatus alterDatabase(
+      final DatabaseSchemaPlan databaseSchemaPlan, final boolean 
isGeneratedByPipe) {
     TSStatus result;
     TDatabaseSchema databaseSchema = databaseSchemaPlan.getSchema();
 
@@ -232,7 +233,7 @@ public class ClusterSchemaManager {
     }
     if (databaseSchema.isSetMinDataRegionGroupNum()) {
       // Validate alter DataRegionGroupNum
-      int minDataRegionGroupNum =
+      final int minDataRegionGroupNum =
           getMinRegionGroupNum(databaseSchema.getName(), 
TConsensusGroupType.DataRegion);
       if (databaseSchema.getMinDataRegionGroupNum() <= minDataRegionGroupNum) {
         result = new 
TSStatus(TSStatusCode.DATABASE_CONFIG_ERROR.getStatusCode());
@@ -259,7 +260,7 @@ public class ClusterSchemaManager {
           databaseSchemaPlan.getSchema().getDataReplicationFactor(),
           databaseSchemaPlan.getSchema().getSchemaReplicationFactor());
       return result;
-    } catch (ConsensusException e) {
+    } catch (final ConsensusException e) {
       LOGGER.warn(CONSENSUS_WRITE_ERROR, e);
       result = new 
TSStatus(TSStatusCode.EXECUTE_STATEMENT_ERROR.getStatusCode());
       result.setMessage(e.getMessage());
diff --git 
a/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/persistence/schema/ClusterSchemaInfo.java
 
b/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/persistence/schema/ClusterSchemaInfo.java
index c78feaef2bc..3c43ceb6a7d 100644
--- 
a/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/persistence/schema/ClusterSchemaInfo.java
+++ 
b/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/persistence/schema/ClusterSchemaInfo.java
@@ -79,6 +79,7 @@ import 
org.apache.iotdb.confignode.consensus.response.template.TemplateSetInfoRe
 import org.apache.iotdb.confignode.exception.DatabaseNotExistsException;
 import org.apache.iotdb.confignode.rpc.thrift.TDatabaseSchema;
 import org.apache.iotdb.confignode.rpc.thrift.TTableInfo;
+import org.apache.iotdb.db.exception.metadata.DatabaseModelException;
 import org.apache.iotdb.db.exception.metadata.SchemaQuotaExceededException;
 import org.apache.iotdb.db.schemaengine.template.Template;
 import org.apache.iotdb.db.schemaengine.template.TemplateInternalRPCUtil;
@@ -200,6 +201,18 @@ public class ClusterSchemaInfo implements 
SnapshotProcessor {
 
       final TDatabaseSchema currentSchema =
           
mTree.getDatabaseNodeByDatabasePath(partialPathName).getAsMNode().getDatabaseSchema();
+
+      // Model conflict detection
+      if (alterSchema.isIsTableModel() && !currentSchema.isIsTableModel()) {
+        final DatabaseModelException exception =
+            new DatabaseModelException(currentSchema.getName(), false);
+        return RpcUtils.getStatus(exception.getErrorCode(), 
exception.getMessage());
+      } else if (!alterSchema.isIsTableModel() && 
currentSchema.isIsTableModel()) {
+        final DatabaseModelException exception =
+            new DatabaseModelException(currentSchema.getName(), true);
+        return RpcUtils.getStatus(exception.getErrorCode(), 
exception.getMessage());
+      }
+
       // TODO: Support alter other fields
       if (alterSchema.isSetMinSchemaRegionGroupNum()) {
         
currentSchema.setMinSchemaRegionGroupNum(alterSchema.getMinSchemaRegionGroupNum());
diff --git 
a/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/service/thrift/ConfigNodeRPCServiceProcessor.java
 
b/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/service/thrift/ConfigNodeRPCServiceProcessor.java
index 95997bff47d..75ffcc413c1 100644
--- 
a/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/service/thrift/ConfigNodeRPCServiceProcessor.java
+++ 
b/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/service/thrift/ConfigNodeRPCServiceProcessor.java
@@ -476,7 +476,7 @@ public class ConfigNodeRPCServiceProcessor implements 
IConfigNodeRPCService.Ifac
   }
 
   @Override
-  public TSStatus alterDatabase(TDatabaseSchema databaseSchema) {
+  public TSStatus alterDatabase(final TDatabaseSchema databaseSchema) {
     TSStatus errorResp = null;
 
     // TODO: Support alter the following fields
@@ -517,9 +517,9 @@ public class ConfigNodeRPCServiceProcessor implements 
IConfigNodeRPCService.Ifac
       return errorResp;
     }
 
-    DatabaseSchemaPlan alterPlan =
+    final DatabaseSchemaPlan alterPlan =
         new DatabaseSchemaPlan(ConfigPhysicalPlanType.AlterDatabase, 
databaseSchema);
-    TSStatus resp = configManager.alterDatabase(alterPlan);
+    final TSStatus resp = configManager.alterDatabase(alterPlan);
 
     // Print log to record the ConfigNode that performs the set 
SetDatabaseRequest
     LOGGER.info("Execute AlterDatabase: {} with result: {}", databaseSchema, 
resp);
diff --git 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/execution/config/TableConfigTaskVisitor.java
 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/execution/config/TableConfigTaskVisitor.java
index e91984f17da..fb53a804db8 100644
--- 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/execution/config/TableConfigTaskVisitor.java
+++ 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/execution/config/TableConfigTaskVisitor.java
@@ -464,7 +464,7 @@ public class TableConfigTaskVisitor extends 
AstVisitor<IConfigTask, MPPQueryCont
               throw new SemanticException(
                   "ttl value must be 'INF' or a long literal, but now is: " + 
value);
             }
-            map.put(key, strValue.get());
+            map.put(key, strValue.get().toUpperCase(Locale.ENGLISH));
             continue;
           }
           // TODO: support validation for other properties
diff --git 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/execution/config/executor/ClusterConfigTaskExecutor.java
 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/execution/config/executor/ClusterConfigTaskExecutor.java
index 3ff44e25afb..d8a0cb73406 100644
--- 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/execution/config/executor/ClusterConfigTaskExecutor.java
+++ 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/execution/config/executor/ClusterConfigTaskExecutor.java
@@ -389,15 +389,16 @@ public class ClusterConfigTaskExecutor implements 
IConfigTaskExecutor {
 
   @Override
   public SettableFuture<ConfigTaskResult> alterDatabase(
-      DatabaseSchemaStatement databaseSchemaStatement) {
-    SettableFuture<ConfigTaskResult> future = SettableFuture.create();
+      final DatabaseSchemaStatement databaseSchemaStatement) {
+    final SettableFuture<ConfigTaskResult> future = SettableFuture.create();
     // Construct request using statement
-    TDatabaseSchema databaseSchema =
+    final TDatabaseSchema databaseSchema =
         DatabaseSchemaTask.constructDatabaseSchema(databaseSchemaStatement);
-    try (ConfigNodeClient configNodeClient =
+    databaseSchema.setIsTableModel(false);
+    try (final ConfigNodeClient configNodeClient =
         
CONFIG_NODE_CLIENT_MANAGER.borrowClient(ConfigNodeInfo.CONFIG_REGION_ID)) {
       // Send request to some API server
-      TSStatus tsStatus = configNodeClient.alterDatabase(databaseSchema);
+      final TSStatus tsStatus = configNodeClient.alterDatabase(databaseSchema);
       // Get response or throw exception
       if (TSStatusCode.SUCCESS_STATUS.getStatusCode() != tsStatus.getCode()) {
         if (databaseSchemaStatement.getEnablePrintExceptionLog()) {
@@ -410,7 +411,7 @@ public class ClusterConfigTaskExecutor implements 
IConfigTaskExecutor {
       } else {
         future.set(new ConfigTaskResult(TSStatusCode.SUCCESS_STATUS));
       }
-    } catch (ClientManagerException | TException e) {
+    } catch (final ClientManagerException | TException e) {
       future.setException(e);
     }
     return future;

Reply via email to