- Debug( LDAP_DEBUG_TRACE, "<= id2entry_%s( %ld ) (disk)\n",
- rw ? "w" : "r", id, 0 );
- return( e );
-}
+ if( cache_add_entry_rw( &li->li_cache, e, rw ) != 0 ) {
+ entry_free( 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 ) {
+#ifdef NEW_LOGGING
+ LDAP_LOG( INDEX, DETAIL1,
+ "id2entry_rw: %s of %ld 0x%lx (cache)\n",
+ rw ? "write" : "read", id, (unsigned long)e );
+#else
+ Debug( LDAP_DEBUG_TRACE, "<= id2entry_%s( %ld ) 0x%lx (cache)\n",
+ rw ? "w" : "r", id, (unsigned long) e );
+#endif