Skip to content

dba: lmdb: allow to override the MDB_NOSUBDIR flag #8856

Closed

Description

@martinvonwittich

Description

The lmdb driver of DBA always sets the MDB_NOSUBDIR flag and does not allow PHP code to override it:

int rc, flags = MDB_NOSUBDIR;

This is a problem for interoperability when sharing a single LMDB database between multiple programs written in different languages. LMDB itself defaults to using a subdirectory as a database, and will create two files data.mdb and lock.mdb in this directory. When using PHP, one has to open subdir/data.mdb explicitly, but now the PHP code will use subdir/data.mdb-lock instead of subdir/lock.mdb as a lock file, leading to two separate lock files when using different codebases:

host ~/test (master) # ls -l pkg.db
total 156K
-rw------- 1 root root 148K Jun 22 16:49 data.mdb
-rw------- 1 root root 8.0K Jun 23 19:30 lock.mdb
-rw-r--r-- 1 root root 8.0K Jun 22 18:49 data.mdb-lock

Currently, the only way to work around this issue is by changing all other codebases to use MDB_NOSUBDIR too because there is no way to disable it in PHP.

Activity

  1. martinvonwittich commented on Jun 23, 2022

    @martinvonwittich
    Author

    Hm, apparently there's also no way to open the environment with MDB_RDONLY, which causes a significant overhead when opening the environment just to read a key. In my Perl, Python and Rust implementations, enabling readonly increases the speed from ~150us to ~50us, but my PHP implementation is stuck at ~150us. Maybe it would be sensible to expose flags and the required constants completely?

  2. cmb69 commented on Jun 24, 2022

    @cmb69
    Member

    Looks like a reasonable improvement; users should be able to at least specify some of the flags which are passed to mdb_env_open(). PR welcome!

  3. self-assigned this
    on Jun 25, 2022
  4. Girgias commented on Jun 29, 2022

    @Girgias
    Member

    I'm trying to determine what flags would be useful to support, and I'm currently thinking of just including MDB_NOSUBDIR (and probably a custom PHP constant MDB_USE_SUB_DIR) as the other ones don't seem that relevant

  5. cmb69 commented on Jun 29, 2022

    @cmb69
    Member

    Well, MDB_RDONLY has been requested here, and I think it may make sense to support that.

  6. Girgias commented on Jun 29, 2022

    @Girgias
    Member

    Well, MDB_RDONLY has been requested here, and I think it may make sense to support that.

    This should be passed when the "r" mode is passed to dba_open() and I'm working on that

  7. cmb69 commented on Jun 29, 2022

    @cmb69
    Member

    This should be passed when the "r" mode is passed to dba_open()

    Ah, right. It might make sense to set it automatically in that case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions