From 54ced52c047425b432075946dd2997c52f020de0 Mon Sep 17 00:00:00 2001 From: Howard Chu Date: Fri, 9 Sep 2011 00:10:48 -0700 Subject: [PATCH] Keep cursor open for id2entry --- servers/slapd/back-mdb/config.c | 16 +++++++-------- servers/slapd/back-mdb/dn2entry.c | 17 +++++++++++++--- servers/slapd/back-mdb/id2entry.c | 5 ++--- servers/slapd/back-mdb/proto-mdb.h | 2 +- servers/slapd/back-mdb/search.c | 31 +++++++++++++++++------------- 5 files changed, 43 insertions(+), 28 deletions(-) diff --git a/servers/slapd/back-mdb/config.c b/servers/slapd/back-mdb/config.c index c6cb3cb043..4041fabac6 100644 --- a/servers/slapd/back-mdb/config.c +++ b/servers/slapd/back-mdb/config.c @@ -144,25 +144,25 @@ mdb_online_index( void *ctx, void *arg ) rc = mdb_txn_begin( mdb->mi_dbenv, 0, &txn ); if ( rc ) break; + rc = mdb_cursor_open( txn, mdb->mi_id2entry, &curs ); + if ( rc ) { + mdb_txn_abort( txn ); + break; + } if ( getnext ) { getnext = 0; - rc = mdb_cursor_open( txn, mdb->mi_id2entry, &curs ); - if ( rc ) { - mdb_txn_abort( txn ); - break; - } rc = mdb_cursor_get( curs, &key, &data, MDB_SET_RANGE ); - memcpy( &id, key.mv_data, sizeof( id )); - mdb_cursor_close( curs ); if ( rc ) { mdb_txn_abort( txn ); if ( rc == MDB_NOTFOUND ) rc = 0; break; } + memcpy( &id, key.mv_data, sizeof( id )); } - rc = mdb_id2entry( op, txn, id, &e ); + rc = mdb_id2entry( op, curs, id, &e ); + mdb_cursor_close( curs ); if ( rc ) { mdb_txn_abort( txn ); if ( rc == MDB_NOTFOUND ) { diff --git a/servers/slapd/back-mdb/dn2entry.c b/servers/slapd/back-mdb/dn2entry.c index 3aa8167534..e12a9da2a6 100644 --- a/servers/slapd/back-mdb/dn2entry.c +++ b/servers/slapd/back-mdb/dn2entry.c @@ -35,9 +35,11 @@ mdb_dn2entry( Entry **e, int matched ) { + struct mdb_info *mdb = (struct mdb_info *) op->o_bd->be_private; int rc, rc2; ID id = NOID; struct berval mbv, nmbv; + MDB_cursor *mc; Debug(LDAP_DEBUG_TRACE, "mdb_dn2entry(\"%s\")\n", dn->bv_val, 0, 0 ); @@ -46,11 +48,20 @@ mdb_dn2entry( rc = mdb_dn2id( op, tid, dn, &id, &mbv, &nmbv ); if ( rc ) { - if ( matched ) - rc2 = mdb_id2entry( op, tid, id, e ); + if ( matched ) { + rc2 = mdb_cursor_open( tid, mdb->mi_id2entry, &mc ); + if ( rc2 == MDB_SUCCESS ) { + rc2 = mdb_id2entry( op, mc, id, e ); + mdb_cursor_close( mc ); + } + } } else { - rc = mdb_id2entry( op, tid, id, e ); + rc = mdb_cursor_open( tid, mdb->mi_id2entry, &mc ); + if ( rc == MDB_SUCCESS ) { + rc = mdb_id2entry( op, mc, id, e ); + mdb_cursor_close(mc); + } } if ( *e ) { (*e)->e_name = mbv; diff --git a/servers/slapd/back-mdb/id2entry.c b/servers/slapd/back-mdb/id2entry.c index e6c389ee34..c849aaf0ba 100644 --- a/servers/slapd/back-mdb/id2entry.c +++ b/servers/slapd/back-mdb/id2entry.c @@ -82,12 +82,11 @@ int mdb_id2entry_update( int mdb_id2entry( Operation *op, - MDB_txn *tid, + MDB_cursor *mc, ID id, Entry **e ) { struct mdb_info *mdb = (struct mdb_info *) op->o_bd->be_private; - MDB_dbi dbi = mdb->mi_id2entry; MDB_val key, data; int rc = 0; @@ -97,7 +96,7 @@ int mdb_id2entry( key.mv_size = sizeof(ID); /* fetch it */ - rc = mdb_get( tid, dbi, &key, &data ); + rc = mdb_cursor_get( mc, &key, &data, MDB_SET ); if ( rc == MDB_NOTFOUND ) { /* Looking for root entry on an empty-dn suffix? */ if ( !id && BER_BVISEMPTY( &op->o_bd->be_nsuffix[0] )) { diff --git a/servers/slapd/back-mdb/proto-mdb.h b/servers/slapd/back-mdb/proto-mdb.h index b2fe351815..8662b11e42 100644 --- a/servers/slapd/back-mdb/proto-mdb.h +++ b/servers/slapd/back-mdb/proto-mdb.h @@ -166,7 +166,7 @@ int mdb_id2entry_delete( int mdb_id2entry( Operation *op, - MDB_txn *tid, + MDB_cursor *mc, ID id, Entry **e); diff --git a/servers/slapd/back-mdb/search.c b/servers/slapd/back-mdb/search.c index a457dd57ce..47b767a864 100644 --- a/servers/slapd/back-mdb/search.c +++ b/servers/slapd/back-mdb/search.c @@ -32,6 +32,7 @@ static int search_candidates( SlapReply *rs, Entry *e, MDB_txn *txn, + MDB_cursor *mci, ID *ids, ID *scopes ); @@ -130,6 +131,7 @@ static int search_aliases( SlapReply *rs, Entry *e, MDB_txn *txn, + MDB_cursor *mci, ID *scopes, ID *stack ) { @@ -187,7 +189,7 @@ static int search_aliases( for (ida = mdb_idl_first(curscop, &cursora); ida != NOID; ida = mdb_idl_next(curscop, &cursora)) { - rs->sr_err = mdb_id2entry(op, txn, ida, &a); + rs->sr_err = mdb_id2entry(op, mci, ida, &a); if (rs->sr_err != LDAP_SUCCESS) { continue; } @@ -243,7 +245,7 @@ nextido: * be found, ignore it and move on. This should never happen; * we should never see the ID of an entry that doesn't exist. */ - rs->sr_err = mdb_id2entry(op, txn, ido, &e); + rs->sr_err = mdb_id2entry(op, mci, ido, &e); if ( rs->sr_err != LDAP_SUCCESS ) { goto nextido; } @@ -255,21 +257,16 @@ nextido: * a range and simple iteration hits missing entryIDs */ static int -mdb_get_nextid(struct mdb_info *mdb, MDB_txn *txn, ID *cursor) +mdb_get_nextid(MDB_cursor *mci, ID *cursor) { - MDB_cursor *curs; MDB_val key; ID id; int rc; id = *cursor + 1; - rc = mdb_cursor_open( txn, mdb->mi_id2entry, &curs ); - if ( rc ) - return rc; key.mv_data = &id; key.mv_size = sizeof(ID); - rc = mdb_cursor_get( curs, &key, NULL, MDB_SET_RANGE ); - mdb_cursor_close( curs ); + rc = mdb_cursor_get( mci, &key, NULL, MDB_SET_RANGE ); if ( rc ) return rc; memcpy( cursor, key.mv_data, sizeof(ID)); @@ -292,6 +289,7 @@ mdb_search( Operation *op, SlapReply *rs ) int manageDSAit; int tentries = 0; IdScopes isc; + MDB_cursor *mci; mdb_op_info opinfo = {0}, *moi = &opinfo; MDB_txn *ltid = NULL; @@ -315,6 +313,12 @@ mdb_search( Operation *op, SlapReply *rs ) isc.mc = NULL; isc.scopes = scopes; + rs->sr_err = mdb_cursor_open( ltid, mdb->mi_id2entry, &mci ); + if ( rs->sr_err ) { + send_ldap_error( op, rs, LDAP_OTHER, "internal error" ); + goto done; + } + if ( op->ors_deref & LDAP_DEREF_FINDING ) { MDB_IDL_ZERO(candidates); } @@ -489,7 +493,7 @@ dn2entry_retry: MDB_IDL_ZERO( scopes ); mdb_idl_insert( scopes, base->e_id ); rs->sr_err = search_candidates( op, rs, base, - ltid, candidates, scopes ); + ltid, mci, candidates, scopes ); } /* start cursor at beginning of candidates. @@ -592,7 +596,7 @@ loop_begin: } else { /* get the entry */ - rs->sr_err = mdb_id2entry( op, ltid, id, &e ); + rs->sr_err = mdb_id2entry( op, mci, id, &e ); if (rs->sr_err == LDAP_BUSY) { rs->sr_text = "ldap server busy"; @@ -614,7 +618,7 @@ loop_begin: (long) id, 0, 0 ); } else { /* get the next ID from the DB */ - rs->sr_err = mdb_get_nextid( mdb, ltid, &cursor ); + rs->sr_err = mdb_get_nextid( mci, &cursor ); if ( rs->sr_err == MDB_NOTFOUND ) { break; } @@ -958,6 +962,7 @@ static int search_candidates( SlapReply *rs, Entry *e, MDB_txn *txn, + MDB_cursor *mci, ID *ids, ID *scopes ) { @@ -1024,7 +1029,7 @@ static int search_candidates( } if( op->ors_deref & LDAP_DEREF_SEARCHING ) { - rc = search_aliases( op, rs, e, txn, scopes, stack ); + rc = search_aliases( op, rs, e, txn, mci, scopes, stack ); } else { rc = LDAP_SUCCESS; } -- 2.39.5