mirror of
https://gitee.com/BDWare/cp.git
synced 2025-01-10 09:54:07 +00:00
fix: fix bugs in RocksDBUtil
use correct path in RocksDB.open
This commit is contained in:
parent
4e7863b38b
commit
2f7411d5e6
@ -119,7 +119,6 @@ public class ContractProcess {
|
|||||||
}
|
}
|
||||||
System.out.println("[Create CP]");
|
System.out.println("[Create CP]");
|
||||||
instance = new ContractProcess(port, cmi);
|
instance = new ContractProcess(port, cmi);
|
||||||
;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isArchiveFile(File file) {
|
public static boolean isArchiveFile(File file) {
|
||||||
@ -169,8 +168,9 @@ public class ContractProcess {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static String getContractDir() {
|
public static String getContractDir() {
|
||||||
if (instance!=null && instance.cn!=null && instance.cn.getContractName()!=null)
|
if (null != instance && null != instance.cn && null != instance.cn.getContractName()) {
|
||||||
return instance.cn.getContractName();
|
return instance.cn.getContractName();
|
||||||
|
}
|
||||||
return "debug";
|
return "debug";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
package org.bdware.sc.boundry.utils;
|
package org.bdware.sc.boundry.utils;
|
||||||
|
|
||||||
|
import org.apache.logging.log4j.LogManager;
|
||||||
|
import org.apache.logging.log4j.Logger;
|
||||||
import org.bdware.sc.ContractProcess;
|
import org.bdware.sc.ContractProcess;
|
||||||
import org.bdware.sc.compiler.PermissionStub;
|
import org.bdware.sc.compiler.PermissionStub;
|
||||||
import org.bdware.sc.node.Permission;
|
import org.bdware.sc.node.Permission;
|
||||||
@ -17,11 +19,14 @@ import java.util.Map;
|
|||||||
|
|
||||||
@PermissionStub(permission = Permission.RocksDB)
|
@PermissionStub(permission = Permission.RocksDB)
|
||||||
public class RocksDBUtil {
|
public class RocksDBUtil {
|
||||||
|
private static final Logger LOGGER = LogManager.getLogger(RocksDBUtil.class);
|
||||||
|
|
||||||
|
static Map<String, RocksDBUtil> cacheDB = new HashMap<>();
|
||||||
|
|
||||||
static {
|
static {
|
||||||
RocksDB.loadLibrary();
|
RocksDB.loadLibrary();
|
||||||
}
|
}
|
||||||
|
|
||||||
static Map<String, RocksDBUtil> cacheDB = new HashMap<>();
|
|
||||||
RocksDB rocksDB;
|
RocksDB rocksDB;
|
||||||
String path;
|
String path;
|
||||||
|
|
||||||
@ -31,24 +36,28 @@ public class RocksDBUtil {
|
|||||||
Options options = new Options();
|
Options options = new Options();
|
||||||
options.setCreateIfMissing(true);
|
options.setCreateIfMissing(true);
|
||||||
|
|
||||||
File parent = new File("./ContractDB/" + ContractProcess.getContractDir());
|
File parent = new File("./ContractDB/" + ContractProcess.getContractDir());
|
||||||
File dir = new File(parent, path);
|
File dir = new File(parent, path);
|
||||||
if (!dir.exists()) dir.mkdirs();
|
LOGGER.info("init RocksDB in " + dir.getAbsolutePath());
|
||||||
File lockFile = new File(dir, "LOCK");
|
if (!dir.exists()) {
|
||||||
lockFile.delete();
|
LOGGER.trace("create directory " + dir.getAbsolutePath() + ": " + dir.mkdirs());
|
||||||
if (readOnly) {
|
}
|
||||||
rocksDB = RocksDB.openReadOnly(options, path);
|
File lockFile = new File(dir, "LOCK");
|
||||||
} else {
|
LOGGER.trace("delete file" + lockFile.getAbsolutePath() + ": " + lockFile.delete());
|
||||||
rocksDB = RocksDB.open(options, path);
|
if (readOnly) {
|
||||||
|
rocksDB = RocksDB.openReadOnly(options, dir.getAbsolutePath());
|
||||||
|
} else {
|
||||||
|
rocksDB = RocksDB.open(options, dir.getAbsolutePath());
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (RocksDBException e) {
|
} catch (RocksDBException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static RocksDBUtil loadDB(String path, boolean readOnly) {
|
public static RocksDBUtil loadDB(String path, boolean readOnly) {
|
||||||
if (cacheDB.containsKey(path)) return cacheDB.get(path);
|
if (cacheDB.containsKey(path)) {
|
||||||
|
return cacheDB.get(path);
|
||||||
|
}
|
||||||
RocksDBUtil ret = new RocksDBUtil(path, readOnly);
|
RocksDBUtil ret = new RocksDBUtil(path, readOnly);
|
||||||
cacheDB.put(path, ret);
|
cacheDB.put(path, ret);
|
||||||
return ret;
|
return ret;
|
||||||
|
Loading…
Reference in New Issue
Block a user