1 /* readw.c - deal with read waiters subsystem */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 2001-2004 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"
76 "createTimestamp: %s\n"
77 "modifyTimestamp: %s\n",
78 monitor_subsys[SLAPD_MONITOR_RWW].mss_dn.bv_val,
79 mi->mi_oc_monitorCounterObject->soc_cname.bv_val,
80 mi->mi_oc_monitorCounterObject->soc_cname.bv_val,
81 mi->mi_creatorsName.bv_val,
82 mi->mi_creatorsName.bv_val,
83 mi->mi_startTime.bv_val,
84 mi->mi_startTime.bv_val );
89 LDAP_LOG( OPERATION, CRIT,
90 "monitor_subsys_rww_init: "
91 "unable to create entry 'cn=Read,%s'\n",
92 monitor_subsys[SLAPD_MONITOR_RWW].mss_ndn.bv_val, 0, 0 );
94 Debug( LDAP_DEBUG_ANY,
95 "monitor_subsys_rww_init: "
96 "unable to create entry 'cn=Read,%s'\n",
97 monitor_subsys[SLAPD_MONITOR_RWW].mss_ndn.bv_val, 0, 0 );
104 attr_merge_one( e, mi->mi_ad_monitorCounter, &bv, NULL );
106 mp = ( struct monitorentrypriv * )ch_calloc( sizeof( struct monitorentrypriv ), 1 );
107 e->e_private = ( void * )mp;
109 mp->mp_children = NULL;
110 mp->mp_info = &monitor_subsys[SLAPD_MONITOR_RWW];
111 mp->mp_flags = monitor_subsys[SLAPD_MONITOR_RWW].mss_flags \
112 | MONITOR_F_SUB | MONITOR_F_PERSISTENT;
114 if ( monitor_cache_add( mi, e ) ) {
116 LDAP_LOG( OPERATION, CRIT,
117 "monitor_subsys_rww_init: "
118 "unable to add entry 'cn=Read,%s'\n",
119 monitor_subsys[SLAPD_MONITOR_RWW].mss_ndn.bv_val, 0, 0 );
121 Debug( LDAP_DEBUG_ANY,
122 "monitor_subsys_rww_init: "
123 "unable to add entry 'cn=Read,%s'\n",
124 monitor_subsys[SLAPD_MONITOR_RWW].mss_ndn.bv_val, 0, 0 );
134 snprintf( buf, sizeof( buf ),
137 "structuralObjectClass: %s\n"
140 "modifiersName: %s\n"
141 "createTimestamp: %s\n"
142 "modifyTimestamp: %s\n",
143 monitor_subsys[SLAPD_MONITOR_RWW].mss_dn.bv_val,
144 mi->mi_oc_monitorCounterObject->soc_cname.bv_val,
145 mi->mi_oc_monitorCounterObject->soc_cname.bv_val,
146 mi->mi_creatorsName.bv_val,
147 mi->mi_creatorsName.bv_val,
148 mi->mi_startTime.bv_val,
149 mi->mi_startTime.bv_val );
151 e = str2entry( buf );
154 LDAP_LOG( OPERATION, CRIT,
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 );
159 Debug( LDAP_DEBUG_ANY,
160 "monitor_subsys_rww_init: "
161 "unable to create entry 'cn=Write,%s'\n",
162 monitor_subsys[SLAPD_MONITOR_RWW].mss_ndn.bv_val, 0, 0 );
169 attr_merge_one( e, mi->mi_ad_monitorCounter, &bv, NULL );
171 mp = ( struct monitorentrypriv * )ch_calloc( sizeof( struct monitorentrypriv ), 1 );
172 e->e_private = ( void * )mp;
174 mp->mp_children = NULL;
175 mp->mp_info = &monitor_subsys[SLAPD_MONITOR_RWW];
176 mp->mp_flags = monitor_subsys[SLAPD_MONITOR_RWW].mss_flags \
177 | MONITOR_F_SUB | MONITOR_F_PERSISTENT;
179 if ( monitor_cache_add( mi, e ) ) {
181 LDAP_LOG( OPERATION, CRIT,
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 );
186 Debug( LDAP_DEBUG_ANY,
187 "monitor_subsys_rww_init: "
188 "unable to add entry 'cn=Write,%s'\n",
189 monitor_subsys[SLAPD_MONITOR_RWW].mss_ndn.bv_val, 0, 0 );
196 mp = ( struct monitorentrypriv * )e_conn->e_private;
197 mp->mp_children = e_tmp;
199 monitor_cache_release( mi, e_conn );
205 monitor_subsys_rww_update(
210 struct monitorinfo *mi = (struct monitorinfo *)op->o_bd->be_private;
213 long nconns, nwritewaiters, nreadwaiters;
221 char buf[] = "+9223372036854775807L";
224 assert( mi != NULL );
227 if ( strncasecmp( e->e_ndn, "cn=read",
228 sizeof("cn=read")-1 ) == 0 ) {
231 } else if ( strncasecmp( e->e_ndn, "cn=write",
232 sizeof("cn=write")-1 ) == 0 ) {
239 nconns = nwritewaiters = nreadwaiters = 0;
240 for ( c = connection_first( &connindex );
242 c = connection_next( c, &connindex ), nconns++ ) {
243 if ( c->c_writewaiter ) {
246 if ( c->c_currentber != NULL ) {
265 snprintf( buf, sizeof( buf ), "%ld", num );
267 a = attr_find( e->e_attrs, mi->mi_ad_monitorCounter );
269 free( a->a_vals[0].bv_val );
270 ber_str2bv( buf, 0, 1, &a->a_vals[ 0 ] );