1 /* readw.c - deal with read waiters subsystem */
3 * Copyright 1998-2003 The OpenLDAP Foundation, All Rights Reserved.
4 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
7 * Copyright 2001, Pierangelo Masarati, All rights reserved. <ando@sys-net.it>
9 * This work has beed deveolped for the OpenLDAP Foundation
10 * in the hope that it may be useful to the Open Source community,
11 * but WITHOUT ANY WARRANTY.
13 * Permission is granted to anyone to use this software for any purpose
14 * on any computer system, and to alter it and redistribute it, subject
15 * to the following restrictions:
17 * 1. The author and SysNet s.n.c. are not responsible for the consequences
18 * of use of this software, no matter how awful, even if they arise from
21 * 2. The origin of this software must not be misrepresented, either by
22 * explicit claim or by omission. Since few users ever read sources,
23 * credits should appear in the documentation.
25 * 3. Altered versions must be plainly marked as such, and must not be
26 * misrepresented as being the original software. Since few users
27 * ever read sources, credits should appear in the documentation.
28 * SysNet s.n.c. cannot be responsible for the consequences of the
31 * 4. This notice may not be removed or altered.
40 #include "back-monitor.h"
43 monitor_subsys_rww_init(
47 struct monitorinfo *mi;
49 Entry *e, *e_tmp, *e_conn;
50 struct monitorentrypriv *mp;
51 char buf[ BACKMONITOR_BUFSIZE ];
56 mi = ( struct monitorinfo * )be->be_private;
58 if ( monitor_cache_get( mi,
59 &monitor_subsys[SLAPD_MONITOR_RWW].mss_ndn, &e_conn ) ) {
61 LDAP_LOG( OPERATION, CRIT,
62 "monitor_subsys_rww_init: "
63 "unable to get entry '%s'\n",
64 monitor_subsys[SLAPD_MONITOR_RWW].mss_ndn.bv_val, 0, 0 );
66 Debug( LDAP_DEBUG_ANY,
67 "monitor_subsys_rww_init: "
68 "unable to get entry '%s'\n%s%s",
69 monitor_subsys[SLAPD_MONITOR_RWW].mss_ndn.bv_val,
80 snprintf( buf, sizeof( buf ),
83 "structuralObjectClass: %s\n"
85 monitor_subsys[SLAPD_MONITOR_RWW].mss_dn.bv_val,
86 mi->oc_monitorCounterObject->soc_cname.bv_val,
87 mi->oc_monitorCounterObject->soc_cname.bv_val );
92 LDAP_LOG( OPERATION, CRIT,
93 "monitor_subsys_rww_init: "
94 "unable to create entry 'cn=Read,%s'\n",
95 monitor_subsys[SLAPD_MONITOR_RWW].mss_ndn.bv_val, 0, 0 );
97 Debug( LDAP_DEBUG_ANY,
98 "monitor_subsys_rww_init: "
99 "unable to create entry 'cn=Read,%s'\n",
100 monitor_subsys[SLAPD_MONITOR_RWW].mss_ndn.bv_val, 0, 0 );
107 attr_merge_one( e, mi->ad_monitorCounter, &bv, NULL );
109 mp = ( struct monitorentrypriv * )ch_calloc( sizeof( struct monitorentrypriv ), 1 );
110 e->e_private = ( void * )mp;
112 mp->mp_children = NULL;
113 mp->mp_info = &monitor_subsys[SLAPD_MONITOR_RWW];
114 mp->mp_flags = monitor_subsys[SLAPD_MONITOR_RWW].mss_flags \
115 | MONITOR_F_SUB | MONITOR_F_PERSISTENT;
117 if ( monitor_cache_add( mi, e ) ) {
119 LDAP_LOG( OPERATION, CRIT,
120 "monitor_subsys_rww_init: "
121 "unable to add entry 'cn=Read,%s'\n",
122 monitor_subsys[SLAPD_MONITOR_RWW].mss_ndn.bv_val, 0, 0 );
124 Debug( LDAP_DEBUG_ANY,
125 "monitor_subsys_rww_init: "
126 "unable to add entry 'cn=Read,%s'\n",
127 monitor_subsys[SLAPD_MONITOR_RWW].mss_ndn.bv_val, 0, 0 );
137 snprintf( buf, sizeof( buf ),
140 "structuralObjectClass: %s\n"
142 monitor_subsys[SLAPD_MONITOR_RWW].mss_dn.bv_val,
143 mi->oc_monitorCounterObject->soc_cname.bv_val,
144 mi->oc_monitorCounterObject->soc_cname.bv_val );
146 e = str2entry( buf );
149 LDAP_LOG( OPERATION, CRIT,
150 "monitor_subsys_rww_init: "
151 "unable to create entry 'cn=Write,%s'\n",
152 monitor_subsys[SLAPD_MONITOR_RWW].mss_ndn.bv_val, 0, 0 );
154 Debug( LDAP_DEBUG_ANY,
155 "monitor_subsys_rww_init: "
156 "unable to create entry 'cn=Write,%s'\n",
157 monitor_subsys[SLAPD_MONITOR_RWW].mss_ndn.bv_val, 0, 0 );
164 attr_merge_one( e, mi->ad_monitorCounter, &bv, NULL );
166 mp = ( struct monitorentrypriv * )ch_calloc( sizeof( struct monitorentrypriv ), 1 );
167 e->e_private = ( void * )mp;
169 mp->mp_children = NULL;
170 mp->mp_info = &monitor_subsys[SLAPD_MONITOR_RWW];
171 mp->mp_flags = monitor_subsys[SLAPD_MONITOR_RWW].mss_flags \
172 | MONITOR_F_SUB | MONITOR_F_PERSISTENT;
174 if ( monitor_cache_add( mi, e ) ) {
176 LDAP_LOG( OPERATION, CRIT,
177 "monitor_subsys_rww_init: "
178 "unable to add entry 'cn=Write,%s'\n",
179 monitor_subsys[SLAPD_MONITOR_RWW].mss_ndn.bv_val, 0, 0 );
181 Debug( LDAP_DEBUG_ANY,
182 "monitor_subsys_rww_init: "
183 "unable to add entry 'cn=Write,%s'\n",
184 monitor_subsys[SLAPD_MONITOR_RWW].mss_ndn.bv_val, 0, 0 );
191 mp = ( struct monitorentrypriv * )e_conn->e_private;
192 mp->mp_children = e_tmp;
194 monitor_cache_release( mi, e_conn );
200 monitor_subsys_rww_update(
205 struct monitorinfo *mi = (struct monitorinfo *)op->o_bd->be_private;
208 long nconns, nwritewaiters, nreadwaiters;
216 struct berval *b = NULL;
217 char buf[] = "+9223372036854775807L";
222 assert( mi != NULL );
225 if ( strncasecmp( e->e_ndn, "cn=read",
226 sizeof("cn=read")-1 ) == 0 ) {
229 } else if ( strncasecmp( e->e_ndn, "cn=write",
230 sizeof("cn=write")-1 ) == 0 ) {
237 nconns = nwritewaiters = nreadwaiters = 0;
238 for ( c = connection_first( &connindex );
240 c = connection_next( c, &connindex ), nconns++ ) {
241 if ( c->c_writewaiter ) {
244 if ( c->c_currentber != NULL ) {
263 snprintf( buf, sizeof( buf ), "%ld", num );
265 a = attr_find( e->e_attrs, mi->ad_monitorCounter );
267 free( a->a_vals[0].bv_val );
268 ber_str2bv( buf, 0, 1, &a->a_vals[ 0 ] );