Beispiel #1
0
static int
bdb_tool_index_add(
	Operation *op,
	DB_TXN *txn,
	Entry *e )
{
	struct bdb_info *bdb = (struct bdb_info *) op->o_bd->be_private;

	if ( !bdb->bi_nattrs )
		return 0;

	if ( bdb_tool_threads > 1 ) {
		IndexRec *ir;
		int i, rc;
		Attribute *a;
		
		ir = bdb_tool_index_rec;
		memset(ir, 0, bdb->bi_nattrs * sizeof( IndexRec ));

		for ( a = e->e_attrs; a != NULL; a = a->a_next ) {
			rc = bdb_index_recset( bdb, a, a->a_desc->ad_type, 
				&a->a_desc->ad_tags, ir );
			if ( rc )
				return rc;
		}
		bdb_tool_ix_id = e->e_id;
		bdb_tool_ix_op = op;
		ldap_pvt_thread_mutex_lock( &bdb_tool_index_mutex );
		/* Wait for all threads to be ready */
		while ( bdb_tool_index_tcount > 0 ) {
			ldap_pvt_thread_cond_wait( &bdb_tool_index_cond_main, 
				&bdb_tool_index_mutex );
		}
		for ( i=1; i<bdb_tool_threads; i++ )
			bdb_tool_index_threads[i] = LDAP_BUSY;
		bdb_tool_index_tcount = bdb_tool_threads - 1;
		ldap_pvt_thread_cond_broadcast( &bdb_tool_index_cond_work );
		ldap_pvt_thread_mutex_unlock( &bdb_tool_index_mutex );
		rc = bdb_index_recrun( op, bdb, ir, e->e_id, 0 );
		if ( rc )
			return rc;
		ldap_pvt_thread_mutex_lock( &bdb_tool_index_mutex );
		for ( i=1; i<bdb_tool_threads; i++ ) {
			if ( bdb_tool_index_threads[i] == LDAP_BUSY ) {
				ldap_pvt_thread_cond_wait( &bdb_tool_index_cond_main, 
					&bdb_tool_index_mutex );
				i--;
				continue;
			}
			if ( bdb_tool_index_threads[i] ) {
				rc = bdb_tool_index_threads[i];
				break;
			}
		}
		ldap_pvt_thread_mutex_unlock( &bdb_tool_index_mutex );
		return rc;
	} else {
		return bdb_index_entry_add( op, txn, e );
	}
}
Beispiel #2
0
/* Get the list of which indices apply to this attr */
int
bdb_index_recset(
	struct bdb_info *bdb,
	Attribute *a,
	AttributeType *type,
	struct berval *tags,
	IndexRec *ir )
{
	int rc, slot;
	AttrList *al;

	if( type->sat_sup ) {
		/* recurse */
		rc = bdb_index_recset( bdb, a, type->sat_sup, tags, ir );
		if( rc ) return rc;
	}
	/* If this type has no AD, we've never used it before */
	if( type->sat_ad ) {
		slot = bdb_attr_slot( bdb, type->sat_ad, NULL );
		if ( slot >= 0 ) {
			ir[slot].ai = bdb->bi_attrs[slot];
			al = ch_malloc( sizeof( AttrList ));
			al->attr = a;
			al->next = ir[slot].attrs;
			ir[slot].attrs = al;
		}
	}
	if( tags->bv_len ) {
		AttributeDescription *desc;

		desc = ad_find_tags( type, tags );
		if( desc ) {
			slot = bdb_attr_slot( bdb, desc, NULL );
			if ( slot >= 0 ) {
				ir[slot].ai = bdb->bi_attrs[slot];
				al = ch_malloc( sizeof( AttrList ));
				al->attr = a;
				al->next = ir[slot].attrs;
				ir[slot].attrs = al;
			}
		}
	}
	return LDAP_SUCCESS;
}