Re[2]: Curious "missing parent" check in mdb_idscopes(), how may this occur?
Konstantin Andreev <[email protected]> Wed, 30 Oct 2019 20:37:44 +0300
| Newsgroups | gmane.network.openldap.devel |
|---|---|
| Organization | Swemel JSC |
| Message-ID | <[email protected]> |
Hi, I have carefully traced this part of code and was unable to reproduce what you describe.
If mdb_id2l_search does not find an id in the isc->scopes (lines 782-783, see the excerpt below), the loop just looks id up directly in the dn2id (lines 751-752).
I was also unable to observe that mdb_idscopes could differentiate between paged and non-paged requests, or be affected by the difference. This difference is encapsulated by the caller, mdb_search().
Specifically, if the underlying set of entries changes between page requests, the loop (may) ascend up to "super-root" with zero id. That's exactly what it does for non-paged requests.
And now I am almost sure that the check [if(id == prev)] at line 778 can not succeed, because always compares the parent and child ids coming from the same [child -> parent] record of "dn2id".
Could you, please, take one more look at this part of code? If the check [if(id == prev)] could succeed, could you, please, give a bit more detailed explanation, how may this happen?
Regards, Konstantin.
| 749 while (id) {
| 750 if ( !rc ) {
| 751 key.mv_data = &id;
| 752 rc = mdb_cursor_get( isc->mc, &key, &data, MDB_SET );
...
| 777 /* If we didn't advance, some parent is missing */
| 778 if ( id == prev )
| 779 return MDB_NOTFOUND;
| 780
| 781 x = mdb_id2l_search( isc->scopes, id );
| 782 if ( x <= isc->scopes[0].mid && isc->scopes[x].mid == id ) {
| 783 if ( !isc->scopes[x].mval.mv_data ) {
| 784 /* This node is in scope, add parent chain to scope */
Howard Chu, 28 Oct 2019 20:22 MSK:
>
> If the checks in
> http://www.openldap.org/devel/gitweb.cgi?p=openldap.git;a=blob;f=servers/slapd/back-mdb/dn2id.c;h=93fd3e387e968a1928eaa0f82211bcbc3687e777;hb=HEAD#l782
>
> don't find a result, then id doesn't get advanced any further.
>
> This can happen in a pagedResults search when the underlying set of entries changes between page requests.
Konstantin Andreev, 28 Oct 2019 15:03 MSK:
>
> I am contemplating the mdb search mechanics, and puzzled by "missing parent" check in mdb_idscopes():
>
> | /* If we didn't advance, some parent is missing */
> | if ( id == prev )
> | return MDB_NOTFOUND;
>
> where "id" and "prev" are parent and child ids that come from the same "UP" ( child -> parent ) record of "dn2id" table. Here is a source code approximation for easier reading:
>
> | MDB_val key = { sizeof(ID), & id }, data;
> | mdb_cursor_get( "dn2id", key, data, MDB_SET );
> | // reading last sizeof(ID) bytes of data.mv_data
> | ID prev = *(ID *)(data.mv_data + data.mv_size - sizeof(ID));
>
> IIUC, there is no records in "dn2id" where parent and child ids are the same. There is no by construction, except "super-root", where both ids are zeros, but zero id doesn't follow this execution path.
>
> So, how may [id == prev] occur? Could you, please, explain?
>
> The check came from 5a08b661 and 437f21b commits (ITS#7705,#7800 fix ...), I have read both, but they haven't helped either.