From 321780eb66babb690901e88a021c46dfe567d742 Mon Sep 17 00:00:00 2001 From: Howard Chu Date: Wed, 26 Feb 2003 15:33:20 +0000 Subject: [PATCH] Complain about holes in database at end of slapadd --- servers/slapd/back-bdb/tools.c | 54 ++++++++++++++++++++++++++++++++-- servers/slapd/tools/slapadd.c | 2 +- 2 files changed, 52 insertions(+), 4 deletions(-) diff --git a/servers/slapd/back-bdb/tools.c b/servers/slapd/back-bdb/tools.c index bf9a5bc690..cd7a446041 100644 --- a/servers/slapd/back-bdb/tools.c +++ b/servers/slapd/back-bdb/tools.c @@ -15,6 +15,16 @@ static DBC *cursor = NULL; static DBT key, data; +typedef struct dn_id { + ID id; + struct berval dn; +} dn_id; + +#define HOLE_SIZE 4096 +dn_id hbuf[HOLE_SIZE], *holes = hbuf; +unsigned nhmax = HOLE_SIZE; +unsigned nholes; + int bdb_tool_entry_open( BackendDB *be, int mode ) { @@ -46,6 +56,16 @@ int bdb_tool_entry_close( cursor = NULL; } + if( nholes ) { + unsigned i; + fprintf( stderr, "Error, entries missing!\n"); + for (i=0; ibe_private; struct berval dn = e->e_nname; @@ -126,7 +147,7 @@ int bdb_tool_next_id( } else { dnParent( &dn, &pdn ); e->e_nname = pdn; - rc = bdb_tool_next_id( be, tid, e, text ); + rc = bdb_tool_next_id( be, tid, e, text, 1 ); if ( rc ) { return rc; } @@ -158,6 +179,33 @@ int bdb_tool_next_id( Debug( LDAP_DEBUG_ANY, "=> bdb_tool_entry_put: %s\n", text->bv_val, 0, 0 ); #endif + } else if ( hole ) { + if ( nholes == nhmax - 1 ) { + if ( holes == hbuf ) { + holes = malloc( nhmax * sizeof(ID) * 2 ); + AC_MEMCPY( holes, hbuf, sizeof(hbuf) ); + } else { + holes = realloc( holes, nhmax * sizeof(ID) * 2 ); + } + nhmax *= 2; + } + ber_dupbv( &holes[nholes].dn, &dn ); + holes[nholes++].id = e->e_id; + } + } else if ( !hole ) { + unsigned i; + + for ( i=0; ie_id ) { + int j; + free(holes[i].dn.bv_val); + for (j=i;j e->e_id ) { + break; + } } } return rc; @@ -205,7 +253,7 @@ ID bdb_tool_entry_put( } /* add dn2id indices */ - rc = bdb_tool_next_id( be, tid, e, text ); + rc = bdb_tool_next_id( be, tid, e, text, 0 ); if( rc != 0 ) { goto done; } diff --git a/servers/slapd/tools/slapadd.c b/servers/slapd/tools/slapadd.c index af26cdd4e7..edb068278c 100644 --- a/servers/slapd/tools/slapadd.c +++ b/servers/slapd/tools/slapadd.c @@ -301,7 +301,7 @@ main( int argc, char **argv ) ch_free( buf ); - be->be_entry_close( be ); + if( be->be_entry_close( be )) rc = EXIT_FAILURE; if( be->be_sync ) { be->be_sync( be ); -- 2.39.5