Added the suffix=<dn> parameter to replica config directive

to allow selective replication of subtrees of a single database.
Multiple occurrences allow the same replica to handle different
subtrees
This commit is contained in:
Pierangelo Masarati 2001-07-21 14:15:23 +00:00
parent 9ee9f1e0e1
commit ece9bdb0eb
7 changed files with 117 additions and 6 deletions

View file

@ -1560,11 +1560,13 @@ read_config( const char *fname )
#endif
} else {
int nr = -1;
for ( i = 1; i < cargc; i++ ) {
if ( strncasecmp( cargv[i], "host=", 5 )
== 0 ) {
charray_add( &be->be_replica,
cargv[i] + 5 );
nr = add_replica_info( be,
cargv[i] + 5 );
break;
}
}
@ -1579,6 +1581,39 @@ read_config( const char *fname )
fname, lineno, 0 );
#endif
} else if ( nr == -1 ) {
#ifdef NEW_LOGGING
LDAP_LOG(( "config", LDAP_LEVEL_INFO,
"%s: line %d: unable to add"
" replica \"%s\""
" (ignored)\n",
fname, lineno,
cargv[i] + 5 ));
#else
Debug( LDAP_DEBUG_ANY,
"%s: line %d: unable to add replica \"%s\" (ignored)\n",
fname, lineno, cargv[i] + 5 );
#endif
} else {
for ( i = 1; i < cargc; i++ ) {
if ( strncasecmp( cargv[i], "suffix=", 7 ) == 0 ) {
char *nsuffix = ch_strdup( cargv[i] + 7 );
if ( dn_normalize( nsuffix ) != NULL ) {
charray_add( &be->be_replica[nr]->ri_nsuffix, nsuffix );
} else {
#ifdef NEW_LOGGING
LDAP_LOG(( "config", LDAP_LEVEL_INFO,
"%s: line %d: unable to normalize suffix in \"replica\" line (ignored)\n",
fname, lineno ));
#else
Debug( LDAP_DEBUG_ANY,
"%s: line %d: unable to normalize suffix in \"replica\" line (ignored)\n",
fname, lineno, 0 );
#endif
}
free( nsuffix );
}
}
}
}

View file

@ -490,7 +490,7 @@ LDAP_SLAPD_F (char *) phonetic LDAP_P(( char *s ));
/*
* repl.c
*/
LDAP_SLAPD_F (int) add_replica_info LDAP_P(( Backend *be, const char *host ));
LDAP_SLAPD_F (void) replog LDAP_P(( Backend *be, Operation *op, char *dn, void *change ));
/*

View file

@ -19,6 +19,31 @@
#include "slap.h"
int
add_replica_info(
Backend *be,
const char *host
)
{
int i = 0;
assert( be );
assert( host );
if ( be->be_replica != NULL ) {
for ( ; be->be_replica[ i ] != NULL; i++ );
}
be->be_replica = ch_realloc( be->be_replica,
sizeof( struct slap_replica_info * )*( i + 2 ) );
be->be_replica[ i ]
= ch_calloc( sizeof( struct slap_replica_info ), 1 );
be->be_replica[ i ]->ri_host = ch_strdup( host );
be->be_replica[ i + 1 ] = NULL;
return( i );
}
void
replog(
@ -33,7 +58,7 @@ replog(
struct replog_moddn *moddn;
char *tmp;
FILE *fp, *lfp;
int len, i;
int len, i, count = 0;
if ( be->be_replogfile == NULL && replogfile == NULL ) {
return;
@ -46,10 +71,48 @@ replog(
return;
}
tmp = ch_strdup( dn );
if ( dn_normalize( tmp ) == NULL ) {
/* something has gone really bad */
ch_free( tmp );
lock_fclose( fp, lfp );
ldap_pvt_thread_mutex_unlock( &replog_mutex );
return;
}
for ( i = 0; be->be_replica != NULL && be->be_replica[i] != NULL;
i++ ) {
fprintf( fp, "replica: %s\n", be->be_replica[i] );
/* check if dn's suffix matches legal suffixes, if any */
if ( be->be_replica[i]->ri_nsuffix != NULL ) {
int j;
for ( j = 0; be->be_replica[i]->ri_nsuffix[j]; j++ ) {
if ( dn_issuffix( tmp, be->be_replica[i]->ri_nsuffix[j] ) ) {
break;
}
}
if ( !be->be_replica[i]->ri_nsuffix[j] ) {
/* do not add "replica:" line */
continue;
}
}
fprintf( fp, "replica: %s\n", be->be_replica[i]->ri_host );
++count;
}
ch_free( tmp );
if ( count == 0 ) {
/* if no replicas matched, drop the log
* (should we log it anyway?) */
lock_fclose( fp, lfp );
ldap_pvt_thread_mutex_unlock( &replog_mutex );
return;
}
fprintf( fp, "time: %ld\n", (long) slap_get_time() );
fprintf( fp, "dn: %s\n", dn );

View file

@ -813,6 +813,11 @@ LDAP_SLAPD_F (int) slapMode;
#define SLAP_TRUNCATE_MODE 0x0100
struct slap_replica_info {
char *ri_host; /* supersedes be_replica */
char **ri_nsuffix; /* array of suffixes this replica accepts */
};
/* temporary aliases */
typedef BackendDB Backend;
#define nbackends nBackendDB
@ -912,7 +917,7 @@ struct slap_backend_db {
int be_timelimit; /* time limit for this backend */
AccessControl *be_acl; /* access control list for this backend */
slap_access_t be_dfltaccess; /* access given if no acl matches */
char **be_replica; /* replicas of this backend (in master) */
struct slap_replica_info **be_replica; /* replicas of this backend (in master) */
char *be_replogfile; /* replication log file (in master) */
char *be_update_ndn; /* allowed to make changes (in replicas) */
struct berval **be_update_refs; /* where to refer modifying clients to */

View file

@ -196,3 +196,8 @@ void slap_mods_free( Modifications *ml )
assert(0);
}
int add_replica_info( Backend *be, const char *host )
{
assert(0);
}

View file

@ -377,6 +377,8 @@ parse_replica_line(
}
ri->ri_hostname = strdup( val );
gots |= GOT_HOST;
} else if ( !strncasecmp( cargv[ i ], SUFFIXSTR, strlen( HOSTSTR ))) {
/* ignore it */ ;
} else if ( !strncasecmp( cargv[ i ], TLSSTR, strlen( TLSSTR ))) {
val = cargv[ i ] + strlen( TLSSTR ) + 1;
if( !strcasecmp( val, TLSCRITICALSTR ) ) {

View file

@ -119,6 +119,7 @@
/* Config file keywords */
#define HOSTSTR "host"
#define SUFFIXSTR "suffix"
#define BINDDNSTR "binddn"
#define BINDMETHSTR "bindmethod"
#define KERBEROSSTR "kerberos"