1 /* readw.c - deal with read waiters subsystem */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 2001-2003 The OpenLDAP Foundation.
6 * Portions Copyright 2001-2003 Pierangelo Masarati.
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted only as authorized by the OpenLDAP
13 * A copy of this license is available in file LICENSE in the
14 * top-level directory of the distribution or, alternatively, at
15 * <http://www.OpenLDAP.org/license.html>.
18 * This work was initially developed by Pierangelo Masarati for inclusion
19 * in OpenLDAP Software.
25 #include <ac/string.h>
29 #include "back-monitor.h"
32 monitor_subsys_rww_init(
36 struct monitorinfo *mi;
38 Entry *e, *e_tmp, *e_conn;
39 struct monitorentrypriv *mp;
40 char buf[ BACKMONITOR_BUFSIZE ];
45 mi = ( struct monitorinfo * )be->be_private;
47 if ( monitor_cache_get( mi,
48 &monitor_subsys[SLAPD_MONITOR_RWW].mss_ndn, &e_conn ) ) {
50 LDAP_LOG( OPERATION, CRIT,
51 "monitor_subsys_rww_init: "
52 "unable to get entry '%s'\n",
53 monitor_subsys[SLAPD_MONITOR_RWW].mss_ndn.bv_val, 0, 0 );
55 Debug( LDAP_DEBUG_ANY,
56 "monitor_subsys_rww_init: "
57 "unable to get entry '%s'\n%s%s",
58 monitor_subsys[SLAPD_MONITOR_RWW].mss_ndn.bv_val,
69 snprintf( buf, sizeof( buf ),
72 "structuralObjectClass: %s\n"
74 "createTimestamp: %s\n"
75 "modifyTimestamp: %s\n",
76 monitor_subsys[SLAPD_MONITOR_RWW].mss_dn.bv_val,
77 mi->mi_oc_monitorCounterObject->soc_cname.bv_val,
78 mi->mi_oc_monitorCounterObject->soc_cname.bv_val,
79 mi->mi_startTime.bv_val,
80 mi->mi_startTime.bv_val );
85 LDAP_LOG( OPERATION, CRIT,
86 "monitor_subsys_rww_init: "
87 "unable to create entry 'cn=Read,%s'\n",
88 monitor_subsys[SLAPD_MONITOR_RWW].mss_ndn.bv_val, 0, 0 );
90 Debug( LDAP_DEBUG_ANY,
91 "monitor_subsys_rww_init: "
92 "unable to create entry 'cn=Read,%s'\n",
93 monitor_subsys[SLAPD_MONITOR_RWW].mss_ndn.bv_val, 0, 0 );
100 attr_merge_one( e, mi->mi_ad_monitorCounter, &bv, NULL );
102 mp = ( struct monitorentrypriv * )ch_calloc( sizeof( struct monitorentrypriv ), 1 );
103 e->e_private = ( void * )mp;
105 mp->mp_children = NULL;
106 mp->mp_info = &monitor_subsys[SLAPD_MONITOR_RWW];
107 mp->mp_flags = monitor_subsys[SLAPD_MONITOR_RWW].mss_flags \
108 | MONITOR_F_SUB | MONITOR_F_PERSISTENT;
110 if ( monitor_cache_add( mi, e ) ) {
112 LDAP_LOG( OPERATION, CRIT,
113 "monitor_subsys_rww_init: "
114 "unable to add entry 'cn=Read,%s'\n",
115 monitor_subsys[SLAPD_MONITOR_RWW].mss_ndn.bv_val, 0, 0 );
117 Debug( LDAP_DEBUG_ANY,
118 "monitor_subsys_rww_init: "
119 "unable to add entry 'cn=Read,%s'\n",
120 monitor_subsys[SLAPD_MONITOR_RWW].mss_ndn.bv_val, 0, 0 );
130 snprintf( buf, sizeof( buf ),
133 "structuralObjectClass: %s\n"
135 "createTimestamp: %s\n"
136 "modifyTimestamp: %s\n",
137 monitor_subsys[SLAPD_MONITOR_RWW].mss_dn.bv_val,
138 mi->mi_oc_monitorCounterObject->soc_cname.bv_val,
139 mi->mi_oc_monitorCounterObject->soc_cname.bv_val,
140 mi->mi_startTime.bv_val,
141 mi->mi_startTime.bv_val );
143 e = str2entry( buf );
146 LDAP_LOG( OPERATION, CRIT,
147 "monitor_subsys_rww_init: "
148 "unable to create entry 'cn=Write,%s'\n",
149 monitor_subsys[SLAPD_MONITOR_RWW].mss_ndn.bv_val, 0, 0 );
151 Debug( LDAP_DEBUG_ANY,
152 "monitor_subsys_rww_init: "
153 "unable to create entry 'cn=Write,%s'\n",
154 monitor_subsys[SLAPD_MONITOR_RWW].mss_ndn.bv_val, 0, 0 );
161 attr_merge_one( e, mi->mi_ad_monitorCounter, &bv, NULL );
163 mp = ( struct monitorentrypriv * )ch_calloc( sizeof( struct monitorentrypriv ), 1 );
164 e->e_private = ( void * )mp;
166 mp->mp_children = NULL;
167 mp->mp_info = &monitor_subsys[SLAPD_MONITOR_RWW];
168 mp->mp_flags = monitor_subsys[SLAPD_MONITOR_RWW].mss_flags \
169 | MONITOR_F_SUB | MONITOR_F_PERSISTENT;
171 if ( monitor_cache_add( mi, e ) ) {
173 LDAP_LOG( OPERATION, CRIT,
174 "monitor_subsys_rww_init: "
175 "unable to add entry 'cn=Write,%s'\n",
176 monitor_subsys[SLAPD_MONITOR_RWW].mss_ndn.bv_val, 0, 0 );
178 Debug( LDAP_DEBUG_ANY,
179 "monitor_subsys_rww_init: "
180 "unable to add entry 'cn=Write,%s'\n",
181 monitor_subsys[SLAPD_MONITOR_RWW].mss_ndn.bv_val, 0, 0 );
188 mp = ( struct monitorentrypriv * )e_conn->e_private;
189 mp->mp_children = e_tmp;
191 monitor_cache_release( mi, e_conn );
197 monitor_subsys_rww_update(
202 struct monitorinfo *mi = (struct monitorinfo *)op->o_bd->be_private;
205 long nconns, nwritewaiters, nreadwaiters;
213 char buf[] = "+9223372036854775807L";
216 assert( mi != NULL );
219 if ( strncasecmp( e->e_ndn, "cn=read",
220 sizeof("cn=read")-1 ) == 0 ) {
223 } else if ( strncasecmp( e->e_ndn, "cn=write",
224 sizeof("cn=write")-1 ) == 0 ) {
231 nconns = nwritewaiters = nreadwaiters = 0;
232 for ( c = connection_first( &connindex );
234 c = connection_next( c, &connindex ), nconns++ ) {
235 if ( c->c_writewaiter ) {
238 if ( c->c_currentber != NULL ) {
257 snprintf( buf, sizeof( buf ), "%ld", num );
259 a = attr_find( e->e_attrs, mi->mi_ad_monitorCounter );
261 free( a->a_vals[0].bv_val );
262 ber_str2bv( buf, 0, 1, &a->a_vals[ 0 ] );