]> git.sur5r.net Git - openldap/commitdiff
More for SLAP_TOOL_QUICK, disable locks as well
authorHoward Chu <hyc@openldap.org>
Mon, 24 Jan 2005 08:21:55 +0000 (08:21 +0000)
committerHoward Chu <hyc@openldap.org>
Mon, 24 Jan 2005 08:21:55 +0000 (08:21 +0000)
servers/slapd/back-bdb/dn2id.c
servers/slapd/back-bdb/idl.c
servers/slapd/back-bdb/init.c
servers/slapd/back-bdb/tools.c

index b157ad23a9245f40b15eff0d8005893ef342181b..b1eee39761040af88865352a4d0461cf10a9a1e7 100644 (file)
@@ -577,7 +577,7 @@ hdb_dn2id_delete(
        data.data = d;
 
        /* Delete our ID from the parent's list */
-       rc = cursor->c_get( cursor, &key, &data, DB_GET_BOTH_RANGE | DB_RMW );
+       rc = cursor->c_get( cursor, &key, &data, DB_GET_BOTH_RANGE );
        if ( rc == 0 ) {
                if ( !strcmp( d->nrdn, BEI(e)->bei_nrdn.bv_val ))
                        rc = cursor->c_del( cursor, 0 );
@@ -591,7 +591,7 @@ hdb_dn2id_delete(
         */
        if ( rc == 0 ) {
                BDB_ID2DISK( e->e_id, &nid );
-               rc = cursor->c_get( cursor, &key, &data, DB_SET | DB_RMW );
+               rc = cursor->c_get( cursor, &key, &data, DB_SET );
                if ( rc == 0 )
                        rc = cursor->c_del( cursor, 0 );
        }
index 186ad24b3cd6bc8eb1dcc60b697b91993b0a391b..29a337218d3baa4facd6bbdd1bba9186caafe58c 100644 (file)
@@ -482,8 +482,6 @@ bdb_idl_fetch_key(
        data.ulen = sizeof(buf);
        data.flags = DB_DBT_USERMEM;
 
-       if ( tid ) flags |= DB_RMW;
-
        /* If we're not reusing an existing cursor, get a new one */
        if( opflag != DB_NEXT ) {
                rc = db->cursor( db, tid, &cursor, bdb->bi_db_opflags );
@@ -646,7 +644,7 @@ bdb_idl_insert_key(
        /* Fetch the first data item for this key, to see if it
         * exists and if it's a range.
         */
-       rc = cursor->c_get( cursor, key, &data, DB_SET | DB_RMW );
+       rc = cursor->c_get( cursor, key, &data, DB_SET );
        err = "c_get";
        if ( rc == 0 ) {
                if ( nlo != 0 ) {
@@ -690,42 +688,30 @@ bdb_idl_insert_key(
                                /* Update hi/lo if needed, then delete all the items
                                 * between lo and hi
                                 */
-                               data.data = &nid;
-                               if ( id > hi ) {
-                                       rc = cursor->c_del( cursor, 0 );
-                                       if ( rc != 0 ) {
-                                               err = "c_del hi";
-                                               goto fail;
-                                       }
-                                       rc = cursor->c_put( cursor, key, &data, DB_KEYLAST );
-                                       if ( rc != 0 ) {
-                                               err = "c_put hi";
-                                               goto fail;
-                                       }
+                               if ( id < lo ) {
+                                       lo = id;
+                                       nlo = nid;
+                               } else if ( id > hi ) {
+                                       hi = id;
+                                       nhi = nid;
                                }
+                               data.data = &nid;
                                /* Don't fetch anything, just position cursor */
                                data.flags = DB_DBT_USERMEM | DB_DBT_PARTIAL;
                                data.dlen = data.ulen = 0;
-                               rc = cursor->c_get( cursor, key, &data, DB_SET | DB_RMW );
+                               rc = cursor->c_get( cursor, key, &data, DB_SET );
                                if ( rc != 0 ) {
                                        err = "c_get 2";
                                        goto fail;
                                }
-                               if ( id < lo ) {
-                                       rc = cursor->c_del( cursor, 0 );
-                                       if ( rc != 0 ) {
-                                               err = "c_del lo";
-                                               goto fail;
-                                       }
-                                       rc = cursor->c_put( cursor, key, &data, DB_KEYFIRST );
-                                       if ( rc != 0 ) {
-                                               err = "c_put lo";
-                                               goto fail;
-                                       }
+                               rc = cursor->c_del( cursor, 0 );
+                               if ( rc != 0 ) {
+                                       err = "c_del range1";
+                                       goto fail;
                                }
-                               /* Delete all the records between lo and hi */
-                               for ( i=2; i<count; i++ ) {
-                                       rc = cursor->c_get( cursor, &key2, &data, DB_NEXT_DUP | DB_RMW );
+                               /* Delete all the records */
+                               for ( i=1; i<count; i++ ) {
+                                       rc = cursor->c_get( cursor, &key2, &data, DB_NEXT_DUP );
                                        if ( rc != 0 ) {
                                                err = "c_get next_dup";
                                                goto fail;
@@ -745,6 +731,18 @@ bdb_idl_insert_key(
                                        err = "c_put range";
                                        goto fail;
                                }
+                               nid = nlo;
+                               rc = cursor->c_put( cursor, key, &data, DB_KEYLAST );
+                               if ( rc != 0 ) {
+                                       err = "c_put lo";
+                                       goto fail;
+                               }
+                               nid = nhi;
+                               rc = cursor->c_put( cursor, key, &data, DB_KEYLAST );
+                               if ( rc != 0 ) {
+                                       err = "c_put hi";
+                                       goto fail;
+                               }
                        } else {
                        /* There's room, just store it */
                                goto put1;
@@ -854,7 +852,7 @@ bdb_idl_delete_key(
        /* Fetch the first data item for this key, to see if it
         * exists and if it's a range.
         */
-       rc = cursor->c_get( cursor, key, &data, DB_SET | DB_RMW );
+       rc = cursor->c_get( cursor, key, &data, DB_SET );
        err = "c_get";
        if ( rc == 0 ) {
                if ( tmp != 0 ) {
@@ -862,8 +860,7 @@ bdb_idl_delete_key(
                        if (tmp != nid) {
                                /* position to correct item */
                                tmp = nid;
-                               rc = cursor->c_get( cursor, key, &data, 
-                                       DB_GET_BOTH | DB_RMW  );
+                               rc = cursor->c_get( cursor, key, &data, DB_GET_BOTH );
                                if ( rc != 0 ) {
                                        err = "c_get id";
                                        goto fail;
index cb5616bd2cf061f6c3dc7aa2f1e35ec01c37207f..53e036a6de1303cfa6d6a0e74fb43530d76d3413 100644 (file)
@@ -138,10 +138,10 @@ bdb_db_open( BackendDB *be )
                return rc;
        }
 
-       flags = DB_INIT_MPOOL | DB_THREAD | DB_CREATE | DB_INIT_LOCK;
+       flags = DB_INIT_MPOOL | DB_THREAD | DB_CREATE;
 
 if ( !( slapMode & SLAP_TOOL_QUICK ))
-               flags |= DB_INIT_LOG | DB_INIT_TXN;
+               flags |= DB_INIT_LOCK | DB_INIT_LOG | DB_INIT_TXN;
        
 #if 0
        /* Never do automatic recovery, must perform it manually.
@@ -371,7 +371,9 @@ if ( !( slapMode & SLAP_TOOL_QUICK ))
                return rc;
        }
 
-       XLOCK_ID(bdb->bi_dbenv, &bdb->bi_cache.c_locker);
+       if ( !( slapMode & SLAP_TOOL_QUICK )) {
+               XLOCK_ID(bdb->bi_dbenv, &bdb->bi_cache.c_locker);
+       }
 
        /* If we're in server mode and time-based checkpointing is enabled,
         * submit a task to perform periodic checkpoints.
@@ -424,7 +426,9 @@ bdb_db_close( BackendDB *be )
                ldap_pvt_thread_rdwr_wunlock ( &bdb->bi_idl_tree_rwlock );
        }
 
-       XLOCK_ID_FREE(bdb->bi_dbenv, bdb->bi_cache.c_locker);
+       if ( !( slapMode & SLAP_TOOL_QUICK )) {
+               XLOCK_ID_FREE(bdb->bi_dbenv, bdb->bi_cache.c_locker);
+       }
 
        return 0;
 }
@@ -441,11 +445,13 @@ bdb_db_destroy( BackendDB *be )
        /* close db environment */
        if( bdb->bi_dbenv ) {
                /* force a checkpoint */
-               rc = TXN_CHECKPOINT( bdb->bi_dbenv, 0, 0, DB_FORCE );
-               if( rc != 0 ) {
-                       Debug( LDAP_DEBUG_ANY,
-                               "bdb_db_destroy: txn_checkpoint failed: %s (%d)\n",
-                               db_strerror(rc), rc, 0 );
+               if ( !( slapMode & SLAP_TOOL_QUICK )) {
+                       rc = TXN_CHECKPOINT( bdb->bi_dbenv, 0, 0, DB_FORCE );
+                       if( rc != 0 ) {
+                               Debug( LDAP_DEBUG_ANY,
+                                       "bdb_db_destroy: txn_checkpoint failed: %s (%d)\n",
+                                       db_strerror(rc), rc, 0 );
+                       }
                }
 
                rc = bdb->bi_dbenv->close( bdb->bi_dbenv, 0 );
index 395c57e55ef9ba0cdab0218bae66550237f9e324..ec38daa6cd17481e767d38f721ef4b5bd3f062b0 100644 (file)
@@ -426,6 +426,7 @@ int bdb_tool_entry_reindex(
                return -1;
        }
 
+       if (! (slapMode & SLAP_TOOL_QUICK)) {
        rc = TXN_BEGIN( bi->bi_dbenv, NULL, &tid, bi->bi_db_opflags );
        if( rc != 0 ) {
                Debug( LDAP_DEBUG_ANY,
@@ -434,6 +435,7 @@ int bdb_tool_entry_reindex(
                        db_strerror(rc), rc, 0 );
                goto done;
        }
+       }
        
        /*
         * just (re)add them for now
@@ -451,22 +453,11 @@ int bdb_tool_entry_reindex(
        op.o_tmpmemctx = NULL;
        op.o_tmpmfuncs = &ch_mfuncs;
 
-#if 0 /* ndef BDB_HIER */
-       /* add dn2id indices */
-       rc = bdb_dn2id_add( &op, tid, NULL, e );
-       if( rc != 0 && rc != DB_KEYEXIST ) {
-               Debug( LDAP_DEBUG_ANY,
-                       "=> " LDAP_XSTRING(bdb_tool_entry_reindex)
-                       ": dn2id_add failed: %s (%d)\n",
-                       db_strerror(rc), rc, 0 );
-               goto done;
-       }
-#endif
-
        rc = bdb_index_entry_add( &op, tid, e );
 
 done:
        if( rc == 0 ) {
+               if (! (slapMode & SLAP_TOOL_QUICK)) {
                rc = TXN_COMMIT( tid, 0 );
                if( rc != 0 ) {
                        Debug( LDAP_DEBUG_ANY,
@@ -475,13 +466,16 @@ done:
                                db_strerror(rc), rc, 0 );
                        e->e_id = NOID;
                }
+               }
 
        } else {
+               if (! (slapMode & SLAP_TOOL_QUICK)) {
                TXN_ABORT( tid );
                Debug( LDAP_DEBUG_ANY,
                        "=> " LDAP_XSTRING(bdb_tool_entry_reindex)
                        ": txn_aborted! %s (%d)\n",
                        db_strerror(rc), rc, 0 );
+               }
                e->e_id = NOID;
        }
        bdb_entry_release( &op, e, 0 );
@@ -514,6 +508,7 @@ ID bdb_tool_entry_modify(
                "=> " LDAP_XSTRING(bdb_tool_entry_modify) "( %ld, \"%s\" )\n",
                (long) e->e_id, e->e_dn, 0 );
 
+       if (! (slapMode & SLAP_TOOL_QUICK)) {
        rc = TXN_BEGIN( bdb->bi_dbenv, NULL, &tid, 
                bdb->bi_db_opflags );
        if( rc != 0 ) {
@@ -525,6 +520,7 @@ ID bdb_tool_entry_modify(
                         text->bv_val, 0, 0 );
                return NOID;
        }
+       }
 
        op.o_hdr = &ohdr;
        op.o_bd = be;
@@ -567,6 +563,7 @@ ID bdb_tool_entry_modify(
 
 done:
        if( rc == 0 ) {
+               if (! (slapMode & SLAP_TOOL_QUICK)) {
                rc = TXN_COMMIT( tid, 0 );
                if( rc != 0 ) {
                        snprintf( text->bv_val, text->bv_len,
@@ -577,8 +574,10 @@ done:
                                "%s\n", text->bv_val, 0, 0 );
                        e->e_id = NOID;
                }
+               }
 
        } else {
+               if (! (slapMode & SLAP_TOOL_QUICK)) {
                TXN_ABORT( tid );
                snprintf( text->bv_val, text->bv_len,
                        "txn_aborted! %s (%d)",
@@ -586,6 +585,7 @@ done:
                Debug( LDAP_DEBUG_ANY,
                        "=> " LDAP_XSTRING(bdb_tool_entry_modify) ": %s\n",
                        text->bv_val, 0, 0 );
+               }
                e->e_id = NOID;
        }