SlapReply *rs
);
-void
+static void
add_func (
Operation *op,
SlapReply *rs
SlapReply *rs
);
+static int
+null_response (
+ Operation *op,
+ SlapReply *rs
+);
+
+static int
+normalize_values( Attribute* attr );
+
struct entry_info {
int size_init;
int size_final;
Backend* glue_be;
};
+
int
get_entry_size(
Entry* e,
{
switch ( rs->sr_type ) {
case REP_SEARCH:
- add_func( op, rs );
+ merge_func( op, rs );
break;
case REP_RESULT:
- merge_func( op, rs );
+ add_func( op, rs );
break;
+
+ default:
+ assert( 0 );
}
return 0;
}
struct berval normdn;
struct berval prettydn;
+ SlapReply sreply = {REP_RESULT};
+
Operation op_tmp = *op;
slap_callback cb = { add_merge_func, NULL };
Filter* filter = str2filter( bv_queryid_any.bv_val );
+ sreply.sr_entry = NULL;
+ sreply.sr_nentries = 0;
dnPrettyNormal(0, &rs->sr_entry->e_name, &prettydn, &normdn,
op->o_tmpmemctx);
op_tmp.ors_attrs = NULL;
op_tmp.ors_attrsonly = 0;
- op->o_bd->be_search( &op_tmp, rs );
+ op->o_bd->be_search( &op_tmp, &sreply );
result->type = info.err;
if ( result->type == SUCCESS )
result->rc = info.added;
AttributeDescription *a_new_desc;
const char *text = NULL;
Operation op_tmp = *op;
+ SlapReply sreply = {REP_RESULT};
+ SlapReply sreply1 = {REP_RESULT};
info->err = SUCCESS;
mod->sml_op = LDAP_MOD_REPLACE;
ber_dupbv(&mod->sml_type, &a_new_desc->ad_cname);
- for (count = 0; a_new->a_vals[count].bv_val; count++)
+ for ( count = 0; a_new->a_vals[count].bv_val; count++ )
;
+
mod->sml_bvalues = (struct berval*) malloc(
(count+1) * sizeof( struct berval) );
- for (i=0; i < count; i++) {
+ for ( i = 0; i < count; i++ ) {
ber_dupbv(mod->sml_bvalues+i, a_new->a_vals+i);
}
op_tmp.o_req_ndn = entry->e_nname;
op_tmp.orm_modlist = modhead;
- if (be->be_modify(op, rs ) != 0 ) {
+ op_tmp.o_callback->sc_response = null_response;
+ /* FIXME: &op_tmp ??? */
+ if (be->be_modify(op, &sreply ) != 0 ) {
/* FIXME: cleanup ? */
info->err = MERGE_ERR;
- return 0;
+ goto cleanup;
}
/* compute the size of the entry */
op_tmp.ors_filterstr = bv_queryid_any;
op_tmp.ors_attrs = NULL;
op_tmp.ors_attrsonly = 0;
-
- if (be->be_search( &op_tmp, rs ) != 0) {
+
+ sreply1.sr_entry = NULL;
+ sreply1.sr_nentries = 0;
+
+ if (be->be_search( &op_tmp, &sreply1 ) != 0) {
info->err = GET_SIZE_ERR;
}
+cleanup:;
+ if ( modhead != NULL) {
+ slap_mods_free( modhead );
+ }
+
return 0;
}
-void
+static void
add_func (
Operation *op,
SlapReply *rs
Backend *be;
BerVarray value_array;
Entry *e;
- Attribute *a;
+ Attribute *a, *attr;
+ int i,j;
+ SlapReply sreply = {REP_RESULT};
struct timeval time; /* time */
long timediff; /* time */
* new entry, construct an entry with
* the projected attributes
*/
- if (rs->sr_nentries)
- return;
+ if (rs->sr_nentries) {
+ return;
+ }
+ op_tmp.o_callback->sc_response = null_response;
be = select_backend(&entry->e_nname, 0, 0);
e = (Entry*)malloc(sizeof(Entry));
a->a_next = entry->e_attrs;
entry->e_attrs = NULL;
- info->size_final = get_entry_size(e, 0, NULL);
+ for ( attr = e->e_attrs; attr; attr = attr->a_next ) {
+ if ( normalize_values( attr ) ) {
+ info->err = MERGE_ERR;
+ return;
+ }
+ }
+
+ info->size_final = get_entry_size( e, 0, NULL );
op_tmp.o_bd = be;
op_tmp.ora_e = e;
- if ( be->be_add( &op_tmp, rs ) == 0 ) {
+ if ( be->be_add( &op_tmp, &sreply ) == 0 ) {
info->added = 1;
be_entry_release_w( &op_tmp, e );
} else {
return 0;
}
+
+static int
+null_response (
+ Operation *op,
+ SlapReply *rs )
+{
+ return 0;
+}
+
+static int
+normalize_values( Attribute* attr )
+{
+ int nvals, rc, i;
+
+ if (attr->a_vals == NULL) {
+ attr->a_nvals = NULL;
+ return 0;
+ }
+
+ for ( nvals = 0; attr->a_vals[nvals].bv_val; nvals++ )
+ ;
+
+ attr->a_nvals = (struct berval*)ch_malloc((nvals+1)*sizeof(struct berval));
+
+ if ( attr->a_desc->ad_type->sat_equality &&
+ attr->a_desc->ad_type->sat_equality->smr_normalize )
+ {
+ for ( i = 0; i < nvals; i++ ) {
+ rc = attr->a_desc->ad_type->sat_equality->smr_normalize(
+ 0,
+ attr->a_desc->ad_type->sat_syntax,
+ attr->a_desc->ad_type->sat_equality,
+ &attr->a_vals[i], &attr->a_nvals[i], NULL );
+ if ( rc ) {
+#ifdef NEW_LOGGING
+ LDAP_LOG( OPERATION, DETAIL1,
+ "Error in normalizing attribute %s value %d (%d)\n",
+ attr->a_desc->ad_cname.bv_val, i, rc );
+#else
+ Debug( LDAP_DEBUG_ANY,
+ "Error in normalizing attribute %s value %d (%d)\n",
+ attr->a_desc->ad_cname.bv_val, i, rc );
+#endif
+ return rc;
+ }
+ }
+ } else {
+ for ( i = 0; i < nvals; i++ ) {
+ ber_dupbv( &attr->a_nvals[i], &attr->a_vals[i] );
+ }
+ }
+
+ attr->a_nvals[i].bv_val = NULL;
+ attr->a_nvals[i].bv_len = 0;
+
+ return LDAP_SUCCESS;
+}
+
#endif /* LDAP_CACHING */
int template_id
);
-static void
+static void*
consistency_check(
- Operation *op,
- SlapReply *rs,
- Backend *glue_be
+ void *op
);
static int
SlapReply *rs
);
+
int
meta_back_cache_search(
Operation *op,
attrs[ count ].an_name.bv_len = 0;
}
+
result->type = SUCCESS;
result->rc = 0;
ldap_pvt_thread_mutex_lock(&cm->cache_mutex);
#endif /* !NEW_LOGGING */
ldap_pvt_thread_mutex_unlock(&cm->cache_mutex);
+ ldap_pvt_thread_mutex_lock(&cm->cc_mutex);
+ if (!cm->cc_thread_started) {
+ cm->cc_thread_started = 1;
+ ldap_pvt_thread_create(&(cm->cc_thread), 1, consistency_check, (void*)op);
+ }
+ ldap_pvt_thread_mutex_unlock(&cm->cc_mutex);
+
filter2template(filter, &tempstr, &filter_attrs, &fattr_cnt, result);
if (result->type != SUCCESS)
goto Catch;
op_tmp.o_caching_on = 1;
op_tmp.o_callback = &cb;
- li->glue_be->be_search(op, rs);
- ber_memfree( ncachebase.bv_val );
+ li->glue_be->be_search(&op_tmp, rs);
+ free( ncachebase.bv_val );
if ( cachebase.bv_val != op->o_req_dn.bv_val ) {
/* free only if rewritten */
free( cachebase.bv_val );
ldap_pvt_thread_rdwr_runlock(&qm->templates[i].t_rwlock);
} else {
+ Operation op_tmp = *op;
+
#ifdef NEW_LOGGING
LDAP_LOG( BACK_META, DETAIL1, "QUERY NOT ANSWERABLE\n",
0, 0, 0 );
Debug( LDAP_DEBUG_ANY, "QUERY NOT ANSWERABLE\n", 0, 0, 0 );
#endif /* !NEW_LOGGING */
- if ( op->ors_scope == LDAP_SCOPE_BASE ) {
+ if ( op_tmp.ors_scope == LDAP_SCOPE_BASE ) {
op_type = META_OP_REQUIRE_SINGLE;
} else {
op_type = META_OP_ALLOW_MULTIPLE;
}
- lc = metaConnect(op, rs, op_type,
- &op->o_req_ndn, result);
+ lc = metaConnect(&op_tmp, rs, op_type,
+ &op_tmp.o_req_ndn, result);
if (result->type != SUCCESS)
goto Catch;
/*
* Inits searches
*/
-
for ( i = 0, lsc = lc->conns; !META_LAST(lsc); ++i, ++lsc ) {
char *realbase = ( char * )op->o_req_dn.bv_val;
int realscope = op->ors_scope;
++candidates;
}
- num_entries = handleLdapResult(lc, op, rs, msgid,
+ num_entries = handleLdapResult(lc, &op_tmp, rs, msgid,
op->o_bd, attrs,
op->ors_attrsonly, candidates,
cacheable, &entry_array,
if (result->type != SUCCESS)
goto Catch;
if (cacheable && (num_entries <= curr_limit)) {
- Operation op_tmp = *op;
#ifdef NEW_LOGGING
LDAP_LOG( BACK_META, DETAIL1,
break;
}
- ldap_pvt_thread_mutex_lock(&cm->consistency_mutex);
- curr_time = slap_get_time();
- if (curr_time - cm->consistency_time > cm->consistency_cycle_time) {
- cm->consistency_time = curr_time;
- consistency_check(op, rs, li->glue_be);
- }
- ldap_pvt_thread_mutex_unlock(&cm->consistency_mutex);
if ( msgid ) {
ch_free( msgid );
attr->a_flags = 0;
attr->a_next = 0;
attr->a_desc = NULL;
+ attr->a_nvals = NULL;
if ( slap_bv2ad( &mapped, &attr->a_desc, &text ) != LDAP_SUCCESS) {
if ( slap_bv2undef_ad( &mapped, &attr->a_desc, &text )
!= LDAP_SUCCESS) {
static struct metaconn*
metaConnect(
- Operation* op,
+ Operation *op,
SlapReply *rs,
int op_type,
struct berval *nbase,
AttributeName* attrs,
AttributeName* filter_attrs )
{
- struct berval all_user = { sizeof(LDAP_ALL_USER_ATTRIBUTES) -1,
- LDAP_ALL_USER_ATTRIBUTES };
-
- struct berval all_op = { sizeof(LDAP_ALL_OPERATIONAL_ATTRIBUTES) -1,
- LDAP_ALL_OPERATIONAL_ATTRIBUTES};
+ struct berval all_user = BER_BVC(LDAP_ALL_USER_ATTRIBUTES);
+ struct berval all_op = BER_BVC(LDAP_ALL_OPERATIONAL_ATTRIBUTES);
int alluser = 0;
int allop = 0;
if ((entry = get_result_entry(be, lc, lsc,
msgid, i, &tv, result))) {
rs->sr_entry = entry;
+ rs->sr_attrs = op->ors_attrs;
send_search_entry( op, rs );
rs->sr_entry = NULL;
+ rs->sr_attrs = NULL;
if ((cacheable) &&
(num_entries < curr_limit)) {
rewriteSession( li->rwinfo,
return 0;
}
-static void
-consistency_check(Operation *op, SlapReply *rs, Backend* glue_be)
+static void*
+consistency_check(void* operation)
{
- struct metainfo *li = ( struct metainfo * )op->o_bd->be_private;
+ Operation* op_tmp = (Operation*)operation;
+
+ Operation op = *op_tmp;
+ SlapReply rs = {REP_RESULT};
+
+ struct metainfo *li = ( struct metainfo * )op.o_bd->be_private;
cache_manager* cm = li->cm;
query_manager* qm = cm->qm;
CachedQuery* query, *query_prev;
struct exception result;
int i, return_val;
QueryTemplate* templ;
- Backend *be = op->o_bd;
- op->o_bd = glue_be;
+
+ op.o_bd = li->glue_be;
- for (i=0; qm->templates[i].querystr; i++) {
- templ = qm->templates + i;
- query = templ->query_last;
- curr_time = slap_get_time();
- ldap_pvt_thread_mutex_lock(&cm->remove_mutex);
- while (query && (query->expiry_time < curr_time)) {
- ldap_pvt_thread_mutex_lock(&qm->lru_mutex);
- remove_query(qm, query);
- ldap_pvt_thread_mutex_unlock(&qm->lru_mutex);
+ for(;;) {
+ ldap_pvt_thread_sleep(cm->cc_period);
+ for (i=0; qm->templates[i].querystr; i++) {
+ templ = qm->templates + i;
+ query = templ->query_last;
+ curr_time = slap_get_time();
+ ldap_pvt_thread_mutex_lock(&cm->remove_mutex);
+ while (query && (query->expiry_time < curr_time)) {
+ ldap_pvt_thread_mutex_lock(&qm->lru_mutex);
+ remove_query(qm, query);
+ ldap_pvt_thread_mutex_unlock(&qm->lru_mutex);
#ifdef NEW_LOGGING
- LDAP_LOG( BACK_META, DETAIL1, "Lock CR index = %d\n",
- i, 0, 0 );
+ LDAP_LOG( BACK_META, DETAIL1, "Lock CR index = %d\n",
+ i, 0, 0 );
#else /* !NEW_LOGGING */
- Debug( LDAP_DEBUG_ANY, "Lock CR index = %d\n",
- i, 0, 0 );
+ Debug( LDAP_DEBUG_ANY, "Lock CR index = %d\n",
+ i, 0, 0 );
#endif /* !NEW_LOGGING */
- ldap_pvt_thread_rdwr_wlock(&templ->t_rwlock);
- remove_from_template(query, templ);
+ ldap_pvt_thread_rdwr_wlock(&templ->t_rwlock);
+ remove_from_template(query, templ);
#ifdef NEW_LOGGING
- LDAP_LOG( BACK_META, DETAIL1,
- "TEMPLATE %d QUERIES-- %d\n",
- i, templ->no_of_queries, 0 );
+ LDAP_LOG( BACK_META, DETAIL1,
+ "TEMPLATE %d QUERIES-- %d\n",
+ i, templ->no_of_queries, 0 );
#else /* !NEW_LOGGING */
- Debug( LDAP_DEBUG_ANY, "TEMPLATE %d QUERIES-- %d\n",
- i, templ->no_of_queries, 0 );
+ Debug( LDAP_DEBUG_ANY, "TEMPLATE %d QUERIES-- %d\n",
+ i, templ->no_of_queries, 0 );
#endif /* !NEW_LOGGING */
#ifdef NEW_LOGGING
- LDAP_LOG( BACK_META, DETAIL1, "Unlock CR index = %d\n",
- i, 0, 0 );
+ LDAP_LOG( BACK_META, DETAIL1, "Unlock CR index = %d\n",
+ i, 0, 0 );
#else /* !NEW_LOGGING */
- Debug( LDAP_DEBUG_ANY, "Unlock CR index = %d\n",
- i, 0, 0 );
+ Debug( LDAP_DEBUG_ANY, "Unlock CR index = %d\n",
+ i, 0, 0 );
#endif /* !NEW_LOGGING */
- ldap_pvt_thread_rdwr_wunlock(&templ->t_rwlock);
- uuid.bv_val = query->q_uuid;
- uuid.bv_len = strlen(query->q_uuid);
- return_val = remove_query_data(op, rs, &uuid, &result);
+ ldap_pvt_thread_rdwr_wunlock(&templ->t_rwlock);
+ uuid.bv_val = query->q_uuid;
+ uuid.bv_len = strlen(query->q_uuid);
+ return_val = remove_query_data(&op, &rs, &uuid, &result);
#ifdef NEW_LOGGING
- LDAP_LOG( BACK_META, DETAIL1,
- "STALE QUERY REMOVED, SIZE=%d\n",
- return_val, 0, 0 );
-#else /* !NEW_LOGGING */
- Debug( LDAP_DEBUG_ANY, "STALE QUERY REMOVED, SIZE=%d\n",
+ LDAP_LOG( BACK_META, DETAIL1,
+ "STALE QUERY REMOVED, SIZE=%d\n",
return_val, 0, 0 );
+#else /* !NEW_LOGGING */
+ Debug( LDAP_DEBUG_ANY, "STALE QUERY REMOVED, SIZE=%d\n",
+ return_val, 0, 0 );
#endif /* !NEW_LOGGING */
- ldap_pvt_thread_mutex_lock(&cm->cache_mutex);
- cm->total_entries -= result.rc;
- cm->num_cached_queries--;
+ ldap_pvt_thread_mutex_lock(&cm->cache_mutex);
+ cm->total_entries -= result.rc;
+ cm->num_cached_queries--;
#ifdef NEW_LOGGING
- LDAP_LOG( BACK_META, DETAIL1, "STORED QUERIES = %lu\n",
- cm->num_cached_queries, 0, 0 );
+ LDAP_LOG( BACK_META, DETAIL1, "STORED QUERIES = %lu\n",
+ cm->num_cached_queries, 0, 0 );
#else /* !NEW_LOGGING */
- Debug( LDAP_DEBUG_ANY, "STORED QUERIES = %lu\n",
- cm->num_cached_queries, 0, 0 );
+ Debug( LDAP_DEBUG_ANY, "STORED QUERIES = %lu\n",
+ cm->num_cached_queries, 0, 0 );
#endif /* !NEW_LOGGING */
- ldap_pvt_thread_mutex_unlock(&cm->cache_mutex);
- cm->cache_size = (return_val > cm->cache_size) ?
- 0: (cm->cache_size-return_val);
+ ldap_pvt_thread_mutex_unlock(&cm->cache_mutex);
+ cm->cache_size = (return_val > cm->cache_size) ?
+ 0: (cm->cache_size-return_val);
#ifdef NEW_LOGGING
- LDAP_LOG( BACK_META, DETAIL1,
- "STALE QUERY REMOVED, CACHE SIZE=%lu bytes %d "
- "entries\n", cm->cache_size,
- cm->total_entries, 0 );
+ LDAP_LOG( BACK_META, DETAIL1,
+ "STALE QUERY REMOVED, CACHE SIZE=%lu bytes %d "
+ "entries\n", cm->cache_size,
+ cm->total_entries, 0 );
#else /* !NEW_LOGGING */
- Debug( LDAP_DEBUG_ANY,
- "STALE QUERY REMOVED, CACHE SIZE=%lu bytes %d "
- "entries\n", cm->cache_size,
- cm->total_entries, 0 );
+ Debug( LDAP_DEBUG_ANY,
+ "STALE QUERY REMOVED, CACHE SIZE=%lu bytes %d "
+ "entries\n", cm->cache_size,
+ cm->total_entries, 0 );
#endif /* !NEW_LOGGING */
- query_prev = query;
- query = query->prev;
- free_query(query_prev);
+ query_prev = query;
+ query = query->prev;
+ free_query(query_prev);
+ }
+ ldap_pvt_thread_mutex_unlock(&cm->remove_mutex);
}
- ldap_pvt_thread_mutex_unlock(&cm->remove_mutex);
}
-
- op->o_bd = be;
}
static int
SlapReply *rs )
{
slap_callback *cb = op->o_callback;
- struct metainfo *li = ( struct metainfo * )op->o_bd->be_private;
+ /*struct metainfo *li = ( struct metainfo * )op->o_bd->be_private;*/
+ Backend* be = (Backend*)(cb->sc_private);
+ struct metainfo *li = ( struct metainfo * )be->be_private;
char *ename = NULL;
struct exception result;
struct berval dn;
struct berval ndn;
-
- dn = rs->sr_entry->e_name;
- ndn = rs->sr_entry->e_nname;
-
- rewriteSession( li->rwinfo, "cacheReturn",
- rs->sr_entry->e_name.bv_val, op->o_conn,
- &ename, &result );
- ber_str2bv(ename, strlen(ename), 0, &rs->sr_entry->e_name);
- /* FIXME: should we normalize this? */
- ber_dupbv(&rs->sr_entry->e_nname, &rs->sr_entry->e_name);
-
- op->o_callback = NULL;
-
- send_search_entry( op, rs );
- rs->sr_entry->e_name = dn;
- rs->sr_entry->e_nname = ndn;
-
- op->o_callback = cb;
+ if (rs->sr_type == REP_SEARCH) {
+ dn = rs->sr_entry->e_name;
+ ndn = rs->sr_entry->e_nname;
+
+ rewriteSession( li->rwinfo, "cacheReturn",
+ rs->sr_entry->e_name.bv_val, op->o_conn,
+ &ename, &result );
+ ber_str2bv(ename, strlen(ename), 0, &rs->sr_entry->e_name);
+ /* FIXME: should we normalize this? */
+ ber_dupbv(&rs->sr_entry->e_nname, &rs->sr_entry->e_name);
+
+ op->o_callback = NULL;
+
+ send_search_entry( op, rs );
+
+ rs->sr_entry->e_name = dn;
+ rs->sr_entry->e_nname = ndn;
+
+ op->o_callback = cb;
+ return 0;
+
+ } else if (rs->sr_type == REP_RESULT) {
+ op->o_callback = NULL;
+ send_ldap_result( op, rs );
+ return 0;
+ }
- return 0;
+ return -1;
}
#endif