#include <stdio.h>
#include <ac/string.h>
+#define AVL_INTERNAL
#include "back-bdb.h"
#include "external.h"
static unsigned nhmax = HOLE_SIZE;
static unsigned nholes;
+Avlnode *index_attrs, index_dummy;
+
int bdb_tool_entry_open(
BackendDB *be, int mode )
{
return 0;
}
+static int bdb_reindex_cmp(const void *a, const void *b) { return 0; }
+
ID bdb_tool_entry_next(
BackendDB *be )
{
assert( slapMode & SLAP_TOOL_MODE );
assert( bdb != NULL );
+ /* Initialization */
if (cursor == NULL) {
rc = bdb->bi_id2entry->bdi_db->cursor(
bdb->bi_id2entry->bdi_db, NULL, &cursor,
rc = cursor->c_get( cursor, &key, &data, DB_NEXT );
if( rc != 0 ) {
- return NOID;
+ /* If we're doing linear indexing and there are more attrs to
+ * index, and we're at the end of the database, start over.
+ */
+ if ( bdb->bi_attrs == &index_dummy ) {
+ if ( index_attrs && rc == DB_NOTFOUND ) {
+ /* optional - do a checkpoint here? */
+ index_dummy.avl_data = avl_delete(&index_attrs, NULL, bdb_reindex_cmp);
+ rc = cursor->c_get( cursor, &key, &data, DB_FIRST );
+ }
+ if ( rc ) {
+ bdb->bi_attrs = NULL;
+ return NOID;
+ }
+ } else {
+ return NOID;
+ }
}
if( data.data == NULL ) {
int hole )
{
struct bdb_info *bdb = (struct bdb_info *) op->o_bd->be_private;
- struct berval dn = e->e_nname;
- struct berval pdn;
+ struct berval dn = e->e_name;
+ struct berval ndn = e->e_nname;
+ struct berval pdn, npdn;
EntryInfo *ei = NULL;
int rc;
- rc = bdb_cache_find_ndn( op, tid, &dn, &ei );
+ if (ndn.bv_len == 0) return 0;
+
+ rc = bdb_cache_find_ndn( op, tid, &ndn, &ei );
if ( ei ) bdb_cache_entryinfo_unlock( ei );
if ( rc == DB_NOTFOUND ) {
- if ( be_issuffix( op->o_bd, &dn ) ) {
- pdn = slap_empty_bv;
- } else {
+ if ( !be_issuffix( op->o_bd, &ndn ) ) {
dnParent( &dn, &pdn );
- e->e_nname = pdn;
+ dnParent( &ndn, &npdn );
+ e->e_name = pdn;
+ e->e_nname = npdn;
rc = bdb_tool_next_id( op, tid, e, text, 1 );
- e->e_nname = dn;
+ e->e_name = dn;
+ e->e_nname = ndn;
if ( rc ) {
return rc;
}
}
nhmax *= 2;
}
- ber_dupbv( &holes[nholes].dn, &dn );
+ ber_dupbv( &holes[nholes].dn, &ndn );
holes[nholes++].id = e->e_id;
}
} else if ( !hole ) {
goto done;
}
- rc = bdb_index_entry_add( &op, tid, e );
+ if ( !bdb->bi_linear_index )
+ rc = bdb_index_entry_add( &op, tid, e );
if( rc != 0 ) {
snprintf( text->bv_val, text->bv_len,
"index_entry_add failed: %s (%d)",
(long) id, 0, 0 );
#endif
+ /* No indexes configured, nothing to do. Could return an
+ * error here to shortcut things.
+ */
+ if (!bi->bi_attrs) {
+ return 0;
+ }
+
+ /* Get the first attribute to index */
+ if (bi->bi_linear_index && !index_attrs && bi->bi_attrs != &index_dummy) {
+ index_attrs = bi->bi_attrs;
+ bi->bi_attrs = &index_dummy;
+ index_dummy.avl_data = avl_delete(&index_attrs, NULL, bdb_reindex_cmp);
+ }
+
e = bdb_tool_entry_get( be, id );
if( e == NULL ) {
op.o_tmpmemctx = NULL;
op.o_tmpmfuncs = &ch_mfuncs;
-#ifndef BDB_HIER
+#if 0 /* ndef BDB_HIER */
/* add dn2id indices */
rc = bdb_dn2id_add( &op, tid, NULL, e );
if( rc != 0 && rc != DB_KEYEXIST ) {