]> git.sur5r.net Git - openldap/commitdiff
cache: implement try_again loop if cache entry is not ready.
authorKurt Zeilenga <kurt@openldap.org>
Fri, 2 Apr 1999 19:09:59 +0000 (19:09 +0000)
committerKurt Zeilenga <kurt@openldap.org>
Fri, 2 Apr 1999 19:09:59 +0000 (19:09 +0000)
id2entry: when an error occurs attempting to insert fetched
entry into cache, check to see if entry was added by another
thread.  If so, return the entry added by the other thread.
The concurrency tests now run without the dreaded "no such object"
error messages!

servers/slapd/back-bdb2/cache.c
servers/slapd/back-bdb2/id2entry.c
servers/slapd/back-ldbm/cache.c
servers/slapd/back-ldbm/id2entry.c

index a22085c17b6254c11dcfcfdcc72f39bae9976e0f..f37b870234d80abcc2a0ccb40573ceb39829c940 100644 (file)
@@ -362,12 +362,13 @@ bdb2i_cache_find_entry_dn2id(
        Entry           e, *ep;
        ID                      id;
 
-       /* set cache mutex */
-       ldap_pvt_thread_mutex_lock( &cache->c_mutex );
-
        e.e_dn = dn;
        e.e_ndn = dn_normalize_case( ch_strdup( dn ) );
 
+try_again:
+       /* set cache mutex */
+       ldap_pvt_thread_mutex_lock( &cache->c_mutex );
+
        if ( (ep = (Entry *) avl_find( cache->c_dntree, (caddr_t) &e,
                (AVL_CMP) entry_dn_cmp )) != NULL )
        {
@@ -395,7 +396,8 @@ bdb2i_cache_find_entry_dn2id(
 
                        /* free cache mutex */
                        ldap_pvt_thread_mutex_unlock( &cache->c_mutex );
-                       return( NOID );
+                       ldap_pvt_thread_yield();
+                       goto try_again;
                }
 
                Debug(LDAP_DEBUG_TRACE,
@@ -439,6 +441,7 @@ bdb2i_cache_find_entry_id(
 
        e.e_id = id;
 
+try_again:
        /* set cache mutex */
        ldap_pvt_thread_mutex_lock( &cache->c_mutex );
 
@@ -462,7 +465,8 @@ bdb2i_cache_find_entry_id(
 
                        /* free cache mutex */
                        ldap_pvt_thread_mutex_unlock( &cache->c_mutex );
-                       return( NULL );
+                       ldap_pvt_thread_yield();
+                       goto try_again;
                }
 
                Debug(LDAP_DEBUG_TRACE,
index bbcb8be1b1545f1bee6c33d767a10d3ae6b35d96..a2cc63690c8396426932c13f37cfcd06a0d60262 100644 (file)
@@ -159,10 +159,19 @@ bdb2i_id2entry_rw( BackendDB *be, ID id, int rw )
        }
 
        if ( bdb2i_cache_add_entry_rw( &li->li_cache, e, rw ) != 0 ) {
+               entry_free( e );
+
+               /* see if it got added underneath us */
+               if((e = bdb2i_cache_find_entry_id( &li->li_cache, id, rw )) != NULL ) {
+                       Debug( LDAP_DEBUG_TRACE,
+                               "<= bdb2i_id2entry_%s( %ld ) 0x%lx (cache)\n",
+                               rw ? "w" : "r", id, (unsigned long)e );
+                       return( e );
+               }
+
                Debug( LDAP_DEBUG_TRACE,
                        "<= bdb2i_id2entry_%s( %ld ) (cache add failed)\n",
                        rw ? "w" : "r", id, 0 );
-               entry_free( e );
                return( NULL );
        }
 
index e5bd055b5149d35ac0f6249c00839e9adcb11164..6fb33306b6a00f7ce26a60c1e54d97ff799b000f 100644 (file)
@@ -430,12 +430,13 @@ cache_find_entry_dn2id(
        Entry           e, *ep;
        ID                      id;
 
-       /* set cache mutex */
-       ldap_pvt_thread_mutex_lock( &cache->c_mutex );
-
        e.e_dn = dn;
        e.e_ndn = dn_normalize_case( ch_strdup( dn ) );
 
+try_again:
+       /* set cache mutex */
+       ldap_pvt_thread_mutex_lock( &cache->c_mutex );
+
        if ( (ep = (Entry *) avl_find( cache->c_dntree, (caddr_t) &e,
                (AVL_CMP) entry_dn_cmp )) != NULL )
        {
@@ -462,7 +463,8 @@ cache_find_entry_dn2id(
 
                        /* free cache mutex */
                        ldap_pvt_thread_mutex_unlock( &cache->c_mutex );
-                       return( NOID );
+                       ldap_pvt_thread_yield();
+                       goto try_again;
                }
 
                Debug(LDAP_DEBUG_TRACE,
@@ -529,7 +531,8 @@ try_again:
 
                        /* free cache mutex */
                        ldap_pvt_thread_mutex_unlock( &cache->c_mutex );
-                       return( NULL );
+                       ldap_pvt_thread_yield();
+                       goto try_again;
                }
 
                Debug(LDAP_DEBUG_TRACE,
index 58de12b7c7ebfa4d4d014f95059f1b6fa4bff2a6..783fccc8b2acdebe47d6cb8e5c2a28ed894d994b 100644 (file)
@@ -158,9 +158,17 @@ id2entry_rw( Backend *be, ID id, int rw )
        }
 
        if( cache_add_entry_rw( &li->li_cache, e, rw ) != 0 ) {
+               entry_free( e );
+
+               /* maybe the entry got added underneath us */
+               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 );
+               }
+
                Debug( LDAP_DEBUG_TRACE, "<= id2entry_%s( %ld ) (cache add failed)\n",
                        rw ? "w" : "r", id, 0 );
-               entry_free( e );
                return NULL;
        }