Merge branch 'master' of ssh://git-master.openldap.org/~git/git/openldap

This commit is contained in:
Quanah Gibson-Mount 2011-09-08 14:06:30 -07:00
commit d97d1e148c
7 changed files with 827 additions and 810 deletions

View file

@ -338,6 +338,7 @@ wait4msg(
}
if ( lc_ready ) {
LDAPConn *lnext;
int serviced = 0;
rc = LDAP_MSG_X_KEEP_LOOKING;
LDAP_MUTEX_LOCK( &ld->ld_req_mutex );
if ( ld->ld_requests &&
@ -345,6 +346,7 @@ wait4msg(
ldap_is_write_ready( ld,
ld->ld_requests->lr_conn->lconn_sb ) )
{
serviced = 1;
ldap_int_flush_request( ld, ld->ld_requests );
}
for ( lc = ld->ld_conns;
@ -354,6 +356,7 @@ wait4msg(
if ( lc->lconn_status == LDAP_CONNST_CONNECTED &&
ldap_is_read_ready( ld, lc->lconn_sb ) )
{
serviced = 1;
/* Don't let it get freed out from under us */
++lc->lconn_refcnt;
rc = try_read1msg( ld, msgid, all, lc, result );
@ -370,6 +373,9 @@ wait4msg(
}
}
LDAP_MUTEX_UNLOCK( &ld->ld_req_mutex );
/* Quit looping if no one handled any events */
if (!serviced)
rc = -1;
}
LDAP_MUTEX_UNLOCK( &ld->ld_conn_mutex );
}

File diff suppressed because it is too large Load diff

129
libraries/libmdb/mtest5.c Normal file
View file

@ -0,0 +1,129 @@
/* mtest5.c - memory-mapped database tester/toy */
/*
* Copyright 2011 Howard Chu, Symas Corp.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted only as authorized by the OpenLDAP
* Public License.
*
* A copy of this license is available in the file LICENSE in the
* top-level directory of the distribution or, alternatively, at
* <http://www.OpenLDAP.org/license.html>.
*/
/* Tests for sorted duplicate DBs using cursor_put */
#define _XOPEN_SOURCE 500 /* srandom(), random() */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include "mdb.h"
int main(int argc,char * argv[])
{
int i = 0, j = 0, rc;
MDB_env *env;
MDB_dbi dbi;
MDB_val key, data;
MDB_txn *txn;
MDB_stat mst;
MDB_cursor *cursor;
int count;
int *values;
char sval[32];
char kval[sizeof(int)];
srandom(time(NULL));
memset(sval, 0, sizeof(sval));
count = (random()%384) + 64;
values = (int *)malloc(count*sizeof(int));
for(i = 0;i<count;i++) {
values[i] = random()%1024;
}
rc = mdb_env_create(&env);
rc = mdb_env_set_mapsize(env, 10485760);
rc = mdb_env_set_maxdbs(env, 4);
rc = mdb_env_open(env, "./testdb", MDB_FIXEDMAP|MDB_NOSYNC, 0664);
rc = mdb_txn_begin(env, 0, &txn);
rc = mdb_open(txn, "id2", MDB_CREATE|MDB_DUPSORT, &dbi);
rc = mdb_cursor_open(txn, dbi, &cursor);
key.mv_size = sizeof(int);
key.mv_data = kval;
data.mv_size = sizeof(sval);
data.mv_data = sval;
printf("Adding %d values\n", count);
for (i=0;i<count;i++) {
if (!(i & 0x0f))
sprintf(kval, "%03x", values[i]);
sprintf(sval, "%03x %d foo bar", values[i], values[i]);
rc = mdb_cursor_put(cursor, &key, &data, MDB_NODUPDATA);
if (rc) j++;
}
if (j) printf("%d duplicates skipped\n", j);
mdb_cursor_close(cursor);
rc = mdb_txn_commit(txn);
rc = mdb_env_stat(env, &mst);
rc = mdb_txn_begin(env, 1, &txn);
rc = mdb_cursor_open(txn, dbi, &cursor);
while ((rc = mdb_cursor_get(cursor, &key, &data, MDB_NEXT)) == 0) {
printf("key: %p %.*s, data: %p %.*s\n",
key.mv_data, (int) key.mv_size, (char *) key.mv_data,
data.mv_data, (int) data.mv_size, (char *) data.mv_data);
}
mdb_cursor_close(cursor);
mdb_txn_abort(txn);
j=0;
for (i= count - 1; i > -1; i-= (random()%5)) {
j++;
txn=NULL;
rc = mdb_txn_begin(env, 0, &txn);
sprintf(kval, "%03x", values[i & ~0x0f]);
sprintf(sval, "%03x %d foo bar", values[i], values[i]);
key.mv_size = sizeof(int);
key.mv_data = kval;
data.mv_size = sizeof(sval);
data.mv_data = sval;
rc = mdb_del(txn, dbi, &key, &data);
if (rc) {
j--;
mdb_txn_abort(txn);
} else {
rc = mdb_txn_commit(txn);
}
}
free(values);
printf("Deleted %d values\n", j);
rc = mdb_env_stat(env, &mst);
rc = mdb_txn_begin(env, 1, &txn);
rc = mdb_cursor_open(txn, dbi, &cursor);
printf("Cursor next\n");
while ((rc = mdb_cursor_get(cursor, &key, &data, MDB_NEXT)) == 0) {
printf("key: %.*s, data: %.*s\n",
(int) key.mv_size, (char *) key.mv_data,
(int) data.mv_size, (char *) data.mv_data);
}
printf("Cursor prev\n");
while ((rc = mdb_cursor_get(cursor, &key, &data, MDB_PREV)) == 0) {
printf("key: %.*s, data: %.*s\n",
(int) key.mv_size, (char *) key.mv_data,
(int) data.mv_size, (char *) data.mv_data);
}
mdb_cursor_close(cursor);
mdb_close(txn, dbi);
mdb_txn_abort(txn);
mdb_env_close(env);
return 0;
}

View file

@ -530,8 +530,12 @@ int mdb_ad_read( struct mdb_info *mdb, MDB_txn *txn )
AttributeDescription *ad;
rc = mdb_cursor_open( txn, mdb->mi_ad2id, &mc );
if ( rc )
if ( rc ) {
Debug( LDAP_DEBUG_ANY,
"mdb_ad_read: cursor_open failed %s(%d)\n",
mdb_strerror(rc), rc, 0);
return rc;
}
/* our array is 1-based, an index of 0 means no data */
i = mdb->mi_numads+1;
@ -569,6 +573,9 @@ int mdb_ad_get( struct mdb_info *mdb, MDB_txn *txn, AttributeDescription *ad )
MDB_val key;
rc = mdb_ad_read( mdb, txn );
if (rc)
return rc;
if ( mdb->mi_adxs[ad->ad_index] )
return 0;
@ -581,6 +588,10 @@ int mdb_ad_get( struct mdb_info *mdb, MDB_txn *txn, AttributeDescription *ad )
mdb->mi_adxs[ad->ad_index] = i;
mdb->mi_ads[i] = ad;
mdb->mi_numads++;
} else {
Debug( LDAP_DEBUG_ANY,
"mdb_ad_get: mdb_put failed %s(%d)\n",
mdb_strerror(rc), rc, 0);
}
return rc;

View file

@ -42,12 +42,18 @@ static int mdb_id2entry_put(
rc = mdb_entry_encode( op, tid, e, &data );
if( rc != LDAP_SUCCESS ) {
return -1;
return LDAP_OTHER;
}
rc = mdb_put( tid, dbi, &key, &data, flag );
op->o_tmpfree( data.mv_data, op->o_tmpmemctx );
if (rc) {
Debug( LDAP_DEBUG_ANY,
"mdb_id2entry_put: mdb_put failed: %s(%d) \"%s\"\n",
mdb_strerror(rc), rc,
e->e_nname.bv_val );
rc = LDAP_OTHER;
}
return rc;
}
@ -482,6 +488,7 @@ static int mdb_entry_partsize(struct mdb_info *mdb, MDB_txn *txn, Entry *e,
eh->bv.bv_len = len;
eh->nattrs = nat;
eh->nvals = nval;
return 0;
}
/* Flatten an Entry into a buffer. The buffer is filled with just the
@ -507,6 +514,7 @@ static int mdb_entry_encode(Operation *op, MDB_txn *txn, Entry *e, MDB_val *data
; /* empty */
rc = mdb_entry_partsize( mdb, txn, e, &eh );
if (rc) return rc;
data->mv_size = eh.bv.bv_len;
data->mv_data = op->o_tmpalloc(data->mv_size, op->o_tmpmemctx);

View file

@ -313,6 +313,7 @@ mdb_search( Operation *op, SlapReply *rs )
ltid = moi->moi_txn;
isc.mt = ltid;
isc.mc = NULL;
isc.scopes = scopes;
if ( op->ors_deref & LDAP_DEREF_FINDING ) {
MDB_IDL_ZERO(candidates);
@ -552,8 +553,6 @@ dn2entry_retry:
goto loop_begin;
}
isc.scopes = scopes;
for ( id = mdb_idl_first( candidates, &cursor );
id != NOID ; id = mdb_idl_next( candidates, &cursor ) )
{

View file

@ -257,6 +257,9 @@ while [ $COUNTER -le $LOOP ]; do
fi
if [ $RC -ne 0 ]; then
if [ $LOOP -gt 1 ]; then
echo "Failed after $COUNTER of $LOOP iterations"
fi
exit $RC
else
COUNTER=`expr $COUNTER + 1`