Skip to content

Dbi creation within transaction not supported #192

@fbiricotti

Description

@fbiricotti

The APIs for creating a database (openDbi) don't take a transaction as input parameter (it's generated internally and immediately committed). This code works:

    Dbi<ByteBuffer> dbi = env.openDbi("TEST", new DbiFlags [] { DbiFlags.MDB_CREATE });
    Txn<ByteBuffer> txn = renv.txnWrite();
    dbi.put(txn, key, val);
    txn.commit();

This code DOES NOT:

    Txn<ByteBuffer> txn = repoEnv.txnWrite();
    Dbi<ByteBuffer> dbi = repoEnv.openDbi("TEST", new DbiFlags [] { DbiFlags.MDB_CREATE });
    dbi.put(txn, key, val);
    txn.commit();

by throwing this exception:

Exception in thread "main" org.lmdbjava.LmdbNativeException$ConstantDerivedException: Platform constant error code: EINVAL Invalid argument (22)
at org.lmdbjava.ResultCodeMapper.checkRc(ResultCodeMapper.java:114)
at org.lmdbjava.Dbi.put(Dbi.java:411)
at test.TestMain.main(TestMain.java:34)

This seems to be a blocking issue in a complex application where databases may be require to be created on-demand while a write transaction is already up and running. Or there is an alternative ? Please note that the native LMDB API for opening/creating a database do require a transaction., why not exposing it as parameter?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions