Adjust data directories (#342)

This commit is contained in:
March250 2018-04-09 11:24:19 +08:00 committed by XuYi
parent 2e127419b8
commit a8f855167d
4 changed files with 152 additions and 32 deletions

View File

@ -3,6 +3,7 @@ echo ````````````````````````
echo Starting IoTDB
echo ````````````````````````
if "%OS%" == "Windows_NT" setlocal
pushd %~dp0..
@ -31,7 +32,7 @@ set JAVA_OPTS=-ea^
@REM ***** CLASSPATH library setting *****
@REM Ensure that any user defined CLASSPATH variables are not used on startup
set CLASSPATH="IOTDB_HOME%\lib"
set CLASSPATH="%IOTDB_HOME%\lib"
REM For each jar in the IOTDB_HOME lib directory call append to build the CLASSPATH variable.
for %%i in ("%IOTDB_HOME%\lib\*.jar") do call :append "%%i"
@ -50,7 +51,6 @@ rem echo CLASSPATH: %CLASSPATH%
"%JAVA_HOME%\bin\java" %JAVA_OPTS% %IOTDB_HEAP_OPTS% -cp %CLASSPATH% %IOTDB_DERBY_OPTS% %IOTDB_JMX_OPTS% %MAIN_CLASS%
goto finally
:err
echo JAVA_HOME environment variable must be set!
pause
@ -61,4 +61,4 @@ pause
pause
ENDLOCAL
ENDLOCAL

View File

@ -23,11 +23,41 @@ flush_wal_period_in_ms=10
# database features configuration
# data dir
# If this value starts with "/", use absolute path. Otherwise, it will save the data in the relative path directory under the IoTDB folder
# If this property is unset, system will save the data in the default relative path directory under the IoTDB folder(i.e., %IOTDB_HOME%).
# If it is absolute, system will save the data in exact location it points to.
# If it is relative, system will save the data in the relative path directory it indicates under the IoTDB folder.
# Note: If data_dir is assigned an empty string(i.e.,zero-length), it will be handled as a relative path.
# For windows platform
# data_dir=D:\\iotdb\\data
# If its prefix is a drive specifier followed by "\\", or if its prefix is "\\\\", then the path is absolute. Otherwise, it is relative.
# data_dir=D:\\iotdb\\data\\data
# For Linux platform
# data_dir=/path/iotdb/data
# If its prefix is "/", then the path is absolute. Otherwise, it is relative.
# data_dir=/path/iotdb/data/data
# system dir
# If this property is unset, system will save the data in the default relative path directory under the IoTDB folder(i.e., %IOTDB_HOME%).
# If it is absolute, system will save the data in exact location it points to.
# If it is relative, system will save the data in the relative path directory it indicates under the IoTDB folder.
# Note: If sys_dir is assigned an empty string(i.e.,zero-length), it will be handled as a relative path.
# For windows platform
# If its prefix is a drive specifier followed by "\\", or if its prefix is "\\\\", then the path is absolute. Otherwise, it is relative.
# sys_dir=D:\\iotdb\\data\\system
# For Linux platform
# If its prefix is "/", then the path is absolute. Otherwise, it is relative.
# sys_dir=/path/iotdb/data/system
# wal dir
# If this property is unset, system will save the data in the default relative path directory under the IoTDB folder(i.e., %IOTDB_HOME%).
# If it is absolute, system will save the data in the exact location it points to.
# If it is relative, system will save the data in the relative path directory it indicates under the IoTDB folder.
# Note: If wal_dir is assigned an empty string(i.e.,zero-length), it will be handled as a relative path.
# For windows platform
# If its prefix is a drive specifier followed by "\\", or if its prefix is "\\\\", then the path is absolute. Otherwise, it is relative.
# wal_dir=D:\\iotdb\\data
# For Linux platform
# If its prefix is "/", then the path is absolute. Otherwise, it is relative.
# wal_dir=/path/iotdb/data
# The maximum concurrent thread number for merging overflow
# Increase this value, it will increase IO and CPU consumption

View File

@ -1,13 +1,16 @@
package cn.edu.tsinghua.iotdb.conf;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import org.joda.time.DateTimeZone;
public class TsfileDBConfig {
public static final String CONFIG_NAME = "iotdb-engine.properties";
public static final String default_data_dir = "data";
public static final String default_sys_dir = "system";
/**
* Port which JDBC server listens to
*/
@ -34,6 +37,14 @@ public class TsfileDBConfig {
* Data directory
*/
public String dataDir = null;
/**
* System directory
*/
public String sysDir = null;
/**
* Wal directory
*/
public String walDir = null;
/**
* Data directory of Overflow data
*/
@ -47,22 +58,22 @@ public class TsfileDBConfig {
/**
* Data directory of bufferWrite data
*/
public String bufferWriteDir = "delta";
public String bufferWriteDir = "info";
/**
* Data directory of metadata data
*/
public String metadataDir = "metadata";
public String metadataDir = "settled";
/**
* Data directory of derby data
*/
public String derbyHome = "derby";
public String derbyHome = "schema";
/**
* Data directory of Write ahead log folder.
*/
public String walFolder = "wals";
public String walFolder = "wal";
/**
* Data directory for index files (KV-match indexes)
@ -219,28 +230,105 @@ public class TsfileDBConfig {
public TsfileDBConfig() {}
public void updateDataPath() {
if(dataDir == null){
dataDir = System.getProperty(TsFileDBConstant.IOTDB_HOME, null);
if(dataDir == null){
dataDir = "data";
} else {
if (dataDir.length() > 0 && !dataDir.endsWith(File.separator)) {
dataDir = dataDir + File.separatorChar + "data";
}
}
}
// filenode dir
public void updatePath() {
preUpdatePath();
// update the paths of subdirectories in the dataDir
if (dataDir.length() > 0 && !dataDir.endsWith(File.separator)) {
dataDir = dataDir + File.separatorChar;
}
fileNodeDir = dataDir + fileNodeDir;
bufferWriteDir = dataDir + bufferWriteDir;
overflowDataDir = dataDir + overflowDataDir;
metadataDir = dataDir + metadataDir;
derbyHome = dataDir + derbyHome;
walFolder = dataDir + walFolder;
// update the paths of subdirectories in the sysDir
if (sysDir.length() > 0 && !sysDir.endsWith(File.separator)) {
sysDir = sysDir + File.separatorChar;
}
fileNodeDir = sysDir + fileNodeDir;
metadataDir = sysDir + metadataDir;
// update the paths of subdirectories in the walDir
if (walDir.length() > 0 && !walDir.endsWith(File.separator)) {
walDir = walDir + File.separatorChar;
}
walFolder = walDir + walFolder;
derbyHome = sysDir + derbyHome;
indexFileDir = dataDir + indexFileDir;
readTmpFileDir = dataDir + readTmpFileDir;
}
/*
First, if dataDir is null, dataDir will be assigned the default value(i.e.,"data"+File.separatorChar+"data".
Then, if dataDir is absolute, leave dataDir as it is. If dataDir is relative,
dataDir will be converted to the complete version using non-empty %IOTDB_HOME%.
e.g. for windows platform,
| IOTDB_HOME | dataDir before | dataDir after |
|-----------------|--------------------|---------------------------|
| D:\\iotdb\iotdb | null | D:\\iotdb\iotdb\data\data |
| D:\\iotdb\iotdb | dataDir | D:\\iotdb\iotdb\dataDir |
| D:\\iotdb\iotdb | C:\\dataDir | C:\\dataDir |
| D:\\iotdb\iotdb | "" | D:\\iotdb\iotdb\ |
First, if sysDir is null, sysDir will be assigned the default value(i.e.,"data"+File.separatorChar+"system".
Then, if sysDir is absolute, leave sysDir as it is. If sysDir is relative,
sysDir will be converted to the complete version using non-empty %IOTDB_HOME%.
e.g. for windows platform,
| IOTDB_HOME | sysDir before | sysDir after |
|-----------------|--------------------|-----------------------------|
| D:\\iotdb\iotdb | null | D:\\iotdb\iotdb\data\system |
| D:\\iotdb\iotdb | sysDir | D:\\iotdb\iotdb\sysDir |
| D:\\iotdb\iotdb | C:\\sysDir | C:\\sysDir |
| D:\\iotdb\iotdb | "" | D:\\iotdb\iotdb\ |
First, if walDir is null, walDir will be assigned the default value(i.e.,"data"+File.separatorChar+"data".
Then, if walDir is absolute, leave walDir as it is. If walDir is relative,
walDir will be converted to the complete version using non-empty %IOTDB_HOME%.
e.g. for windows platform,
| IOTDB_HOME | walDir before | walDir after |
|-----------------|--------------------|-----------------------------|
| D:\\iotdb\iotdb | null | D:\\iotdb\iotdb\data\wal |
| D:\\iotdb\iotdb | walDir | D:\\iotdb\iotdb\walDir |
| D:\\iotdb\iotdb | C:\\walDir | C:\\walDir |
| D:\\iotdb\iotdb | "" | D:\\iotdb\iotdb\ |
*/
public void preUpdatePath() {
if (dataDir == null) {
dataDir = default_data_dir + File.separatorChar + default_data_dir;
}
if (sysDir == null) {
sysDir = default_data_dir + File.separatorChar + default_sys_dir;
}
if (walDir == null) {
walDir = default_data_dir;
}
List<String> dirs = new ArrayList<>();
dirs.add(dataDir);
dirs.add(sysDir);
dirs.add(walDir);
List<String> newdirs = new ArrayList<>();
String homeDir = System.getProperty(TsFileDBConstant.IOTDB_HOME, null);
for (int i = 0; i < 3; i++) {
String dir = dirs.get(i);
if (new File(dir).isAbsolute()) {
continue;
} else {
if (homeDir != null) {
if (homeDir.length() > 0) {
if (!homeDir.endsWith(File.separator)) {
dir = homeDir + File.separatorChar + dir;
} else {
dir = homeDir + dir;
}
dirs.set(i, dir);
}
}
}
}
dataDir = dirs.get(0);
sysDir = dirs.get(1);
walDir = dirs.get(2);
}
}

View File

@ -47,7 +47,7 @@ public class TsfileDBDescriptor {
} else {
LOGGER.warn("Cannot find IOTDB_HOME or IOTDB_CONF environment variable when loading config file {}, use default configuration", TsfileDBConfig.CONFIG_NAME);
// update all data path
conf.updateDataPath();
conf.updatePath();
return;
}
} else{
@ -59,7 +59,7 @@ public class TsfileDBDescriptor {
} catch (FileNotFoundException e) {
LOGGER.warn("Fail to find config file {}", url);
// update all data path
conf.updateDataPath();
conf.updatePath();
return;
}
@ -92,7 +92,9 @@ public class TsfileDBDescriptor {
conf.flushWalPeriodInMs = Integer.parseInt(properties.getProperty("flush_wal_period_in_ms", conf.flushWalPeriodInMs+""));
conf.dataDir = properties.getProperty("data_dir", conf.dataDir);
conf.sysDir = properties.getProperty("sys_dir", conf.sysDir);
conf.walDir = properties.getProperty("wal_dir", conf.walDir);
conf.maxOpenFolder = Integer.parseInt(properties.getProperty("max_opened_folder", conf.maxOpenFolder + ""));
conf.mergeConcurrentThreads = Integer.parseInt(properties.getProperty("merge_concurrent_threads", conf.mergeConcurrentThreads + ""));
if (conf.mergeConcurrentThreads <= 0
@ -151,7 +153,7 @@ public class TsfileDBDescriptor {
LOGGER.warn("Error format in config file because {}, use default configuration", e.getMessage());
} finally {
// update all data path
conf.updateDataPath();
conf.updatePath();
}
if (inputStream != null) {
try {