Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
# under the License.
#

source "$(dirname "$0")/iotdb-common.sh"
CONFIGNODE_CONF="$(dirname "$0")/../conf"

if [ -f "${CONFIGNODE_CONF}/iotdb-system.properties" ]; then
Expand All @@ -26,6 +27,7 @@ else
cn_internal_port=$(sed '/^cn_internal_port=/!d;s/.*=//' "${CONFIGNODE_CONF}"/iotdb-confignode.properties)
fi

check_config_unique "cn_internal_port" "$cn_internal_port"

echo Check whether the internal_port is used..., port is "$cn_internal_port"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ public Object sendSyncRequestToConfigNodeWithRetry(
return client.stopConfigNode((TConfigNodeLocation) req);
case SET_CONFIGURATION:
return client.setConfiguration((TSetConfigurationReq) req);
case SHOW_CONFIGURATION:
return client.showConfiguration((int) req);
case SUBMIT_TEST_CONNECTION_TASK:
return client.submitTestConnectionTask((TNodeLocations) req);
case TEST_CONNECTION:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
# under the License.
#

source "$(dirname "$0")/iotdb-common.sh"
DATANODE_CONF="`dirname "$0"`/../conf"

if [ -f "${DATANODE_CONF}/iotdb-system.properties" ]; then
Expand All @@ -26,6 +27,8 @@ else
dn_rpc_port=`sed '/^dn_rpc_port=/!d;s/.*=//' ${DATANODE_CONF}/iotdb-datanode.properties`
fi

check_config_unique "dn_rpc_port" "$dn_rpc_port"

force=""

while true; do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,18 @@ checkAllConfigNodeVariables()
fi
}

check_config_unique() {
local key=$1
local values=$2

line_count=$(echo "$values" | wc -l)

if [ "$line_count" -gt 1 ]; then
echo "Error: Duplicate $key entries found"
exit 1
fi
}

