Commit 07401e58 authored by Ondřej Kuzník's avatar Ondřej Kuzník
Browse files

Implement runtime monitor (un)registration

Unregistration is a hack and we shoould either make the subsystems into
an entry (if monitor allows subentry generation) or implement subsystem
unregistration in back-monitor.
parent 1ea5ee1f
...@@ -503,6 +503,20 @@ lload_backend_destroy( LloadBackend *b ) ...@@ -503,6 +503,20 @@ lload_backend_destroy( LloadBackend *b )
current_backend = next; current_backend = next;
} }
#ifdef BALANCER_MODULE
if ( b->b_monitor ) {
BackendDB *be;
struct berval monitordn = BER_BVC("cn=monitor");
int rc;
be = select_backend( &monitordn, 0 );
/* FIXME: implement proper subsys shutdown in back-monitor or make
* backend just an entry, not a subsys */
rc = b->b_monitor->mss_destroy( be, b->b_monitor );
assert( rc == LDAP_SUCCESS );
}
#endif /* BALANCER_MODULE */
ldap_pvt_thread_mutex_destroy( &b->b_mutex ); ldap_pvt_thread_mutex_destroy( &b->b_mutex );
event_del( b->b_retry_event ); event_del( b->b_retry_event );
......
...@@ -1460,6 +1460,15 @@ lload_handle_backend_invalidation( LloadChange *change ) ...@@ -1460,6 +1460,15 @@ lload_handle_backend_invalidation( LloadChange *change )
assert( change->object == LLOAD_BACKEND ); assert( change->object == LLOAD_BACKEND );
if ( change->type == LDAP_REQ_ADD ) { if ( change->type == LDAP_REQ_ADD ) {
BackendInfo *mi = backend_info( "monitor" );
if ( mi ) {
monitor_extra_t *mbe = mi->bi_extra;
if ( mbe->is_configured() ) {
lload_monitor_backend_init( mi, b );
}
}
if ( !current_backend ) { if ( !current_backend ) {
current_backend = b; current_backend = b;
} }
......
...@@ -208,6 +208,10 @@ struct LloadBackend { ...@@ -208,6 +208,10 @@ struct LloadBackend {
lload_counters_t b_counters[LLOAD_STATS_OPS_LAST]; lload_counters_t b_counters[LLOAD_STATS_OPS_LAST];
#ifdef BALANCER_MODULE
monitor_subsys_t *b_monitor;
#endif /* BALANCER_MODULE */
LDAP_CIRCLEQ_ENTRY(LloadBackend) b_next; LDAP_CIRCLEQ_ENTRY(LloadBackend) b_next;
}; };
......
...@@ -269,6 +269,28 @@ lload_monitor_subsystem_destroy( BackendDB *be, monitor_subsys_t *ms ) ...@@ -269,6 +269,28 @@ lload_monitor_subsystem_destroy( BackendDB *be, monitor_subsys_t *ms )
return LDAP_SUCCESS; return LDAP_SUCCESS;
} }
static int
lload_monitor_backend_destroy( BackendDB *be, monitor_subsys_t *ms )
{
LloadBackend *b = ms->mss_private;
monitor_extra_t *mbe;
int rc = LDAP_SUCCESS;
mbe = (monitor_extra_t *)be->bd_info->bi_extra;
if ( b->b_monitor ) {
ms->mss_destroy = lload_monitor_subsystem_destroy;
assert( b->b_monitor == ms );
b->b_monitor = NULL;
rc = mbe->unregister_entry( &ms->mss_ndn );
ber_memfree( ms->mss_dn.bv_val );
ber_memfree( ms->mss_ndn.bv_val );
}
return rc;
}
static void static void
lload_monitor_balancer_dispose( void **priv ) lload_monitor_balancer_dispose( void **priv )
{ {
...@@ -803,8 +825,46 @@ lload_monitor_backend_open( BackendDB *be, monitor_subsys_t *ms ) ...@@ -803,8 +825,46 @@ lload_monitor_backend_open( BackendDB *be, monitor_subsys_t *ms )
e->e_name.bv_val ); e->e_name.bv_val );
goto done; goto done;
} }
b->b_monitor = ms;
ms->mss_destroy = lload_monitor_backend_destroy;
done: done:
entry_free( e ); entry_free( e );
return rc;
}
int
lload_monitor_backend_init( BackendInfo *bi, LloadBackend *b )
{
monitor_extra_t *mbe;
monitor_subsys_t *bk_mss;
mbe = (monitor_extra_t *)bi->bi_extra;
/* FIXME: With back-monitor as it works now, there is no way to know when
* this can be safely freed so we leak it on shutdown */
bk_mss = ch_calloc( 1, sizeof(monitor_subsys_t) );
bk_mss->mss_rdn.bv_len = sizeof("cn=") + b->b_name.bv_len;
bk_mss->mss_rdn.bv_val = ch_malloc( bk_mss->mss_rdn.bv_len );
bk_mss->mss_rdn.bv_len = snprintf( bk_mss->mss_rdn.bv_val,
bk_mss->mss_rdn.bv_len, "cn=%s", b->b_name.bv_val );
ber_str2bv( LLOAD_MONITOR_BACKENDS_DN, 0, 0, &bk_mss->mss_dn );
bk_mss->mss_name = b->b_name.bv_val;
bk_mss->mss_flags = MONITOR_F_VOLATILE_CH;
bk_mss->mss_open = lload_monitor_backend_open;
bk_mss->mss_create = lload_monitor_up_conn_create;
bk_mss->mss_destroy = lload_monitor_subsystem_destroy;
bk_mss->mss_update = NULL;
bk_mss->mss_private = b;
if ( mbe->register_subsys_late( bk_mss ) ) {
Debug( LDAP_DEBUG_ANY, "lload_monitor_backend_init: "
"failed to register backend %s\n",
bk_mss->mss_name );
return -1;
}
return LDAP_SUCCESS; return LDAP_SUCCESS;
} }
...@@ -843,27 +903,8 @@ lload_monitor_backends_init( BackendDB *be, monitor_subsys_t *ms ) ...@@ -843,27 +903,8 @@ lload_monitor_backends_init( BackendDB *be, monitor_subsys_t *ms )
} }
LDAP_CIRCLEQ_FOREACH ( b, &backend, b_next ) { LDAP_CIRCLEQ_FOREACH ( b, &backend, b_next ) {
monitor_subsys_t *bk_mss = ch_calloc( 1, sizeof(monitor_subsys_t) ); if ( (rc = lload_monitor_backend_init( be->bd_info, b )) ) {
break;
bk_mss->mss_rdn.bv_len = sizeof("cn=") + b->b_name.bv_len;
bk_mss->mss_rdn.bv_val = ch_malloc( bk_mss->mss_rdn.bv_len );
bk_mss->mss_rdn.bv_len = snprintf( bk_mss->mss_rdn.bv_val,
bk_mss->mss_rdn.bv_len, "cn=%s", b->b_name.bv_val );
ber_str2bv( LLOAD_MONITOR_BACKENDS_DN, 0, 0, &bk_mss->mss_dn );
bk_mss->mss_name = b->b_name.bv_val;
bk_mss->mss_flags = MONITOR_F_VOLATILE_CH;
bk_mss->mss_open = lload_monitor_backend_open;
bk_mss->mss_create = lload_monitor_up_conn_create;
bk_mss->mss_destroy = lload_monitor_subsystem_destroy;
bk_mss->mss_update = NULL;
bk_mss->mss_private = b;
if ( mbe->register_subsys_late( bk_mss ) ) {
Debug( LDAP_DEBUG_ANY, "lload_monitor_backends_init: "
"failed to register %s subsystem",
bk_mss->mss_name );
return -1;
} }
} }
done: done:
......
...@@ -151,6 +151,7 @@ LDAP_SLAPD_F (void) lload_libevent_destroy( void ); ...@@ -151,6 +151,7 @@ LDAP_SLAPD_F (void) lload_libevent_destroy( void );
* monitor.c * monitor.c
*/ */
LDAP_SLAPD_F (int) lload_monitor_open( void ); LDAP_SLAPD_F (int) lload_monitor_open( void );
LDAP_SLAPD_F (int) lload_monitor_backend_init( BackendInfo *bi, LloadBackend *b );
#endif /* BALANCER_MODULE */ #endif /* BALANCER_MODULE */
/* /*
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment