From: Howard Chu Date: Tue, 23 Dec 2003 18:48:36 +0000 (+0000) Subject: Fix replog sequencing - assign sequence numbers at beginning of operation, X-Git-Tag: OPENLDAP_REL_ENG_2_1_MP~111 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=d31230f859fcc2fdb5fc05214fc1d933266be81a;p=openldap Fix replog sequencing - assign sequence numbers at beginning of operation, instead of getting a timestamp at the end. This makes it possible for slurpd to sort the log later. --- diff --git a/servers/slapd/add.c b/servers/slapd/add.c index ed9a8e37a5..0f87f21552 100644 --- a/servers/slapd/add.c +++ b/servers/slapd/add.c @@ -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 ) diff --git a/servers/slapd/delete.c b/servers/slapd/delete.c index 90d2a95ff0..e1f01cd601 100644 --- a/servers/slapd/delete.c +++ b/servers/slapd/delete.c @@ -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 ) diff --git a/servers/slapd/modify.c b/servers/slapd/modify.c index 9ab73b0725..0b1101fd17 100644 --- a/servers/slapd/modify.c +++ b/servers/slapd/modify.c @@ -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 diff --git a/servers/slapd/modrdn.c b/servers/slapd/modrdn.c index e6137f13b6..88b251156f 100644 --- a/servers/slapd/modrdn.c +++ b/servers/slapd/modrdn.c @@ -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 ) diff --git a/servers/slapd/passwd.c b/servers/slapd/passwd.c index 79e9e3f0cc..4339db208a 100644 --- a/servers/slapd/passwd.c +++ b/servers/slapd/passwd.c @@ -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 ) { diff --git a/servers/slapd/proto-slap.h b/servers/slapd/proto-slap.h index 4e8f412aab..11871540a4 100644 --- a/servers/slapd/proto-slap.h +++ b/servers/slapd/proto-slap.h @@ -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 diff --git a/servers/slapd/repl.c b/servers/slapd/repl.c index 6a54a9bb74..eb20c6681e 100644 --- a/servers/slapd/repl.c +++ b/servers/slapd/repl.c @@ -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 ); diff --git a/servers/slapd/slap.h b/servers/slapd/slap.h index 357858ddfa..b70938be99 100644 --- a/servers/slapd/slap.h +++ b/servers/slapd/slap.h @@ -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; diff --git a/servers/slapd/slapi/slapi_ops.c b/servers/slapd/slapi/slapi_ops.c index 6444baa32c..1b4a4cda7c 100644 --- a/servers/slapd/slapi/slapi_ops.c +++ b/servers/slapd/slapi/slapi_ops.c @@ -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 ); diff --git a/servers/slapd/tools/mimic.c b/servers/slapd/tools/mimic.c index 2c9cd1c364..d8dde1d711 100644 --- a/servers/slapd/tools/mimic.c +++ b/servers/slapd/tools/mimic.c @@ -194,6 +194,11 @@ const char * connection_state2str( int state ) return NULL; } +void repstamp( Operation *op ) +{ + assert(0); +} + void replog( Operation *op ) { assert(0);