checkDataNodePortUsages () {
echo "Checking whether the ports are already occupied..."
if [ "$(id -u)" -ne 0 ]; then
Expand Down Expand Up @@ -183,6 +195,13 @@ checkDataNodePortUsages () {
else
echo "Warning: cannot find iotdb-system.properties or iotdb-datanode.properties, check the default configuration"
fi

check_config_unique "dn_rpc_port" "$dn_rpc_port"
check_config_unique "dn_internal_port" "$dn_internal_port"
check_config_unique "dn_mpp_data_exchange_port" "$dn_mpp_data_exchange_port"
check_config_unique "dn_schema_region_consensus_port" "$dn_schema_region_consensus_port"
check_config_unique "dn_data_region_consensus_port" "$dn_data_region_consensus_port"

dn_rpc_port=${dn_rpc_port:-6667}
dn_internal_port=${dn_internal_port:-10730}
dn_mpp_data_exchange_port=${dn_mpp_data_exchange_port:-10740}
Expand Down Expand Up @@ -271,6 +290,10 @@ checkConfigNodePortUsages () {
else
echo "Cannot find iotdb-system.properties or iotdb-confignode.properties, check the default configuration"
fi

check_config_unique "cn_internal_port" "$cn_internal_port"
check_config_unique "cn_consensus_port" "$cn_consensus_port"

cn_internal_port=${cn_internal_port:-10710}
cn_consensus_port=${cn_consensus_port:-10720}
if type lsof >/dev/null 2>&1; then
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.slf4j.LoggerFactory;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
Expand All @@ -35,11 +36,13 @@
import java.nio.file.StandardCopyOption;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
import java.util.StringJoiner;
import java.util.concurrent.TimeUnit;

public class ConfigurationFileUtils {
Expand All @@ -48,24 +51,27 @@ public class ConfigurationFileUtils {
private static final long maxTimeMillsToAcquireLock = TimeUnit.SECONDS.toMillis(20);
private static final long waitTimeMillsPerCheck = TimeUnit.MILLISECONDS.toMillis(100);
private static Logger logger = LoggerFactory.getLogger(ConfigurationFileUtils.class);
private static String license =
"#\n"
+ "# Licensed to the Apache Software Foundation (ASF) under one\n"
+ "# or more contributor license agreements. See the NOTICE file\n"
+ "# distributed with this work for additional information\n"
+ "# regarding copyright ownership. The ASF licenses this file\n"
+ "# to you under the Apache License, Version 2.0 (the\n"
+ "# \"License\"); you may not use this file except in compliance\n"
+ "# with the License. You may obtain a copy of the License at\n"
+ "#\n"
+ "# http://www.apache.org/licenses/LICENSE-2.0\n"
+ "#\n"
+ "# Unless required by applicable law or agreed to in writing,\n"
+ "# software distributed under the License is distributed on an\n"
+ "# \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY\n"
+ "# KIND, either express or implied. See the License for the\n"
+ "# specific language governing permissions and limitations\n"
+ "# under the License.";
private static final String lineSeparator = "\n";
private static final String license =
new StringJoiner(lineSeparator)
.add("# Licensed to the Apache Software Foundation (ASF) under one")
.add("# or more contributor license agreements. See the NOTICE file")
.add("# distributed with this work for additional information")
.add("# regarding copyright ownership. The ASF licenses this file")
.add("# to you under the Apache License, Version 2.0 (the")
.add("# \"License\"); you may not use this file except in compliance")
.add("# with the License. You may obtain a copy of the License at")
.add("#")
.add("# http://www.apache.org/licenses/LICENSE-2.0")
.add("#")
.add("# Unless required by applicable law or agreed to in writing,")
.add("# software distributed under the License is distributed on an")
.add("# \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY")
.add("# KIND, either express or implied. See the License for the")
.add("# specific language governing permissions and limitations")
.add("# under the License.")
.toString();
;

// This is a temporary implementations
private static final Set<String> ignoreConfigKeys =
Expand Down Expand Up @@ -160,7 +166,7 @@ public static String readConfigurationTemplateFile() throws IOException {
BufferedReader reader = new BufferedReader(isr)) {
String line;
while ((line = reader.readLine()) != null) {
content.append(line).append("\n");
content.append(line).append(lineSeparator);
}
} catch (IOException e) {
logger.warn("Failed to read configuration template", e);
Expand Down Expand Up @@ -194,7 +200,7 @@ public static void updateConfigurationFile(File file, Properties newConfigItems)
StringBuilder contentsOfNewConfigurationFile = new StringBuilder();
for (String currentLine : lines) {
if (currentLine.trim().isEmpty() || currentLine.trim().startsWith("#")) {
contentsOfNewConfigurationFile.append(currentLine).append("\n");
contentsOfNewConfigurationFile.append(currentLine).append(lineSeparator);
continue;
}
int equalsIndex = currentLine.indexOf('=');
Expand All @@ -203,14 +209,14 @@ public static void updateConfigurationFile(File file, Properties newConfigItems)
String key = currentLine.substring(0, equalsIndex).trim();
String value = currentLine.substring(equalsIndex + 1).trim();
if (!newConfigItems.containsKey(key)) {
contentsOfNewConfigurationFile.append(currentLine).append("\n");
contentsOfNewConfigurationFile.append(currentLine).append(lineSeparator);
continue;
}
if (newConfigItems.getProperty(key).equals(value)) {
contentsOfNewConfigurationFile.append(currentLine).append("\n");
contentsOfNewConfigurationFile.append(currentLine).append(lineSeparator);
newConfigItems.remove(key);
} else {
contentsOfNewConfigurationFile.append("#").append(currentLine).append("\n");
contentsOfNewConfigurationFile.append("#").append(currentLine).append(lineSeparator);
}
}
}
Expand All @@ -222,10 +228,13 @@ public static void updateConfigurationFile(File file, Properties newConfigItems)
acquireTargetFileLock(lockFile);
logger.info("Updating configuration file {}", file.getAbsolutePath());
try {
try (FileWriter writer = new FileWriter(lockFile)) {
try (BufferedWriter writer = new BufferedWriter(new FileWriter(lockFile))) {
writer.write(contentsOfNewConfigurationFile.toString());
// add new config items
newConfigItems.store(writer, null);
// Properties.store is not used as Properties.store may generate '\' automatically
writer.write("#" + new Date().toString() + lineSeparator);
for (String key : newConfigItems.stringPropertyNames()) {
writer.write(key + "=" + newConfigItems.get(key) + lineSeparator);
}
writer.flush();
}
Files.move(lockFile.toPath(), file.toPath(), StandardCopyOption.REPLACE_EXISTING);
Expand Down