Search in sources :

Example 1 with EnvFlags

use of org.lmdbjava.EnvFlags in project twister2 by DSC-SPIDAL.

the class LMDBMemoryManager method init.

@Override
public boolean init() {
    try {
        if (lmdbDataPath == null || lmdbDataPath.isNullOrEmpty()) {
            lmdbDataPath = new Path(LMDBMemoryManagerContext.DEFAULT_FOLDER_PATH);
        }
        final File path = new File(lmdbDataPath.getPath());
        if (!path.exists()) {
            path.mkdirs();
        }
        final EnvFlags[] envFlags = envFlags(true, false);
        this.env = create().setMapSize(LMDBMemoryManagerContext.MAP_SIZE_LIMIT).setMaxDbs(LMDBMemoryManagerContext.MAX_DB_INSTANCES).setMaxReaders(LMDBMemoryManagerContext.MAX_READERS).open(path, envFlags);
        // The database supports duplicate values for a single key
        db = env.openDbi(LMDBMemoryManagerContext.DB_NAME, MDB_CREATE);
        dbMap = new HashMap<Integer, Dbi<ByteBuffer>>();
        keyBuffer = ByteBuffer.allocateDirect(LMDBMemoryManagerContext.KEY_BUFF_INIT_CAP);
        dataBuffer = ByteBuffer.allocateDirect(LMDBMemoryManagerContext.DATA_BUFF_INIT_CAP);
        dataQueueMap = new HashMap<>();
        LMDBMemoryManager.needsCommitReader = false;
        LMDBMemoryManager.needsCommitWriter = true;
        Thread writerThread = new Thread(new LMDBDataWriter(dbMap, dataQueueMap, env));
        writerThread.start();
        // populate readTxnStack
        // readTxns = new Stack<>();
        // for (int i = 0; i < 10; i++) {
        // readTxns.push(env.txnRead());
        // }
        threadReadTxn = new ThreadLocal<>();
        // threadWriteTxn = new ThreadLocal<>();
        // threadWriteCursor = new ThreadLocal<>();
        // threadNeedCommit = new ThreadLocal<>();
        threadappendBuffer = new ThreadLocal<>();
    } catch (RuntimeException e) {
        throw new RuntimeException("Error while creating LMDB database at Path " + lmdbDataPath.toString(), e);
    }
    return true;
}
Also used : Path(edu.iu.dsc.tws.api.data.Path) Dbi(org.lmdbjava.Dbi) File(java.io.File) EnvFlags(org.lmdbjava.EnvFlags)

Aggregations

Path (edu.iu.dsc.tws.api.data.Path)1 File (java.io.File)1 Dbi (org.lmdbjava.Dbi)1 EnvFlags (org.lmdbjava.EnvFlags)1