]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/back-ldbm/cache.c
error message from be_entry_put tool backend function
[openldap] / servers / slapd / back-ldbm / cache.c
index 65c1e4fec24934c9c9f72bb87b266f931837cf88..1a9f1c6fcfe3006acbf68e023d20bc565479c11f 100644 (file)
@@ -1,7 +1,7 @@
 /* cache.c - routines to maintain an in-core cache of entries */
 /* $OpenLDAP$ */
 /*
- * Copyright 1998-2000 The OpenLDAP Foundation, All Rights Reserved.
+ * Copyright 1998-2002 The OpenLDAP Foundation, All Rights Reserved.
  * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
  */
 
@@ -29,9 +29,9 @@ typedef struct ldbm_entry_info {
        int             lei_state;      /* for the cache */
 #define        CACHE_ENTRY_UNDEFINED   0
 #define CACHE_ENTRY_CREATING   1
-#define CACHE_ENTRY_READY              2
-#define CACHE_ENTRY_DELETED            3
-#define CACHE_ENTRY_DESTROY_PRIVATE    4
+#define CACHE_ENTRY_READY      2
+#define CACHE_ENTRY_DELETED    3
+#define CACHE_ENTRY_COMMITTED  4
        
        int             lei_refcnt;     /* # threads ref'ing this entry */
        Entry   *lei_lrunext;   /* for cache lru list */
@@ -136,17 +136,20 @@ cache_entry_private_init( Entry*e )
 }
 
 /*
- * assumes that the entry is write-locked;marks it i a manner that
- * makes e_private be destroyed at the following cache_return_entry_w,
+ * marks an entry in CREATING state as committed, so it is really returned
+ * to the cache. Otherwise an entry in CREATING state is removed.
+ * Makes e_private be destroyed at the following cache_return_entry_w,
  * but lets the entry untouched (owned by someone else)
  */
 void
-cache_entry_private_destroy_mark( Entry *e )
+cache_entry_commit( Entry *e )
 {
        assert( e );
        assert( e->e_private );
+       assert( LEI(e)->lei_state == CACHE_ENTRY_CREATING );
+       /* assert( LEI(e)->lei_refcnt == 1 ); */
 
-       LEI(e)->lei_state = CACHE_ENTRY_DESTROY_PRIVATE;
+       LEI(e)->lei_state = CACHE_ENTRY_COMMITTED;
 }
 
 static int
@@ -165,7 +168,7 @@ void
 cache_return_entry_rw( Cache *cache, Entry *e, int rw )
 {
        ID id;
-       int refcnt;
+       int refcnt, freeit = 1;
 
        /* set cache mutex */
        ldap_pvt_thread_mutex_lock( &cache->c_mutex );
@@ -177,7 +180,18 @@ cache_return_entry_rw( Cache *cache, Entry *e, int rw )
        id = e->e_id;
        refcnt = --LEI(e)->lei_refcnt;
 
-       if ( LEI(e)->lei_state == CACHE_ENTRY_CREATING ) {
+       /*
+        * if the entry is returned when in CREATING state, it is deleted
+        * but not freed because it may belong to someone else (do_add,
+        * for instance)
+        */
+       if (  LEI(e)->lei_state == CACHE_ENTRY_CREATING ) {
+               cache_delete_entry_internal( cache, e );
+               freeit = 0;
+               /* now the entry is in DELETED state */
+       }
+
+       if ( LEI(e)->lei_state == CACHE_ENTRY_COMMITTED ) {
                LEI(e)->lei_state = CACHE_ENTRY_READY;
 
                /* free cache mutex */
@@ -194,8 +208,7 @@ cache_return_entry_rw( Cache *cache, Entry *e, int rw )
 #endif
 
 
-       } else if ( LEI(e)->lei_state == CACHE_ENTRY_DELETED
-                || LEI(e)->lei_state == CACHE_ENTRY_DESTROY_PRIVATE ) {
+       } else if ( LEI(e)->lei_state == CACHE_ENTRY_DELETED ) {
                if( refcnt > 0 ) {
                        /* free cache mutex */
                        ldap_pvt_thread_mutex_unlock( &cache->c_mutex );
@@ -212,10 +225,8 @@ cache_return_entry_rw( Cache *cache, Entry *e, int rw )
 
 
                } else {
-                       int state = LEI(e)->lei_state;
-
                        cache_entry_private_destroy( e );
-                       if ( state == CACHE_ENTRY_DELETED ) {
+                       if ( freeit ) {
                                entry_free( e );
                        }
 
@@ -552,35 +563,11 @@ cache_update_entry(
        return( 0 );
 }
 
-/*
- * cache_find_entry_dn2id - find an entry in the cache, given dn
- */
-
-ID
-cache_find_entry_dn2id(
-       Backend         *be,
-    Cache      *cache,
-    const char         *dn
-)
-{
-       char                    *ndn;
-       ID                      id;
-
-       ndn = ch_strdup( dn );
-       (void) dn_normalize( ndn );
-
-       id = cache_find_entry_ndn2id( be, cache, ndn );
-
-       free( ndn );
-
-       return ( id );
-}
-
 ID
 cache_find_entry_ndn2id(
        Backend         *be,
     Cache      *cache,
-    const char         *ndn
+    struct berval      *ndn
 )
 {
        Entry           e, *ep;
@@ -588,7 +575,7 @@ cache_find_entry_ndn2id(
        int count = 0;
 
        /* this function is always called with normalized DN */
-       e.e_ndn = (char *)ndn;
+       e.e_nname = *ndn;
 
 try_again:
        /* set cache mutex */
@@ -623,12 +610,12 @@ try_again:
 
 #ifdef NEW_LOGGING
                        LDAP_LOG(( "cache", LDAP_LEVEL_INFO,
-                                  "cache_find_entry_dn2id: (%s)%ld not ready: %d\n",
-                                  dn, id, state ));
+                                  "cache_find_entry_dn2id: (%s) %ld not ready: %d\n",
+                                  ndn->bv_val, id, state ));
 #else
                        Debug(LDAP_DEBUG_TRACE,
                                "====> cache_find_entry_dn2id(\"%s\"): %ld (not ready) %d\n",
-                               ndn, id, state);
+                               ndn->bv_val, id, state);
 #endif
 
 
@@ -645,12 +632,12 @@ try_again:
 
 #ifdef NEW_LOGGING
                LDAP_LOG(( "cache", LDAP_LEVEL_DETAIL1,
-                          "cache_find_entry_dn2id: (%s)%ld %d tries\n",
-                          dn, id, count ));
+                          "cache_find_entry_dn2id: (%s)%ld %d tries\n",
+                          ndn->bv_val, id, count ));
 #else
                Debug(LDAP_DEBUG_TRACE,
                        "====> cache_find_entry_dn2id(\"%s\"): %ld (%d tries)\n",
-                       ndn, id, count);
+                       ndn->bv_val, id, count);
 #endif
 
 
@@ -709,7 +696,7 @@ try_again:
                        ldap_pvt_thread_mutex_unlock( &cache->c_mutex );
 
 #ifdef NEW_LOGGING
-                       LDAP_LOG(( "caceh", LDAP_LEVEL_INFO,
+                       LDAP_LOG(( "cache", LDAP_LEVEL_INFO,
                                   "cache_find_entry_id: (%ld)->%ld not ready (%d).\n",
                                   id, ep_id, state ));