#include "slap.h"
#include "back-ldbm.h"
+/*
+ * This routine adds (or updates) an entry on disk.
+ * The cache should already be updated.
+ */
+
int
id2entry_add( Backend *be, Entry *e )
{
ldbm_datum_init( key );
ldbm_datum_init( data );
- Debug( LDAP_DEBUG_TRACE, "=> id2entry_add( %lu, \"%s\" )\n", e->e_id,
+ Debug( LDAP_DEBUG_TRACE, "=> id2entry_add( %ld, \"%s\" )\n", e->e_id,
e->e_dn, 0 );
if ( (db = ldbm_cache_open( be, "id2entry", LDBM_SUFFIX, LDBM_WRCREAT ))
ldap_pvt_thread_mutex_unlock( &entry2str_mutex );
ldbm_cache_close( be, db );
- (void) cache_add_entry_lock( &li->li_cache, e, 0 );
Debug( LDAP_DEBUG_TRACE, "<= id2entry_add %d\n", rc, 0, 0 );
- /* XXX should entries be born locked, i.e. apply writer lock here? */
return( rc );
}
Datum key;
int rc;
- Debug(LDAP_DEBUG_TRACE, "=> id2entry_delete( %lu, \"%s\" )\n", e->e_id,
+ Debug(LDAP_DEBUG_TRACE, "=> id2entry_delete( %ld, \"%s\" )\n", e->e_id,
e->e_dn, 0 );
+#ifdef notdef
#ifdef LDAP_DEBUG
/* check for writer lock */
assert(ldap_pvt_thread_rdwr_writers(&e->e_rdwr) == 1);
+#endif
#endif
ldbm_datum_init( key );
}
if ( cache_delete_entry( &li->li_cache, e ) != 0 ) {
- Debug(LDAP_DEBUG_ANY, "could not delete %lu (%s) from cache\n",
+ Debug(LDAP_DEBUG_ANY, "could not delete %ld (%s) from cache\n",
e->e_id, e->e_dn, 0 );
}
return( rc );
}
-/* XXX returns entry with reader/writer lock */
+/* returns entry with reader/writer lock */
Entry *
-id2entry( Backend *be, ID id, int rw )
+id2entry_rw( Backend *be, ID id, int rw )
{
struct ldbminfo *li = (struct ldbminfo *) be->be_private;
struct dbcache *db;
rw ? "w" : "r", id, 0 );
if ( (e = cache_find_entry_id( &li->li_cache, id, rw )) != NULL ) {
- Debug( LDAP_DEBUG_TRACE, "<= id2entry_%s 0x%lx (cache)\n",
- rw ? "w" : "r", (unsigned long)e, 0 );
+ Debug( LDAP_DEBUG_TRACE, "<= id2entry_%s( %ld ) 0x%lx (cache)\n",
+ rw ? "w" : "r", id, (unsigned long) e );
return( e );
}
ldbm_cache_close( be, db );
if ( e == NULL ) {
- Debug( LDAP_DEBUG_TRACE, "<= id2entry_%s( %ld ) (failed)\n",
+ Debug( LDAP_DEBUG_TRACE, "<= id2entry_%s( %ld ) (failed)\n",
rw ? "w" : "r", id, 0 );
return( NULL );
}
- /* acquire required reader/writer lock */
- if (entry_rdwr_lock(e, rw)) {
- /* XXX set DELETE flag?? */
- entry_free(e);
- return(NULL);
+ if ( e->e_id != id ) {
+ Debug( LDAP_DEBUG_TRACE, "<= id2entry_%s( %ld ) (wrong id %ld on disk)\n",
+ rw ? "w" : "r", id, e->e_id );
+ entry_free( e );
+ return( NULL );
}
- e->e_id = id;
- (void) cache_add_entry_lock( &li->li_cache, e, 0 );
+ if( cache_add_entry_rw( &li->li_cache, e, rw ) != 0 ) {
+ entry_free( e );
- Debug( LDAP_DEBUG_TRACE, "<= id2entry_%s( %ld ) (disk)\n",
- rw ? "w" : "r", id, 0 );
- return( e );
-}
+ /* XXX this is a kludge.
+ * maybe the entry got added underneath us
+ * There are many underlying race condtions in the cache/disk code.
+ */
+ if ( (e = cache_find_entry_id( &li->li_cache, id, rw )) != NULL ) {
+ Debug( LDAP_DEBUG_TRACE, "<= id2entry_%s( %ld ) 0x%lx (cache)\n",
+ rw ? "w" : "r", id, (unsigned long) e );
+ return( e );
+ }
-Entry *
-id2entry_r( Backend *be, ID id )
-{
- return( id2entry( be, id, 0 ) );
-}
+ Debug( LDAP_DEBUG_TRACE, "<= id2entry_%s( %ld ) (cache add failed)\n",
+ rw ? "w" : "r", id, 0 );
+ return NULL;
+ }
-Entry *
-id2entry_w( Backend *be, ID id )
-{
- return( id2entry( be, id, 1 ) );
-}
+ Debug( LDAP_DEBUG_TRACE, "<= id2entry_%s( %ld ) 0x%lx (disk)\n",
+ rw ? "w" : "r", id, (unsigned long) e );
+ return( e );
+}