X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=servers%2Fslapd%2Fback-bdb%2Fsearch.c;h=1d7e52fb4e7c1ede5488dfc0e45bab873dd74936;hb=34adb8692935262a09e21c62d9bcd0284a272b0c;hp=3a29064538405ac183648ac37f191d440a5aaff4;hpb=b928fa97d89ff76ece9e6fb703e50c121bcc0181;p=openldap diff --git a/servers/slapd/back-bdb/search.c b/servers/slapd/back-bdb/search.c index 3a29064538..1d7e52fb4e 100644 --- a/servers/slapd/back-bdb/search.c +++ b/servers/slapd/back-bdb/search.c @@ -2,7 +2,7 @@ /* $OpenLDAP$ */ /* This work is part of OpenLDAP Software . * - * Copyright 2000-2009 The OpenLDAP Foundation. + * Copyright 2000-2011 The OpenLDAP Foundation. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -310,6 +310,36 @@ sameido: return rs->sr_err; } +/* Get the next ID from the DB. Used if the candidate list is + * a range and simple iteration hits missing entryIDs + */ +static int +bdb_get_nextid(struct bdb_info *bdb, DB_TXN *ltid, ID *cursor) +{ + DBC *curs; + DBT key, data; + ID id, nid; + int rc; + + id = *cursor + 1; + BDB_ID2DISK( id, &nid ); + rc = bdb->bi_id2entry->bdi_db->cursor( + bdb->bi_id2entry->bdi_db, ltid, &curs, bdb->bi_db_opflags ); + if ( rc ) + return rc; + key.data = &nid; + key.size = key.ulen = sizeof(ID); + key.flags = DB_DBT_USERMEM; + data.flags = DB_DBT_USERMEM | DB_DBT_PARTIAL; + data.dlen = data.ulen = 0; + rc = curs->c_get( curs, &key, &data, DB_SET_RANGE ); + curs->c_close( curs ); + if ( rc ) + return rc; + BDB_DISK2ID( &nid, cursor ); + return 0; +} + int bdb_search( Operation *op, SlapReply *rs ) { @@ -717,6 +747,7 @@ fetch_entry_retry: ltid->flags &= ~TXN_DEADLOCK; goto fetch_entry_retry; } +txnfail: opinfo->boi_err = rs->sr_err; send_ldap_error( op, rs, LDAP_BUSY, "ldap server busy" ); goto done; @@ -743,13 +774,32 @@ fetch_entry_retry: LDAP_XSTRING(bdb_search) ": candidate %ld not found\n", (long) id, 0, 0 ); + } else { + /* get the next ID from the DB */ +id_retry: + rs->sr_err = bdb_get_nextid( bdb, ltid, &cursor ); + if ( rs->sr_err == DB_NOTFOUND ) { + break; + } else if ( rs->sr_err == DB_LOCK_DEADLOCK ) { + if ( opinfo ) + goto txnfail; + ltid->flags &= ~TXN_DEADLOCK; + goto id_retry; + } else if ( rs->sr_err == DB_LOCK_NOTGRANTED ) { + goto id_retry; + } + if ( rs->sr_err ) { + rs->sr_err = LDAP_OTHER; + rs->sr_text = "internal error in get_nextid"; + send_ldap_result( op, rs ); + goto done; + } + cursor--; } goto loop_continue; } - rs->sr_entry = e; - if ( is_entry_subentry( e ) ) { if( op->oq_search.rs_scope != LDAP_SCOPE_BASE ) { if(!get_subentries_visibility( op )) { @@ -881,6 +931,7 @@ fetch_entry_retry: blis.bli_lock = lock; blis.bli_flag = BLI_DONTFREE; + rs->sr_entry = e; rs->sr_flags = REP_ENTRY_MUSTRELEASE; send_search_reference( op, rs ); @@ -912,7 +963,7 @@ fetch_entry_retry: } /* if it matches the filter and scope, send it */ - rs->sr_err = test_filter( op, rs->sr_entry, op->oq_search.rs_filter ); + rs->sr_err = test_filter( op, e, op->oq_search.rs_filter ); if ( rs->sr_err == LDAP_COMPARE_TRUE ) { /* check size limit */ @@ -956,9 +1007,13 @@ fetch_entry_retry: rs->sr_attrs = op->oq_search.rs_attrs; rs->sr_operational_attrs = NULL; rs->sr_ctrls = NULL; + rs->sr_entry = e; + RS_ASSERT( e->e_private != NULL ); rs->sr_flags = REP_ENTRY_MUSTRELEASE; rs->sr_err = LDAP_SUCCESS; rs->sr_err = send_search_entry( op, rs ); + rs->sr_attrs = NULL; + rs->sr_entry = NULL; /* send_search_entry will usually free it. * an overlay might leave its own copy here; @@ -976,7 +1031,6 @@ fetch_entry_retry: OpExtra, oe_next ); } } - rs->sr_entry = NULL; e = NULL; switch ( rs->sr_err ) { @@ -1012,6 +1066,7 @@ loop_continue: slap_zn_runlock(bdb->bi_cache.c_zctx, e); #endif bdb_cache_return_entry_r( bdb, e , &lock ); + RS_ASSERT( rs->sr_entry == NULL ); e = NULL; rs->sr_entry = NULL; } @@ -1262,6 +1317,9 @@ parse_paged_cookie( Operation *op, SlapReply *rs ) goto done; } + } else { + /* we're going to use ps_cookie */ + op->o_conn->c_pagedresults_state.ps_cookie = 0; } done:; @@ -1323,4 +1381,3 @@ send_paged_response( done: (void) ber_free_buf( ber ); } -