mirror of
				https://gitee.com/BDWare/cp.git
				synced 2025-06-12 10:44:02 +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]");
 | 
			
		||||
        instance = new ContractProcess(port, cmi);
 | 
			
		||||
        ;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static boolean isArchiveFile(File file) {
 | 
			
		||||
@ -169,8 +168,9 @@ public class ContractProcess {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    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 "debug";
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -1,5 +1,7 @@
 | 
			
		||||
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.compiler.PermissionStub;
 | 
			
		||||
import org.bdware.sc.node.Permission;
 | 
			
		||||
@ -17,11 +19,14 @@ import java.util.Map;
 | 
			
		||||
 | 
			
		||||
@PermissionStub(permission = Permission.RocksDB)
 | 
			
		||||
public class RocksDBUtil {
 | 
			
		||||
    private static final Logger LOGGER = LogManager.getLogger(RocksDBUtil.class);
 | 
			
		||||
 | 
			
		||||
    static Map<String, RocksDBUtil> cacheDB = new HashMap<>();
 | 
			
		||||
 | 
			
		||||
    static {
 | 
			
		||||
        RocksDB.loadLibrary();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    static Map<String, RocksDBUtil> cacheDB = new HashMap<>();
 | 
			
		||||
    RocksDB rocksDB;
 | 
			
		||||
    String path;
 | 
			
		||||
 | 
			
		||||
@ -31,24 +36,28 @@ public class RocksDBUtil {
 | 
			
		||||
            Options options = new Options();
 | 
			
		||||
            options.setCreateIfMissing(true);
 | 
			
		||||
 | 
			
		||||
             File parent = new File("./ContractDB/" + ContractProcess.getContractDir());
 | 
			
		||||
            File parent = new File("./ContractDB/" + ContractProcess.getContractDir());
 | 
			
		||||
            File dir = new File(parent, path);
 | 
			
		||||
            if (!dir.exists()) dir.mkdirs();
 | 
			
		||||
            File lockFile = new File(dir, "LOCK");
 | 
			
		||||
            lockFile.delete();
 | 
			
		||||
            if (readOnly) {
 | 
			
		||||
                rocksDB = RocksDB.openReadOnly(options, path);
 | 
			
		||||
            } else {
 | 
			
		||||
                rocksDB = RocksDB.open(options, path);
 | 
			
		||||
            LOGGER.info("init RocksDB in " + dir.getAbsolutePath());
 | 
			
		||||
            if (!dir.exists()) {
 | 
			
		||||
                LOGGER.trace("create directory " + dir.getAbsolutePath() + ": " + dir.mkdirs());
 | 
			
		||||
            }
 | 
			
		||||
            File lockFile = new File(dir, "LOCK");
 | 
			
		||||
            LOGGER.trace("delete file" + lockFile.getAbsolutePath() + ": " + lockFile.delete());
 | 
			
		||||
            if (readOnly) {
 | 
			
		||||
                rocksDB = RocksDB.openReadOnly(options, dir.getAbsolutePath());
 | 
			
		||||
            } else {
 | 
			
		||||
                rocksDB = RocksDB.open(options, dir.getAbsolutePath());
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
        } catch (RocksDBException e) {
 | 
			
		||||
            e.printStackTrace();
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    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);
 | 
			
		||||
        cacheDB.put(path, ret);
 | 
			
		||||
        return ret;
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user