]> git.sur5r.net Git - openldap/commitdiff
Fixed slapd context CSN not updating issue (ITS#4384)
authorKurt Zeilenga <kurt@openldap.org>
Mon, 13 Feb 2006 20:50:35 +0000 (20:50 +0000)
committerKurt Zeilenga <kurt@openldap.org>
Mon, 13 Feb 2006 20:50:35 +0000 (20:50 +0000)
14 files changed:
CHANGES
servers/slapd/add.c
servers/slapd/back-bdb/add.c
servers/slapd/back-bdb/delete.c
servers/slapd/back-bdb/modify.c
servers/slapd/back-bdb/modrdn.c
servers/slapd/back-ldbm/delete.c
servers/slapd/back-ldbm/modify.c
servers/slapd/back-ldbm/modrdn.c
servers/slapd/back-ldif/ldif.c
servers/slapd/back-sql/add.c
servers/slapd/back-sql/modify.c
servers/slapd/back-sql/modrdn.c
servers/slapd/modify.c

diff --git a/CHANGES b/CHANGES
index 94254cd13c3df220c24536e18a26431dbeab3937..3b1c01b5a6b7cb8297e903f4a12b7d297b37e802 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -4,6 +4,7 @@ OpenLDAP 2.3.20 Engineering
        Added libldap SASL workaround for broken LDAP servers (ITS#4391)
        Fixed slapd config_generic_wrapper missing parameter bug (ITS#4376)
        Fixed slapd extensible filter value normalization bug (ITS#4380)
+       Fixed slapd context CSN not updating issue (ITS#4384)
        Fixed slapd non-read/write epoll event handling (ITS#4395)
        Fixed slapd syncrepl de-normalize UUID issue
        Added slapd syncrepl log messages (ITS#4369)
index 16e1656553973f1b9d4caa3461d81ec2d0bb6d17..acf2e2f85ecb4b4cb56ce7521eaed42d00bfa39c 100644 (file)
@@ -656,13 +656,23 @@ int slap_add_opattrs(
 
        if ( SLAP_LASTMOD( op->o_bd ) ) {
                char *ptr;
+               int gotcsn = 0;
                timestamp.bv_val = timebuf;
+
+               a = attr_find( op->ora_e->e_attrs, slap_schema.si_ad_entryCSN );
+               if ( a ) {
+                       gotcsn = 1;
+                       csn = a->a_vals[0];
+               }
                if ( BER_BVISEMPTY( &op->o_csn )) {
-                       if ( SLAP_SHADOW( op->o_bd ))
-                               manage_ctxcsn = 0;
-                       csn.bv_val = csnbuf;
-                       csn.bv_len = sizeof(csnbuf);
-                       slap_get_csn( op, &csn, manage_ctxcsn );
+                       if ( !gotcsn ) {
+                               csn.bv_val = csnbuf;
+                               csn.bv_len = sizeof(csnbuf);
+                               slap_get_csn( op, &csn, manage_ctxcsn );
+                       } else {
+                               if ( manage_ctxcsn )
+                                       slap_queue_csn( op, &csn );
+                       }
                } else {
                        csn = op->o_csn;
                }
@@ -715,9 +725,7 @@ int slap_add_opattrs(
                                slap_schema.si_ad_createTimestamp, &timestamp, NULL );
                }
 
-               a = attr_find( op->ora_e->e_attrs,
-                       slap_schema.si_ad_entryCSN );
-               if ( !a ) {
+               if ( !gotcsn ) {
                        attr_merge_one( op->ora_e,
                                slap_schema.si_ad_entryCSN, &csn, NULL );
                }
index ef2c6dfc296a6f2c20ae0cffbc71386a37fe7516..cd37908a20a8f29e479e798f8d1af21a60d3884a 100644 (file)
@@ -410,8 +410,7 @@ retry:      /* transaction retry */
 
 return_results:
        send_ldap_result( op, rs );
-       if ( !SLAP_SHADOW( op->o_bd ))
-               slap_graduate_commit_csn( op );
+       slap_graduate_commit_csn( op );
 
        if( ltid != NULL ) {
                TXN_ABORT( ltid );
index 0d353188ca64114ad34c086af49b350180c6f107..14815d5d7b7a2fdc052087f1281882b23e9a5a85 100644 (file)
@@ -58,7 +58,7 @@ bdb_delete( Operation *op, SlapReply *rs )
                op->o_req_dn.bv_val, 0, 0 );
 
        /* allocate CSN */
-       if ( !SLAP_SHADOW( op->o_bd )) {
+       if ( BER_BVISEMPTY( &op->o_csn )) {
                struct berval csn;
                char csnbuf[LDAP_LUTIL_CSNSTR_BUFSIZE];
 
@@ -525,8 +525,7 @@ return_results:
        op->o_private = NULL;
 
        send_ldap_result( op, rs );
-       if ( !SLAP_SHADOW( op->o_bd ))
-               slap_graduate_commit_csn( op );
+       slap_graduate_commit_csn( op );
 
        if( preread_ctrl != NULL ) {
                slap_sl_free( (*preread_ctrl)->ldctl_value.bv_val, op->o_tmpmemctx );
index 317a1797d10ed85ab4897658b76f7fa932e28a6c..21faa993e6e383f03ff32e3e49db0841eeea4937 100644 (file)
@@ -298,8 +298,7 @@ bdb_modify( Operation *op, SlapReply *rs )
 
        ctrls[num_ctrls] = NULL;
 
-       if ( !SLAP_SHADOW( op->o_bd ))
-               slap_mods_opattrs( op, &op->orm_modlist, 1 );
+       slap_mods_opattrs( op, &op->orm_modlist, 1 );
 
        if( 0 ) {
 retry: /* transaction retry */
@@ -590,8 +589,6 @@ return_results:
                attrs_free( dummy.e_attrs );
        }
        send_ldap_result( op, rs );
-       if ( !SLAP_SHADOW( op->o_bd ))
-               slap_graduate_commit_csn( op );
 
        if( rs->sr_err == LDAP_SUCCESS && bdb->bi_txn_cp ) {
                TXN_CHECKPOINT( bdb->bi_dbenv,
@@ -599,6 +596,8 @@ return_results:
        }
 
 done:
+       slap_graduate_commit_csn( op );
+
        if( ltid != NULL ) {
                TXN_ABORT( ltid );
        }
index 4a7f6e862665fa2f028d9685bdca09f293f30b01..e63d71286efae22073aa431519a29c443dc9ca63 100644 (file)
@@ -787,6 +787,8 @@ return_results:
        }
 
 done:
+       slap_graduate_commit_csn( op );
+
        if( new_dn.bv_val != NULL ) free( new_dn.bv_val );
        if( new_ndn.bv_val != NULL ) free( new_ndn.bv_val );
 
index 00372aa02919f292556602652a6013b01bf2b073..ec623e62537b0a4bfc43234b8c2900e968580500 100644 (file)
@@ -46,7 +46,7 @@ ldbm_back_delete(
        ldap_pvt_thread_rdwr_wlock(&li->li_giant_rwlock);
 
        /* allocate CSN */
-       if ( !SLAP_SHADOW( op->o_bd )) {
+       if ( BER_BVISEMPTY( &op->o_csn )) {
                struct berval csn;
                char csnbuf[LDAP_LUTIL_CSNSTR_BUFSIZE];
 
@@ -217,8 +217,7 @@ return_results:;
        ldap_pvt_thread_rdwr_wunlock(&li->li_giant_rwlock);
 
        send_ldap_result( op, rs );
-       if ( !SLAP_SHADOW( op->o_bd ))
-               slap_graduate_commit_csn( op );
+       slap_graduate_commit_csn( op );
 
        return rc;
 }
index 191365ba1990504409dd9688e041a29c6e2214b8..9625682841c9decf629faa986a2ca0896b1ed036 100644 (file)
@@ -241,8 +241,7 @@ ldbm_back_modify(
 
        Debug(LDAP_DEBUG_ARGS, "ldbm_back_modify:\n", 0, 0, 0);
 
-       if ( !SLAP_SHADOW( op->o_bd ))
-               slap_mods_opattrs( op, &op->orm_modlist, 1 );
+       slap_mods_opattrs( op, &op->orm_modlist, 1 );
 
        /* grab giant lock for writing */
        ldap_pvt_thread_rdwr_wlock(&li->li_giant_rwlock);
@@ -300,8 +299,7 @@ return_results:;
        ldap_pvt_thread_rdwr_wunlock(&li->li_giant_rwlock);
 
        send_ldap_result( op, rs );
-       if ( !SLAP_SHADOW( op->o_bd ))
-               slap_graduate_commit_csn( op );
+       slap_graduate_commit_csn( op );
 
        rs->sr_text = NULL;
        return rs->sr_err;
index 1dd3669b41622a29d31fb30394ed3224291b5a57..b8683a373629b444ed6afbda77a6747c563287b5 100644 (file)
@@ -460,6 +460,7 @@ ldbm_back_modrdn(
        cache_entry_commit( e );
 
 return_results:
+       slap_graduate_commit_csn( op );
        if( new_dn.bv_val != NULL ) free( new_dn.bv_val );
        if( new_ndn.bv_val != NULL ) free( new_ndn.bv_val );
        if( old_ndn.bv_val != NULL ) free( old_ndn.bv_val );
index 3bf061ca6ebfa0af0a1141bb8671b1107589ac4b..a8593e79a952939d83c8ec0474322a771dbcb779 100644 (file)
@@ -817,8 +817,7 @@ static int ldif_back_add(Operation *op, SlapReply *rs) {
 
 send_res:
        send_ldap_result(op, rs);
-       if ( !SLAP_SHADOW( op->o_bd ))
-               slap_graduate_commit_csn( op );
+       slap_graduate_commit_csn( op );
        return 0;
 }
 
@@ -829,8 +828,7 @@ static int ldif_back_modify(Operation *op, SlapReply *rs) {
        Entry * entry = NULL;
        int spew_res;
 
-       if ( !SLAP_SHADOW( op->o_bd ))
-               slap_mods_opattrs( op, &op->orm_modlist, 1 );
+       slap_mods_opattrs( op, &op->orm_modlist, 1 );
 
        ldap_pvt_thread_mutex_lock(&ni->li_mutex);
        dn2path(&op->o_req_ndn, &op->o_bd->be_nsuffix[0], &ni->li_base_path,
@@ -860,8 +858,7 @@ static int ldif_back_modify(Operation *op, SlapReply *rs) {
        rs->sr_text = NULL;
        ldap_pvt_thread_mutex_unlock(&ni->li_mutex);
        send_ldap_result(op, rs);
-       if ( !SLAP_SHADOW( op->o_bd ))
-               slap_graduate_commit_csn( op );
+       slap_graduate_commit_csn( op );
        return 0;
 }
 
@@ -870,7 +867,7 @@ static int ldif_back_delete(Operation *op, SlapReply *rs) {
        struct berval path = BER_BVNULL;
        int res = 0;
 
-       if ( !SLAP_SHADOW( op->o_bd )) {
+       if ( BER_BVISEMPTY( &op->o_csn )) {
                struct berval csn;
                char csnbuf[LDAP_LUTIL_CSNSTR_BUFSIZE];
 
@@ -903,8 +900,7 @@ static int ldif_back_delete(Operation *op, SlapReply *rs) {
        SLAP_FREE(path.bv_val);
        ldap_pvt_thread_mutex_unlock(&ni->li_mutex);
        send_ldap_result(op, rs);
-       if ( !SLAP_SHADOW( op->o_bd ))
-               slap_graduate_commit_csn( op );
+       slap_graduate_commit_csn( op );
        return 0;
 }
 
@@ -970,6 +966,8 @@ static int ldif_back_modrdn(Operation *op, SlapReply *rs) {
        Modifications * mods = NULL;
        int res;
 
+       slap_mods_opattrs( op, &op->orm_modlist, 1 );
+
        ldap_pvt_thread_mutex_lock(&ni->li_mutex);
        ldap_pvt_thread_mutex_lock(&entry2str_mutex);
        entry = (Entry *) get_entry(op, &ni->li_base_path);
@@ -1026,6 +1024,7 @@ static int ldif_back_modrdn(Operation *op, SlapReply *rs) {
        ldap_pvt_thread_mutex_unlock(&ni->li_mutex);
        ldap_pvt_thread_mutex_unlock(&entry2str_mutex);
        send_ldap_result(op, rs);
+       slap_graduate_commit_csn( op );
        return 0;
 }
 
index b2c945290995a39e4eabea48567f6c9f6225890e..e9f011a9946ec91abc1ac2bab57a82d2bc001f78 100644 (file)
@@ -1515,6 +1515,7 @@ done:;
 #endif /* SLAP_ACL_HONOR_DISCLOSE */
 
        send_ldap_result( op, rs );
+       slap_graduate_commit_csn( op );
 
        if ( !BER_BVISNULL( &realdn )
                        && realdn.bv_val != op->ora_e->e_name.bv_val )
index a12e4ebd4359056752edb83ea90bdf6afa70cba5..45d21bda26b511f7f5ad2609edc8e83d4380f253 100644 (file)
@@ -191,6 +191,7 @@ done:;
 #endif /* SLAP_ACL_HONOR_DISCLOSE */
 
        send_ldap_result( op, rs );
+       slap_graduate_commit_csn( op );
 
        if ( !BER_BVISNULL( &bsi.bsi_base_id.eid_ndn ) ) {
                (void)backsql_free_entryID( op, &bsi.bsi_base_id, 0 );
index 00a477a46f1f20b01e692ad9db3a4716a8453404..49cd073373b97669345a3f96209b7f53d8300ca0 100644 (file)
@@ -520,8 +520,6 @@ done:;
        }
 #endif /* SLAP_ACL_HONOR_DISCLOSE */
 
-       send_ldap_result( op, rs );
-
        /*
         * Commit only if all operations succeed
         */
@@ -535,6 +533,9 @@ done:;
                SQLTransact( SQL_NULL_HENV, dbh, CompletionType );
        }
 
+       send_ldap_result( op, rs );
+       slap_graduate_commit_csn( op );
+
        if ( !BER_BVISNULL( &realnew_dn ) && realnew_dn.bv_val != new_dn.bv_val ) {
                ch_free( realnew_dn.bv_val );
        }
index 6d1aa6f67f6d43fd4f24310e6ac41d6ffd35bf09..ab707358d16831cd8593d0c382eb18d1c19140ad 100644 (file)
@@ -805,7 +805,8 @@ void slap_timestamp( time_t *tm, struct berval *bv )
 #endif
 }
 
-/* modify only calls this for non-replicas. modrdn always calls.
+/* Called for all modify and modrdn ops. If the current op was replicated
+ * from elsewhere, all of the attrs should already be present.
  */
 void slap_mods_opattrs(
        Operation *op,
@@ -817,14 +818,34 @@ void slap_mods_opattrs(
        char timebuf[ LDAP_LUTIL_GENTIME_BUFSIZE ];
        char csnbuf[ LDAP_LUTIL_CSNSTR_BUFSIZE ];
        Modifications *mod, **modtail, *modlast;
+       int gotcsn = 0, gotmname = 0, gotmtime = 0;
 
        if ( SLAP_LASTMOD( op->o_bd ) ) {
                char *ptr;
                timestamp.bv_val = timebuf;
+               for ( modtail = modsp; *modtail; modtail = &(*modtail)->sml_next ) {
+                       if ( (*modtail)->sml_op != LDAP_MOD_ADD &&
+                               (*modtail)->sml_op != LDAP_MOD_REPLACE ) continue;
+                       if ( (*modtail)->sml_desc == slap_schema.si_ad_entryCSN ) {
+                               csn = (*modtail)->sml_values[0];
+                               gotcsn = 1;
+                       } else
+                       if ( (*modtail)->sml_desc == slap_schema.si_ad_modifiersName ) {
+                               gotmname = 1;
+                       } else
+                       if ( (*modtail)->sml_desc == slap_schema.si_ad_modifyTimestamp ) {
+                               gotmtime = 1;
+                       }
+               }
                if ( BER_BVISEMPTY( &op->o_csn )) {
-                       csn.bv_val = csnbuf;
-                       csn.bv_len = sizeof( csnbuf );
-                       slap_get_csn( op, &csn, manage_ctxcsn );
+                       if ( !gotcsn ) {
+                               csn.bv_val = csnbuf;
+                               csn.bv_len = sizeof( csnbuf );
+                               slap_get_csn( op, &csn, manage_ctxcsn );
+                       } else {
+                               if ( manage_ctxcsn )
+                                       slap_queue_csn( op, &csn );
+                       }
                } else {
                        csn = op->o_csn;
                }
@@ -851,33 +872,24 @@ void slap_mods_opattrs(
                        nname = op->o_ndn;
                }
 
-               for ( modtail = modsp; *modtail; modtail = &(*modtail)->sml_next )
-                       ;
-
-               mod = (Modifications *) ch_malloc( sizeof( Modifications ) );
-               mod->sml_op = LDAP_MOD_REPLACE;
-               mod->sml_flags = SLAP_MOD_INTERNAL;
-               mod->sml_next = NULL;
-               BER_BVZERO( &mod->sml_type );
-               mod->sml_desc = slap_schema.si_ad_entryCSN;
-               mod->sml_values = (BerVarray) ch_malloc( 2 * sizeof( struct berval ) );
-               ber_dupbv( &mod->sml_values[0], &csn );
-               BER_BVZERO( &mod->sml_values[1] );
-               assert( !BER_BVISNULL( &mod->sml_values[0] ) );
-               mod->sml_nvalues = NULL;
-               *modtail = mod;
-               modlast = mod;
-               modtail = &mod->sml_next;
-       
-               if ( get_manageDIT( op ) ) {
-                       for ( mod = *modsp; mod != modlast; mod = mod->sml_next ) {
-                               if ( mod->sml_desc == slap_schema.si_ad_modifiersName ) {
-                                       break;
-                               }
-                       }
+               if ( !gotcsn ) {
+                       mod = (Modifications *) ch_malloc( sizeof( Modifications ) );
+                       mod->sml_op = LDAP_MOD_REPLACE;
+                       mod->sml_flags = SLAP_MOD_INTERNAL;
+                       mod->sml_next = NULL;
+                       BER_BVZERO( &mod->sml_type );
+                       mod->sml_desc = slap_schema.si_ad_entryCSN;
+                       mod->sml_values = (BerVarray) ch_malloc( 2 * sizeof( struct berval ) );
+                       ber_dupbv( &mod->sml_values[0], &csn );
+                       BER_BVZERO( &mod->sml_values[1] );
+                       assert( !BER_BVISNULL( &mod->sml_values[0] ) );
+                       mod->sml_nvalues = NULL;
+                       *modtail = mod;
+                       modlast = mod;
+                       modtail = &mod->sml_next;
                }
 
-               if ( mod->sml_desc != slap_schema.si_ad_modifiersName ) {
+               if ( !gotmname ) {
                        mod = (Modifications *) ch_malloc( sizeof( Modifications ) );
                        mod->sml_op = LDAP_MOD_REPLACE;
                        mod->sml_flags = SLAP_MOD_INTERNAL;
@@ -897,15 +909,7 @@ void slap_mods_opattrs(
                        modtail = &mod->sml_next;
                }
 
-               if ( get_manageDIT( op ) ) {
-                       for ( mod = *modsp; mod != modlast; mod = mod->sml_next ) {
-                               if ( mod->sml_desc == slap_schema.si_ad_modifyTimestamp ) {
-                                       break;
-                               }
-                       }
-               }
-
-               if ( mod->sml_desc != slap_schema.si_ad_modifyTimestamp ) {
+               if ( !gotmtime ) {
                        mod = (Modifications *) ch_malloc( sizeof( Modifications ) );
                        mod->sml_op = LDAP_MOD_REPLACE;
                        mod->sml_flags = SLAP_MOD_INTERNAL;