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

rong 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 058c5f6eab6 [IOTDB-6241] Load: Check System READ_ONLY mode in 
Analysis, Dispatch and Writing Stage (#11488)
058c5f6eab6 is described below

commit 058c5f6eab6b24ce48654492c8661020d473f78a
Author: Itami Sho <[email protected]>
AuthorDate: Wed Nov 8 15:51:04 2023 +0800

    [IOTDB-6241] Load: Check System READ_ONLY mode in Analysis, Dispatch and 
Writing Stage (#11488)
---
 .../iotdb/db/exception/LoadReadOnlyException.java  | 33 ++++++++++++++++++++++
 .../plan/analyze/LoadTsfileAnalyzer.java           | 11 ++++++++
 .../plan/scheduler/load/LoadTsFileScheduler.java   |  9 +++++-
 .../iotdb/db/storageengine/StorageEngine.java      |  7 +++++
 4 files changed, 59 insertions(+), 1 deletion(-)

diff --git 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/exception/LoadReadOnlyException.java
 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/exception/LoadReadOnlyException.java
new file mode 100644
index 00000000000..d2da6e70df4
--- /dev/null
+++ 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/exception/LoadReadOnlyException.java
@@ -0,0 +1,33 @@
+/*
+ * 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.exception;
+
+import org.apache.iotdb.commons.exception.IoTDBException;
+import org.apache.iotdb.rpc.TSStatusCode;
+
+public class LoadReadOnlyException extends IoTDBException {
+
+  public static final String MESSAGE =
+      "Current system mode is read only, does not support load file";
+
+  public LoadReadOnlyException() {
+    super(MESSAGE, TSStatusCode.SYSTEM_READ_ONLY.getStatusCode());
+  }
+}
diff --git 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/analyze/LoadTsfileAnalyzer.java
 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/analyze/LoadTsfileAnalyzer.java
index 4cd2c3c4c6e..db2d6cc5b28 100644
--- 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/analyze/LoadTsfileAnalyzer.java
+++ 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/analyze/LoadTsfileAnalyzer.java
@@ -24,6 +24,7 @@ import org.apache.iotdb.commons.auth.AuthException;
 import org.apache.iotdb.commons.auth.entity.PrivilegeType;
 import org.apache.iotdb.commons.client.IClientManager;
 import org.apache.iotdb.commons.client.exception.ClientManagerException;
+import org.apache.iotdb.commons.conf.CommonDescriptor;
 import org.apache.iotdb.commons.consensus.ConfigRegionId;
 import org.apache.iotdb.commons.exception.IllegalPathException;
 import org.apache.iotdb.commons.exception.IoTDBException;
@@ -36,6 +37,7 @@ import org.apache.iotdb.db.auth.AuthorityChecker;
 import org.apache.iotdb.db.conf.IoTDBConfig;
 import org.apache.iotdb.db.conf.IoTDBDescriptor;
 import org.apache.iotdb.db.exception.LoadFileException;
+import org.apache.iotdb.db.exception.LoadReadOnlyException;
 import org.apache.iotdb.db.exception.VerifyMetadataException;
 import org.apache.iotdb.db.exception.sql.SemanticException;
 import org.apache.iotdb.db.protocol.client.ConfigNodeClient;
@@ -119,6 +121,15 @@ public class LoadTsfileAnalyzer {
   public Analysis analyzeFileByFile() {
     context.setQueryType(QueryType.WRITE);
 
+    // check if the system is read only
+    if (CommonDescriptor.getInstance().getConfig().isReadOnly()) {
+      Analysis analysis = new Analysis();
+      analysis.setFinishQueryAfterAnalyze(true);
+      analysis.setFailStatus(
+          RpcUtils.getStatus(TSStatusCode.SYSTEM_READ_ONLY, 
LoadReadOnlyException.MESSAGE));
+      return analysis;
+    }
+
     // analyze tsfile metadata file by file
     for (int i = 0, tsfileNum = loadTsFileStatement.getTsFiles().size(); i < 
tsfileNum; i++) {
       final File tsFile = loadTsFileStatement.getTsFiles().get(i);
diff --git 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/scheduler/load/LoadTsFileScheduler.java
 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/scheduler/load/LoadTsFileScheduler.java
index d960a86ba23..388d3bd5ec2 100644
--- 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/scheduler/load/LoadTsFileScheduler.java
+++ 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/scheduler/load/LoadTsFileScheduler.java
@@ -28,6 +28,7 @@ import 
org.apache.iotdb.commons.client.sync.SyncDataNodeInternalServiceClient;
 import org.apache.iotdb.commons.conf.CommonDescriptor;
 import org.apache.iotdb.commons.consensus.ConsensusGroupId;
 import org.apache.iotdb.commons.consensus.DataRegionId;
+import org.apache.iotdb.commons.exception.IoTDBException;
 import org.apache.iotdb.commons.partition.DataPartition;
 import org.apache.iotdb.commons.partition.DataPartitionQueryParam;
 import org.apache.iotdb.commons.partition.StorageExecutor;
@@ -36,6 +37,7 @@ import org.apache.iotdb.commons.service.metric.enums.Metric;
 import org.apache.iotdb.commons.service.metric.enums.Tag;
 import org.apache.iotdb.db.conf.IoTDBConfig;
 import org.apache.iotdb.db.conf.IoTDBDescriptor;
+import org.apache.iotdb.db.exception.LoadReadOnlyException;
 import org.apache.iotdb.db.exception.mpp.FragmentInstanceDispatchException;
 import org.apache.iotdb.db.queryengine.common.MPPQueryContext;
 import org.apache.iotdb.db.queryengine.common.PlanFragmentId;
@@ -325,8 +327,13 @@ public class LoadTsFileScheduler implements IScheduler {
     return true;
   }
 
-  private boolean loadLocally(LoadSingleTsFileNode node) {
+  private boolean loadLocally(LoadSingleTsFileNode node) throws IoTDBException 
{
     logger.info("Start load TsFile {} locally.", 
node.getTsFileResource().getTsFile().getPath());
+
+    if (CommonDescriptor.getInstance().getConfig().isReadOnly()) {
+      throw new LoadReadOnlyException();
+    }
+
     try {
       FragmentInstance instance =
           new FragmentInstance(
diff --git 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/StorageEngine.java
 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/StorageEngine.java
index e6870b1f14a..30e5de4c56e 100644
--- 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/StorageEngine.java
+++ 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/StorageEngine.java
@@ -41,6 +41,7 @@ import org.apache.iotdb.db.conf.IoTDBDescriptor;
 import 
org.apache.iotdb.db.consensus.statemachine.dataregion.DataExecutionVisitor;
 import org.apache.iotdb.db.exception.DataRegionException;
 import org.apache.iotdb.db.exception.LoadFileException;
+import org.apache.iotdb.db.exception.LoadReadOnlyException;
 import org.apache.iotdb.db.exception.StorageEngineException;
 import org.apache.iotdb.db.exception.TsFileProcessorException;
 import org.apache.iotdb.db.exception.WriteProcessRejectException;
@@ -767,6 +768,12 @@ public class StorageEngine implements IService {
       DataRegionId dataRegionId, LoadTsFilePieceNode pieceNode, String uuid) {
     TSStatus status = new TSStatus();
 
+    if (CommonDescriptor.getInstance().getConfig().isReadOnly()) {
+      status.setCode(TSStatusCode.SYSTEM_READ_ONLY.getStatusCode());
+      status.setMessage(LoadReadOnlyException.MESSAGE);
+      return status;
+    }
+
     try {
       getLoadTsFileManager().writeToDataRegion(getDataRegion(dataRegionId), 
pieceNode, uuid);
     } catch (IOException e) {

Reply via email to