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 @@ -120,9 +120,6 @@ public class ClusterConstant {
public static final String COMMON_PROPERTIES_FILE = "iotdb-common.properties";
public static final String IOTDB_SYSTEM_PROPERTIES_FILE = "iotdb-system.properties";

public static final String SYSTEM_PROPERTIES_FILE = "system.properties";
public static final String CONFIG_NODE_SYSTEM_PROPERTIES_FILE = "confignode-system.properties";

// Properties' keys
// Common
public static final String CONFIG_NODE_CONSENSUS_PROTOCOL_CLASS =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
package org.apache.iotdb.it.env.cluster.node;

import org.apache.iotdb.commons.conf.IoTDBConstant;
import org.apache.iotdb.confignode.conf.ConfigNodeConstant;
import org.apache.iotdb.it.env.cluster.EnvUtils;
import org.apache.iotdb.it.env.cluster.config.MppBaseConfig;
import org.apache.iotdb.it.env.cluster.config.MppJVMConfig;
Expand All @@ -37,7 +38,6 @@
import static org.apache.iotdb.it.env.cluster.ClusterConstant.CONFIG_NODE_INIT_HEAP_SIZE;
import static org.apache.iotdb.it.env.cluster.ClusterConstant.CONFIG_NODE_MAX_DIRECT_MEMORY_SIZE;
import static org.apache.iotdb.it.env.cluster.ClusterConstant.CONFIG_NODE_MAX_HEAP_SIZE;
import static org.apache.iotdb.it.env.cluster.ClusterConstant.CONFIG_NODE_SYSTEM_PROPERTIES_FILE;
import static org.apache.iotdb.it.env.cluster.ClusterConstant.DATA_REGION_CONSENSUS_PROTOCOL_CLASS;
import static org.apache.iotdb.it.env.cluster.ClusterConstant.DATA_REPLICATION_FACTOR;
import static org.apache.iotdb.it.env.cluster.ClusterConstant.DEFAULT_CONFIG_NODE_COMMON_PROPERTIES;
Expand Down Expand Up @@ -105,7 +105,7 @@ protected String getDefaultCommonConfigPath() {

@Override
public String getSystemPropertiesPath() {
return workDirFilePath("data/confignode/system", CONFIG_NODE_SYSTEM_PROPERTIES_FILE);
return workDirFilePath("data/confignode/system", ConfigNodeConstant.SYSTEM_FILE_NAME);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
package org.apache.iotdb.it.env.cluster.node;

import org.apache.iotdb.commons.conf.IoTDBConstant;
import org.apache.iotdb.db.conf.IoTDBStartCheck;
import org.apache.iotdb.it.env.cluster.EnvUtils;
import org.apache.iotdb.it.env.cluster.config.MppBaseConfig;
import org.apache.iotdb.it.env.cluster.config.MppJVMConfig;
Expand Down Expand Up @@ -61,7 +62,6 @@
import static org.apache.iotdb.it.env.cluster.ClusterConstant.REST_SERVICE_PORT;
import static org.apache.iotdb.it.env.cluster.ClusterConstant.SCHEMA_REGION_CONSENSUS_PROTOCOL_CLASS;
import static org.apache.iotdb.it.env.cluster.ClusterConstant.SCHEMA_REPLICATION_FACTOR;
import static org.apache.iotdb.it.env.cluster.ClusterConstant.SYSTEM_PROPERTIES_FILE;
import static org.apache.iotdb.it.env.cluster.ClusterConstant.TARGET;
import static org.apache.iotdb.it.env.cluster.ClusterConstant.USER_DIR;

Expand Down Expand Up @@ -139,7 +139,7 @@ protected String getDefaultCommonConfigPath() {

@Override
public String getSystemPropertiesPath() {
return workDirFilePath("data/datanode/system/schema", SYSTEM_PROPERTIES_FILE);
return workDirFilePath("data/datanode/system/schema", IoTDBStartCheck.PROPERTIES_FILE_NAME);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public void tearDown() throws Exception {
}

@Test
public void RecoverTest1() {
public void recoverTest1() {
// stop cluster
EnvFactory.getEnv().shutdownAllDataNodes();
logger.info("All DataNodes are shut down");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* 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.confignode.conf;

import org.apache.iotdb.commons.file.SystemPropertiesHandler;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.File;

public class ConfigNodeSystemPropertiesHandler extends SystemPropertiesHandler {
private static final Logger LOGGER =
LoggerFactory.getLogger(ConfigNodeSystemPropertiesHandler.class);

private static ConfigNodeSystemPropertiesHandler INSTANCE;

private ConfigNodeSystemPropertiesHandler(String filePath) {
super(filePath);
}

public static synchronized SystemPropertiesHandler getInstance() {
if (INSTANCE == null) {
INSTANCE =
new ConfigNodeSystemPropertiesHandler(
ConfigNodeDescriptor.getInstance().getConf().getSystemDir()
+ File.separator
+ ConfigNodeConstant.SYSTEM_FILE_NAME);
INSTANCE.recover();
}
return INSTANCE;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,14 @@
import org.apache.iotdb.commons.conf.CommonDescriptor;
import org.apache.iotdb.commons.conf.IoTDBConstant;
import org.apache.iotdb.commons.exception.BadNodeUrlException;
import org.apache.iotdb.commons.file.SystemPropertiesHandler;
import org.apache.iotdb.commons.utils.NodeUrlUtils;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
Expand All @@ -48,11 +44,8 @@ public class SystemPropertiesUtils {

private static final Logger LOGGER = LoggerFactory.getLogger(SystemPropertiesUtils.class);

private static File systemPropertiesFile =
new File(
ConfigNodeDescriptor.getInstance().getConf().getSystemDir()
+ File.separator
+ ConfigNodeConstant.SYSTEM_FILE_NAME);
private static SystemPropertiesHandler systemPropertiesHandler =
ConfigNodeSystemPropertiesHandler.getInstance();

private static final ConfigNodeConfig conf = ConfigNodeDescriptor.getInstance().getConf();
private static final CommonConfig COMMON_CONFIG = CommonDescriptor.getInstance().getConfig();
Expand All @@ -74,11 +67,10 @@ private SystemPropertiesUtils() {

// TODO: This needs removal of statics ...
public static void reinitializeStatics() {
systemPropertiesFile =
new File(
ConfigNodeDescriptor.getInstance().getConf().getSystemDir()
+ File.separator
+ ConfigNodeConstant.SYSTEM_FILE_NAME);
systemPropertiesHandler.resetFilePath(
ConfigNodeDescriptor.getInstance().getConf().getSystemDir()
+ File.separator
+ ConfigNodeConstant.SYSTEM_FILE_NAME);
}

/**
Expand All @@ -87,7 +79,7 @@ public static void reinitializeStatics() {
* @return True if confignode-system.properties file exist.
*/
public static boolean isRestarted() {
return systemPropertiesFile.exists();
return !systemPropertiesHandler.isFirstStart();
}

/**
Expand All @@ -97,7 +89,7 @@ public static boolean isRestarted() {
* @throws IOException When read the confignode-system.properties file failed
*/
public static void checkSystemProperties() throws IOException {
Properties systemProperties = getSystemProperties();
Properties systemProperties = systemPropertiesHandler.read();
boolean needReWrite = false;
final String format =
"[SystemProperties] The parameter \"{}\" can't be modified after first startup."
Expand Down Expand Up @@ -234,11 +226,6 @@ public static void checkSystemProperties() throws IOException {
COMMON_CONFIG.setTimePartitionInterval(timePartitionInterval);
}
}

if (needReWrite) {
// Re-write special parameters if necessary
storeSystemParameters();
}
}

/**
Expand All @@ -251,7 +238,7 @@ public static void checkSystemProperties() throws IOException {
*/
public static List<TConfigNodeLocation> loadConfigNodeList()
throws IOException, BadNodeUrlException {
Properties systemProperties = getSystemProperties();
Properties systemProperties = systemPropertiesHandler.read();
String addresses = systemProperties.getProperty("config_node_list", null);

if (addresses != null && !addresses.isEmpty()) {
Expand All @@ -265,10 +252,10 @@ public static List<TConfigNodeLocation> loadConfigNodeList()
* The system parameters can't be changed after the ConfigNode first started. Therefore, store
* them in confignode-system.properties during the first startup.
*
* @throws IOException getSystemProperties()
* @throws IOException systemPropertiesHandler.read()
*/
public static void storeSystemParameters() throws IOException {
Properties systemProperties = getSystemProperties();
Properties systemProperties = systemPropertiesHandler.read();

systemProperties.setProperty("iotdb_version", IoTDBConstant.VERSION);
systemProperties.setProperty("commit_id", IoTDBConstant.BUILD_INFO);
Expand Down Expand Up @@ -311,7 +298,7 @@ public static void storeSystemParameters() throws IOException {
systemProperties.setProperty(
"tag_attribute_total_size", String.valueOf(COMMON_CONFIG.getTagAttributeTotalSize()));

storeSystemProperties(systemProperties);
systemPropertiesHandler.overwrite(systemProperties);
}

/**
Expand All @@ -321,7 +308,7 @@ public static void storeSystemParameters() throws IOException {
* @throws IOException When store confignode-system.properties file failed
*/
public static void storeConfigNodeList(List<TConfigNodeLocation> configNodes) throws IOException {
if (!systemPropertiesFile.exists()) {
if (!systemPropertiesHandler.fileExist()) {
// Avoid creating confignode-system.properties files during
// synchronizing the ApplyConfigNode logs from the ConsensusLayer.
// 1. For the Non-Seed-ConfigNode, We don't need to create confignode-system.properties file
Expand All @@ -330,12 +317,8 @@ public static void storeConfigNodeList(List<TConfigNodeLocation> configNodes) th
// in which case the latest config_node_list will be updated.
return;
}

Properties systemProperties = getSystemProperties();
systemProperties.setProperty(
systemPropertiesHandler.put(
"config_node_list", NodeUrlUtils.convertTConfigNodeUrls(configNodes));

storeSystemProperties(systemProperties);
}

/**
Expand All @@ -346,7 +329,7 @@ public static void storeConfigNodeList(List<TConfigNodeLocation> configNodes) th
* @throws IOException When load confignode-system.properties file failed
*/
public static String loadClusterNameWhenRestarted() throws IOException {
Properties systemProperties = getSystemProperties();
Properties systemProperties = systemPropertiesHandler.read();
String clusterName = systemProperties.getProperty(CLUSTER_NAME, null);
if (clusterName == null) {
LOGGER.warn(
Expand All @@ -366,7 +349,7 @@ public static String loadClusterNameWhenRestarted() throws IOException {
* @throws IOException When load confignode-system.properties file failed
*/
public static int loadConfigNodeIdWhenRestarted() throws IOException {
Properties systemProperties = getSystemProperties();
Properties systemProperties = systemPropertiesHandler.read();
try {
return Integer.parseInt(systemProperties.getProperty("config_node_id", null));
} catch (NumberFormatException e) {
Expand All @@ -387,7 +370,7 @@ public static int loadConfigNodeIdWhenRestarted() throws IOException {
*/
public static boolean isSeedConfigNode() {
try {
Properties systemProperties = getSystemProperties();
Properties systemProperties = systemPropertiesHandler.read();
boolean isSeedConfigNode =
Boolean.parseBoolean(systemProperties.getProperty("is_seed_config_node", null));
if (isSeedConfigNode) {
Expand All @@ -399,37 +382,4 @@ public static boolean isSeedConfigNode() {
return false;
}
}

private static synchronized Properties getSystemProperties() throws IOException {
// Create confignode-system.properties file if necessary
if (!systemPropertiesFile.exists()) {
if (systemPropertiesFile.createNewFile()) {
LOGGER.info(
"System properties file {} for ConfigNode is created.",
systemPropertiesFile.getAbsolutePath());
} else {
LOGGER.error(
"Can't create the system properties file {} for ConfigNode. "
+ "IoTDB-ConfigNode is shutdown.",
systemPropertiesFile.getAbsolutePath());
throw new IOException("Can't create system properties file");
}
}

Properties systemProperties = new Properties();
try (FileInputStream inputStream = new FileInputStream(systemPropertiesFile)) {
systemProperties.load(new InputStreamReader(inputStream, StandardCharsets.UTF_8));
}
return systemProperties;
}

private static synchronized void storeSystemProperties(Properties systemProperties)
throws IOException {
try (FileOutputStream fileOutputStream = new FileOutputStream(systemPropertiesFile)) {
systemProperties.store(
new OutputStreamWriter(fileOutputStream, StandardCharsets.UTF_8),
" THIS FILE IS AUTOMATICALLY GENERATED. PLEASE DO NOT MODIFY THIS FILE !!!");
fileOutputStream.getFD().sync();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@
import java.io.IOException;
import java.util.List;
import java.util.Map;
import java.util.Optional;

public class DataNodeRegisterResp implements DataSet {

private TSStatus status;
private List<TConfigNodeLocation> configNodeList;
private Integer dataNodeId;

private TRuntimeConfiguration runtimeConfiguration;

public DataNodeRegisterResp() {
Expand Down Expand Up @@ -85,8 +85,8 @@ public TDataNodeRegisterResp convertToRpcDataNodeRegisterResp() {
resp.setConfigNodeList(configNodeList);

if (status.getCode() == TSStatusCode.SUCCESS_STATUS.getStatusCode()) {
resp.setDataNodeId(dataNodeId);
resp.setRuntimeConfiguration(runtimeConfiguration);
Optional.ofNullable(dataNodeId).ifPresent(resp::setDataNodeId);
Optional.ofNullable(runtimeConfiguration).ifPresent(resp::setRuntimeConfiguration);
}

return resp;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ public DataSet registerDataNode(TDataNodeRegisterReq req) {
req.getClusterName(),
req.getDataNodeConfiguration().getLocation(),
this);
if (status.getCode() == TSStatusCode.SUCCESS_STATUS.getStatusCode()) {
if (!req.isPreCheck() && status.getCode() == TSStatusCode.SUCCESS_STATUS.getStatusCode()) {
return nodeManager.registerDataNode(req);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.apache.iotdb.common.rpc.thrift.TSStatus;
import org.apache.iotdb.commons.cluster.NodeType;
import org.apache.iotdb.commons.conf.CommonConfig;
import org.apache.iotdb.commons.conf.CommonDescriptor;
import org.apache.iotdb.confignode.conf.ConfigNodeDescriptor;
import org.apache.iotdb.confignode.manager.ConfigManager;
import org.apache.iotdb.rpc.TSStatusCode;
Expand Down Expand Up @@ -112,10 +113,23 @@ public static TSStatus confirmNodeRegistration(
nodeType.getNodeType(),
CommonConfig.SYSTEM_CONFIG_NAME));
return status;
} else {
/* Accept registration if all TEndPoints aren't conflict */
return ACCEPT_NODE_REGISTRATION;
}

// Check cluster id
final String clusterId =
configManager
.getClusterManager()
.getClusterIdWithRetry(
CommonDescriptor.getInstance().getConfig().getConnectionTimeoutInMS() / 2);
if (clusterId == null) {
status
.setCode(TSStatusCode.GET_CLUSTER_ID_ERROR.getStatusCode())
.setMessage("clusterId has not generated, please try again later");
return status;
}

/* Accept registration if all TEndPoints aren't conflict */
return ACCEPT_NODE_REGISTRATION;
}

public static TSStatus confirmNodeRestart(
Expand Down
Loading