]> git.sur5r.net Git - openldap/commitdiff
Fix replog sequencing - assign sequence numbers at beginning of operation,
authorHoward Chu <hyc@openldap.org>
Tue, 23 Dec 2003 18:48:36 +0000 (18:48 +0000)
committerHoward Chu <hyc@openldap.org>
Tue, 23 Dec 2003 18:48:36 +0000 (18:48 +0000)
instead of getting a timestamp at the end. This makes it possible for
slurpd to sort the log later.

servers/slapd/add.c
servers/slapd/delete.c
servers/slapd/modify.c
servers/slapd/modrdn.c
servers/slapd/passwd.c
servers/slapd/proto-slap.h
servers/slapd/repl.c
servers/slapd/slap.h
servers/slapd/slapi/slapi_ops.c
servers/slapd/tools/mimic.c

index ed9a8e37a57a23e5f64290660709bb608c6f55db..0f87f2155299f0bd3f0ea28bd28bb212595ef3cf 100644 (file)
@@ -308,6 +308,7 @@ do_add( Operation *op, SlapReply *rs )
 #endif /* LDAP_SLAPI */
 
                        op->ora_e = e;
+                       repstamp( op );
                        if ( (op->o_bd->be_add)( op, rs ) == 0 ) {
 #ifdef SLAPD_MULTIMASTER
                                if ( !repl_user )
index 90d2a95ff0e65c690898d4f16132e9f30111c0c2..e1f01cd601102361b0c1ccc8606f6ef246cd1aee 100644 (file)
@@ -213,6 +213,7 @@ do_delete(
                                slap_get_csn( op, csnbuf, sizeof(csnbuf), &csn, 1 );
                        }
 
+                       repstamp( op );
                        if ( (op->o_bd->be_delete)( op, rs ) == 0 ) {
 #ifdef SLAPD_MULTIMASTER
                                if ( !op->o_bd->be_update_ndn.bv_len || !repl_user )
index 9ab73b0725b944b6a92a721eaab0f8204f0712b0..0b1101fd17a92663192fdae845d8eadc556f6e96 100644 (file)
@@ -498,6 +498,7 @@ do_modify(
                        }
 
                        op->orm_modlist = modlist;
+                       repstamp( op );
                        if ( (op->o_bd->be_modify)( op, rs ) == 0
 #ifdef SLAPD_MULTIMASTER
                                && !repl_user
index e6137f13b6a5e38ac872200854dbb2fe2c406ea1..88b251156ff130697a82a27352f7968e16e80953 100644 (file)
@@ -363,6 +363,7 @@ do_modrdn(
 #endif
                {
                        op->orr_deleteoldrdn = deloldrdn;
+                       repstamp( op );
                        if ( (op->o_bd->be_modrdn)( op, rs ) == 0
 #ifdef SLAPD_MULTIMASTER
                                && ( !op->o_bd->be_update_ndn.bv_len || !repl_user )
index 79e9e3f0cc38c1f92776f001329b4638afa36bb1..4339db208a1440719eb710b44e48d2b68f700f03 100644 (file)
@@ -166,6 +166,7 @@ int passwd_extop(
                NULL, 0 );
        
        if ( rs->sr_err == LDAP_SUCCESS ) {
+               repstamp( op );
                rs->sr_err = op2.o_bd->be_modify( &op2, rs );
        }
        if ( rs->sr_err == LDAP_SUCCESS ) {
index 4e8f412aabe1876160823a012f006c3223976dbb..11871540a4bb1c4e6ee28d4dda793a4b5dadf663 100644 (file)
@@ -913,6 +913,7 @@ LDAP_SLAPD_F (int) add_replica_suffix LDAP_P(( Backend *be,
 LDAP_SLAPD_F (int) add_replica_attrs LDAP_P(( Backend *be,
        int nr, char *attrs, int exclude ));
 LDAP_SLAPD_F (void) replog LDAP_P(( Operation *op ));
+LDAP_SLAPD_F (void) repstamp LDAP_P(( Operation *op ));
 
 /*
  * result.c
index 6a54a9bb74948d4472aaafa156b0a5de2d4fce82..eb20c6681e516fd54877b40ab72f8c3e921642f9 100644 (file)
@@ -116,10 +116,30 @@ add_replica_attrs(
        return ( be->be_replica[nr]->ri_attrs == NULL );
 }
    
+static struct timestamp {
+       long time;
+       long seq;
+} oldstamp;
+
 static void
 print_vals( FILE *fp, struct berval *type, struct berval *bv );
 static void
-replog1( struct slap_replica_info *ri, Operation *op, FILE *fp, long now);
+replog1( struct slap_replica_info *ri, Operation *op, FILE *fp );
+
+void
+repstamp( Operation *op )
+{
+       ldap_pvt_thread_mutex_lock( &replog_mutex );
+       op->o_time = slap_get_time();
+       if ( op->o_time == oldstamp.time ) {
+               op->o_tseq = ++oldstamp.seq;
+       } else {
+               oldstamp.time = op->o_time;
+               oldstamp.seq = 0;
+               op->o_tseq = 0;
+       }
+       ldap_pvt_thread_mutex_unlock( &replog_mutex );
+}
 
 void
 replog( Operation *op )
@@ -133,7 +153,6 @@ replog( Operation *op )
        int     count = 0;
 #endif
        int     subsets = 0;
-       long now = slap_get_time();
 
        if ( op->o_bd->be_replogfile == NULL && replogfile == NULL ) {
                return;
@@ -189,7 +208,7 @@ replog( Operation *op )
        }
 #endif
 
-       replog1( NULL, op, fp, now );
+       replog1( NULL, op, fp );
 
        if ( subsets > 0 ) {
                for ( i = subsets - 1; op->o_bd->be_replica[i] != NULL; i++ ) {
@@ -226,7 +245,7 @@ replog( Operation *op )
                                /* Other operations were logged in the first pass */
                                continue;
                        }
-                       replog1( op->o_bd->be_replica[i], op, fp, now );
+                       replog1( op->o_bd->be_replica[i], op, fp );
                }
        }
 
@@ -238,14 +257,13 @@ static void
 rephdr(
        struct slap_replica_info *ri,
        Operation *op,
-       FILE *fp,
-       long now
+       FILE *fp
 )
 {
        if ( ri ) {
                fprintf( fp, "replica: %s\n", ri->ri_host );
        }
-       fprintf( fp, "time: %ld\n", now );
+       fprintf( fp, "time: %ld.%ld\n", op->o_time, op->o_tseq );
        fprintf( fp, "dn: %s\n", op->o_req_dn.bv_val );
 }
 
@@ -253,8 +271,7 @@ static void
 replog1(
        struct slap_replica_info *ri,
        Operation *op,
-       FILE    *fp,
-       long    now
+       FILE    *fp
 )
 {
        Modifications   *ml;
@@ -328,7 +345,7 @@ replog1(
                                                /* Found a match, log it */
                                                if ( match ) {
                                                        if ( dohdr ) {
-                                                               rephdr( ri, op, fp, now );
+                                                               rephdr( ri, op, fp );
                                                                fprintf( fp, "changetype: modify\n" );
                                                                dohdr = 0;
                                                        }
@@ -352,7 +369,7 @@ replog1(
                                }
                        }
                        if ( dohdr ) {
-                               rephdr( ri, op, fp, now );
+                               rephdr( ri, op, fp );
                                fprintf( fp, "changetype: modify\n" );
                                dohdr = 0;
                        }
@@ -400,7 +417,7 @@ replog1(
                                                match ^= ri->ri_exclude;
                                                if ( match ) {
                                                        if ( dohdr ) {
-                                                               rephdr( ri, op, fp, now );
+                                                               rephdr( ri, op, fp );
                                                                fprintf( fp, "changetype: add\n" );
                                                                dohdr = 0;
                                                        }
@@ -412,7 +429,7 @@ replog1(
                                }
                        }
                        if ( dohdr ) {
-                               rephdr( ri, op, fp, now );
+                               rephdr( ri, op, fp );
                                fprintf( fp, "changetype: add\n" );
                                dohdr = 0;
                        }
@@ -421,12 +438,12 @@ replog1(
                break;
 
        case LDAP_REQ_DELETE:
-               rephdr( ri, op, fp, now );
+               rephdr( ri, op, fp );
                fprintf( fp, "changetype: delete\n" );
                break;
 
        case LDAP_REQ_MODRDN:
-               rephdr( ri, op, fp, now );
+               rephdr( ri, op, fp );
                fprintf( fp, "changetype: modrdn\n" );
                fprintf( fp, "newrdn: %s\n", op->orr_newrdn.bv_val );
                fprintf( fp, "deleteoldrdn: %d\n", op->orr_deleteoldrdn ? 1 : 0 );
index 357858ddfa98d727252e1f5eaaa803048c2fa4ac..b70938be99a1a6d0a604ac4c0ec39b3ccc9d674e 100644 (file)
@@ -1904,6 +1904,7 @@ typedef struct slap_op {
        ber_int_t       o_protocol;     /* version of the LDAP protocol used by client */
        ber_tag_t       o_tag;          /* tag of the request */
        time_t          o_time;         /* time op was initiated */
+       long            o_tseq;         /* time/sequence number */
 
        struct berval   o_req_dn;       /* DN of target of request */
        struct berval   o_req_ndn;
index 6444baa32c97c28947609485d812767bc95b7ab4..1b4a4cda7c991acc74ece5264a45207c943976e8 100644 (file)
@@ -559,6 +559,7 @@ slapi_delete_internal(
        if ( op->o_bd->be_delete ) {
                int repl_user = be_isupdate( op->o_bd, &op->o_ndn );
                if ( !op->o_bd->be_update_ndn.bv_len || repl_user ) {
+                       if ( log_change ) repstamp( op );
                        if ( (*op->o_bd->be_delete)( op, &rs ) == 0 ) {
                                if ( log_change ) {
                                        replog( op );
@@ -640,6 +641,7 @@ slapi_add_entry_internal_locked(
        if ( op->o_bd->be_add ) {
                int repl_user = be_isupdate( op->o_bd, &op->o_ndn );
                if ( !op->o_bd->be_update_ndn.bv_len || repl_user ) {
+                       if ( log_changes ) repstamp( op );
                        if ( (*op->o_bd->be_add)( op, &rs ) == 0 ) {
                                if ( log_changes ) {
                                        replog( op );
@@ -832,6 +834,7 @@ slapi_modrdn_internal(
        if ( op->o_bd->be_modrdn ) {
                int repl_user = be_isupdate( op->o_bd, &op->o_ndn );
                if ( !op->o_bd->be_update_ndn.bv_len || repl_user ) {
+                       if ( log_change ) repstamp( op );
                        if ( (*op->o_bd->be_modrdn)( op, &rs ) == 0 ) {
                                if ( log_change ) {
                                        replog( op );
@@ -1044,6 +1047,7 @@ slapi_modify_internal(
                                        goto cleanup;
                                }
                        }
+                       if ( log_change ) repstamp( op );
                        if ( (*op->o_bd->be_modify)( op, &rs ) == 0 ) {
                                if ( log_change ) {
                                        replog( op );
index 2c9cd1c364ef1e98e9f6f8b7138a31b3e72d54c3..d8dde1d711483ea618904f943f329f88db284e15 100644 (file)
@@ -194,6 +194,11 @@ const char * connection_state2str( int state )
        return NULL;
 }
 
+void repstamp( Operation *op )
+{
+       assert(0);
+}
+
 void replog( Operation *op )
 {
        assert(0);