Skip to content

Fix #78808: [LMDB] MDB_MAP_FULL: Environment mapsize limit reached #4910

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from

Conversation

cmb69
Copy link
Member

@cmb69 cmb69 commented Nov 14, 2019

We implement support for a fifth parameter, which allows to specify the
mapsize. The parameter defaults to zero, in which case the compiled in
default mapsize (usually 1048576) will be used. The mapsize should be
a multiple of the page size of the OS.


I'm not really happy with this solution. I would have preferred to introduce an option array, but all driver specific parameters are converted to string (why?), so that's not possible, even though it might bite us when we may want to add support for further mdb_env_set_*() functions.

Furthermore, I'm not sure which version to target. I think not being able to specify the mapsize is a bug, because the default mapsize is pretty small, but am uncomfortable to fix it this late for PHP 7.2, so I've targeted 7.3.

We implement support for a fifth parameter, which allows to specify the
mapsize.  The parameter defaults to zero, in which case the compiled in
default mapsize (usually 1048576) will be used.  The mapsize should be
a multiple of the page size of the OS.

if(info->argc > 0) {
mode = zval_get_long(&info->argv[0]);

if (info->argc > 1) {
mapsize = zval_get_long(&info->argv[1]);
if (mapsize < 0) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mapsize may be equal 0

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mapsize==0 is supposed to be the default (which also may be passed explicitly), in which case no warning should be emitted. Do you suggest to change the default to -1, and let the user pass 0 to have a mapsize of zero?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, I thought it was a mistake :)

@@ -56,6 +64,14 @@ DBA_OPEN_FUNC(lmdb)
return FAILURE;
}

if (mapsize > 0) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mapsize greater 0

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that's deliberate. If mapsize==0 that means use the default mapsize, so there is no need to call mdb_env_set_mapsize().

--FILE--
<?php
$handler = 'lmdb';
require_once __DIR__ .'/test.inc';

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need add for lmdb:

@unlink($db_filename.'-lock');

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That should be handled by the --CLEAN-- section.

@saippuakauppias
Copy link

For the future or discussion: in multi-thread read database I was caught an exception: "MDB_READERS_FULL: Environment maxreaders limit reached".

By default MDB_READERS_FULL=126, but it can be changed through environment export MDB_READERS_FULL=1024.

I think, in future maybe cool to change mdb_env_set_maxreaders() in dba_open() args.

PS: I wanted to send a bug about it, but could not make a test script.

@cmb69
Copy link
Member Author

cmb69 commented Nov 14, 2019

@saippuakauppias, yes, I've seen that change in your lmdb patch, but I'm really unsure how to go about that. Having more and more optional parameters doesn't look desireable, but we can't pass an option array due to the mentioned string conversion. It might be sensible to change this in PHP 8, but we would need to assess the impact an other drivers.

@cmb69
Copy link
Member Author

cmb69 commented Dec 2, 2019

[…], but we would need to assess the impact an other drivers.

The optional driver parameters are now documented. TL;DR: some drivers don't support any params, and the others all support a single $filemode param. So switching to an option array doesn't seem to be an issue (actually, the fact that $filemode is passed as string might be confusing, since $filemode is usually expressed as octal number, which would loose its expected meaning when given as string).

Anyhow, since this PR would introduce an optional parameter in a patch revision, I'd like to get some feedback of others.

Thanks.

@cmb69 cmb69 added the Bug label Dec 2, 2019
@saippuakauppias
Copy link

Yes, it does not look elegant ...
It might be worth rewriting method dba_open and doing something like:

dba_open ( string $path , string $mode [, string $handler [, string $filemode [, array $params]]] ) : resource

?

I understand that this requires additional work, but maybe it’s better to do well right away?

LMDB is a really fast and cool database! I am using it in production now and it seems that this is the best solution for key=>value that I have met!

I also want to test fork libmdbx - it seems that it should be even better and more stable. But I don’t understand yet - will it work with PHP if I just replace library files or do I need to write my own extension?

@cmb69
Copy link
Member Author

cmb69 commented Dec 27, 2019

I'm afraid we can't change the signature of dba_open() during PHP 7; even if none of the bundled drivers use further arguments, custom code might expect such to be passed as strings.

To use another database with DBA, you would have to implement the driver (see, for instance, https://github.com/php/php-src/blob/php-7.4.1/ext/dba/dba_lmdb.c). Probably no need to fork the actual implementation library.

Anyhow, if there are no objections, I'll merge this in a week.

@cmb69
Copy link
Member Author

cmb69 commented Jan 3, 2020

Applied as c05a069. Thanks.

@cmb69 cmb69 closed this Jan 3, 2020
@cmb69 cmb69 deleted the fix-78808 branch January 3, 2020 17:53
php-pulls pushed a commit to php/doc-en that referenced this pull request Jan 23, 2020
salathe pushed a commit to salathe/phpdoc-en that referenced this pull request Jan 23, 2020
heiglandreas pushed a commit to phpdoctest/en that referenced this pull request Feb 4, 2020
salathe pushed a commit to salathe/phpdoc-en that referenced this pull request Sep 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants