修改RocksDB文件目录配置,使其支持使用相对路径
This commit is contained in:
@@ -7,27 +7,18 @@ import org.springframework.util.StringUtils;
|
||||
@Component
|
||||
public class RocksDBConfig {
|
||||
|
||||
public static String RocksDB_Path_Windows = "D://RocksDB";
|
||||
|
||||
public static String RocksDB_Path_Linux = "/usr/local/rocksdb";
|
||||
public static String RocksDB_Path = "./cache/rocksdb";
|
||||
|
||||
public static String RocksDB_Column_Family = "default";
|
||||
|
||||
@Value("${somkit.db.rocks.path.windows}")
|
||||
public void setRocksDB_Path_Windows(String rocksDB_Path_Windows) {
|
||||
if(StringUtils.hasText(rocksDB_Path_Windows)){
|
||||
RocksDB_Path_Windows = rocksDB_Path_Windows;
|
||||
@Value("${somkit.cache.rocks-db.path}")
|
||||
public void setRocksDB_Path(String rocksDB_Path) {
|
||||
if(StringUtils.hasText(rocksDB_Path)){
|
||||
RocksDB_Path = rocksDB_Path;
|
||||
}
|
||||
}
|
||||
|
||||
@Value("${somkit.db.rocks.path.linux}")
|
||||
public void setRocksDB_Path_Linux(String rocksDB_Path_Linux) {
|
||||
if(StringUtils.hasText(rocksDB_Path_Linux)){
|
||||
RocksDB_Path_Linux = rocksDB_Path_Linux;
|
||||
}
|
||||
}
|
||||
|
||||
@Value("${somkit.db.rocks.column-family}")
|
||||
@Value("${somkit.cache.rocks-db.column-family}")
|
||||
public void setRocksDB_Column_Family(String rocksDB_Column_Family){
|
||||
if(StringUtils.hasText(rocksDB_Column_Family)){
|
||||
RocksDB_Column_Family = rocksDB_Column_Family;
|
||||
|
||||
53
src/main/java/cn/somkit/fmt/utils/PathUtils.java
Normal file
53
src/main/java/cn/somkit/fmt/utils/PathUtils.java
Normal file
@@ -0,0 +1,53 @@
|
||||
package cn.somkit.fmt.utils;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
|
||||
/**
|
||||
* 路径工具类
|
||||
*/
|
||||
public class PathUtils {
|
||||
|
||||
/**
|
||||
* 解析相对路径为绝对路径
|
||||
* @param relativePath 相对路径
|
||||
* @return 绝对路径
|
||||
*/
|
||||
public static String resolve(String relativePath) {
|
||||
if(relativePath.startsWith("./")){
|
||||
relativePath = relativePath.replace("./", "");
|
||||
}
|
||||
// 获取当前工作目录的Path对象
|
||||
Path currentWorkingDirectory = Paths.get("").toAbsolutePath();
|
||||
// 使用相对路径创建Path对象
|
||||
Path relativePathObject = Paths.get(relativePath);
|
||||
// 解析相对路径,补全为绝对路径
|
||||
Path absolutePath = currentWorkingDirectory.resolve(relativePathObject);
|
||||
return absolutePath.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建文件夹
|
||||
* @param directoryPath 文件夹路径
|
||||
*/
|
||||
public static void directory(String directoryPath){
|
||||
// 使用Paths.get()方法创建Path对象
|
||||
Path dirPath = Paths.get(directoryPath);
|
||||
// 检查文件夹是否存在
|
||||
if (Files.notExists(dirPath)) {
|
||||
try {
|
||||
// 如果不存在,则创建文件夹及其所有必需的父目录
|
||||
Files.createDirectories(dirPath);
|
||||
System.out.println("Directory created: " + dirPath);
|
||||
} catch (IOException e) {
|
||||
// 如果创建过程中出现异常,打印错误信息
|
||||
System.err.println("Failed to create directory: " + dirPath);
|
||||
e.printStackTrace();
|
||||
}
|
||||
} else {
|
||||
System.out.println("Directory already exists: " + dirPath);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -22,12 +22,12 @@ public class RocksDBUtils {
|
||||
|
||||
static {
|
||||
try {
|
||||
String rocksDBPath = null; //RocksDB文件目录
|
||||
if (OsInfoUtil.isWindows()) {
|
||||
rocksDBPath = RocksDBConfig.RocksDB_Path_Windows; // 指定windows系统下RocksDB文件目录
|
||||
} else if(OsInfoUtil.isLinux()){
|
||||
rocksDBPath = RocksDBConfig.RocksDB_Path_Linux; // 指定linux系统下RocksDB文件目录
|
||||
String rocksDBPath = RocksDBConfig.RocksDB_Path; //RocksDB文件目录
|
||||
//如果使用相对路径,转换为绝对路径
|
||||
if(rocksDBPath != null && rocksDBPath.startsWith("./")){
|
||||
rocksDBPath = PathUtils.resolve(rocksDBPath);
|
||||
}
|
||||
PathUtils.directory(rocksDBPath); // 创建RocksDB文件目录
|
||||
RocksDB.loadLibrary();
|
||||
Options options = new Options();
|
||||
options.setCreateIfMissing(true); //如果数据库不存在则创建
|
||||
|
||||
@@ -21,11 +21,9 @@ somkit:
|
||||
path:
|
||||
windows: D://data/install/upload
|
||||
linux: /mnt/files
|
||||
db:
|
||||
rocks:
|
||||
path:
|
||||
windows: D://RocksDB//fmt
|
||||
linux: /usr/local/rocksdb/fmt
|
||||
cache:
|
||||
rocks-db:
|
||||
path: ./cache/rocksdb # RocksDB缓存路径 可以使用绝对路径,也可使用相对路径
|
||||
column-family: default
|
||||
logging:
|
||||
socket:
|
||||
|
||||
@@ -16,4 +16,8 @@
|
||||
修改日志文件生成及读取位置
|
||||
上传文件格式新增支持js、css、html、vsdx、dmp、7z、ppt、pptx
|
||||
AxUI的axAjax方法,timeout默认值改为6000000
|
||||
```
|
||||
> v1.3.0
|
||||
```
|
||||
修改RocksDB文件目录配置,使其支持使用相对路径
|
||||
```
|
||||
Reference in New Issue
Block a user