]> git.sur5r.net Git - openldap/commitdiff
ITS#2593? get entry lock sooner...
authorHoward Chu <hyc@openldap.org>
Thu, 12 Jun 2003 11:11:37 +0000 (11:11 +0000)
committerHoward Chu <hyc@openldap.org>
Thu, 12 Jun 2003 11:11:37 +0000 (11:11 +0000)
servers/slapd/back-bdb/cache.c

index d1e8fe1648a1fa4f80f0915574ca309390d252e6..35101c2bb4592a2e80569872a603c46fc996cf47 100644 (file)
@@ -568,37 +568,43 @@ again:            ldap_pvt_thread_rdwr_rlock( &bdb->bi_cache.c_rwlock );
        if ( *eip && rc == 0 ) {
                if ( (*eip)->bei_state & CACHE_ENTRY_DELETED ) {
                        rc = DB_NOTFOUND;
-               } else if ( !(*eip)->bei_e ) {
-                       if (!ep) {
-                               rc = bdb_id2entry( op->o_bd, tid, id, &ep );
-                       }
-                       if ( rc == 0 ) {
-                               bdb_cache_entry_db_lock( bdb->bi_dbenv, locker,
-                                       *eip, 1, 0, lock );
-                               ep->e_private = *eip;
+               } else {
+                       bdb_cache_entry_db_lock( bdb->bi_dbenv, locker,
+                                       *eip, 0, 0, lock );
+
+                       if ( !(*eip)->bei_e ) {
+                               if (!ep) {
+                                       rc = bdb_id2entry( op->o_bd, tid, id, &ep );
+                               }
+                               if ( rc == 0 ) {
+                                       bdb_cache_entry_db_relock( bdb->bi_dbenv, locker,
+                                               *eip, 1, 0, lock );
+                                       /* Make sure no other modifier beat us to it */
+                                       if ( (*eip)->bei_e ) {
+                                               bdb_entry_return( ep );
+                                               ep = NULL;
+                                       } else {
+                                               ep->e_private = *eip;
 #ifdef BDB_HIER
-                               bdb_fix_dn( ep, 0 );
+                                               bdb_fix_dn( ep, 0 );
 #endif
-                               (*eip)->bei_e = ep;
-                               bdb_cache_entry_db_relock( bdb->bi_dbenv, locker,
-                                       *eip, 0, 0, lock );
+                                               (*eip)->bei_e = ep;
+                                       }
+                                       bdb_cache_entry_db_relock( bdb->bi_dbenv, locker,
+                                               *eip, 0, 0, lock );
+                               }
                        }
-               } else {
 #ifdef BDB_HIER
-                       rc = bdb_fix_dn( (*eip)->bei_e, 1 );
-                       if ( rc ) {
-                               bdb_cache_entry_db_lock( bdb->bi_dbenv,
-                                       locker, *eip, 1, 0, lock );
-                               rc = bdb_fix_dn( (*eip)->bei_e, 2 );
-                               bdb_cache_entry_db_relock( bdb->bi_dbenv,
-                                       locker, *eip, 0, 0, lock );
-                       } else {
-                               bdb_cache_entry_db_lock( bdb->bi_dbenv,
-                                       locker, *eip, 0, 0, lock );
+                       else {
+                               rc = bdb_fix_dn( (*eip)->bei_e, 1 );
+                               if ( rc ) {
+                                       bdb_cache_entry_db_relock( bdb->bi_dbenv,
+                                               locker, *eip, 1, 0, lock );
+                                       rc = bdb_fix_dn( (*eip)->bei_e, 2 );
+                                       bdb_cache_entry_db_relock( bdb->bi_dbenv,
+                                               locker, *eip, 0, 0, lock );
+                               }
                        }
-#else
-                       bdb_cache_entry_db_lock( bdb->bi_dbenv, locker,
-                                       *eip, 0, 0, lock );
 #endif
                }
        }