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;
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;
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 ));
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:
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 );
ID id;
int rc = EXIT_SUCCESS;
const char *progname = "slapindex";
+ AttributeDescription *ad, **adv = NULL;
slap_tool_init( progname, SLAPINDEX, argc, 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 ) )
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;