]> git.sur5r.net Git - openldap/commitdiff
ITS#4554 slapindex takes a list of attributes to index
authorHoward Chu <hyc@openldap.org>
Mon, 15 Jan 2007 01:14:14 +0000 (01:14 +0000)
committerHoward Chu <hyc@openldap.org>
Mon, 15 Jan 2007 01:14:14 +0000 (01:14 +0000)
servers/slapd/back-bdb/tools.c
servers/slapd/slap.h
servers/slapd/slapcommon.c
servers/slapd/slapindex.c

index 475f4acc099906b08f69c8a63db775f86a7398ce..d79bc18d6e562f843d1a492b0f392aa0c206a0f9 100644 (file)
@@ -579,7 +579,8 @@ done:
 
 int bdb_tool_entry_reindex(
        BackendDB *be,
-       ID id )
+       ID id,
+       AttributeDescription **adv )
 {
        struct bdb_info *bi = (struct bdb_info *) be->be_private;
        int rc;
@@ -599,6 +600,45 @@ int bdb_tool_entry_reindex(
                return 0;
        }
 
+       /* Check for explicit list of attrs to index */
+       if ( adv ) {
+               int i, j, n;
+
+               /* count */
+               for ( n = 0; adv[n]; n++ ) ;
+
+               /* insertion sort */
+               for ( i = 0; i < n; i++ ) {
+                       AttributeDescription *ad = adv[i];
+                       for ( j = i-1; j>=0; j--) {
+                               if ( SLAP_PTRCMP( adv[j], ad ) <= 0 ) break;
+                               adv[j+1] = adv[j];
+                       }
+                       adv[j+1] = ad;
+               }
+
+               for ( i = 0; adv[i]; i++ ) {
+                       if ( bi->bi_attrs[i]->ai_desc != adv[i] ) {
+                               for ( j = i+1; j < bi->bi_nattrs; j++ ) {
+                                       if ( bi->bi_attrs[j]->ai_desc == adv[i] ) {
+                                               AttrInfo *ai = bi->bi_attrs[i];
+                                               bi->bi_attrs[i] = bi->bi_attrs[j];
+                                               bi->bi_attrs[j] = ai;
+                                               break;
+                                       }
+                               }
+                               if ( j == bi->bi_nattrs ) {
+                                       Debug( LDAP_DEBUG_ANY,
+                                               LDAP_XSTRING(bdb_tool_entry_reindex)
+                                               ": no index configured for %s\n",
+                                               adv[i]->ad_cname.bv_val, 0, 0 );
+                                       return -1;
+                               }
+                       }
+               }
+               bi->bi_nattrs = i;
+       }
+
        /* Get the first attribute to index */
        if (bi->bi_linear_index && !index_nattrs) {
                index_nattrs = bi->bi_nattrs - 1;
index 930e9fd8226fccf46b62023231125d19604c59ba..fa30ea09cb9927a648017a1ad89985b88bd4e6e4 100644 (file)
@@ -2077,7 +2077,7 @@ typedef ID (BI_tool_entry_next) LDAP_P(( BackendDB *be ));
 typedef Entry* (BI_tool_entry_get) LDAP_P(( BackendDB *be, ID id ));
 typedef ID (BI_tool_entry_put) LDAP_P(( BackendDB *be, Entry *e, 
        struct berval *text ));
-typedef int (BI_tool_entry_reindex) LDAP_P(( BackendDB *be, ID id ));
+typedef int (BI_tool_entry_reindex) LDAP_P(( BackendDB *be, ID id, AttributeDescription **adv ));
 typedef int (BI_tool_sync) LDAP_P(( BackendDB *be ));
 typedef ID (BI_tool_dn2id_get) LDAP_P(( BackendDB *be, struct berval *dn ));
 typedef int (BI_tool_id2entry_get) LDAP_P(( BackendDB *be, ID id, Entry **e ));
index 37a91a1801dbc79923623e905a1d0b302430f53c..70843c731e9c6c2317c568974ad916eafb46de17 100644 (file)
@@ -88,7 +88,7 @@ usage( int tool, const char *progname )
                break;
 
        case SLAPINDEX:
-               options = " [-c]\n\t[-g] [-n databasenumber | -b suffix] [-q]\n";
+               options = " [-c]\n\t[-g] [-n databasenumber | -b suffix] [attr ...] [-q]\n";
                break;
 
        case SLAPTEST:
@@ -441,13 +441,19 @@ slap_tool_init(
        switch ( tool ) {
        case SLAPADD:
        case SLAPCAT:
-       case SLAPINDEX:
                if ( ( argc != optind ) || (dbnum >= 0 && base.bv_val != NULL ) ) {
                        usage( tool, progname );
                }
 
                break;
 
+       case SLAPINDEX:
+               if ( dbnum >= 0 && base.bv_val != NULL ) {
+                       usage( tool, progname );
+               }
+
+               break;
+
        case SLAPDN:
                if ( argc == optind ) {
                        usage( tool, progname );
index 21734f1e116dadcd9c863033a419e2f3899009d1..e7c2d9e8e9b97c89b4ef76f01e1fc03f133513d4 100644 (file)
@@ -37,6 +37,7 @@ slapindex( int argc, char **argv )
        ID id;
        int rc = EXIT_SUCCESS;
        const char *progname = "slapindex";
+       AttributeDescription *ad, **adv = NULL;
 
        slap_tool_init( progname, SLAPINDEX, argc, argv );
 
@@ -51,12 +52,32 @@ slapindex( int argc, char **argv )
                exit( EXIT_FAILURE );
        }
 
+       argc -= optind;
+       if ( argc > 0 ) {
+               const char *text;
+               int i;
+
+               argv = &argv[optind];
+               adv = (AttributeDescription **)argv;
+
+               for (i = 0; i < argc; i++ ) {
+                       ad = NULL;
+                       rc = slap_str2ad( argv[i], &ad, &text );
+                       if ( rc != LDAP_SUCCESS ) {
+                               fprintf( stderr, "slap_str2ad(%s) failed %d (%s)\n",
+                                       argv[i], rc, ldap_err2string( rc ));
+                               exit( EXIT_FAILURE );
+                       }
+                       adv[i] = ad;
+               }
+       }
+
        if( be->be_entry_open( be, 0 ) != 0 ) {
                fprintf( stderr, "%s: could not open database.\n",
                        progname );
                exit( EXIT_FAILURE );
        }
-
+       
        for ( id = be->be_entry_first( be );
                id != NOID;
                id = be->be_entry_next( be ) )
@@ -67,7 +88,11 @@ slapindex( int argc, char **argv )
                        printf("indexing id=%08lx\n", (long) id );
                }
 
-               rtn =  be->be_entry_reindex( be, id );
+               /* Backend will set its attr list on first call. Clear
+                * the list on all subsequent calls.
+                */
+               rtn =  be->be_entry_reindex( be, id, adv );
+               adv = NULL;
 
                if( rtn != LDAP_SUCCESS ) {
                        rc = EXIT_FAILURE;