fix rocksdb bugs

This commit is contained in:
CaiHQ 2022-09-02 21:21:07 +08:00
parent c077d425ab
commit 363a20049a
7 changed files with 60 additions and 55 deletions

View File

@ -43,7 +43,7 @@ dependencies {
implementation 'com.sun.mail:javax.mail:1.6.2'
implementation 'com.squareup.okhttp3:okhttp:4.9.1'
implementation 'org.bdware.bdcontract:sdk-java:1.0.0'
implementation 'org.bdware.doip:doip-audit-tool:0.9.4'
implementation 'org.bdware.doip:doip-audit-tool:1.0.8'
implementation fileTree(dir: 'lib', include: '*.jar')
testImplementation 'junit:junit:4.13.2'
}
@ -58,7 +58,8 @@ jar {
libs = libs + " libs/" + it.name
}
from {
// uncomment this when publish!
// uncomment this when publish,
// while develop at local use "false"
configurations.runtimeClasspath.filter {
// it.getAbsolutePath().contains("/lib/")
false

View File

@ -39,7 +39,6 @@ import org.bdware.sc.util.JsonUtil;
import org.objectweb.asm.ClassReader;
import org.objectweb.asm.tree.ClassNode;
import org.objectweb.asm.tree.MethodNode;
import wrp.jdk.nashorn.api.scripting.ScriptObjectMirror;
import javax.script.ScriptContext;
import javax.script.ScriptEngine;
@ -477,18 +476,6 @@ public class ContractProcess {
cn = zipBundle.mergeContractNode();
// check functionNodes
List<FunctionNode> functionNodes = cn.getFunctions();
LOGGER.debug(
"functionNodes jointInfo: "
+ JsonUtil.toPrettyJson(
functionNodes.stream()
.map(
x -> {
JoinInfo joinInfo = x.getJoinInfo();
return null == joinInfo
? "null"
: joinInfo;
})
.toArray()));
injectHandlers();
this.contract.setYjsType(cn.getYjsType());
@ -644,6 +631,8 @@ public class ContractProcess {
return ver;
}
handleLog();
LOGGER.info("load script, contract:" + JsonUtil.toJson(contract.getScriptStr()));
LOGGER.info("load cn:" + JsonUtil.toJson(cn));
String ret =
JsonUtil.toJson(engine.loadContract(contract, cn, cn.getInstrumentBranch()));
invokeOnCreate(contract.getCreateParam());
@ -897,6 +886,7 @@ public class ContractProcess {
}
String reqID = request.getRequestID();
if (cachedRequests.contains(reqID)) {
LOGGER.info("[Hit Cache]:" + reqID);
try {
String cachedResult = edion.get(reqID);
if (cachedResult != null && !cachedResult.isEmpty()) {
@ -946,10 +936,6 @@ public class ContractProcess {
result = engine.executeContract(request);
result.analysis = bo.toString();
// System.out.println(
// "[withEvaluatesAnalysis ContractProcess] result.analysis =
// "
// + result.analysis);
engine.redirectTracePS(previous);
} else {
@ -958,15 +944,12 @@ public class ContractProcess {
result = engine.executeContract(request);
engine.redirectTracePS(previous);
}
//
// System.out.println("res" + result.result);
// result.addProperty("result",maskResult.getMaskResult(maskConf,
// ret.get("result")).toString());
String ret = JsonUtil.toJson(result);
cachedRequests.add(reqID);
edion.put(reqID, ret);
if (reqID != null && reqID.endsWith("_mul")) {
cachedRequests.add(reqID);
edion.put(reqID, ret);
}
return ret;
} catch (Exception e) {
ByteArrayOutputStream bo = new ByteArrayOutputStream();
@ -976,7 +959,6 @@ public class ContractProcess {
}
public String evaluatesAnalysis(String getFunction) {
// System.out.println("当前的function:" + getFunction);
Map<String, byte[]> clzs = engine.dumpClass();
Map<String, MethodNode> methods = new HashMap<>();
for (byte[] clz : clzs.values()) {

View File

@ -91,7 +91,8 @@ public class DOIPUtil {
return respDO.toString();
} catch (Exception ie) {
ie.printStackTrace();
return "send doip message error: " + ie.getMessage();
return ret.body.getDataAsJsonString();
}
}
@ -102,7 +103,8 @@ public class DOIPUtil {
public String retrieve(String doi, String args) {
DoipMessage msg = (new DoipMessageFactory.DoipMessageBuilder()).createRequest(doi, BasicOperations.Retrieve.getName())
.setBody(args.getBytes(StandardCharsets.UTF_8)).create();
.create();
msg.header.parameters.addAttribute("element", "");
return convertDoipMsgToString(syncGetMessage(msg));
}

View File

@ -7,7 +7,6 @@ import org.bdware.sc.compiler.PermissionStub;
import org.bdware.sc.node.Permission;
import org.rocksdb.Options;
import org.rocksdb.RocksDB;
import org.rocksdb.RocksDBException;
import org.rocksdb.RocksIterator;
import wrp.jdk.nashorn.internal.runtime.PropertyMap;
import wrp.jdk.nashorn.internal.runtime.ScriptObject;
@ -30,29 +29,43 @@ public class RocksDBUtil {
RocksDB rocksDB;
String path;
public RocksDBUtil(String path, boolean readOnly) {
try {
this.path = path;
Options options = new Options();
options.setCreateIfMissing(true);
File parent = new File("./ContractDB/" + ContractProcess.getContractDir());
File dir = new File(parent, path);
//LOGGER.info("init RocksDB in " + dir.getAbsolutePath());
if (!dir.exists()) {
LOGGER.info("create directory " + dir.getAbsolutePath() + ": " + dir.mkdirs());
}
File lockFile = new File(dir, "LOCK");
if (readOnly) {
rocksDB = RocksDB.openReadOnly(options, dir.getAbsolutePath());
} else {
rocksDB = RocksDB.open(options, dir.getAbsolutePath());
}
} catch (RocksDBException e) {
e.printStackTrace();
public void tryLoad(String path, boolean readOnly) throws Exception {
this.path = path;
Options options = new Options();
options.setCreateIfMissing(true);
File parent = new File("./ContractDB/" + ContractProcess.getContractDir());
File dir = new File(parent, path);
//LOGGER.info("init RocksDB in " + dir.getAbsolutePath());
if (!dir.exists()) {
LOGGER.info("create directory " + dir.getAbsolutePath() + ": " + dir.mkdirs());
}
File lockFile = new File(dir, "LOCK");
if (readOnly) {
rocksDB = RocksDB.openReadOnly(options, dir.getAbsolutePath());
} else {
rocksDB = RocksDB.open(options, dir.getAbsolutePath());
}
}
public static RocksDBUtil loadDB(String path, boolean readOnly) {
public RocksDBUtil(String path, boolean readOnly) {
try {
tryLoad(path, readOnly);
} catch (Exception e) {
LOGGER.info("======TRY Load Again 2s later====");
try {
Thread.sleep(2000L);
} catch (InterruptedException ex) {
}
try {
tryLoad(path, readOnly);
} catch (Exception ex) {
LOGGER.info("======LOAD FAILED!====");
e.printStackTrace();
}
}
}
public static synchronized RocksDBUtil loadDB(String path, boolean readOnly) {
if (cacheDB.containsKey(path)) {
return cacheDB.get(path);
}
@ -125,4 +138,8 @@ public class RocksDBUtil {
}
return null;
}
public String clean() {
return "todo";
}
}

View File

@ -56,7 +56,6 @@ public class UtilRegistry {
String.format(
"%sUtil = %s.%sUtil%s;\n",
s, UtilRegistry.class.getPackage().getName(), s, open ? "" : "Stub");
LOGGER.debug(ret);
return ret;
}
return "";

View File

@ -270,6 +270,7 @@ public class DesktopEngine extends JSEngine {
ScriptEngine.FILENAME,
fun.getFileName(),
ScriptContext.ENGINE_SCOPE);
LOGGER.info("loadFun:" + str);
compileFunction(str, isInsnLimit);
} catch (ScriptException e) {
return wrapperException(e, fun);
@ -496,6 +497,7 @@ public class DesktopEngine extends JSEngine {
} else {
synchronized (this) {
ret = executeWithoutLock(fun, input);
}
}
//System.out.println("[DesktopEngine MaskConfig]"+ContractProcess.instance.getProjectConfig().getMaskConfig().config.toString());
@ -526,10 +528,10 @@ public class DesktopEngine extends JSEngine {
if (syncUtil.startFlag && !recovering) {
switch (syncUtil.currType) {
case Trace:
syncUtil.traceRecordUtil.eachFinish();
// syncUtil.traceRecordUtil.eachFinish();
break;
case Trans:
syncUtil.transRecordUtil.eachFinish();
// syncUtil.transRecordUtil.eachFinish();
break;
case Memory:
default:

View File

@ -15,8 +15,8 @@ public class LedgerUtilTest {
public static void main(String[] arg) {
String ip = "39.104.202.92";
ip = "39.104.205.122";
ip = "39.104.202.92";
Client c = new Client(ip, 18021);
ip = "39.104.201.40";
Client c = new Client(ip, 21121);
System.out.println(c.clientVersionSync().getVersion());
System.out.println(c.getLedgersSync().toString());
String from = "0xb60e8dd61c5d32be8058bb8eb970870f07233155";
@ -38,6 +38,8 @@ public class LedgerUtilTest {
str = "d16da370021447c1c1136f97f9975069b1f22ddb";
str = "448b314de358384a55b9c5d2eae7596cff4e3587";
str ="a114aa22365c2d61ee1c242c755d82c035783e41";
str = "d9be17b4287ed9a548901ef0e738f65f25dc7041";
str="e90dbc995add64b26fa483b1b0ad7747b19ad579";
byte[] bytes = ByteUtils.fromHexString(str);
String hash = ByteUtil.encodeBASE64(bytes);
System.out.println(URLEncoder.encode(hash));