From e60536c04ae9092d39d6c71546634dcc08dc4292 Mon Sep 17 00:00:00 2001 From: Howard Chu Date: Mon, 8 Oct 2007 06:21:13 +0000 Subject: [PATCH] Fix for dynamic adds --- servers/slapd/overlays/pcache.c | 145 +++++++++++++++++++++----------- 1 file changed, 95 insertions(+), 50 deletions(-) diff --git a/servers/slapd/overlays/pcache.c b/servers/slapd/overlays/pcache.c index 6a20a1efc1..b6c59566fa 100644 --- a/servers/slapd/overlays/pcache.c +++ b/servers/slapd/overlays/pcache.c @@ -185,15 +185,16 @@ typedef struct cache_manager_s { int numattrsets; /* number of attribute sets */ int cur_entries; /* current number of entries cached */ int max_entries; /* max number of entries cached */ - int num_entries_limit; /* max # of entries in a cacheable query */ + int num_entries_limit; /* max # of entries in a cacheable query */ char response_cb; /* install the response callback * at the tail of the callback list */ #define PCACHE_RESPONSE_CB_HEAD 0 #define PCACHE_RESPONSE_CB_TAIL 1 + char defer_db_open; /* defer open for online add */ time_t cc_period; /* interval between successive consistency checks (sec) */ - int cc_paused; + int cc_paused; void *cc_arg; ldap_pvt_thread_mutex_t cache_mutex; @@ -2499,7 +2500,7 @@ consistency_check( op->o_dn = cm->db.be_rootdn; op->o_ndn = cm->db.be_rootndn; - cm->cc_arg = arg; + cm->cc_arg = arg; for (templ = qm->templates; templ; templ=templ->qmnext) { query = templ->query_last; @@ -2610,6 +2611,15 @@ static ConfigTable pccfg[] = { { NULL, NULL, 0, 0, 0, ARG_IGNORED } }; +/* Need to no-op this keyword for dynamic config */ +static ConfigTable pcdummy[] = { + { "", "", 0, 0, 0, ARG_IGNORED, + NULL, "( OLcfgGlAt:13 NAME 'olcDatabase' " + "DESC 'The backend type for a database instance' " + "SUP olcBackend SINGLE-VALUE X-ORDERED 'SIBLINGS' )", NULL, NULL }, + { NULL, NULL, 0, 0, 0, ARG_IGNORED } +}; + static ConfigOCs pcocs[] = { { "( OLcfgOvOc:2.1 " "NAME 'olcPcacheConfig' " @@ -2621,10 +2631,19 @@ static ConfigOCs pcocs[] = { { "( OLcfgOvOc:2.2 " "NAME 'olcPcacheDatabase' " "DESC 'Cache database configuration' " - "AUXILIARY )", Cft_Misc, pccfg, pc_ldadd }, + "AUXILIARY )", Cft_Misc, pcdummy, pc_ldadd }, { NULL, 0, NULL } }; +static int pcache_db_open2( slap_overinst *on, ConfigReply *cr ); + +static int +pc_ldadd_cleanup( ConfigArgs *c ) +{ + slap_overinst *on = c->private; + return pcache_db_open2( on, &c->reply ); +} + static int pc_ldadd( CfEntryInfo *p, Entry *e, ConfigArgs *ca ) { @@ -2638,6 +2657,8 @@ pc_ldadd( CfEntryInfo *p, Entry *e, ConfigArgs *ca ) on = (slap_overinst *)p->ce_bi; cm = on->on_bi.bi_private; ca->be = &cm->db; + ca->cleanup = pc_ldadd_cleanup; + ca->private = on; return LDAP_SUCCESS; } @@ -2826,6 +2847,9 @@ pc_cf_gen( ConfigArgs *c ) Debug( LDAP_DEBUG_CONFIG, "%s: %s.\n", c->log, c->cr_msg, 0 ); return( 1 ); } + if ( CONFIG_ONLINE_ADD( c )) + cm->defer_db_open = 1; + cm->cc_period = (time_t)t; Debug( pcache_debug, "Total # of attribute sets to be cached = %d.\n", @@ -3093,8 +3117,10 @@ pcache_db_init( cm->max_queries = 10000; cm->save_queries = 0; cm->response_cb = PCACHE_RESPONSE_CB_TAIL; + cm->defer_db_open = 0; cm->cc_period = 1000; cm->cc_paused = 0; + cm->cc_arg = NULL; qm->attr_sets = NULL; qm->templates = NULL; @@ -3149,55 +3175,13 @@ pcache_cachedquery_count_cb( Operation *op, SlapReply *rs ) } static int -pcache_db_open( - BackendDB *be, +pcache_db_open2( + slap_overinst *on, ConfigReply *cr ) { - slap_overinst *on = (slap_overinst *)be->bd_info; cache_manager *cm = on->on_bi.bi_private; query_manager* qm = cm->qm; - int i, ncf = 0, rf = 0, nrf = 0, rc = 0; - - /* check attr sets */ - for ( i = 0; i < cm->numattrsets; i++) { - if ( !( qm->attr_sets[i].flags & PC_CONFIGURED ) ) { - if ( qm->attr_sets[i].flags & PC_REFERENCED ) { - Debug( LDAP_DEBUG_CONFIG, "pcache: attr set #%d not configured but referenced.\n", i, 0, 0 ); - rf++; - - } else { - Debug( LDAP_DEBUG_CONFIG, "pcache: warning, attr set #%d not configured.\n", i, 0, 0 ); - } - ncf++; - - } else if ( !( qm->attr_sets[i].flags & PC_REFERENCED ) ) { - Debug( LDAP_DEBUG_CONFIG, "pcache: attr set #%d configured but not referenced.\n", i, 0, 0 ); - nrf++; - } - } - - if ( ncf || rf || nrf ) { - Debug( LDAP_DEBUG_CONFIG, "pcache: warning, %d attr sets configured but not referenced.\n", nrf, 0, 0 ); - Debug( LDAP_DEBUG_CONFIG, "pcache: warning, %d attr sets not configured.\n", ncf, 0, 0 ); - Debug( LDAP_DEBUG_CONFIG, "pcache: %d attr sets not configured but referenced.\n", rf, 0, 0 ); - - if ( rf > 0 ) { - return 1; - } - } - - /* need to inherit something from the original database... */ - cm->db.be_def_limit = be->be_def_limit; - cm->db.be_limits = be->be_limits; - cm->db.be_acl = be->be_acl; - cm->db.be_dfltaccess = be->be_dfltaccess; - - if ( SLAP_DBMONITORING( be ) ) { - SLAP_DBFLAGS( &cm->db ) |= SLAP_DBFLAG_MONITORING; - - } else { - SLAP_DBFLAGS( &cm->db ) &= ~SLAP_DBFLAG_MONITORING; - } + int rc; rc = backend_startup_one( &cm->db, NULL ); @@ -3206,7 +3190,7 @@ pcache_db_open( ldap_pvt_thread_mutex_lock( &slapd_rq.rq_mutex ); ldap_pvt_runqueue_insert( &slapd_rq, cm->cc_period, consistency_check, on, - "pcache_consistency", be->be_suffix[0].bv_val ); + "pcache_consistency", cm->db.be_suffix[0].bv_val ); ldap_pvt_thread_mutex_unlock( &slapd_rq.rq_mutex ); /* Cached database must have the rootdn */ @@ -3304,6 +3288,62 @@ pcache_db_open( rc = 0; } } + return rc; +} + +static int +pcache_db_open( + BackendDB *be, + ConfigReply *cr ) +{ + slap_overinst *on = (slap_overinst *)be->bd_info; + cache_manager *cm = on->on_bi.bi_private; + query_manager* qm = cm->qm; + int i, ncf = 0, rf = 0, nrf = 0, rc = 0; + + /* check attr sets */ + for ( i = 0; i < cm->numattrsets; i++) { + if ( !( qm->attr_sets[i].flags & PC_CONFIGURED ) ) { + if ( qm->attr_sets[i].flags & PC_REFERENCED ) { + Debug( LDAP_DEBUG_CONFIG, "pcache: attr set #%d not configured but referenced.\n", i, 0, 0 ); + rf++; + + } else { + Debug( LDAP_DEBUG_CONFIG, "pcache: warning, attr set #%d not configured.\n", i, 0, 0 ); + } + ncf++; + + } else if ( !( qm->attr_sets[i].flags & PC_REFERENCED ) ) { + Debug( LDAP_DEBUG_CONFIG, "pcache: attr set #%d configured but not referenced.\n", i, 0, 0 ); + nrf++; + } + } + + if ( ncf || rf || nrf ) { + Debug( LDAP_DEBUG_CONFIG, "pcache: warning, %d attr sets configured but not referenced.\n", nrf, 0, 0 ); + Debug( LDAP_DEBUG_CONFIG, "pcache: warning, %d attr sets not configured.\n", ncf, 0, 0 ); + Debug( LDAP_DEBUG_CONFIG, "pcache: %d attr sets not configured but referenced.\n", rf, 0, 0 ); + + if ( rf > 0 ) { + return 1; + } + } + + /* need to inherit something from the original database... */ + cm->db.be_def_limit = be->be_def_limit; + cm->db.be_limits = be->be_limits; + cm->db.be_acl = be->be_acl; + cm->db.be_dfltaccess = be->be_dfltaccess; + + if ( SLAP_DBMONITORING( be ) ) { + SLAP_DBFLAGS( &cm->db ) |= SLAP_DBFLAG_MONITORING; + + } else { + SLAP_DBFLAGS( &cm->db ) &= ~SLAP_DBFLAG_MONITORING; + } + + if ( !cm->defer_db_open ) + rc = pcache_db_open2( on, cr ); return rc; } @@ -3904,6 +3944,11 @@ pcache_initialize() code = config_register_schema( pccfg, pcocs ); if ( code ) return code; + { + const char *text; + code = slap_str2ad( "olcDatabase", &pcdummy[0].ad, &text ); + if ( code ) return code; + } return overlay_register( &pcache ); } -- 2.39.5