]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/back-bdb/modify.c
ITS#8789 avoid unnecessary writes of context entry
[openldap] / servers / slapd / back-bdb / modify.c
index 3cab8770eea34e91ac93e0f023e875bf4a458f4c..10b4283ab0fc98910f9ca4d177e7a8528a7114fd 100644 (file)
@@ -2,7 +2,7 @@
 /* $OpenLDAP$ */
 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
  *
- * Copyright 2000-2013 The OpenLDAP Foundation.
+ * Copyright 2000-2017 The OpenLDAP Foundation.
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -389,6 +389,7 @@ int bdb_modify_internal(
                                        ap->a_nvals,
                                        e->e_id, SLAP_INDEX_ADD_OP );
                        } else {
+                               int found = 0;
                                /* if this was only an add, we only need to index
                                 * the added values.
                                 */
@@ -396,6 +397,7 @@ int bdb_modify_internal(
                                        struct berval *vals;
                                        if ( ml->sml_desc != ap->a_desc || !ml->sml_numvals )
                                                continue;
+                                       found = 1;
                                        switch( ml->sml_op ) {
                                        case LDAP_MOD_ADD:
                                        case LDAP_MOD_REPLACE:
@@ -415,6 +417,15 @@ int bdb_modify_internal(
                                        if ( rc )
                                                break;
                                }
+                               /* This attr was affected by a modify of a subtype, so
+                                * there was no direct match in the modlist. Just readd
+                                * all of its values.
+                                */
+                               if ( !found ) {
+                                       rc = bdb_index_values( op, tid, ap->a_desc,
+                                               ap->a_nvals,
+                                               e->e_id, SLAP_INDEX_ADD_OP );
+                               }
                        }
                        if ( rc != LDAP_SUCCESS ) {
                                Debug( LDAP_DEBUG_ANY,
@@ -455,49 +466,12 @@ bdb_modify( Operation *op, SlapReply *rs )
 
        int rc;
 
-#ifdef LDAP_X_TXN
-       int settle = 0;
-#endif
-
        Debug( LDAP_DEBUG_ARGS, LDAP_XSTRING(bdb_modify) ": %s\n",
                op->o_req_dn.bv_val, 0, 0 );
 
 #ifdef LDAP_X_TXN
-       if( op->o_txnSpec ) {
-               /* acquire connection lock */
-               ldap_pvt_thread_mutex_lock( &op->o_conn->c_mutex );
-               if( op->o_conn->c_txn == CONN_TXN_INACTIVE ) {
-                       rs->sr_text = "invalid transaction identifier";
-                       rs->sr_err = LDAP_X_TXN_ID_INVALID;
-                       goto txnReturn;
-               } else if( op->o_conn->c_txn == CONN_TXN_SETTLE ) {
-                       settle=1;
-                       goto txnReturn;
-               }
-
-               if( op->o_conn->c_txn_backend == NULL ) {
-                       op->o_conn->c_txn_backend = op->o_bd;
-
-               } else if( op->o_conn->c_txn_backend != op->o_bd ) {
-                       rs->sr_text = "transaction cannot span multiple database contexts";
-                       rs->sr_err = LDAP_AFFECTS_MULTIPLE_DSAS;
-                       goto txnReturn;
-               }
-
-               /* insert operation into transaction */
-
-               rs->sr_text = "transaction specified";
-               rs->sr_err = LDAP_X_TXN_SPECIFY_OKAY;
-
-txnReturn:
-               /* release connection lock */
-               ldap_pvt_thread_mutex_unlock( &op->o_conn->c_mutex );
-
-               if( !settle ) {
-                       send_ldap_result( op, rs );
-                       return rs->sr_err;
-               }
-       }
+       if( op->o_txnSpec && txn_preop( op, rs ))
+               return rs->sr_err;
 #endif
 
        ctrls[num_ctrls] = NULL;
@@ -541,8 +515,12 @@ retry:     /* transaction retry */
        }
 
        /* begin transaction */
-       rs->sr_err = TXN_BEGIN( bdb->bi_dbenv, NULL, &ltid, 
-               bdb->bi_db_opflags );
+       {
+               int tflags = bdb->bi_db_opflags;
+               if ( get_lazyCommit( op ))
+                       tflags |= DB_TXN_NOSYNC;
+               rs->sr_err = TXN_BEGIN( bdb->bi_dbenv, NULL, &ltid, tflags );
+       }
        rs->sr_text = NULL;
        if( rs->sr_err != 0 ) {
                Debug( LDAP_DEBUG_TRACE,