diff --git a/integration-test/src/test/java/org/apache/iotdb/db/it/IoTDBSetConfigurationIT.java b/integration-test/src/test/java/org/apache/iotdb/db/it/IoTDBSetConfigurationIT.java index 5fc44c47d8ae..8a792aacc388 100644 --- a/integration-test/src/test/java/org/apache/iotdb/db/it/IoTDBSetConfigurationIT.java +++ b/integration-test/src/test/java/org/apache/iotdb/db/it/IoTDBSetConfigurationIT.java @@ -52,7 +52,6 @@ @RunWith(IoTDBTestRunner.class) @Category({LocalStandaloneIT.class}) public class IoTDBSetConfigurationIT { - @BeforeClass public static void setUp() throws Exception { EnvFactory.getEnv().initClusterEnvironment(); @@ -109,8 +108,6 @@ public void testSetConfiguration() { } catch (Exception e) { Assert.fail(e.getMessage()); } - // set configuration "enable_seq_space_compaction"="false" - // set configuration "enable_unseq_space_compaction"="false" on 0 Assert.assertTrue( EnvFactory.getEnv().getConfigNodeWrapperList().stream() .allMatch( @@ -119,17 +116,14 @@ public void testSetConfiguration() { nodeWrapper, "enable_seq_space_compaction=false", "enable_unseq_space_compaction=false"))); - // set configuration "enable_seq_space_compaction"="false" Assert.assertTrue( EnvFactory.getEnv().getDataNodeWrapperList().stream() .allMatch( nodeWrapper -> - checkConfigFileContains(nodeWrapper, "enable_seq_space_compaction=false"))); - // set configuration "enable_cross_space_compaction"="false" on 1 - assertTrue( - checkConfigFileContains( - EnvFactory.getEnv().getDataNodeWrapperList().get(0), - "enable_cross_space_compaction=false")); + checkConfigFileContains( + nodeWrapper, + "enable_seq_space_compaction=false", + "enable_cross_space_compaction=false"))); } @Test @@ -246,9 +240,6 @@ public void testSetDefaultSGLevel() throws SQLException { assertFalse( checkConfigFileContains( EnvFactory.getEnv().getDataNodeWrapper(0), "default_storage_group_level=-1")); - assertFalse( - checkConfigFileContains( - EnvFactory.getEnv().getConfigNodeWrapper(0), "default_storage_group_level=-1")); assertTrue( checkConfigFileContains( EnvFactory.getEnv().getDataNodeWrapper(0), "default_storage_group_level=3")); diff --git a/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/manager/ConfigManager.java b/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/manager/ConfigManager.java index a0b43ddc7a39..87ceac0acac3 100644 --- a/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/manager/ConfigManager.java +++ b/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/manager/ConfigManager.java @@ -249,7 +249,6 @@ import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicReference; -import java.util.function.Supplier; import java.util.stream.Collectors; import static org.apache.iotdb.commons.conf.IoTDBConstant.ONE_LEVEL_PATH_WILDCARD; @@ -1580,62 +1579,41 @@ public TSStatus setConfiguration(TSetConfigurationReq req) { return tsStatus; } } + if (currentNodeId == req.getNodeId() || req.getNodeId() < 0) { + URL url = ConfigNodeDescriptor.getPropsUrl(CommonConfig.SYSTEM_CONFIG_NAME); + boolean configurationFileFound = (url != null && new File(url.getFile()).exists()); + TrimProperties properties = new TrimProperties(); + properties.putAll(req.getConfigs()); - if (currentNodeId == req.getNodeId()) { - return setConfigLocally(req, null); - } else if (req.getNodeId() < 0) { - // re-config CN in memory -> re-config DN in memory -> re-config DN in file -> re-config CN in - // file - TSStatus finalTsStatus = tsStatus; - return setConfigLocally(req, () -> broadcastSetConfig(finalTsStatus, req)); - } else { - // not for this node, ignore it - return broadcastSetConfig(tsStatus, req); + if (configurationFileFound) { + File file = new File(url.getFile()); + try { + ConfigurationFileUtils.updateConfiguration( + file, + properties, + mergedProps -> { + ConfigNodeDescriptor.getInstance().loadHotModifiedProps(mergedProps); + }); + } catch (Exception e) { + tsStatus = RpcUtils.getStatus(TSStatusCode.EXECUTE_STATEMENT_ERROR, e.getMessage()); + } + } else { + String msg = + "Unable to find the configuration file. Some modifications are made only in memory."; + tsStatus = RpcUtils.getStatus(TSStatusCode.EXECUTE_STATEMENT_ERROR, msg); + LOGGER.warn(msg); + } + if (currentNodeId == req.getNodeId()) { + return tsStatus; + } } - } - - private TSStatus broadcastSetConfig(TSStatus thisNodeResult, TSetConfigurationReq req) { List statusListOfOtherNodes = nodeManager.setConfiguration(req); List statusList = new ArrayList<>(statusListOfOtherNodes.size() + 1); - statusList.add(thisNodeResult); + statusList.add(tsStatus); statusList.addAll(statusListOfOtherNodes); return RpcUtils.squashResponseStatusList(statusList); } - private TSStatus setConfigLocally( - TSetConfigurationReq req, Supplier beforeWriteFileAction) { - // re-config this node only - TSStatus tsStatus; - URL url = ConfigNodeDescriptor.getPropsUrl(CommonConfig.SYSTEM_CONFIG_NAME); - boolean configurationFileFound = (url != null && new File(url.getFile()).exists()); - TrimProperties newProperties = new TrimProperties(); - newProperties.putAll(req.getConfigs()); - - if (configurationFileFound) { - File file = new File(url.getFile()); - try { - tsStatus = - ConfigurationFileUtils.updateConfiguration( - file, - newProperties, - mergedProps -> { - ConfigNodeDescriptor.getInstance().loadHotModifiedProps(mergedProps); - return beforeWriteFileAction != null - ? beforeWriteFileAction.get() - : StatusUtils.OK; - }); - } catch (Exception e) { - tsStatus = RpcUtils.getStatus(TSStatusCode.EXECUTE_STATEMENT_ERROR, e.getMessage()); - } - } else { - String msg = - "Unable to find the configuration file. Some modifications are made only in memory."; - tsStatus = RpcUtils.getStatus(TSStatusCode.EXECUTE_STATEMENT_ERROR, msg); - LOGGER.warn(msg); - } - return tsStatus; - } - @Override public TSStatus startRepairData() { TSStatus status = confirmLeader(); 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 0e1144919e58..cc0b852e3b08 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,7 +41,6 @@ import org.apache.iotdb.commons.service.IService; import org.apache.iotdb.commons.service.ServiceType; import org.apache.iotdb.commons.utils.PathUtils; -import org.apache.iotdb.commons.utils.StatusUtils; import org.apache.iotdb.commons.utils.TestOnly; import org.apache.iotdb.commons.utils.TimePartitionUtils; import org.apache.iotdb.consensus.ConsensusFactory; @@ -687,7 +686,6 @@ public TSStatus setConfiguration(TSetConfigurationReq req) { } catch (Exception e) { throw new IllegalArgumentException(e); } - return StatusUtils.OK; }); } catch (Exception e) { if (e instanceof InterruptedException) { diff --git a/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/conf/ConfigurationFileUtils.java b/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/conf/ConfigurationFileUtils.java index bd7d561f4495..f5702143dd9c 100644 --- a/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/conf/ConfigurationFileUtils.java +++ b/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/conf/ConfigurationFileUtils.java @@ -19,10 +19,6 @@ package org.apache.iotdb.commons.conf; -import org.apache.iotdb.common.rpc.thrift.TSStatus; -import org.apache.iotdb.commons.utils.StatusUtils; -import org.apache.iotdb.rpc.TSStatusCode; - import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -252,7 +248,7 @@ public static List filterInvalidConfigItems(Map configIt return ignoredConfigItems; } - public static TSStatus updateConfiguration( + public static void updateConfiguration( File file, Properties newConfigItems, LoadHotModifiedPropsFunc loadHotModifiedPropertiesFunc) throws IOException, InterruptedException { File lockFile = new File(file.getPath() + lockFileSuffix); @@ -275,10 +271,7 @@ public static TSStatus updateConfiguration( // load hot modified properties if (loadHotModifiedPropertiesFunc != null) { - TSStatus status = loadHotModifiedPropertiesFunc.loadHotModifiedProperties(mergedProps); - if (status.getCode() != TSStatusCode.SUCCESS_STATUS.getStatusCode()) { - return status; - } + loadHotModifiedPropertiesFunc.loadHotModifiedProperties(mergedProps); } // generate new configuration file content in memory @@ -307,7 +300,7 @@ public static TSStatus updateConfiguration( } if (newConfigItems.isEmpty()) { // No configuration needs to be modified - return StatusUtils.OK; + return; } logger.info("Updating configuration file {}", file.getAbsolutePath()); try (BufferedWriter writer = new BufferedWriter(new FileWriter(lockFile))) { @@ -323,7 +316,6 @@ public static TSStatus updateConfiguration( } finally { releaseFileLock(lockFile); } - return StatusUtils.OK; } private static String readConfigLinesWithoutLicense(File file) throws IOException { @@ -366,7 +358,7 @@ private static void releaseFileLock(File file) throws IOException { @FunctionalInterface public interface LoadHotModifiedPropsFunc { - TSStatus loadHotModifiedProperties(TrimProperties properties) + void loadHotModifiedProperties(TrimProperties properties) throws IOException, InterruptedException; } }